first apps :)
This commit is contained in:
@@ -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))
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
+8
-1
@@ -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
|
||||
|
||||
+11
-10
@@ -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
|
||||
|
||||
+2
-1
@@ -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))
|
||||
)
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user