Compare commits

...

2 Commits

Author SHA1 Message Date
Yann Autissier 923c35d0d8 first apps :) 2023-11-26 05:20:15 +01:00
Yann Autissier 5e3782c944 update .env when older than .env.dist 2023-11-26 00:53:32 +01:00
14 changed files with 152 additions and 26 deletions

View File

@ -0,0 +1,4 @@
APP_REPOSITORY_URL ?= https://github.com/purton-tech/bionicgpt
APP_VERSION ?= v1.1.14
ENV_VARS += BIONICGPT_ENVOY_SERVICE_7700_TAGS
BIONICGPT_ENVOY_SERVICE_7700_TAGS ?= $(call tagprefix)

View File

@ -0,0 +1,47 @@
services:
app:
environment:
APP_DATABASE_URL: postgresql://${BIONICGPT_DB_APP_USER:-ft_application}:${BIONICGPT_DB_APP_PASSWORD:-testpassword}@db:5432/${BIONICGPT_DB_POSTGRES_DB:-finetuna}?sslmode=disable
barricade:
environment:
SECRET_KEY: ${BIONICGPT_BARRICADE_SECRET_KEY:-190a5bf4b3cbb6c0991967ab1c48ab30790af876720f1835cbbf3820f4f5d949}
DATABASE_URL: postgresql://${BIONICGPT_DB_POSTGRES_USER:-postgres}:${BIONICGPT_DB_POSTGRES_PASSWORD:-testpassword}@db:5432/${BIONICGPT_DB_POSTGRES_DB:-finetuna}?sslmode=disable
db:
environment:
POSTGRES_PASSWORD: ${BIONICGPT_DB_POSTGRES_PASSWORD:-testpassword}
POSTGRES_USER: ${BIONICGPT_DB_POSTGRES_USER:-postgres}
POSTGRES_DB: ${BIONICGPT_DB_POSTGRES_DB:-finetuna}
PGDATA: /var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${BIONICGPT_DB_POSTGRES_USER:-postgres}"]
interval: 10s
timeout: 5s
retries: 5
volumes:
- pgdata:/var/lib/postgresql/data
embeddings-job:
environment:
APP_DATABASE_URL: postgresql://${BIONICGPT_DB_APP_USER:-ft_application}:${BIONICGPT_DB_APP_PASSWORD:-testpassword}@db:5432/${BIONICGPT_DB_POSTGRES_DB:-finetuna}?sslmode=disable
envoy:
labels:
- SERVICE_7700_CHECK_HTTP=${BIONICGPT_ENVOY_SERVICE_7700_CHECK_HTTP:-/auth/sign_in}
- SERVICE_7700_NAME=${COMPOSE_SERVICE_NAME:-bionicgpt}-envoy-7700
- SERVICE_7700_TAGS=${BIONICGPT_ENVOY_SERVICE_7700_TAGS:-urlprefix-localhost/bionicgpt/*}
llm-api:
networks:
default:
aliases:
- local-ai
migrations:
environment:
DATABASE_URL: postgresql://${BIONICGPT_DB_POSTGRES_USER:-postgres}:${BIONICGPT_DB_POSTGRES_PASSWORD:-testpassword}@db:5432/${BIONICGPT_DB_POSTGRES_DB:-finetuna}?sslmode=disable
volumes:
pgdata:

6
apps/signoz/signoz.mk Normal file
View File

@ -0,0 +1,6 @@
APP_DOCKER_DIR ?= deploy/docker/clickhouse-setup
APP_REPOSITORY_URL ?= https://github.com/SigNoz/signoz
APP_VERSION ?= v0.34.3
ENV_VARS += SIGNOZ_FRONTEND_SERVICE_3301_TAGS
SIGNOZ_FRONTEND_SERVICE_3301_TAGS ?= $(call urlprefix)
STACK += alerting/apprise

6
apps/signoz/signoz.yml Normal file
View File

@ -0,0 +1,6 @@
services:
frontend:
labels:
- SERVICE_3301_CHECK_HTTP=${SIGNOZ_SERVICE_3301_CHECK_HTTP:-/}
- SERVICE_3301_NAME=${COMPOSE_SERVICE_NAME:-signoz}-frontend-3301
- SERVICE_3301_TAGS=${SIGNOZ_FRONTEND_SERVICE_3301_TAGS:-urlprefix-localhost/signoz/*}

View File

@ -192,7 +192,6 @@ ssh@%:
## it updates COMPOSE_FILE with all .yml files of the current stack
.PHONY: stack
stack:
$(call compose-file)
$(foreach stackz,$(STACK),$(call docker-stack,$(stackz)))
$(call compose-file,$(MYOS_STACK),$(MYOS_STACK_FILE))

View File

@ -30,6 +30,7 @@ DOCKER_BUILD_VARS ?= APP BRANCH COMPOSE_VERSION DOCKER_GID DOCKER_
DOCKER_COMPOSE ?= $(or $(shell docker-compose --version 2>/dev/null |awk '$$4 != "v'"$(COMPOSE_VERSION)"'" {exit 1} END {if (NR == 0) exit 1}' && printf 'docker-compose\n'),$(shell docker compose >/dev/null 2>&1 && printf 'docker compose\n'))
DOCKER_COMPOSE_ARGS ?= --ansi=auto
DOCKER_COMPOSE_DOWN_OPTIONS ?=
DOCKER_COMPOSE_LOGS_OPTIONS ?= --follow --tail=100
DOCKER_COMPOSE_PROJECT_NAME ?= $(if $(HOST_STACK),$(HOST_COMPOSE_PROJECT_NAME),$(if $(USER_STACK),$(USER_COMPOSE_PROJECT_NAME)))
DOCKER_COMPOSE_RUN_ENTRYPOINT ?= $(patsubst %,--entrypoint=%,$(DOCKER_COMPOSE_ENTRYPOINT))
DOCKER_COMPOSE_RUN_OPTIONS ?= --rm $(DOCKER_COMPOSE_RUN_ENTRYPOINT) $(DOCKER_COMPOSE_RUN_WORKDIR)

View File

@ -56,7 +56,7 @@ docker-compose-exec:
# target docker-compose-logs: Call docker-compose logs SERVICE
.PHONY: docker-compose-logs
docker-compose-logs:
$(call docker-compose,logs -f --tail=100 $(if $(filter $(SERVICE),$(SERVICES)),$(SERVICE)))
$(call docker-compose,logs $(DOCKER_COMPOSE_LOGS_OPTIONS) $(if $(filter $(SERVICE),$(SERVICES)),$(SERVICE)))
# target docker-compose-ps: Call docker-compose ps
.PHONY: docker-compose-ps

View File

@ -12,8 +12,11 @@ $(APP): myos-user
## ex: app-foo-build will call app-build for app foo in ../foo
.PHONY: app-%
app-%:
$(eval COMPOSE_FILE :=)
$(eval STACK :=)
$(eval app := $(subst -$(lastword $(subst -, ,$*)),,$*))
$(eval command := $(lastword $(subst -, ,$*)))
$(eval include $(wildcard apps/$(app).mk apps/$(app)/$(app).mk)) \
$(if $(wildcard $(RELATIVE)$(app)), \
$(if $(filter app-$(command),$(.VARIABLES)), \
$(call app-bootstrap,$(app)) \
@ -26,7 +29,11 @@ app-%:
) \
) \
, \
$(call WARNING,Unable to find app,$(app),in dir,$(RELATIVE)$(app)) \
$(if $(wildcard apps/$(app).mk apps/$(app)/$(app).mk), \
$(call app-install) \
$(call app-bootstrap) \
,$(call WARNING,Unable to find app,$(app),in dir,$(RELATIVE)$(app)) \
) \
)
# target app-required-install: Call app-install for each APP_REQUIRED

View File

@ -16,15 +16,14 @@ define app-bootstrap
$(eval APP := $(or $(1), $(APP)))
$(eval APP_DIR := $(or $(2), $(RELATIVE)$(APP)))
$(eval APP_NAME := $(or $(3),$(subst -,,$(subst .,,$(call LOWERCASE,$(APP))))))
$(eval COMPOSE_FILE :=)
$(call compose-file,$(APP_DIR) $(APP_DIR)/docker apps/$(APP),docker-compose $(APP))
$(call compose-file,$(MYOS_STACK),$(MYOS_STACK_FILE))
$(eval COMPOSE_PROJECT_NAME := $(if $(DOCKER_COMPOSE_PROJECT_NAME),$(DOCKER_COMPOSE_PROJECT_NAME),$(subst .,,$(call LOWERCASE,$(USER)-$(APP_NAME)-$(ENV)$(addprefix -,$(subst /,,$(subst -,,$(APP_PATH))))))))
$(eval COMPOSE_SERVICE_NAME := $(if $(DOCKER_COMPOSE_SERVICE_NAME),$(DOCKER_COMPOSE_SERVICE_NAME),$(subst _,-,$(COMPOSE_PROJECT_NAME))))
$(eval DOCKER_BUILD_DIR := $(APP_DIR))
$(if $(wildcard $(APP_DIR)/.env.dist), $(call .env,$(APP_DIR)/.env,$(APP_DIR)/.env.dist))
$(if $(wildcard $(APP_DIR)/.env.example), $(call .env,$(APP_DIR)/.env,$(APP_DIR)/.env.example))
$(if $(wildcard $(APP_DIR)/.env.sample), $(call .env,$(APP_DIR)/.env,$(APP_DIR)/.env.sample))
$(call compose-file,$(APP_DIR) $(APP_DIR)/$(or $(APP_DOCKER_DIR),$(DOCKER_DIR)),docker-compose)
$(call compose-file,apps apps/$(APP),$(APP))
$(foreach stackz,$(STACK),$(call docker-stack,$(stackz)))
$(call compose-file,$(MYOS_STACK),$(MYOS_STACK_FILE))
$(call .env,$(APP_DIR)/.env,$(APP_DIR)/.env.dist $(APP_DIR)/.env.example $(APP_DIR)/.env.sample)
endef
# function app-build: Call docker-build for each Dockerfile in dir 1
@ -72,7 +71,7 @@ endef
# function app-down: Call docker rm for each Dockerfile in dir 1
define app-down
$(call INFO,app-down,$(1)$(comma))
$(if $(filter-out $(MYOS_STACK_FILE),$(COMPOSE_FILE)),$(call docker-compose,down -v),
$(if $(filter-out $(MYOS_STACK_FILE),$(COMPOSE_FILE)),$(call docker-compose,down $(DOCKER_COMPOSE_DOWN_OPTIONS)),
$(call docker-file,$(1))
$(foreach dockerfile,$(DOCKER_FILE),
$(call app-docker,$(dockerfile))
@ -94,18 +93,18 @@ endef
# function app-install: Run 'git clone url 1 dir 2'
define app-install
$(call INFO,app-install,$(1)$(comma) $(2))
$(eval url := $(or $(1), $(APP_REPOSITORY_URL)))
$(eval url := $(or $(1), $(REPOSITORY_URL), $(APP_REPOSITORY_URL)))
$(eval dir := $(or $(2), $(RELATIVE)$(lastword $(subst /, ,$(url)))))
$(if $(wildcard $(dir)/.git),
$(call INFO,app $(url) already installed in dir $(dir))
, $(RUN) git clone $(QUIET) $(url) $(dir)
, $(RUN) git clone $(QUIET) $(url) $(dir) && if [ -n "$(APP_VERSION)" ]; then cd $(dir) && git reset --hard $(QUIET) "$(APP_VERSION)"; fi
)
endef
# function app-logs: Call docker logs $(ARGS) for each Dockerfile in dir 1
define app-logs
$(call INFO,app-logs,$(1)$(comma) $(2))
$(if $(filter-out $(MYOS_STACK_FILE),$(COMPOSE_FILE)),$(call docker-compose,logs),
$(if $(filter-out $(MYOS_STACK_FILE),$(COMPOSE_FILE)),$(call docker-compose,logs $(DOCKER_COMPOSE_LOGS_OPTIONS)),
$(call docker-file,$(1))
$(foreach dockerfile,$(DOCKER_FILE),
$(call app-docker,$(dockerfile))
@ -150,7 +149,7 @@ endef
define app-up
$(call INFO,app-up,$(1)$(comma))
$(eval DOCKER_RUN_OPTIONS += -d)
$(if $(filter-out $(MYOS_STACK_FILE),$(COMPOSE_FILE)),$(call docker-compose,up),
$(if $(filter-out $(MYOS_STACK_FILE),$(COMPOSE_FILE)),$(call docker-compose,up $(DOCKER_COMPOSE_UP_OPTIONS)),
$(if $(shell docker ps -q -f name=$(DOCKER_NAME) 2>/dev/null),
$(call INFO,docker $(DOCKER_NAME) already running)
, $(call app-run,$(1))
@ -160,10 +159,10 @@ endef
# function app-update: Run 'cd dir 1 && git pull' or Call app-install
define app-update
$(call INFO,app-update,$(1)$(comma) $(2))
$(eval url := $(or $(1), $(APP_REPOSITORY_URL)))
$(eval url := $(or $(1), $(REPOSITORY_URL), $(APP_REPOSITORY_URL)))
$(eval dir := $(or $(2), $(APP_DIR)))
$(if $(wildcard $(dir)/.git),
$(RUN) sh -c 'cd $(dir) && git pull $(QUIET)'
$(RUN) sh -c 'cd $(dir) && git pull $(QUIET) && if [ -n "$(APP_VERSION)" ]; then git reset --hard $(QUIET) "$(APP_VERSION)"; fi'
, $(call app-install,$(url),$(dir))
)
endef

View File

@ -1,3 +1,4 @@
DOCKER_DIR ?= *
DOCKER_ENV_ARGS ?= $(docker_env_args)
DOCKER_EXEC_OPTIONS ?=
DOCKER_GID ?= $(call gid,docker)
@ -158,7 +159,7 @@ endef
define docker-file
$(call INFO,docker-file,$(1)$(comma))
$(eval dir := $(or $(1),$(APP_DIR)))
$(eval DOCKER_FILE := $(wildcard $(dir)/docker/*/Dockerfile $(dir)/*/Dockerfile $(dir)/Dockerfile))
$(eval DOCKER_FILE := $(wildcard $(dir)/$(DOCKER_DIR)/*/Dockerfile $(dir)/$(DOCKER_DIR)/Dockerfile $(dir)/Dockerfile))
$(if $(DOCKER_FILE),
, $(call ERROR,Unable to find a,Dockerfile,in dir,$(dir))
)

View File

@ -225,6 +225,12 @@ force = $$(while true; do \
# macro gid: Return GID of group 1
gid = $(shell awk -F':' '$$1 == "$(1)" {print $$3}' /etc/group 2>/dev/null)
# macro newer: Return the newest file
newer = $(shell stat -c '%Y %n' $(1) $(2) $(if $(DEBUG),,2>/dev/null) |sort -n |tail -n1 |awk '{print $$2}')
# older newer: Return the oldest file
older = $(shell stat -c '%Y %n' $(1) $(2) $(if $(DEBUG),,2>/dev/null) |sort -n |head -n1 |awk '{print $$2}')
# macro pop: Return last word of string 1 according to separator 2
pop = $(patsubst %$(or $(2),/)$(lastword $(subst $(or $(2),/), ,$(1))),%,$(1))

View File

@ -2,8 +2,9 @@
# ENV
# target .env: Update file .env
## it updates file .env when file .env.dist is newer
.env: .env.dist
## it updates file .env
.PHONY: .env
.env:
$(call .env,,,$(wildcard $(CONFIG)/$(ENV)/$(APP)/.env .env.$(ENV)))
# target .env-clean: Remove file .env
@ -40,16 +41,18 @@ SHELL:=/bin/bash
# function .env: Call .env_update function
## it sets .env, .env.dist and .env.ENV files paths
## it calls .env_update function if .env.dist file exists
## it calls .env_update function if .env.dist exists and is newer than .env
## of when file .env does not exist
# 1st arg: path to .env file to update, default to .env
# 2nd arg: path to .env.dist file, default to .env.dist
# 3rd arg: path to .env override files, default to .env.$(ENV)
define .env
$(call INFO,.env,$(1)$(comma) $(2)$(comma) $(3))
$(eval env_file:=$(or $(1),.env))
$(eval env_dist:=$(or $(2),$(env_file).dist))
$(eval env_over:=$(or $(wildcard $(3)),$(wildcard $(env_file).$(ENV))))
$(if $(wildcard $(env_dist)), $(call .env_update))
$(eval env_dists:=$(wildcard $(or $(2),$(env_file).dist)))
$(eval env_over:=$(wildcard $(or $(3),$(env_file).$(ENV))))
$(if $(FORCE)$(filter $(env_file),$(call newer,$(env_file) $(env_dists) $(env_over))),
,$(foreach env_dist,$(env_dists),$(call .env_update)))
endef
# function .env_update: Update .env file with values from .env.dist

View File

@ -5,6 +5,7 @@
#
################################################################################
# source : https://raw.githubusercontent.com/buildroot/buildroot/master/support/misc/utils.mk
# customized for myos
# Strip quotes and then whitespaces
qstrip = $(strip $(subst ",,$(1)))
@ -14,6 +15,8 @@ qstrip = $(strip $(subst ",,$(1)))
comma := ,
empty :=
space := $(empty) $(empty)
tab := $(empty) $(empty)
escape := $(shell printf '\x1b')
# make 4.3:
# https://lwn.net/Articles/810071/
@ -69,6 +72,7 @@ reverse = $(if $(1),$(call reverse,$(wordlist 2,$(words $(1)),$(1))) $(firstword
# and in rules. Particularly useful for VCS version strings, that can contain
# slashes, colons (OK in filenames but not in rules), and spaces.
sanitize = $(subst $(space),_,$(subst :,_,$(subst /,_,$(strip $(1)))))
# customized for myos: slugify macro cleans up strings so it can be used as url
slugify = $(subst $(space),,$(subst :,,$(subst /,,$(subst .,,$(1)))))
# MESSAGE Macro -- display a message in bold type
@ -86,9 +90,17 @@ finddirclauses = $(call notfirstword,$(patsubst %,-o -path '$(1)/%',$(2)))
# notfirstword(wordlist): returns all but the first word in wordlist
notfirstword = $(wordlist 2,$(words $(1)),$(1))
# build a comma-separated list of quoted items, from a space-separated
# build a comma-separated list of items, from a space-separated
# list of items: a b c d --> a, b, c, d
make-comma-list = $(subst $(space),$(comma)$(space),$(strip $(1)))
# build a comma-separated list of double-quoted items, from a space-separated
# list of unquoted items: a b c d --> "a", "b", "c", "d"
make-comma-list = $(subst $(space),$(comma)$(space),$(patsubst %,"%",$(strip $(1))))
make-dq-comma-list = $(call make-comma-list,$(patsubst %,"%",$(strip $(1))))
# build a comma-separated list of single-quoted items, from a space-separated
# list of unquoted items: a b c d --> 'a', 'b', 'c', 'd'
make-sq-comma-list = $(call make-comma-list,$(patsubst %,'%',$(strip $(1))))
# Needed for the foreach loops to loop over the list of hooks, so that
# each hook call is properly separated by a newline.
@ -124,10 +136,10 @@ QUOTE = '
# (that's why the single-quotes are escaped they way they are, above,
# and why the dollar sign is not escaped) to printf(1). A trailing
# newline is apended, too.
# Note: Removing the apended trailing newline for custom needs
#
# Note: leading or trailing spaces are *not* stripped.
#
# customized for myos: Removing the trailing newline
define PRINTF
printf '$(subst $(sep),\n,\
$(subst $(PERCENT),$(PERCENT)$(PERCENT),\

View File

@ -0,0 +1,35 @@
version: '3.6'
services:
apprise:
image: caronc/apprise:latest
environment:
- APPRISE_STATELESS_URLS=${APPRISE_STATELESS_URLS:-}
- APPRISE_CONFIG_LOCK=true
labels:
- SERVICE_8000_CHECK_HTTP=${APPRISE_SERVICE_8000_CHECK_HTTP:-/}
- SERVICE_8000_NAME=${COMPOSE_SERVICE_NAME:-alerting}-apprise-8000
- SERVICE_8000_TAGS=${APPRISE_SERVICE_8000_TAGS:-urlprefix-localhost/apprise/*}
networks:
- public
restart: always
volumes:
- apprise:/config
apprise-webhook:
image: zzeneg/apprise-webhook
environment:
- APPRISE_URL=http://apprise:8000/notify
- TEMPLATE=alertmanager
labels:
# - SERVICE_3000_CHECK_HTTP=${APPRISE_WEBHOOK_SERVICE_3000_CHECK_HTTP:-/}
# - SERVICE_3000_CHECK_HTTP_METHOD=${APPRISE_WEBHOOK_SERVICE_3000_CHECK_HTTP_METHOD:-POST}
- SERVICE_3000_CHECK_TCP=${APPRISE_WEBHOOK_SERVICE_3000_CHECK_TCP:-true}
- SERVICE_3000_NAME=${COMPOSE_SERVICE_NAME:-alerting}-webhook-3000
- SERVICE_3000_TAGS=${APPRISE_WEBHOOK_SERVICE_3000_TAGS:-urlprefix-localhost/webhook/*}
networks:
- public
restart: always
volumes:
apprise: