move docker and stack dir
This commit is contained in:
+4
-4
@@ -121,8 +121,8 @@ logs: docker-stack-logs ## Display application dockers logs
|
||||
|
||||
# target ps: List application dockers
|
||||
# on local host
|
||||
.PHONY: ps
|
||||
ps: docker-stack-ps ## List application dockers
|
||||
.PHONY: ps status
|
||||
ps status: docker-stack-ps ## List application dockers
|
||||
|
||||
# target rebuild: Rebuild application docker images
|
||||
# on local host
|
||||
@@ -137,8 +137,8 @@ rebuild@%:
|
||||
|
||||
# target recreate: Recreate application dockers
|
||||
# on local host
|
||||
.PHONY: recreate
|
||||
recreate: docker-stack-recreate app-start ## Recreate application dockers
|
||||
.PHONY: recreate reload
|
||||
recreate reload: docker-stack-recreate app-start ## Recreate application dockers
|
||||
|
||||
# target reinstall: Fire clean, Call .env target, Call install target
|
||||
# on local host
|
||||
|
||||
+16
-11
@@ -28,7 +28,7 @@ DOCKER_BUILD_CACHE ?= true
|
||||
DOCKER_BUILD_LABEL ?= $(foreach var,$(filter $(BUILD_LABEL_VARS),$(MAKE_FILE_VARS)),$(if $($(var)),--label $(var)='$($(var))'))
|
||||
DOCKER_BUILD_NO_CACHE ?= false
|
||||
DOCKER_BUILD_TARGET ?= $(if $(filter $(ENV),$(DOCKER_BUILD_TARGETS)),$(ENV),$(DOCKER_BUILD_TARGET_DEFAULT))
|
||||
DOCKER_BUILD_TARGET_DEFAULT ?= master
|
||||
DOCKER_BUILD_TARGET_DEFAULT ?=
|
||||
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 $(call verle,$(COMPOSE_VERSION),$(shell docker compose version --short 2>/dev/null)) && printf 'docker $(DOCKER_ARGS) compose\n'),$(shell $(call verle,$(COMPOSE_VERSION),$(shell docker-compose version --short 2>/dev/null)) && printf 'docker-compose\n'))
|
||||
@@ -42,7 +42,7 @@ DOCKER_COMPOSE_RUN_OPTIONS ?= --rm $(DOCKER_COMPOSE_RUN_ENTRYPOINT) $(DOCKE
|
||||
DOCKER_COMPOSE_RUN_WORKDIR ?= $(if $(DOCKER_COMPOSE_WORKDIR),-w $(DOCKER_COMPOSE_WORKDIR))
|
||||
DOCKER_COMPOSE_SERVICE_NAME ?= $(subst _,-,$(DOCKER_COMPOSE_PROJECT_NAME))
|
||||
DOCKER_COMPOSE_UP_OPTIONS ?= -d
|
||||
DOCKER_IMAGE_TAG ?= $(if $(filter true,$(DEPLOY)),$(if $(filter $(ENV),$(ENV_DEPLOY)),$(VERSION)),$(if $(DRONE_BUILD_NUMBER),$(DRONE_BUILD_NUMBER),$(ENV)))
|
||||
DOCKER_IMAGE_TAG ?= $(if $(filter true,$(DEPLOY)),$(if $(filter $(ENV),$(ENV_DEPLOY)),$(VERSION)),$(if $(DRONE_BUILD_NUMBER),$(DRONE_BUILD_NUMBER),latest))
|
||||
DOCKER_IMAGES ?= $(patsubst %/,%,$(patsubst docker/%,%,$(dir $(wildcard docker/*/Dockerfile))))
|
||||
DOCKER_PLUGIN ?= rexray/s3fs:latest
|
||||
DOCKER_PLUGIN_ARGS ?= $(foreach var,$(DOCKER_PLUGIN_VARS),$(if $(DOCKER_PLUGIN_$(var)),$(var)='$(DOCKER_PLUGIN_$(var))'))
|
||||
@@ -71,23 +71,27 @@ endif
|
||||
# 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 file_path := $(or $(1),. $(APP_DOCKER_DIR)))
|
||||
$(eval file_path := $(or $(1),$(APP_DOCKER_DIR)))
|
||||
$(eval file_name := $(or $(2),$(DOCKER_COMPOSE_FILE)))
|
||||
$(eval file_suffix := $(or $(3),$(COMPOSE_FILE_SUFFIX)))
|
||||
$(eval file_extension := $(or $(4),yml yaml))
|
||||
$(eval COMPOSE_FILE += $(wildcard $(foreach e,$(file_extension),$(foreach n,$(file_name),$(foreach p,$(file_path),$(p)/$(n).$(e) $(p)/$(n).$(ENV).$(e) $(p)/$(ENV)/$(n).$(e) $(p)/$(ENV)/$(n).$(ENV).$(e) $(foreach s,$(file_suffix),$(p)/$(n).$(s).$(e) $(p)/$(n).$(s).$(ENV).$(e)))))))
|
||||
$(call debug,COMPOSE_FILE)
|
||||
endef
|
||||
# function docker-build: Build docker image
|
||||
# function docker-build: Build docker image from dockerfile 1 for service 2 with tag 3 at target 4
|
||||
define docker-build
|
||||
$(call INFO,docker-build,$(1)$(comma) $(2)$(comma) $(3))
|
||||
$(eval build_path := $(patsubst $(DOCKER_BUILD_PATH)/%,%,$(patsubst %/,%,$(1))))
|
||||
$(eval build_service := $(subst .,,$(call LOWERCASE,$(lastword $(subst /, ,$(build_path))))))
|
||||
$(eval build_image_tag := $(or $(2),$(DOCKER_REPOSITORY)/$(build_service):$(DOCKER_IMAGE_TAG)))
|
||||
$(eval build_target := $(subst ",,$(subst ',,$(or $(3),$(DOCKER_BUILD_TARGET)))))
|
||||
$(call INFO,docker-build,$(1)$(comma) $(2)$(comma) $(3)$(comma) $(4))
|
||||
$(eval build_path := $(firstword $(subst $(DOCKER_DIR_NAME), ,$(1))))
|
||||
$(eval build_dir := $(patsubst $(or $(addsuffix /,$(DOCKER_BUILD_PATH)),$(build_path))%,%,$(patsubst %/,%,$(1))))
|
||||
$(eval build_service := $(or $(2),$(subst .,,$(call LOWERCASE,$(lastword $(subst /, ,$(build_dir)))))))
|
||||
$(eval build_image_tag := $(DOCKER_REPOSITORY)/$(if $(findstring :,$(build_service)),$(build_service),$(build_service):$(or $(3),$(DOCKER_IMAGE_TAG))))
|
||||
$(eval build_target := $(subst ",,$(subst ',,$(or $(4),$(DOCKER_BUILD_TARGET)))))
|
||||
$(eval image_id := $(shell docker images -q $(build_image_tag) 2>/dev/null))
|
||||
$(eval build_image := $(or $(filter false,$(DOCKER_BUILD_CACHE)),$(if $(image_id),,true)))
|
||||
$(if $(build_image),$(RUN) docker build $(DOCKER_BUILD_ARGS) --build-arg DOCKER_BUILD_PATH="$(build_path)" $(DOCKER_BUILD_LABEL) --build_image_tag $(build_image_tag) $(if $(build_target),--build_target $(build_target)) -f $(build_path)/Dockerfile $(or $(DOCKER_BUILD_PATH),.),$(call INFO,docker image $(build_image_tag) has id $(image_id)))
|
||||
$(call debug,build_path build_dir build_image_tag)
|
||||
$(if $(build_image),\
|
||||
$(RUN) docker build $(DOCKER_BUILD_ARGS) --build-arg DOCKER_BUILD_DIR="$(build_dir)" $(DOCKER_BUILD_LABEL) --tag $(build_image_tag) $(if $(build_target),--target $(build_target)) -f $(build_dir)/Dockerfile $(or $(DOCKER_BUILD_PATH),$(build_path),.) \
|
||||
,$(call INFO,docker image $(build_image_tag) has id $(image_id)))
|
||||
endef
|
||||
# function docker-commit: Commit docker image
|
||||
define docker-commit
|
||||
@@ -106,7 +110,7 @@ define docker-compose
|
||||
$(if $(DOCKER_COMPOSE),
|
||||
$(call env-exec,$(RUN) $(DOCKER_COMPOSE) $(DOCKER_COMPOSE_ARGS) $(patsubst %,-f %,$(COMPOSE_FILE)) -p $(COMPOSE_PROJECT_NAME) $(1))
|
||||
, $(if $(DOCKER_RUN),
|
||||
$(call docker-build,$(MYOS)/docker/compose,docker/compose:$(COMPOSE_VERSION))
|
||||
$(call docker-build,$(call docker-path,compose),docker/compose,$(COMPOSE_VERSION))
|
||||
$(call docker-run,docker/compose:$(COMPOSE_VERSION) $(DOCKER_COMPOSE_ARGS),$(patsubst %,-f %,$(COMPOSE_FILE)) -p $(COMPOSE_PROJECT_NAME) $(1))
|
||||
, $(call env-exec,$(RUN) docker-compose $(DOCKER_COMPOSE_ARGS) $(patsubst %,-f %,$(COMPOSE_FILE)) -p $(COMPOSE_PROJECT_NAME) $(1))
|
||||
)
|
||||
@@ -153,6 +157,7 @@ define docker-stack-update
|
||||
$(eval stack_name := $(firstword $(subst :, ,$(stack_update))))
|
||||
$(eval stack_version := $(or $(2),$(if $(findstring :,$(stack_update)),$(lastword $(subst :, ,$(stack_update))),latest)))
|
||||
$(eval stack_path := $(patsubst %/,%,$(or $(3),$(foreach stack_dir,$(STACK_DIR),$(if $(findstring /,$(1)),$(if $(wildcard $(stack_dir)/$(1) $(stack_dir)/$(1).yml),$(stack_dir)/$(if $(findstring .yml,$(1)),$(dir $(1)),$(if $(wildcard $(stack_dir)/$(1).yml),$(dir $(1)),$(1))),$(if $(wildcard $(stack_dir)/$(stackz)/$(1) $(stack_dir)/$(stackz)/$(1).yml),$(stack_dir)/$(stackz)/$(if $(findstring .yml,$(1)),$(dir $(1)),$(if $(wildcard $(stack_dir)/$(stackz)/$(1).yml),$(dir $(1)),$(1))),$(dir $(1)))))),$(foreach stack_dir,$(STACK_DIR),$(firstword $(wildcard $(stack_dir)/$(stackz)/$(stack_name) $(stack_dir)/$(stackz) $(stack_dir)/$(stack_name)))))))
|
||||
$(call debug,stack_path)
|
||||
$(call compose-file,$(stack_path),docker-compose $(stack_name),$(COMPOSE_FILE_SUFFIX) $(stack_version))
|
||||
$(if $(wildcard $(stack_path)/.env.dist),$(call .env,,$(stack_path)/.env.dist,$(wildcard $(CONFIG)/$(ENV)/$(APP)/.env $(stack_path)/.env.$(ENV) .env)))
|
||||
$(call env-vars,$(COMPOSE_FILE))
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
APP_DIR ?= $(CURDIR)
|
||||
APP_DOCKER_DIR ?= $(DOCKER_DIR)
|
||||
APP_DOMAIN ?= $(patsubst %,$(APP_DOMAIN_PREFIX)%,$(DOMAIN))
|
||||
APP_DOMAIN_PREFIX ?= $(if $(HOST_STACK),,$(if $(filter true,$(APP_HOST_MULTI_USER)),$(USER).))
|
||||
APP_HOST ?= $(patsubst %,$(APP_HOST_PREFIX)%,$(if $(filter true,$(APP_HOST_MULTI_APP)),$(APP_NAME).)$(APP_DOMAIN))$(if $(HOST_STACK),$(if $(HOST_LB),$(space)$(DOMAIN)))
|
||||
|
||||
+15
-3
@@ -9,9 +9,13 @@ docker-build: docker-image-myos
|
||||
# target docker-build-%: Call docker-build for each Dockerfile in docker/% folder
|
||||
.PHONY: 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)))),""))
|
||||
$(if $(findstring :,$*), \
|
||||
$(eval DOCKER_FILE := $(wildcard $(DOCKER_DIR:%=%/$(subst :,/,$*)/Dockerfile) $(DOCKER_DIR:%=%/*/$(subst :,/,$*)/Dockerfile))) \
|
||||
,$(eval DOCKER_FILE := $(wildcard $(DOCKER_DIR:%=%/$*/Dockerfile) $(DOCKER_DIR:%=%/$*/*/Dockerfile) $(DOCKER_DIR:%=%/*/$*/Dockerfile))))
|
||||
$(call debug,DOCKER_FILE)
|
||||
$(foreach dockerfile,$(DOCKER_FILE), \
|
||||
$(eval docker_service := $(patsubst %/,%,$(lastword $(subst $(DOCKER_DIR_NAME)/, ,$(dir $(dockerfile)))))) \
|
||||
$(call docker-build,$(dir $(dockerfile)),$(if $(findstring :,$*),$(call pop,$(docker_service)),$(docker_service)),$(if $(findstring :,$*),$(lastword $(subst /, ,$(dir $(dockerfile))))))||:)
|
||||
|
||||
# target docker-commit: Call docker-commit for each SERVICES
|
||||
.PHONY: docker-commit
|
||||
@@ -164,6 +168,10 @@ docker-network-rm-%:
|
||||
||: ; \
|
||||
fi
|
||||
|
||||
.PHONY: docker-path-%
|
||||
docker-path-%:
|
||||
echo $(call docker-path,$*)
|
||||
|
||||
# target docker-plugin-install: Run 'docker plugin install DOCKER_PLUGIN_OPTIONS DOCKER_PLUGIN'
|
||||
.PHONY: docker-plugin-install
|
||||
docker-plugin-install:
|
||||
@@ -264,3 +272,7 @@ docker-volume-rm: docker-volume-rm-$(COMPOSE_PROJECT_NAME)
|
||||
.PHONY: docker-volume-rm-%
|
||||
docker-volume-rm-%:
|
||||
docker volume ls |awk '$$2 ~ /^$*/ {print $$2}' |sort -u |while read volume; do $(RUN) docker volume rm $$volume; done
|
||||
|
||||
.PHONY: stack-path-%
|
||||
stack-path-%:
|
||||
echo $(call stack-path,$*)
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
# target ssh: Call ssh-connect ARGS or SHELL
|
||||
.PHONY: ssh
|
||||
ssh: ssh-get-PrivateIpAddress-$(SERVER_NAME) ## Connect to first remote host
|
||||
ssh: # ssh-get-PrivateIpAddress-$(SERVER_NAME) ## Connect to first remote host
|
||||
$(call ssh-connect,$(AWS_INSTANCE_IP),$(if $(ARGS),$(ARGS),$(SHELL)))
|
||||
|
||||
# target ssh-add: Fire ssh-key and ssh-add file SSH_PRIVATE_KEYS in folder SSH_DIR
|
||||
@@ -15,7 +15,7 @@ ssh-add: ssh-key
|
||||
|
||||
# target ssh-connect: Call ssh-connect make connect SERVICE
|
||||
.PHONY: ssh-connect
|
||||
ssh-connect: ssh-get-PrivateIpAddress-$(SERVER_NAME)
|
||||
ssh-connect: # ssh-get-PrivateIpAddress-$(SERVER_NAME)
|
||||
$(call ssh-connect,$(AWS_INSTANCE_IP),make connect COMPOSE_PROJECT_NAME=$(COMPOSE_PROJECT_NAME) ENV=$(ENV) $(if $(SERVICE),SERVICE=$(SERVICE)))
|
||||
|
||||
# target ssh-del: ssh-add -d file SSH_PRIVATE_KEYS in folder SSH_DIR
|
||||
@@ -26,7 +26,7 @@ ssh-del:
|
||||
|
||||
# target ssh-exec: Call ssh-exec make exec SERVICE ARGS
|
||||
.PHONY: ssh-exec
|
||||
ssh-exec: ssh-get-PrivateIpAddress-$(SERVER_NAME)
|
||||
ssh-exec: # ssh-get-PrivateIpAddress-$(SERVER_NAME)
|
||||
$(call ssh-exec,$(AWS_INSTANCE_IP),make exec COMPOSE_PROJECT_NAME=$(COMPOSE_PROJECT_NAME) ENV=$(ENV) $(if $(SERVICE),SERVICE=$(SERVICE)) $(if $(ARGS),ARGS='\''"$(ARGS)"'\''))
|
||||
|
||||
# target ssh-get-PrivateIpAddress-%: Fire aws-ec2-get-instances-PrivateIpAddress-%
|
||||
@@ -43,5 +43,5 @@ endif
|
||||
|
||||
# target ssh-run: Call ssh-run make run SERVICE ARGS
|
||||
.PHONY: ssh-run
|
||||
ssh-run: ssh-get-PrivateIpAddress-$(SERVER_NAME)
|
||||
ssh-run: # ssh-get-PrivateIpAddress-$(SERVER_NAME)
|
||||
$(call ssh-exec,$(AWS_INSTANCE_IP),make run $(if $(SERVICE),SERVICE=$(SERVICE)) $(if $(ARGS),ARGS='\''"$(ARGS)"'\''))
|
||||
|
||||
+4
-3
@@ -15,12 +15,13 @@ $(APP) $(APP_DIR):
|
||||
## 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-%: APP_DIR := $(RELATIVE)$(APP)
|
||||
app-%: APP_DIR := $(or $(WORKDIR), $(RELATIVE)$(APP))
|
||||
app-%: $(APP_DIR)
|
||||
$(eval APP_REPOSITORY_URL :=)
|
||||
$(eval COMPOSE_FILE :=)
|
||||
$(eval STACK :=)
|
||||
$(eval app := $(subst -$(lastword $(subst -, ,$*)),,$*))
|
||||
$(eval app_dir := $(or $(WORKDIR), $(RELATIVE)$(app)))
|
||||
$(eval command := $(lastword $(subst -, ,$*)))
|
||||
$(eval include $(wildcard $(foreach stack_dir,$(STACK_DIR),$(stack_dir)/$(app).mk $(stack_dir)/$(app)/*.mk)))
|
||||
$(foreach var,$(filter $(call UPPERCASE,$(app))_%,$(MAKE_FILE_VARS)), \
|
||||
@@ -28,7 +29,7 @@ app-%: $(APP_DIR)
|
||||
$(eval $(subst $(call UPPERCASE,$(app))_,APP_,$(var)) := $($(var))) \
|
||||
) \
|
||||
)
|
||||
$(if $(wildcard $(RELATIVE)$(app)), \
|
||||
$(if $(wildcard $(app_dir)), \
|
||||
$(if $(filter app-$(command),$(.VARIABLES)), \
|
||||
$(call app-bootstrap,$(app)) \
|
||||
$(call app-$(command)) \
|
||||
@@ -43,7 +44,7 @@ app-%: $(APP_DIR)
|
||||
$(if $(APP_REPOSITORY_URL), \
|
||||
$(call app-install) \
|
||||
$(call app-bootstrap) \
|
||||
,$(call WARNING,Unable to find app,$(app),in dir,$(RELATIVE)$(app)) \
|
||||
,$(call WARNING,Unable to find app,$(app),in dir,$(app_dir)) \
|
||||
) \
|
||||
)
|
||||
|
||||
|
||||
+25
-12
@@ -5,7 +5,7 @@ define app-attach
|
||||
$(call INFO,app-attach,$(1)$(comma))
|
||||
$(if $(APP_COMPOSE_FILE),
|
||||
$(call docker-compose,logs -f $(if $(filter $(SERVICE),$(SERVICES)),$(SERVICE)))
|
||||
, $(call docker-file,$(1))
|
||||
, $(call app-docker-file,$(1))
|
||||
$(foreach dockerfile,$(DOCKER_FILE),
|
||||
$(call app-docker,$(dockerfile))
|
||||
$(call docker-attach)
|
||||
@@ -22,7 +22,7 @@ define app-bootstrap
|
||||
$(eval COMPOSE_PROJECT_NAME := $(or $(DOCKER_COMPOSE_PROJECT_NAME),$(subst .,,$(call LOWERCASE,$(USER)-$(APP_NAME)-$(ENV)$(addprefix -,$(subst /,,$(subst -,,$(APP_PATH))))))))
|
||||
$(eval COMPOSE_SERVICE_NAME := $(or $(DOCKER_COMPOSE_SERVICE_NAME),$(subst _,-,$(COMPOSE_PROJECT_NAME))))
|
||||
$(eval DOCKER_BUILD_PATH := $(APP_DIR))
|
||||
$(call compose-file,$(APP_DIR) $(APP_DIR)/$(or $(APP_DOCKER_DIR),$(DOCKER_DIR)),docker-compose)
|
||||
$(call compose-file,$(APP_DOCKER_DIR:%=$(APP_DIR)/%))
|
||||
$(call compose-file,$(MYOS_STACK),$(MYOS_STACK_FILE))
|
||||
$(eval APP_COMPOSE_FILE ?= $(COMPOSE_FILE))
|
||||
$(call docker-stack,$(APP))
|
||||
@@ -34,7 +34,7 @@ define app-build
|
||||
$(call INFO,app-build,$(1)$(comma))
|
||||
$(if $(APP_COMPOSE_FILE),
|
||||
$(call docker-compose,build $(if $(filter $(SERVICE),$(SERVICES)),$(SERVICE)))
|
||||
, $(call docker-file,$(1))
|
||||
, $(call app-docker-file,$(1))
|
||||
$(foreach dockerfile,$(DOCKER_FILE),
|
||||
$(call app-docker,$(dockerfile))
|
||||
$(call docker-build, $(dir $(dockerfile)), $(DOCKER_IMAGE), "" )
|
||||
@@ -48,7 +48,7 @@ define app-clean
|
||||
$(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))
|
||||
, $(call app-docker-file,$(1))
|
||||
$(foreach dockerfile,$(DOCKER_FILE),
|
||||
$(call app-docker,$(dockerfile))
|
||||
$(call docker-rm)
|
||||
@@ -70,7 +70,7 @@ define app-connect
|
||||
$(call INFO,app-connect,$(1)$(comma))
|
||||
$(if $(APP_COMPOSE_FILE),
|
||||
$(call docker-compose,exec $(or $(SERVICE),$(DOCKER_SERVICE)) $(DOCKER_SHELL))
|
||||
, $(call docker-file,$(1))
|
||||
, $(call app-docker-file,$(1))
|
||||
$(foreach dockerfile,$(DOCKER_FILE),
|
||||
$(call app-docker,$(dockerfile))
|
||||
$(call docker-connect)
|
||||
@@ -94,12 +94,25 @@ define app-docker
|
||||
)
|
||||
endef
|
||||
|
||||
# function app-docker-file: eval DOCKER_FILE in dir 1 or APP_DIR
|
||||
define app-docker-file
|
||||
$(call INFO,app-docker-file,$(1))
|
||||
$(eval dir := $(or $(1),$(APP_DIR)))
|
||||
$(eval DOCKER_FILE := $(wildcard $(dir)/$(DOCKER_DIR_NAME)/*/Dockerfile $(dir)/$(DOCKER_DIR_NAME)/Dockerfile $(dir)/Dockerfile))
|
||||
$(if $(DOCKER_FILE),
|
||||
, $(eval DOCKER_FILE := $(wildcard $(dir)/*/Dockerfile $(dir)/*/*/Dockerfile $(dir)/*/*/*/Dockerfile))
|
||||
)
|
||||
$(if $(DOCKER_FILE),
|
||||
, $(call ERROR,Unable to find a,Dockerfile,in dir,$(dir))
|
||||
)
|
||||
endef
|
||||
|
||||
# function app-down: Call docker rm for each Dockerfile in dir 1
|
||||
define app-down
|
||||
$(call INFO,app-down,$(1)$(comma))
|
||||
$(if $(APP_COMPOSE_FILE),
|
||||
$(call docker-compose,down $(DOCKER_COMPOSE_DOWN_OPTIONS) $(if $(filter $(SERVICE),$(SERVICES)),$(SERVICE)))
|
||||
, $(call docker-file,$(1))
|
||||
, $(call app-docker-file,$(1))
|
||||
$(foreach dockerfile,$(DOCKER_FILE),
|
||||
$(call app-docker,$(dockerfile))
|
||||
$(call docker-rm)
|
||||
@@ -113,7 +126,7 @@ define app-exec
|
||||
$(eval args := $(or $(2), $(ARGS)))
|
||||
$(if $(APP_COMPOSE_FILE),
|
||||
$(call docker-compose,exec $(or $(SERVICE),$(DOCKER_SERVICE)) $(args))
|
||||
, $(call docker-file,$(1))
|
||||
, $(call app-docker-file,$(1))
|
||||
$(foreach dockerfile,$(DOCKER_FILE),
|
||||
$(call app-docker,$(dockerfile))
|
||||
$(call exec,$(args))
|
||||
@@ -137,7 +150,7 @@ define app-logs
|
||||
$(call INFO,app-logs,$(1)$(comma) $(2))
|
||||
$(if $(APP_COMPOSE_FILE),
|
||||
$(call docker-compose,logs $(DOCKER_COMPOSE_LOGS_OPTIONS) $(if $(filter $(SERVICE),$(SERVICES)),$(SERVICE)))
|
||||
, $(call docker-file,$(1))
|
||||
, $(call app-docker-file,$(1))
|
||||
$(foreach dockerfile,$(DOCKER_FILE),
|
||||
$(call app-docker,$(dockerfile))
|
||||
$(call docker-logs)
|
||||
@@ -150,7 +163,7 @@ define app-ps
|
||||
$(call INFO,app-ps,$(1)$(comma))
|
||||
$(if $(APP_COMPOSE_FILE),
|
||||
$(call docker-compose,ps $(if $(filter $(SERVICE),$(SERVICES)),$(SERVICE)))
|
||||
, $(call docker-file,$(1))
|
||||
, $(call app-docker-file,$(1))
|
||||
$(foreach dockerfile,$(DOCKER_FILE),
|
||||
$(call app-docker,$(dockerfile))
|
||||
$(eval DOCKERS += $(DOCKER_NAME))
|
||||
@@ -183,7 +196,7 @@ define app-run
|
||||
$(eval DOCKER_RUN_OPTIONS += -it)
|
||||
$(if $(APP_COMPOSE_FILE),
|
||||
$(call docker-compose,run $(DOCKER_RUN_OPTIONS) $(or $(SERVICE),$(DOCKER_SERVICE)) $(args))
|
||||
, $(call docker-file,$(1))
|
||||
, $(call app-docker-file,$(1))
|
||||
$(foreach dockerfile,$(DOCKER_FILE),
|
||||
$(call app-docker,$(dockerfile))
|
||||
$(if $(shell docker images -q $(DOCKER_IMAGE) 2>/dev/null),
|
||||
@@ -208,7 +221,7 @@ 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))
|
||||
, $(call app-docker-file,$(1))
|
||||
$(foreach dockerfile,$(DOCKER_FILE),
|
||||
$(call app-docker,$(dockerfile))
|
||||
$(call docker-start)
|
||||
@@ -221,7 +234,7 @@ 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))
|
||||
, $(call app-docker-file,$(1))
|
||||
$(foreach dockerfile,$(DOCKER_FILE),
|
||||
$(call app-docker,$(dockerfile))
|
||||
$(call docker-stop)
|
||||
|
||||
+36
-16
@@ -1,4 +1,5 @@
|
||||
DOCKER_DIR ?= docker
|
||||
DOCKER_DIR ?= $(sort $(realpath $(wildcard $(patsubst %,%/docker,$(APP_DIR) $(SHARE_DIR) $(patsubst %,%/myos,$(SHARE_DIR))))))
|
||||
DOCKER_DIR_NAME ?= docker
|
||||
DOCKER_ENV_ARGS ?= $(docker_env_args)
|
||||
DOCKER_EXEC_OPTIONS ?=
|
||||
DOCKER_GID ?= $(call gid,docker)
|
||||
@@ -32,11 +33,13 @@ HOST_DOCKER_VOLUME ?= $(HOST_COMPOSE_PROJECT_NAME)
|
||||
HOST_GID ?= $(HOST_UID)
|
||||
HOST_UID ?= 123
|
||||
HOST_STACK ?= $(filter host,$(firstword $(subst /, ,$(STACK))))
|
||||
MYOS_STACK ?= $(foreach stack_dir,$(STACK_DIR),$(MYOS)/$(stack_dir)/myos)
|
||||
MYOS_STACK ?= $(wildcard $(foreach stack_dir,$(STACK_DIR),$(stack_dir)/myos))
|
||||
MYOS_STACK_FILE ?= networks volumes
|
||||
RESU_DOCKER_REPOSITORY ?= $(subst -,/,$(USER_COMPOSE_PROJECT_NAME))
|
||||
SHARE_DIR ?= . .. ~/.local/share /usr/local/share /usr/share
|
||||
STACK ?= $(APP)
|
||||
STACK_DIR ?= ../mystack
|
||||
STACK_DIR ?= $(sort $(realpath $(wildcard $(patsubst %,%/$(STACK_DIR_NAME),$(APP_DIR) $(SHARE_DIR) $(patsubst %,%/myos,$(SHARE_DIR))))))
|
||||
STACK_DIR_NAME ?= stack
|
||||
USER_COMPOSE_PROJECT_NAME ?= $(subst .,-,$(RESU))
|
||||
USER_COMPOSE_SERVICE_NAME ?= $(USER_COMPOSE_PROJECT_NAME)
|
||||
USER_DOCKER_IMAGE ?= $(USER_DOCKER_REPOSITORY):${DOCKER_IMAGE_TAG}
|
||||
@@ -152,6 +155,11 @@ define docker-exec
|
||||
)
|
||||
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-logs: Print logs of docker 1 or DOCKER_NAME
|
||||
define docker-logs
|
||||
$(call INFO,docker-logs,$(1))
|
||||
@@ -162,19 +170,18 @@ define docker-logs
|
||||
)
|
||||
endef
|
||||
|
||||
# function docker-file: eval DOCKER_FILE in dir 1 or APP_DIR
|
||||
define docker-file
|
||||
$(call INFO,docker-file,$(1)$(comma))
|
||||
$(eval dir := $(or $(1),$(APP_DIR)))
|
||||
$(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)
|
||||
# function docker-path: eval docker_path for docker 1 in DOCKER_DIR 2
|
||||
define docker-path
|
||||
$(strip
|
||||
$(call INFO,docker-path,$(1)$(comma) $(2))
|
||||
$(eval docker_name := $(or $(subst :,/,$(patsubst %:$(DOCKER_IMAGE_TAG),%,$(1))),myos))
|
||||
$(eval docker_dir := $(or $(2),$(DOCKER_DIR)))
|
||||
$(eval docker_path := $(foreach dir,$(docker_dir),$(patsubst %/Dockerfile,%,$(wildcard $(patsubst %,%/$(docker_name)/Dockerfile,$(dir))))))
|
||||
$(call debug,docker_name docker_dir docker_path)
|
||||
$(if $(docker_path),
|
||||
$(docker_path)
|
||||
, $(call ERROR,Unable to find a docker,$(docker_name),in dir,$(docker_dir))
|
||||
))
|
||||
endef
|
||||
|
||||
# function docker-running: Print running dockers matching DOCKER_NAME
|
||||
@@ -224,3 +231,16 @@ define docker-volume-copy
|
||||
$(RUN) docker volume inspect $(to) >/dev/null 2>&1 || $(RUN) docker volume create $(to) >/dev/null
|
||||
$(RUN) docker run --rm -v $(from):/from -v $(to):/to alpine ash -c "cd /from; cp -a . /to"
|
||||
endef
|
||||
|
||||
# function stack-path: eval stack_path for stack 1 in STACK_DIR 2
|
||||
define stack-path
|
||||
$(strip
|
||||
$(call INFO,stack-path,$(1)$(comma) $(2))
|
||||
$(eval stack_name := $(or $(firstword $(subst :, ,$(patsubst %.yml,%,$(notdir $(1))))),myos))
|
||||
$(eval stack_dir := $(or $(2),$(STACK_DIR)))
|
||||
$(eval stack_path := $(foreach dir,$(stack_dir),$(patsubst %/,%,$(wildcard $(patsubst %,%/$(stack_name)/,$(dir))))))
|
||||
$(if $(stack_path),
|
||||
$(stack_path)
|
||||
, $(call ERROR,Unable to find a stack,$(stack_name),in dir,$(stack_dir))
|
||||
))
|
||||
endef
|
||||
|
||||
+8
-5
@@ -8,8 +8,10 @@ percent ?= %
|
||||
quote ?= '
|
||||
rbracket ?= )
|
||||
APP ?= $(if $(wildcard .git),$(notdir $(CURDIR)))
|
||||
APP_DIR ?= $(or $(filter-out .,$(WORKDIR)), $(CURDIR))
|
||||
APP_DOCKER_DIR ?= . $(DOCKER_DIR_NAME)
|
||||
APP_NAME ?= $(subst _,,$(subst -,,$(subst .,,$(call LOWERCASE,$(APP)))))
|
||||
APP_TYPE ?= $(if $(SUBREPO),subrepo) $(if $(filter .,$(MYOS)),myos)
|
||||
APP_TYPE ?= $(if $(SUBREPO),subrepo) $(if $(filter .,$(MYOS)),myos) $(if $(wildcard .git),git)
|
||||
APPS ?= $(if $(MONOREPO),$(sort $(patsubst $(MONOREPO_DIR)/%/.git,%,$(wildcard $(MONOREPO_DIR)/*/.git))))
|
||||
APPS_NAME ?= $(foreach app,$(APPS),$(or $(shell awk -F '=' '$$1 == "APP" {print $$2}' $(or $(wildcard $(MONOREPO_DIR)/$(app)/.env),$(wildcard $(MONOREPO_DIR)/$(app)/.env.$(ENV)),$(MONOREPO_DIR)/$(app)/.env.dist) 2>/dev/null),$(app)))
|
||||
BRANCH ?= $(GIT_BRANCH)
|
||||
@@ -40,7 +42,7 @@ CONFIG_REPOSITORY_PATH ?= $(shell printf '$(CONFIG_REPOSITORY_URI)\n' |
|
||||
CONFIG_REPOSITORY_SCHEME ?= $(shell printf '$(CONFIG_REPOSITORY_URL)\n' |sed 's|://.*||;')
|
||||
CONFIG_REPOSITORY_URI ?= $(shell printf '$(CONFIG_REPOSITORY_URL)\n' |sed 's|.*://||;')
|
||||
CONFIG_REPOSITORY_URL ?= $(call pop,$(APP_UPSTREAM_REPOSITORY))/$(notdir $(CONFIG))
|
||||
CONTEXT ?= ENV $(shell awk 'BEGIN {FS="="}; $$1 !~ /^(\#|$$)/ {print $$1}' .env.dist 2>/dev/null)
|
||||
CONTEXT ?= ENV ENV_PATH $(shell awk 'BEGIN {FS="="}; $$1 !~ /^(\#|$$)/ {print $$1}' .env.dist 2>/dev/null)
|
||||
CONTEXT_DEBUG ?= MAKEFILE_LIST DOCKER_ENV_ARGS ENV_ARGS APPS GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME MAKE_DIR MAKE_SUBDIRS MAKE_CMD_ARGS MAKE_ENV_ARGS UID USER
|
||||
DEBUG ?=
|
||||
DOCKER ?= $(shell type -p docker)
|
||||
@@ -50,11 +52,11 @@ DRONE ?= false
|
||||
DRYRUN ?= false
|
||||
DRYRUN_RECURSIVE ?= false
|
||||
ELAPSED_TIME = $(shell $(call TIME))
|
||||
ENV ?= master
|
||||
ENV ?= local
|
||||
ENV_ARGS ?= $(env_args)
|
||||
ENV_FILE ?= $(wildcard $(if $(filter-out myos,$(MYOS)),$(MONOREPO_DIR)/.env) $(CONFIG)/$(ENV)/$(APP)/.env $(ENV_PATH)/.env)
|
||||
ENV_LIST ?= $(shell ls .git/refs/heads/ 2>/dev/null)
|
||||
ENV_PATH ?= .
|
||||
ENV_PATH ?= $(WORKDIR)
|
||||
ENV_RESET ?= false
|
||||
GID ?= $(shell id -g 2>/dev/null)
|
||||
GIDS ?= $(shell id -G 2>/dev/null)
|
||||
@@ -110,6 +112,7 @@ TAG ?= $(GIT_TAG)
|
||||
UID ?= $(shell id -u 2>/dev/null)
|
||||
USER ?= $(shell id -nu 2>/dev/null)
|
||||
VERSION ?= $(GIT_VERSION)
|
||||
WORKDIR ?= .
|
||||
|
||||
ifneq ($(DEBUG),)
|
||||
CONTEXT += $(CONTEXT_DEBUG)
|
||||
@@ -151,7 +154,7 @@ DEBUG_FD := 2
|
||||
# macro debug: print variable content when DEBUG
|
||||
debug = $(if $(DEBUG), \
|
||||
printf '${COLOR_INFO}$(APP)${COLOR_RESET}[${COLOR_VALUE}$(MAKELEVEL)${COLOR_RESET}]$(if $@, ${COLOR_VALUE}$@${COLOR_RESET}):${COLOR_RESET} ' >&$(DEBUG_FD) \
|
||||
$(foreach variable,$(1),&& printf '${COLOR_DEBUG}$(variable):${COLOR_RESET} ${COLOR_VALUE}$($(variable))${COLOR_RESET}, ' >&$(DEBUG_FD)) \
|
||||
$(foreach variable,$(1),&& printf '${COLOR_DEBUG}$(variable):${COLOR_RESET} ${COLOR_VALUE}' && $(call PRINTF,$($(variable))) && printf '${COLOR_RESET}, ' >&$(DEBUG_FD)) \
|
||||
&& printf '\n' >&$(DEBUG_FD) \
|
||||
)
|
||||
|
||||
|
||||
+4
-4
@@ -14,13 +14,13 @@ MAKE_LATEST := $(MAKE_DIR)/end.mk
|
||||
include $(wildcard $(MAKE_FIRST))
|
||||
## 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))
|
||||
## 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)/$(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)))
|
||||
## 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)),$(foreach stack_dir,$(STACK_DIR),$(wildcard $(stack_dir)/*.mk $(stack_dir)/*/*.mk))))
|
||||
## if not in $(MYOS) nor $(MONOREPO), it includes def.mk def.*.mk */def.mk */def.*.mk *.mk */*.mk
|
||||
include $(if $(filter-out . myos,$(MYOS)),$(wildcard def.mk def.*.mk */def.mk */def.*.mk) $(filter-out $(wildcard def.mk def.*.mk */def.mk */def.*.mk stack/*.mk),$(wildcard *.mk */*.mk)))
|
||||
## it includes $(STACK_DIR)/*.mk $(STACK_DIR)/*/*.mk
|
||||
include $(foreach stack_dir,$(STACK_DIR),$(wildcard $(stack_dir)/*.mk $(stack_dir)/*/*.mk))
|
||||
## it includes $(MAKE_LATEST)
|
||||
include $(wildcard $(MAKE_LATEST))
|
||||
|
||||
Reference in New Issue
Block a user