Compare commits

...

2 Commits

Author SHA1 Message Date
Yann Autissier 1a731109ea update apps: bionicgpt 2023-11-26 20:19:44 +01:00
Yann Autissier 2699a04c84 first apps :) 2023-11-26 12:33:55 +01:00
16 changed files with 329 additions and 97 deletions

View File

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

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
pipeline-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 @@
ENV_VARS += SIGNOZ_FRONTEND_SERVICE_3301_TAGS
SIGNOZ_DOCKER_DIR ?= deploy/docker/clickhouse-setup
SIGNOZ_FRONTEND_SERVICE_3301_TAGS ?= $(call urlprefix)
SIGNOZ_REPOSITORY_URL ?= https://github.com/SigNoz/signoz
SIGNOZ_VERSION ?= v0.34.3
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))
@ -201,7 +200,7 @@ stack:
## the last part of %
## ex: stack-host-up will fire the docker-compose-up target in the host stack
.PHONY: stack-%
stack-%:
stack-%: stack
$(eval stack := $(subst -$(lastword $(subst -, ,$*)),,$*))
$(eval command := $(lastword $(subst -, ,$*)))
$(if $(findstring -,$*), \
@ -241,7 +240,7 @@ upgrade: update app-upgrade release-upgrade ## Upgrade application
# target %: Always fired target
## it fires the stack and %-rule-exists targets everytime
%: FORCE stack %-rule-exists ;
%: FORCE %-rule-exists ;
# target %-rule-exists: Print a warning message if % target does not exists
%-rule-exists:

View File

@ -27,9 +27,11 @@ DOCKER_BUILD_TARGET ?= $(if $(filter $(ENV),$(DOCKER_BUILD_TARGETS))
DOCKER_BUILD_TARGET_DEFAULT ?= master
DOCKER_BUILD_TARGETS ?= $(ENV_DEPLOY)
DOCKER_BUILD_VARS ?= APP BRANCH COMPOSE_VERSION DOCKER_GID DOCKER_MACHINE DOCKER_REPOSITORY DOCKER_SYSTEM GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME SSH_REMOTE_HOSTS USER VERSION
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 := $(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_FILE ?= docker-compose
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)
@ -63,11 +65,11 @@ DOCKER_COMPOSE_DOWN_OPTIONS := --rmi all -v
DOCKER_COMPOSE_UP_OPTIONS := -d --build
endif
# function compose-file: Search compose files to load
# function compose-file: Search compose files to update variable COMPOSE_FILE
define compose-file
$(call INFO,compose-file,$(1)$(comma) $(2)$(comma) $(3)$(comma) $(4))
$(eval path := $(or $(1),. ./docker))
$(eval name := $(or $(2),docker-compose))
$(eval path := $(or $(1),. $(APP_DOCKER_DIR)))
$(eval name := $(or $(2),$(DOCKER_COMPOSE_FILE)))
$(eval suffix := $(or $(3),$(COMPOSE_FILE_SUFFIX)))
$(eval extension := $(or $(4),yml yaml))
$(eval COMPOSE_FILE += $(wildcard $(foreach e,$(extension),$(foreach n,$(name),$(foreach p,$(path),$(p)/$(n).$(e) $(p)/$(n).$(ENV).$(e) $(foreach s,$(suffix),$(p)/$(n).$(s).$(e) $(p)/$(n).$(s).$(ENV).$(e)))))))

View File

@ -1,4 +1,5 @@
APP_DIR ?= $(CURDIR)
APP_DOCKER_DIR ?= $(DOCKER_DIR)
APP_DOMAIN ?= $(patsubst %,$(APP_DOMAIN_PREFIX)%,$(DOMAIN))
APP_DOMAIN_PREFIX ?= $(if $(HOST_STACK),,$(addsuffix .,$(filter-out $(ENV_DEPLOY),$(ENV)))$(USER).)
APP_HOST ?= $(patsubst %,$(APP_HOST_PREFIX)%,$(APP_DOMAIN))$(if $(HOST_LB),$(space)$(APP_DOMAIN))
@ -19,6 +20,7 @@ APP_UPSTREAM_REPOSITORY ?= $(or $(shell git config --get remote.upstream
APP_URI ?= $(patsubst %,%/$(APP_PATH),$(APP_HOST))
APP_URIS ?= $(APP_URI)
APP_URL ?= $(patsubst %,$(APP_SCHEME)://%,$(APP_URI))
APP_VERSION ?= $(VERSION)
CONTEXT += APP APPS BRANCH DOMAIN VERSION RELEASE
CONTEXT_DEBUG += APP_DIR APP_URL APP_REPOSITORY APP_UPSTREAM_REPOSITORY ENV_DEPLOY
ENV_DEPLOY ?= $(patsubst origin/%,%,$(shell git rev-parse --symbolic --remotes=origin |sed '/origin\/HEAD/d' 2>/dev/null))

View File

@ -8,59 +8,59 @@ docker-build: docker-images-myos
# target docker-build-%: Call docker-build for each Dockerfile in docker/% folder
.PHONY: docker-build-%
docker-build-%:
docker-build-%: stack
$(if $(wildcard docker/$*/Dockerfile),$(call docker-build,docker/$*))
$(if $(findstring :,$*),$(eval DOCKER_FILE := $(wildcard docker/$(subst :,/,$*)/Dockerfile)),$(eval DOCKER_FILE := $(wildcard docker/$*/*/Dockerfile)))
$(foreach dockerfile,$(DOCKER_FILE),$(call docker-build,$(dir $(dockerfile)),$(DOCKER_REPOSITORY)/$(word 2,$(subst /, ,$(dir $(dockerfile)))):$(lastword $(subst /, ,$(dir $(dockerfile)))),""))
# target docker-commit: Call docker-commit for each SERVICES
.PHONY: docker-commit
docker-commit:
docker-commit: stack
$(foreach service,$(or $(SERVICE),$(SERVICES)),$(call docker-commit,$(service)))
# target docker-commit-%: Call docker-commit with tag % for each SERVICES
.PHONY: docker-commit-%
docker-commit-%:
docker-commit-%: stack
$(foreach service,$(or $(SERVICE),$(SERVICES)),$(call docker-commit,$(service),,,$*))
# target docker-compose-build: Fire docker-images-myos, Call docker-compose build SERVICE
.PHONY: docker-compose-build
docker-compose-build: DOCKER_RUN_OPTIONS += -it
docker-compose-build: docker-images-myos
docker-compose-build: docker-images-myos stack
$(call docker-compose,build $(DOCKER_BUILD_ARGS) $(if $(filter $(SERVICE),$(SERVICES)),$(SERVICE)))
# target docker-compose-config: Call docker-compose config
.PHONY: docker-compose-config
docker-compose-config:
docker-compose-config: stack
$(call docker-compose,config)
# target docker-compose-connect: Call docker-compose exec SERVICE DOCKER_SHELL
.PHONY: docker-compose-connect
docker-compose-connect: SERVICE ?= $(DOCKER_SERVICE)
docker-compose-connect: DOCKER_RUN_OPTIONS += -it
docker-compose-connect:
docker-compose-connect: stack
$(call docker-compose,exec $(SERVICE) $(DOCKER_SHELL))
# target docker-compose-down: Call docker-compose rm SERVICE or docker-compose down
.PHONY: docker-compose-down
docker-compose-down: DOCKER_RUN_OPTIONS += -it
docker-compose-down:
docker-compose-down: stack
$(if $(filter $(SERVICE),$(SERVICES)),$(call docker-compose,rm -fs $(SERVICE)),$(call docker-compose,down $(DOCKER_COMPOSE_DOWN_OPTIONS) ||:))
# target docker-compose-exec: Call docker-compose-exec SERVICE ARGS
.PHONY: docker-compose-exec
docker-compose-exec: SERVICE ?= $(DOCKER_SERVICE)
docker-compose-exec:
docker-compose-exec: stack
$(call docker-compose-exec-sh,$(SERVICE),$(ARGS))
# 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)))
docker-compose-logs: stack
$(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
docker-compose-ps:
docker-compose-ps: stack
$(call docker-compose,ps)
# target docker-compose-rebuild: Call docker-compose-build target with DOCKER_BUILD_NO_CACHE=true
@ -74,42 +74,42 @@ docker-compose-recreate: docker-compose-rm docker-compose-up
# target docker-compose-restart: Call docker-compose restart SERVICE
.PHONY: docker-compose-restart
docker-compose-restart:
docker-compose-restart: stack
$(call docker-compose,restart $(if $(filter $(SERVICE),$(SERVICES)),$(SERVICE)))
# target docker-compose-rm: Call docker-compose rm SERVICE
.PHONY: docker-compose-rm
docker-compose-rm: DOCKER_RUN_OPTIONS += -it
docker-compose-rm:
docker-compose-rm: stack
$(call docker-compose,rm -fs $(if $(filter $(SERVICE),$(SERVICES)),$(SERVICE)))
# target docker-compose-run: Call docker-compose run SERVICE ARGS
.PHONY: docker-compose-run
docker-compose-run: SERVICE ?= $(DOCKER_SERVICE)
docker-compose-run: DOCKER_RUN_OPTIONS += -it
docker-compose-run:
docker-compose-run: stack
$(call docker-compose,run $(DOCKER_COMPOSE_RUN_OPTIONS) $(SERVICE) $(ARGS))
# target docker-compose-scale: Call docker-compose up --scale SERVICE=NUM
.PHONY: docker-compose-scale
docker-compose-scale: SERVICE ?= $(DOCKER_SERVICE)
docker-compose-scale:
docker-compose-scale: stack
$(call docker-compose,up $(DOCKER_COMPOSE_UP_OPTIONS) --scale $(SERVICE)=$(NUM))
# target docker-compose-start: Call docker-compose start SERVICE
.PHONY: docker-compose-start
docker-compose-start:
docker-compose-start: stack
$(call docker-compose,start $(if $(filter $(SERVICE),$(SERVICES)),$(SERVICE)))
# target docker-compose-stop: Call docker-compose stop SERVICE
.PHONY: docker-compose-stop
docker-compose-stop:
docker-compose-stop: stack
$(call docker-compose,stop $(if $(filter $(SERVICE),$(SERVICES)),$(SERVICE)))
# target docker-compose-up: Fire docker-image-myos, Call docker-compose up SERVICE
.PHONY: docker-compose-up
docker-compose-up: DOCKER_RUN_OPTIONS += -it
docker-compose-up: docker-images-myos bootstrap-stack
docker-compose-up: docker-images-myos bootstrap-stack stack
$(call docker-compose,up $(DOCKER_COMPOSE_UP_OPTIONS) $(if $(filter $(SERVICE),$(SERVICES)),$(SERVICE)))
# target docker-images-myos: Call myos-docker-build-% target for each DOCKER_IMAGES_MYOS
@ -178,7 +178,7 @@ docker-plugin-install:
# target docker-push: Call docker-push for each SERVICES
.PHONY: docker-push
docker-push:
docker-push: stack
ifneq ($(filter $(DEPLOY),true),)
$(foreach service,$(or $(SERVICE),$(SERVICES)),$(call docker-push,$(service)))
else
@ -187,7 +187,7 @@ endif
# target docker-push-%: Call docker-push with tag % for each SERVICES
.PHONY: docker-push-%
docker-push-%:
docker-push-%: stack
ifneq ($(filter $(DEPLOY),true),)
$(foreach service,$(or $(SERVICE),$(SERVICES)),$(call docker-push,$(service),,$*))
else
@ -231,7 +231,7 @@ docker-run-%: docker-build-%
# target docker-tag: Call docker-tag for each SERVICES
.PHONY: docker-tag
docker-tag:
docker-tag: stack
ifneq ($(filter $(DEPLOY),true),)
$(foreach service,$(or $(SERVICE),$(SERVICES)),$(call docker-tag,$(service)))
else
@ -240,7 +240,7 @@ endif
# target docker-tag-%: Call docker-tag with target tag % for each SERVICES
.PHONY: docker-tag-%
docker-tag-%:
docker-tag-%: stack
ifneq ($(filter $(DEPLOY),true),)
$(foreach service,$(or $(SERVICE),$(SERVICES)),$(call docker-tag,$(service),,,,$*))
else

View File

@ -10,10 +10,20 @@ $(APP): myos-user
# target app-%: Call app-$(command) for APP in APP_DIR
## it splits % on dashes and extracts app from the beginning and command from the last part of %
## ex: app-foo-build will call app-build for app foo in ../foo
## it includes apps/$(app)/*.mk file and hydrates APP_* variables
## ex: APP_REPOSITORY_URL is set with value from variable $(APP)_REPOSITORY_URL
.PHONY: app-%
app-%:
$(eval app := $(subst -$(lastword $(subst -, ,$*)),,$*))
$(eval command := $(lastword $(subst -, ,$*)))
$(eval COMPOSE_FILE :=)
$(eval STACK :=)
$(eval app := $(subst -$(lastword $(subst -, ,$*)),,$*))
$(eval command := $(lastword $(subst -, ,$*)))
$(eval include $(wildcard apps/def.mk apps/$(app).mk apps/$(app)/*.mk))
$(foreach var,$(filter $(call UPPERCASE,$(app))_%,$(MAKE_FILE_VARS)), \
$(if $(filter $(subst $(call UPPERCASE,$(app))_,APP_,$(var)),$(MAKE_FILE_VARS)), \
$(eval $(subst $(call UPPERCASE,$(app))_,APP_,$(var)) := $($(var))) \
) \
)
$(if $(wildcard $(RELATIVE)$(app)), \
$(if $(filter app-$(command),$(.VARIABLES)), \
$(call app-bootstrap,$(app)) \
@ -26,7 +36,11 @@ app-%:
) \
) \
, \
$(call WARNING,Unable to find app,$(app),in dir,$(RELATIVE)$(app)) \
$(if $($(call UPPERCASE,$(APP))_REPOSITORY_URL), \
$(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

@ -3,10 +3,13 @@ MAKECMDARGS += app-%-exec app-%-run
# function app-attach: Call docker-attach for each Dockerfile in dir 1
define app-attach
$(call INFO,app-attach,$(1)$(comma))
$(call docker-file,$(1))
$(foreach dockerfile,$(DOCKER_FILE),
$(call app-docker,$(dockerfile))
$(call docker-attach)
$(if $(APP_COMPOSE_FILE),
$(call docker-compose,logs -f $(if $(filter $(SERVICE),$(SERVICES)),$(SERVICE)))
, $(call docker-file,$(1))
$(foreach dockerfile,$(DOCKER_FILE),
$(call app-docker,$(dockerfile))
$(call docker-attach)
)
)
endef
@ -16,38 +19,63 @@ 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))
$(eval APP_COMPOSE_FILE := $(COMPOSE_FILE))
$(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
define app-build
$(call INFO,app-build,$(1)$(comma))
$(call docker-file,$(1))
$(foreach dockerfile,$(DOCKER_FILE),
$(call app-docker,$(dockerfile))
$(call docker-build, $(dir $(dockerfile)), $(DOCKER_IMAGE), "" )
$(if $(APP_COMPOSE_FILE),
$(call docker-compose,build $(if $(filter $(SERVICE),$(SERVICES)),$(SERVICE)))
, $(call docker-file,$(1))
$(foreach dockerfile,$(DOCKER_FILE),
$(call app-docker,$(dockerfile))
$(call docker-build, $(dir $(dockerfile)), $(DOCKER_IMAGE), "" )
)
)
endef
# function app-clean: Remove docker images and volumes for each Dockerfile in dir 1
define app-clean
$(call INFO,app-clean,$(1)$(comma))
$(eval DOCKER_COMPOSE_DOWN_OPTIONS += --rmi all --volumes)
$(if $(APP_COMPOSE_FILE),
$(call docker-compose,down $(DOCKER_COMPOSE_DOWN_OPTIONS) $(if $(filter $(SERVICE),$(SERVICES)),$(SERVICE)))
, $(call docker-file,$(1))
$(foreach dockerfile,$(DOCKER_FILE),
$(call app-docker,$(dockerfile))
$(call docker-rm)
)
)
endef
# function app-config: Call docker-compose config with each docker-compose.yml in dir 1
define app-config
$(call INFO,app-config,$(1)$(comma))
$(call docker-compose,config)
$(if $(APP_COMPOSE_FILE),
$(call docker-compose,config)
, $(call WARNING,Unable to find a file docker-compose.yml in dir,$(APP_DIR)) \
)
endef
# function app-connect: Call docker exec $(DOCKER_SHELL) for each Dockerfile in dir 1
define app-connect
$(call INFO,app-connect,$(1)$(comma))
$(call docker-file,$(1))
$(foreach dockerfile,$(DOCKER_FILE),
$(call app-docker,$(dockerfile))
$(call docker-connect)
$(if $(APP_COMPOSE_FILE),
$(call docker-compose,exec $(or $(SERVICE),$(DOCKER_SERVICE)) $(DOCKER_SHELL))
, $(call docker-file,$(1))
$(foreach dockerfile,$(DOCKER_FILE),
$(call app-docker,$(dockerfile))
$(call docker-connect)
)
)
endef
@ -70,56 +98,66 @@ 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),
$(call docker-file,$(1))
$(foreach dockerfile,$(DOCKER_FILE),
$(call app-docker,$(dockerfile))
$(call docker-rm)
))
$(if $(APP_COMPOSE_FILE),
$(call docker-compose,down $(DOCKER_COMPOSE_DOWN_OPTIONS) $(if $(filter $(SERVICE),$(SERVICES)),$(SERVICE)))
, $(call docker-file,$(1))
$(foreach dockerfile,$(DOCKER_FILE),
$(call app-docker,$(dockerfile))
$(call docker-rm)
)
)
endef
# function app-exec: Call docker exec $(ARGS) for each Dockerfile in dir 1
define app-exec
$(call INFO,app-exec,$(1)$(comma) $(2))
$(call docker-file,$(1))
$(eval args := $(or $(2), $(ARGS)))
$(foreach dockerfile,$(DOCKER_FILE),
$(call app-docker,$(dockerfile))
$(call exec,$(args))
$(if $(APP_COMPOSE_FILE),
$(call docker-compose,exec $(or $(SERVICE),$(DOCKER_SERVICE)) $(args))
, $(call docker-file,$(1))
$(foreach dockerfile,$(DOCKER_FILE),
$(call app-docker,$(dockerfile))
$(call exec,$(args))
)
)
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),
$(call docker-file,$(1))
$(foreach dockerfile,$(DOCKER_FILE),
$(call app-docker,$(dockerfile))
$(call docker-logs)
))
$(if $(APP_COMPOSE_FILE),
$(call docker-compose,logs $(DOCKER_COMPOSE_LOGS_OPTIONS) $(if $(filter $(SERVICE),$(SERVICES)),$(SERVICE)))
, $(call docker-file,$(1))
$(foreach dockerfile,$(DOCKER_FILE),
$(call app-docker,$(dockerfile))
$(call docker-logs)
)
)
endef
# function app-ps: Call docker ps for each Dockerfile in dir 1
define app-ps
$(call INFO,app-ps,$(1)$(comma))
$(call docker-file,$(1))
$(foreach dockerfile,$(DOCKER_FILE),
$(call app-docker,$(dockerfile))
$(eval DOCKERS += $(DOCKER_NAME))
$(if $(APP_COMPOSE_FILE),
$(call docker-compose,ps $(if $(filter $(SERVICE),$(SERVICES)),$(SERVICE)))
, $(call docker-file,$(1))
$(foreach dockerfile,$(DOCKER_FILE),
$(call app-docker,$(dockerfile))
$(eval DOCKERS += $(DOCKER_NAME))
)
$(RUN) docker ps $(patsubst %,-f name=%,$(DOCKERS)) 2>/dev/null
)
$(RUN) docker ps $(patsubst %,-f name=%,$(DOCKERS)) 2>/dev/null
endef
# function app-rebuild: Call app-build with DOCKER_BUILD_CACHE=false
@ -129,17 +167,65 @@ define app-rebuild
$(call app-build,$(1))
endef
# function app-restart: Call app-stop and app-start
define app-restart
$(call INFO,app-restart,$(1)$(comma))
$(if $(APP_COMPOSE_FILE),
$(call docker-compose,restart $(if $(filter $(SERVICE),$(SERVICES)),$(SERVICE)))
, $(call app-stop,$(1)) # NEED FIX
$(call app-start,$(1))
)
endef
# function app-run: Call docker-run for each Dockerfile in dir 1 with args 2
define app-run
$(call INFO,app-run,$(1)$(comma) $(2))
$(call docker-file,$(1))
$(eval args := $(or $(2), $(ARGS)))
$(eval DOCKER_RUN_OPTIONS += -it)
$(foreach dockerfile,$(DOCKER_FILE),
$(call app-docker,$(dockerfile))
$(if $(shell docker images -q $(DOCKER_IMAGE) 2>/dev/null),
$(call docker-run,$(DOCKER_IMAGE),$(args))
, $(call ERROR,Unable to find docker image,$(DOCKER_IMAGE))
$(if $(APP_COMPOSE_FILE),
$(call docker-compose,run $(DOCKER_RUN_OPTIONS) $(or $(SERVICE),$(DOCKER_SERVICE)) $(args))
, $(call docker-file,$(1))
$(foreach dockerfile,$(DOCKER_FILE),
$(call app-docker,$(dockerfile))
$(if $(shell docker images -q $(DOCKER_IMAGE) 2>/dev/null),
$(call docker-run,$(DOCKER_IMAGE),$(args))
, $(call ERROR,Unable to find docker image,$(DOCKER_IMAGE))
)
)
)
endef
# function app-scale: Call docker-compose scale in dir 1
define app-scale
$(call INFO,app-scale,$(1)$(comma))
$(if $(APP_COMPOSE_FILE),
$(call docker-compose,up $(DOCKER_COMPOSE_UP_OPTIONS) --scale $(or $(SERVICE),$(DOCKER_SERVICE))=$(NUM))
, $(call WARNING,Unable to find a file docker-compose.yml in dir,$(APP_DIR)) \
)
endef
# function app-start: Call docker start for each Dockerfile in dir 1
define app-start
$(call INFO,app-start,$(1)$(comma))
$(if $(APP_COMPOSE_FILE),
$(call docker-compose,start $(if $(filter $(SERVICE),$(SERVICES)),$(SERVICE)))
, $(call docker-file,$(1))
$(foreach dockerfile,$(DOCKER_FILE),
$(call app-docker,$(dockerfile))
$(call docker-start)
)
)
endef
# function app-stop: Call docker stop for each Dockerfile in dir 1
define app-stop
$(call INFO,app-stop,$(1)$(comma))
$(if $(APP_COMPOSE_FILE),
$(call docker-compose,stop $(if $(filter $(SERVICE),$(SERVICES)),$(SERVICE)))
, $(call docker-file,$(1))
$(foreach dockerfile,$(DOCKER_FILE),
$(call app-docker,$(dockerfile))
$(call docker-stop)
)
)
endef
@ -147,21 +233,23 @@ endef
# function app-up: Call docker-run (-d) for each Dockerfile in dir 1
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 $(shell docker ps -q -f name=$(DOCKER_NAME) 2>/dev/null),
$(call INFO,docker $(DOCKER_NAME) already running)
, $(call app-run,$(1))
))
$(eval DOCKER_RUN_OPTIONS := -d)
$(if $(APP_COMPOSE_FILE),
$(call docker-compose,up $(DOCKER_COMPOSE_UP_OPTIONS) $(if $(filter $(SERVICE),$(SERVICES)),$(SERVICE)))
, $(if $(shell docker ps -q -f name=$(DOCKER_NAME) 2>/dev/null),
$(call INFO,docker $(DOCKER_NAME) already running)
, $(call app-run,$(1))
)
)
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,8 +1,9 @@
DOCKER_DIR ?= docker
DOCKER_ENV_ARGS ?= $(docker_env_args)
DOCKER_EXEC_OPTIONS ?=
DOCKER_GID ?= $(call gid,docker)
DOCKER_IMAGE ?= $(USER_DOCKER_IMAGE)
DOCKER_MACHINE ?= $(shell docker run --rm alpine uname -m 2>/dev/null)
DOCKER_MACHINE := $(shell docker run --rm alpine uname -m 2>/dev/null)
DOCKER_NAME ?= $(USER_DOCKER_NAME)
DOCKER_NETWORK ?= $(if $(USER_STACK),$(USER),$(DOCKER_NETWORK_PRIVATE))
DOCKER_NETWORK_PRIVATE ?= $(USER)-$(ENV)
@ -15,7 +16,7 @@ DOCKER_RUN_NETWORK += --network $(DOCKER_NETWORK)
DOCKER_RUN_OPTIONS += --rm
DOCKER_RUN_VOLUME ?= $(patsubst %,-v %,$(DOCKER_VOLUME))
DOCKER_RUN_WORKDIR ?= $(if $(DOCKER_WORKDIR),-w $(DOCKER_WORKDIR))
DOCKER_SYSTEM ?= $(shell docker run --rm alpine uname -s 2>/dev/null)
DOCKER_SYSTEM := $(shell docker run --rm alpine uname -s 2>/dev/null)
DOCKER_VOLUME ?= /var/run/docker.sock:/var/run/docker.sock
DOCKER_WORKDIR ?= $(PWD)
ENV_VARS += DOCKER_MACHINE DOCKER_NETWORK DOCKER_NETWORK_PRIVATE DOCKER_NETWORK_PUBLIC DOCKER_SYSTEM HOST_COMPOSE_PROJECT_NAME HOST_COMPOSE_SERVICE_NAME HOST_DOCKER_REPOSITORY HOST_DOCKER_VOLUME HOST_GID HOST_UID USER_COMPOSE_PROJECT_NAME USER_COMPOSE_SERVICE_NAME USER_DOCKER_IMAGE USER_DOCKER_NAME USER_DOCKER_REPOSITORY USER_DOCKER_VOLUME
@ -158,15 +159,20 @@ 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))
)
endef
# function docker-exited: Print exited dockers matching DOCKER_NAME
define docker-exited
$(shell docker ps -q -f status=exited $(patsubst %,-f name=%,$(or $(1), ^$(DOCKER_NAME)$$, ^$)) 2>/dev/null)
endef
# function docker-running: Print running dockers matching DOCKER_NAME
define docker-running
$(shell docker ps -q $(patsubst %,-f name=%,$(or $(1), ^$(DOCKER_NAME)$$, ^$)) 2>/dev/null)
$(shell docker ps -q -f status=running $(patsubst %,-f name=%,$(or $(1), ^$(DOCKER_NAME)$$, ^$)) 2>/dev/null)
endef
# function docker-rm: Remove docker 1
@ -179,6 +185,29 @@ define docker-rm
$(RUN) docker rm -f $(rm)
endef
# function docker-start: Start docker 1
define docker-start
$(call INFO,docker-start,$(1)$(comma))
$(eval start := $(or $(1),$(DOCKER_NAME)))
$(if $(call docker-running,^$(start)$),
$(call WARNING,docker,$(start),is already running)
, $(if $(call docker-exited,^$(start)$),
$(RUN) docker start $(start)
, $(call WARNING,Unable to find docker,$(start),in state exited)
)
)
endef
# function docker-stop: Stop docker 1
define docker-stop
$(call INFO,docker-stop,$(1)$(comma))
$(eval stop := $(or $(1),$(DOCKER_NAME)))
$(if $(call docker-running,^$(stop)$),
$(RUN) docker stop $(stop)
, $(call WARNING,docker,$(stop),is not running)
)
endef
# function docker-volume-copy: Copy files from a docker volume to another
define docker-volume-copy
$(call INFO,docker-volume-copy,$(1)$(comma) $(2))

View File

@ -78,7 +78,7 @@ INSTALL_CMDS ?= APK_INSTALL APT_INSTALL
$(foreach cmd,$(INSTALL_CMDS),$(if $(CMD_$(cmd)),$(eval INSTALL_CMD ?= $(CMD_$(cmd)))))
LOG_LEVEL ?= $(if $(DEBUG),debug,$(if $(VERBOSE),info,error))
MAIL ?= $(GIT_AUTHOR_EMAIL)
MAKE_ARGS ?= $(foreach var,$(MAKE_VARS),$(if $($(var)),$(var)='$($(var))'))
MAKE_ARGS = $(foreach var,$(MAKE_VARS),$(if $($(var)),$(var)='$($(var))'))
MAKE_SUBDIRS ?= $(if $(filter myos,$(MYOS)),monorepo,$(if $(APP),apps $(foreach type,$(APP_LOAD),$(if $(wildcard $(MAKE_DIR)/apps/$(type)),apps/$(type)))))
MAKE_CMD_ARGS ?= $(foreach var,$(MAKE_CMD_VARS),$(var)='$($(var))')
MAKE_CMD_VARS ?= $(strip $(foreach var, $(filter-out .VARIABLES,$(.VARIABLES)), $(if $(filter command\ line,$(origin $(var))),$(var))))
@ -90,7 +90,7 @@ MAKE_OLDFILE ?= $@
MAKE_TARGETS ?= $(filter-out $(.VARIABLES),$(shell $(MAKE) -qp 2>/dev/null |awk -F':' '/^[a-zA-Z0-9][^$$\#\/\t=]*:([^=]|$$)/ {print $$1}' 2>/dev/null |sort -u))
MAKE_UNIXTIME_START := $(shell date -u +'%s' 2>/dev/null)
MAKE_UNIXTIME_CURRENT = $(shell date -u "+%s" 2>/dev/null)
MAKE_VARS ?= ENV DOCKER_COMPOSE DOCKER_MACHINE DOCKER_SYSTEM
MAKE_VARS := ENV COMPOSE_FILE DOCKER_COMPOSE DOCKER_MACHINE DOCKER_SERVICES DOCKER_SYSTEM
MAKECMDARGS ?= apps-install install-app
MONOREPO ?= $(if $(filter myos,$(MYOS)),$(notdir $(CURDIR)),$(if $(APP),$(notdir $(realpath $(CURDIR)/..))))
MONOREPO_DIR ?= $(if $(MONOREPO),$(if $(filter myos,$(MYOS)),$(realpath $(CURDIR)),$(if $(APP),$(realpath $(CURDIR)/..))))

View File

@ -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

View File

@ -18,7 +18,7 @@ contexts: $(foreach var,$(CONTEXT),context-$(var))
# target context-% print-%: Print % value
.PHONY: context-% print-%
context-% print-%:
context-% print-%: stack
@printf "${COLOR_HIGHLIGHT}%-37s${COLOR_RESET}" $*
@printf "${COLOR_VALUE}"
@$(call PRINTF,$($*))

View File

@ -12,15 +12,15 @@ MAKE_LATEST := $(MAKE_DIR)/end.mk
## it includes $(MAKE_FIRST)
include $(wildcard $(MAKE_FIRST))
## it includes $(MAKE_DIR)/*/def.mk $(MAKE_DIR)/*/def.*.mk
## it includes $(MAKE_DIR)/$(MAKE_SUBDIRS)/def.mk $(MAKE_DIR)/$(MAKE_SUBDIRS)/def.*.mk
include $(foreach subdir,$(MAKE_SUBDIRS),$(wildcard $(MAKE_DIR)/$(subdir)/def.mk $(MAKE_DIR)/$(subdir)/def.*.mk))
## it includes def.mk def.*.mk */def.mk */def.*.mk if not myos nor monorepo
## if not in $(MYOS) nor $(MONOREPO), it includes def.mk def.*.mk */def.mk */def.*.mk
include $(if $(filter-out . myos,$(MYOS)),$(wildcard def.mk def.*.mk */def.mk */def.*.mk))
## it includes $(MAKE_DIR)/*.mk
include $(filter-out $(wildcard $(MAKE_FILE) $(MAKE_FIRST) $(MAKE_LATEST)),$(wildcard $(MAKE_DIR)/*.mk))
## it includes $(MAKE_DIR)/*/*.mk
## it includes $(MAKE_DIR)/$(MAKE_SUBDIRS)/*.mk
include $(foreach subdir,$(MAKE_SUBDIRS),$(filter-out $(wildcard $(MAKE_DIR)/$(subdir)/def.mk $(MAKE_DIR)/$(subdir)/def.*.mk),$(wildcard $(MAKE_DIR)/$(subdir)/*.mk)))
## it includes *.mk */*.mk if not myos nor monorepo, stack/*.mk if myos
## if not in $(MYOS) nor $(MONOREPO), it includes *.mk */*.mk, else stack/*.mk if in $(MYOS)
include $(if $(filter-out myos,$(MYOS)),$(if $(filter-out .,$(MYOS)),$(filter-out $(wildcard def.mk def.*.mk */def.mk */def.*.mk),$(wildcard *.mk */*.mk)),$(wildcard stack/*.mk stack/*/*.mk)))
## it includes $(MAKE_LATEST)
include $(wildcard $(MAKE_LATEST))

View File

@ -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: