From 2699a04c8443413e1a9b2d9d43d7a7aa8c8d6662 Mon Sep 17 00:00:00 2001 From: Yann Autissier Date: Sun, 26 Nov 2023 05:14:30 +0100 Subject: [PATCH] first apps :) --- apps/bionicgpt/bionicgpt.mk | 4 +++ apps/bionicgpt/bionicgpt.yml | 47 ++++++++++++++++++++++++++++++++++++ apps/signoz/signoz.mk | 6 +++++ apps/signoz/signoz.yml | 6 +++++ make/apps/common.mk | 1 - make/apps/def.docker.mk | 1 + make/apps/docker.mk | 2 +- make/common.mk | 9 ++++++- make/def.app.mk | 21 ++++++++-------- make/def.docker.mk | 3 ++- make/env.mk | 2 +- stack/alerting/apprise.yml | 35 +++++++++++++++++++++++++++ 12 files changed, 122 insertions(+), 15 deletions(-) create mode 100644 apps/bionicgpt/bionicgpt.mk create mode 100644 apps/bionicgpt/bionicgpt.yml create mode 100644 apps/signoz/signoz.mk create mode 100644 apps/signoz/signoz.yml create mode 100644 stack/alerting/apprise.yml diff --git a/apps/bionicgpt/bionicgpt.mk b/apps/bionicgpt/bionicgpt.mk new file mode 100644 index 0000000..5ecc87b --- /dev/null +++ b/apps/bionicgpt/bionicgpt.mk @@ -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) diff --git a/apps/bionicgpt/bionicgpt.yml b/apps/bionicgpt/bionicgpt.yml new file mode 100644 index 0000000..82177ea --- /dev/null +++ b/apps/bionicgpt/bionicgpt.yml @@ -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: diff --git a/apps/signoz/signoz.mk b/apps/signoz/signoz.mk new file mode 100644 index 0000000..0e4adf4 --- /dev/null +++ b/apps/signoz/signoz.mk @@ -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 diff --git a/apps/signoz/signoz.yml b/apps/signoz/signoz.yml new file mode 100644 index 0000000..82c6991 --- /dev/null +++ b/apps/signoz/signoz.yml @@ -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/*} diff --git a/make/apps/common.mk b/make/apps/common.mk index 7a41d40..afd09b5 100644 --- a/make/apps/common.mk +++ b/make/apps/common.mk @@ -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)) diff --git a/make/apps/def.docker.mk b/make/apps/def.docker.mk index 8a65e6c..d24715a 100644 --- a/make/apps/def.docker.mk +++ b/make/apps/def.docker.mk @@ -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) diff --git a/make/apps/docker.mk b/make/apps/docker.mk index 6642f1e..35375d6 100644 --- a/make/apps/docker.mk +++ b/make/apps/docker.mk @@ -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 diff --git a/make/common.mk b/make/common.mk index 2aeb465..9456050 100644 --- a/make/common.mk +++ b/make/common.mk @@ -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 diff --git a/make/def.app.mk b/make/def.app.mk index cedcf18..af6b29f 100644 --- a/make/def.app.mk +++ b/make/def.app.mk @@ -16,12 +16,13 @@ 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)) + $(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 @@ -70,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)) @@ -92,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)) @@ -148,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)) @@ -158,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 diff --git a/make/def.docker.mk b/make/def.docker.mk index 1868393..2b57db4 100644 --- a/make/def.docker.mk +++ b/make/def.docker.mk @@ -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)) ) diff --git a/make/env.mk b/make/env.mk index 864ece8..d29f8fd 100644 --- a/make/env.mk +++ b/make/env.mk @@ -34,7 +34,7 @@ docker.env.file ?= $(patsubst %,--env-file %,$(wildcard $(ENV_FILE))) docker_env_args = $(docker.env.args) $(docker.env.dist) $(docker.env.file) env.args = $(foreach var,$(ENV_VARS),$(if $($(var)),$(var)='$($(var))')) env.dist ?= $(shell printenv |awk -F '=' 'NR == FNR { if($$1 !~ /^(\#|$$)/) { A[$$1]; next } } ($$1 in A)' .env.dist - 2>/dev/null) -env.file ?= $(shell cat $(or $(ENV_FILE),/dev/null) 2>/dev/null |sed '/^[ \t]*$$/d;/^[ \t]*\#/d;s/='\''/=/;s/'\''$$//;s/='\"'/=/;s/'\"'$$//;' |awk -F '=' '{print $$1"='\''"$$2"'\''"}') +env.file ?= $(shell cat $(or $(ENV_FILE),/dev/null) 2>/dev/null |sed '/^[ \t]*$$/d;/^[ \t]*\#/d;s/='\''/=/;s/'\''$$//;s/='\"'/=/;s/'\"'$$//;s/=/='\''/;s/$$/'\''/;') env_args = $(env.args) $(env.dist) $(env.file) SHELL:=/bin/bash diff --git a/stack/alerting/apprise.yml b/stack/alerting/apprise.yml new file mode 100644 index 0000000..fc0b174 --- /dev/null +++ b/stack/alerting/apprise.yml @@ -0,0 +1,35 @@ +version: '3.6' + +services: + apprise: + image: caronc/apprise:latest + environment: + - APPRISE_STATELESS_URLS + - APPRISE_CONFIG_LOCK=${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: