fix .env permission

This commit is contained in:
2025-12-19 02:19:39 +01:00
parent 4c2619e4e0
commit afa9990f6b
4 changed files with 102 additions and 102 deletions
+34 -34
View File
@@ -71,32 +71,32 @@ 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 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) $(p)/$(ENV)/$(n).$(e) $(p)/$(ENV)/$(n).$(ENV).$(e) $(foreach s,$(suffix),$(p)/$(n).$(s).$(e) $(p)/$(n).$(s).$(ENV).$(e)))))))
$(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
define docker-build
$(call INFO,docker-build,$(1)$(comma) $(2)$(comma) $(3))
$(eval path := $(patsubst $(DOCKER_BUILD_DIR)/%,%,$(patsubst %/,%,$(1))))
$(eval service := $(subst .,,$(call LOWERCASE,$(lastword $(subst /, ,$(path))))))
$(eval tag := $(or $(2),$(DOCKER_REPOSITORY)/$(service):$(DOCKER_IMAGE_TAG)))
$(eval target := $(subst ",,$(subst ',,$(or $(3),$(DOCKER_BUILD_TARGET)))))
$(eval image_id := $(shell docker images -q $(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_DIR="$(path)" $(DOCKER_BUILD_LABEL) --tag $(tag) $(if $(target),--target $(target)) -f $(path)/Dockerfile $(or $(DOCKER_BUILD_DIR),.),$(call INFO,docker image $(tag) has id $(image_id)))
$(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)))))
$(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)))
endef
# function docker-commit: Commit docker image
define docker-commit
$(call INFO,docker-commit,$(1)$(comma) $(2)$(comma) $(3)$(comma) $(4))
$(eval service := $(or $(1),$(DOCKER_SERVICE)))
$(eval container := $(or $(2),$(firstword $(shell $(call docker-compose,ps -q $(service) 2>/dev/null)))))
$(eval repository := $(or $(3),$(DOCKER_REPOSITORY)/$(service)))
$(eval tag := $(or $(4),$(DOCKER_IMAGE_TAG)))
$(RUN) docker commit $(container) $(repository):$(tag)
$(eval commit_service := $(or $(1),$(DOCKER_SERVICE)))
$(eval commit_container := $(or $(2),$(firstword $(shell $(call docker-compose,ps -q $(commit_service) 2>/dev/null)))))
$(eval commit_repository := $(or $(3),$(DOCKER_REPOSITORY)/$(commit_service)))
$(eval commit_image_tag := $(or $(4),$(DOCKER_IMAGE_TAG)))
$(RUN) docker commit $(commit_container) $(commit_repository):$(commit_image_tag)
endef
# function docker-compose: Run docker-compose with arg 1
# TODO: accept $2 COMPOSE_FILE and remove stack from prereq
@@ -121,10 +121,10 @@ endef
# function docker-push: Push docker image
define docker-push
$(call INFO,docker-push,$(1)$(comma) $(2)$(comma) $(3))
$(eval service := $(or $(1),$(DOCKER_SERVICE)))
$(eval name := $(or $(2),$(DOCKER_REGISTRY_REPOSITORY)/$(service)))
$(eval tag := $(or $(3),$(DOCKER_IMAGE_TAG)))
$(RUN) docker push $(name):$(tag)
$(eval push_service := $(or $(1),$(DOCKER_SERVICE)))
$(eval push_name := $(or $(2),$(DOCKER_REGISTRY_REPOSITORY)/$(push_service)))
$(eval push_tag := $(or $(3),$(DOCKER_IMAGE_TAG)))
$(RUN) docker push $(push_name):$(push_tag)
endef
# function docker-stack: Call itself recursively for each stack to expand stacks
# docker-stack: if 1st arg is a variable and can be expand to values, it calls
@@ -133,8 +133,8 @@ endef
# 2nd arg: versions, extract it from stack_names:stack_versions or 2nd arg
define docker-stack
$(call INFO,docker-stack,$(1)$(comma) $(2))
$(eval stacks := $(firstword $(subst :, ,$(1))))
$(eval versions := $(or $(if $(findstring :,$(1)),$(lastword $(subst :, ,$(1)))),$(2)))
$(eval stacks := $(firstword $(subst :, ,$(1))))
$(eval versions := $(or $(if $(findstring :,$(1)),$(lastword $(subst :, ,$(1)))),$(2)))
$(if $($(stacks)),$(foreach substack,$($(stacks)),$(call docker-stack,$(substack),$(if $(findstring :,$(1)),$(versions)))),$(call docker-stack-update,$(stacks),$(versions)))
endef
# function docker-stack-update: Update COMPOSE_FILE with .yml files of the stack
@@ -149,21 +149,21 @@ endef
# if $(path)/.env.dist file exists, update .env file
define docker-stack-update
$(call INFO,docker-stack-update,$(1)$(comma) $(2)$(comma) $(3))
$(eval stack := $(patsubst %.yml,%,$(notdir $(1))))
$(eval name := $(firstword $(subst :, ,$(stack))))
$(eval version := $(or $(2),$(if $(findstring :,$(stack)),$(lastword $(subst :, ,$(stack))),latest)))
$(eval 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)/$(name) $(stack_dir)/$(stackz) $(stack_dir)/$(name)))))))
$(call compose-file,$(path),docker-compose $(name),$(COMPOSE_FILE_SUFFIX) $(version))
$(if $(wildcard $(path)/.env.dist),$(call .env,,$(path)/.env.dist,$(wildcard $(CONFIG)/$(ENV)/$(APP)/.env $(path)/.env.$(ENV) .env)))
$(eval stack_update := $(patsubst %.yml,%,$(notdir $(1))))
$(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 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))
endef
# function docker-tag: Tag docker image
define docker-tag
$(call INFO,docker-tag,$(1)$(comma) $(2)$(comma) $(3)$(comma) $(4)$(comma) $(5))
$(eval service := $(or $(1),$(DOCKER_SERVICE)))
$(eval source := $(or $(2),$(DOCKER_REPOSITORY)/$(service)))
$(eval source_tag := $(or $(3),$(DOCKER_IMAGE_TAG)))
$(eval target := $(or $(4),$(DOCKER_REGISTRY_REPOSITORY)/$(service)))
$(eval target_tag := $(or $(5),$(source_tag)))
$(eval tag_service := $(or $(1),$(DOCKER_SERVICE)))
$(eval source := $(or $(2),$(DOCKER_REPOSITORY)/$(tag_service)))
$(eval source_tag := $(or $(3),$(DOCKER_IMAGE_TAG)))
$(eval target := $(or $(4),$(DOCKER_REGISTRY_REPOSITORY)/$(tag_service)))
$(eval target_tag := $(or $(5),$(source_tag)))
$(RUN) docker tag $(source):$(source_tag) $(target):$(target_tag)
endef
+24 -24
View File
@@ -16,15 +16,15 @@ endef
# function app-bootstrap: Define custom variables for app 1 in dir 2 with name 3 and type 4
define app-bootstrap
$(call INFO,app-bootstrap,$(1)$(comma) $(2$(comma) $(3))$(comma) $(4))
$(eval APP := $(or $(1), $(APP)))
$(eval APP_DIR := $(or $(2), $(RELATIVE)$(APP)))
$(eval APP_NAME := $(or $(3),$(subst -,,$(subst .,,$(call LOWERCASE,$(APP))))))
$(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_DIR := $(APP_DIR))
$(eval APP := $(or $(1), $(APP)))
$(eval APP_DIR := $(or $(2), $(RELATIVE)$(APP)))
$(eval APP_NAME := $(or $(3),$(subst -,,$(subst .,,$(call LOWERCASE,$(APP))))))
$(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,$(MYOS_STACK),$(MYOS_STACK_FILE))
$(eval APP_COMPOSE_FILE ?= $(COMPOSE_FILE))
$(eval APP_COMPOSE_FILE ?= $(COMPOSE_FILE))
$(call docker-stack,$(APP))
$(call .env,$(APP_DIR)/.env,$(APP_DIR)/.env.dist $(APP_DIR)/.env.example $(APP_DIR)/.env.sample)
endef
@@ -81,15 +81,15 @@ endef
# function app-docker: Define custom variables for Dockerfile 1
define app-docker
$(call INFO,app-docker,$(1)$(comma))
$(eval dir := $(or $(APP_DIR)))
$(eval dockerfile := $(or $(1)))
$(eval dir := $(or $(APP_DIR)))
$(eval dockerfile := $(or $(1)))
$(if $(wildcard $(dockerfile)),
$(eval service := $(or $(DOCKER_SERVICE),$(subst .,,$(call LOWERCASE,$(lastword $(subst /, ,$(patsubst %/Dockerfile,%,$(dockerfile)))))),undefined))
$(eval docker := $(or $(DOCKER_COMPOSE_SERVICE_NAME),$(COMPOSE_SERVICE_NAME))-$(service))
$(eval DOCKER_IMAGE := $(DOCKER_REPOSITORY)/$(service):$(DOCKER_IMAGE_TAG))
$(eval DOCKER_LABELS := SERVICE_NAME=$(docker) SERVICE_TAGS=$(call urlprefix,$(APP_PATH),,$(service).$(APP_HOST)))
$(eval DOCKER_NAME := $(docker))
$(eval DOCKER_RUN_NAME := --name $(DOCKER_NAME))
$(eval service := $(or $(DOCKER_SERVICE),$(subst .,,$(call LOWERCASE,$(lastword $(subst /, ,$(patsubst %/Dockerfile,%,$(dockerfile)))))),undefined))
$(eval docker := $(or $(DOCKER_COMPOSE_SERVICE_NAME),$(COMPOSE_SERVICE_NAME))-$(service))
$(eval DOCKER_IMAGE := $(DOCKER_REPOSITORY)/$(service):$(DOCKER_IMAGE_TAG))
$(eval DOCKER_LABELS := SERVICE_NAME=$(docker) SERVICE_TAGS=$(call urlprefix,$(APP_PATH),,$(service).$(APP_HOST)))
$(eval DOCKER_NAME := $(docker))
$(eval DOCKER_RUN_NAME := --name $(DOCKER_NAME))
, $(call ERROR,Unable to find Dockerfile,$(dockerfile))
)
endef
@@ -110,7 +110,7 @@ endef
# function app-exec: Call docker exec $(ARGS) for each Dockerfile in dir 1
define app-exec
$(call INFO,app-exec,$(1)$(comma) $(2))
$(eval args := $(or $(2), $(ARGS)))
$(eval args := $(or $(2), $(ARGS)))
$(if $(APP_COMPOSE_FILE),
$(call docker-compose,exec $(or $(SERVICE),$(DOCKER_SERVICE)) $(args))
, $(call docker-file,$(1))
@@ -124,8 +124,8 @@ 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), $(REPOSITORY_URL), $(APP_REPOSITORY_URL)))
$(eval dir := $(or $(2), $(RELATIVE)$(lastword $(subst /, ,$(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) && if [ -n "$(APP_VERSION)" ]; then cd $(dir) && git reset --hard $(QUIET) "$(APP_VERSION)"; fi
@@ -162,7 +162,7 @@ endef
# function app-rebuild: Call app-build with DOCKER_BUILD_CACHE=false
define app-rebuild
$(call INFO,app-rebuild,$(1)$(comma))
$(eval DOCKER_BUILD_CACHE := false)
$(eval DOCKER_BUILD_CACHE := false)
$(call app-build,$(1))
endef
@@ -179,8 +179,8 @@ 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))
$(eval args := $(or $(2), $(ARGS)))
$(eval DOCKER_RUN_OPTIONS += -it)
$(eval args := $(or $(2), $(ARGS)))
$(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))
@@ -232,7 +232,7 @@ 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)
$(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),
@@ -245,8 +245,8 @@ 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), $(REPOSITORY_URL), $(APP_REPOSITORY_URL)))
$(eval dir := $(or $(2), $(APP_DIR)))
$(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) && if [ -n "$(APP_VERSION)" ]; then git reset --hard $(QUIET) "$(APP_VERSION)"; fi'
, $(call app-install,$(url),$(dir))
+30 -29
View File
@@ -52,8 +52,9 @@ DRYRUN_RECURSIVE ?= false
ELAPSED_TIME = $(shell $(call TIME))
ENV ?= master
ENV_ARGS ?= $(env_args)
ENV_FILE ?= $(wildcard $(if $(filter-out myos,$(MYOS)),$(MONOREPO_DIR)/.env) $(CONFIG)/$(ENV)/$(APP)/.env .env)
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_RESET ?= false
GID ?= $(shell id -g 2>/dev/null)
GIDS ?= $(shell id -G 2>/dev/null)
@@ -154,7 +155,7 @@ debug = $(if $(DEBUG), \
&& printf '\n' >&$(DEBUG_FD) \
)
ERROR_FD := 2
ERROR_FD := 2
# macro ERROR: print colorized warning
ERROR = \
printf '${COLOR_ERROR}ERROR:${COLOR_RESET} ${COLOR_INFO}$(APP)${COLOR_RESET}[${COLOR_VALUE}$(MAKELEVEL)${COLOR_RESET}]$(if $@, ${COLOR_VALUE}$@${COLOR_RESET}):${COLOR_RESET} ' >&$(ERROR_FD) \
@@ -196,27 +197,27 @@ JWT_HEADER = {"alg":"HS256","typ":"JWT"}
# macro JWT: Print Json Web Token for header $1 payload $2 and key $3
JWT := $(strip \
$(eval header := $(or $(1),$(JWT_HEADER))) \
$(eval payload := $(or $(2),$(JWT_PAYLOAD))) \
$(eval secret := $(or $(3),$(JWT_SECRET))) \
$(eval b64_header := $(call base64t,$(header))) \
$(eval b64_payload := $(call base64t,$(payload))) \
$(eval b64_signature := $(call base64t,$(call hs256,$(b64_header).$(b64_payload),$(secret)))) \
$(eval b64_signature := $(call b64_hs256,$(b64_header).$(b64_payload),$(secret))) \
$(eval header := $(or $(1),$(JWT_HEADER))) \
$(eval payload := $(or $(2),$(JWT_PAYLOAD))) \
$(eval secret := $(or $(3),$(JWT_SECRET))) \
$(eval b64_header := $(call base64t,$(header))) \
$(eval b64_payload := $(call base64t,$(payload))) \
$(eval b64_signature := $(call base64t,$(call hs256,$(b64_header).$(b64_payload),$(secret)))) \
$(eval b64_signature := $(call b64_hs256,$(b64_header).$(b64_payload),$(secret))) \
$(b64_header).$(b64_payload).$(b64_signature))
# macro RESU: Print USER associated to MAIL
RESU = $(strip \
$(if $(findstring @,$(MAIL)), \
$(eval user := $(call LOWERCASE,$(subst +,.,$(subst _,.,$(shell printf '$(MAIL)' |awk -F "@" '{print $$1}'))))) \
$(eval domain := $(call LOWERCASE,$(subst +,.,$(subst _,.,$(shell printf '$(MAIL)' |awk -F "@" '{print $$NF}'))))) \
$(eval user := $(call LOWERCASE,$(subst +,.,$(subst _,.,$(shell printf '$(MAIL)' |awk -F "@" '{print $$1}'))))) \
$(eval domain := $(call LOWERCASE,$(subst +,.,$(subst _,.,$(shell printf '$(MAIL)' |awk -F "@" '{print $$NF}'))))) \
$(if $(domain), \
$(eval mail := $(call LOWERCASE,$(subst +,.,$(subst _,.,$(MAIL))))) \
$(eval niamod := $(subst $(space),.,$(strip $(call reverse,$(subst ., ,$(domain)))))) \
$(eval resu := $(subst $(space),.,$(strip $(call reverse,$(subst ., ,$(user)))))) \
$(eval resu.niamod := $(niamod).$(resu)) \
$(eval resu.path := $(subst .,/,$(resu.niamod))) \
$(eval user.domain := $(user).$(domain)) \
$(eval mail := $(call LOWERCASE,$(subst +,.,$(subst _,.,$(MAIL))))) \
$(eval niamod := $(subst $(space),.,$(strip $(call reverse,$(subst ., ,$(domain)))))) \
$(eval resu := $(subst $(space),.,$(strip $(call reverse,$(subst ., ,$(user)))))) \
$(eval resu.niamod := $(niamod).$(resu)) \
$(eval resu.path := $(subst .,/,$(resu.niamod))) \
$(eval user.domain := $(user).$(domain)) \
$(user.domain) \
, $(USER) \
) \
@@ -286,9 +287,9 @@ verlt = [ "$(1)" = "$(2)" ] && return 1 || $(call verlte,$(1),$(2))
## it prints the line with variable 3 definition from block 2 in file 1
define conf
$(call INFO,conf,$(1)$(comma) $(2)$(comma) $(3))
$(eval file := $(1))
$(eval block := $(2))
$(eval variable := $(3))
$(eval file := $(1))
$(eval block := $(2))
$(eval variable := $(3))
[ -r "$(file)" ] && while IFS='=' read -r key value; do \
case $${key} in \
\#*) \
@@ -319,9 +320,9 @@ endef
# function env-vars: Extract variables from file 1 to update variable ENV_VARS
define env-vars
$(call INFO,env-vars,$(1))
$(eval file := $(wildcard $(or $(1),$(COMPOSE_FILE))))
$(if $(file),$(eval ENV_VARS := $(sort $(ENV_VARS) $(shell sed 's/\$$\$$//g' $(file) | grep -oE '\$$\{?[A-Z0-9_]+' | tr -d '{}$$'))))
$(call INFO,env-vars,$(1)$(comma))
$(eval file := $(wildcard $(or $(1),$(COMPOSE_FILE))))
$(if $(file),$(eval ENV_VARS := $(sort $(ENV_VARS) $(shell sed 's/\$$\$$//g' $(file) | grep -oE '\$$\{?[A-Z0-9_]+' | tr -d '{}$$'))))
$(call debug,ENV_VARS)
endef
@@ -338,14 +339,14 @@ endef
# actually run make command
# if DRYRUN_RECURSIVE mode, run make command in DRYRUN mode
define make
$(eval cmd := $(1))
$(eval dir := $(2))
$(eval vars := $(3))
$(eval file := $(4))
$(eval cmd := $(1))
$(eval dir := $(2))
$(eval vars := $(3))
$(eval file := $(4))
$(if $(vars),$(eval MAKE_ARGS += $(foreach var,$(vars),$(if $($(var)),$(var)='$($(var))'))))
$(if $(wildcard $(file)),$(eval MAKE_ARGS += $(shell cat $(file) |sed '/^$$/d; /^#/d; /=/!d; s/^[[\s\t]]*//; s/[[\s\t]]*=[[\s\t]]*/=/;' |awk -F '=' '{print $$1"='\''"$$2"'\''"}')))
$(eval MAKE_DIR := $(if $(dir),-C $(dir)))
$(eval MAKE_OLDFILE += $(filter-out $(MAKE_OLDFILE), $^))
$(eval MAKE_DIR := $(if $(dir),-C $(dir)))
$(eval MAKE_OLDFILE += $(filter-out $(MAKE_OLDFILE), $^))
$(call INFO,make,$(MAKE_ARGS) $(cmd),$(dir))
$(RUN) $(MAKE) $(MAKE_DIR) $(patsubst %,-o %,$(MAKE_OLDFILE)) MAKE_OLDFILE="$(MAKE_OLDFILE)" $(MAKE_ARGS) $(cmd)
$(if $(filter true,$(DRYRUN_RECURSIVE)),$(MAKE) $(MAKE_DIR) $(patsubst %,-o %,$(MAKE_OLDFILE)) MAKE_OLDFILE="$(MAKE_OLDFILE)" DRYRUN=$(DRYRUN) RECURSIVE=$(RECURSIVE) $(MAKE_ARGS) $(cmd))
+14 -15
View File
@@ -18,7 +18,6 @@
## it can override ENV_DIST with values from file ENV_OVER
.PHONY: .env-update
.env-update:
$(call INFO,.env-update,$(ENV_FILE)$(comma) $(ENV_DIST)$(comma) $(ENV_OVER))
$(foreach env_file,$(ENV_FILE),$(call .env,$(env_file),$(or $(ENV_DIST),$(env_file).dist),$(ENV_OVER)))
# include .env file
@@ -28,16 +27,16 @@ ifneq (,$(filter true,$(ENV_RESET)))
env_reset := -i
endif
docker.env.args = $(foreach var,$(ENV_VARS),$(if $($(var)),-e $(var)='$($(var))'))
docker.env.dist ?= $(shell printenv |awk -F '=' 'NR == FNR { if($$1 !~ /^(\#|$$)/) { A[$$1]; next } } ($$1 in A) {print "-e "$$0}' .env.dist - 2>/dev/null)
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/'\"'$$//;s/=/='\''/;s/$$/'\''/;')
env_args = $(env.args) $(env.dist) $(env.file)
docker.env.args = $(foreach var,$(ENV_VARS),$(if $($(var)),-e $(var)='$($(var))'))
docker.env.dist ?= $(shell printenv |awk -F '=' 'NR == FNR { if($$1 !~ /^(\#|$$)/) { A[$$1]; next } } ($$1 in A) {print "-e "$$0}' .env.dist - 2>/dev/null)
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/'\"'$$//;s/=/='\''/;s/$$/'\''/;')
env_args = $(env.args) $(env.dist) $(env.file)
SHELL:=/bin/bash
SHELL := /bin/bash
# function .env: Call .env_update function
## it sets .env, .env.dist and .env.ENV files paths
@@ -48,9 +47,9 @@ SHELL:=/bin/bash
# 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_dists:=$(wildcard $(or $(2),$(env_file).dist)))
$(eval env_over:=$(wildcard $(or $(3),$(env_file).$(ENV))))
$(eval env_file := $(or $(1),$(ENV_PATH)/.env))
$(eval env_dists := $(filter-out .,$(wildcard $(or $(2),$(env_file).dist))))
$(eval env_over := $(filter-out .,$(wildcard $(or $(3),$(env_file).$(ENV)))))
$(if $(FORCE)$(call newenv,$(env_file),$(env_dists) $(env_over))$(if $(wildcard $(env_file)),,FORCE),
$(foreach env_dist,$(env_dists),$(call .env_update)))
endef
@@ -84,8 +83,8 @@ endef
# add variables definition to the .env file
define .env_update
$(call INFO,.env_update,$(env_file)$(comma) $(env_dist)$(comma) $(env_over))
touch $(env_file) $(if $(VERBOSE)$(DEBUG),,2> /dev/null) ||:
printenv \
touch $(env_file) $(if $(VERBOSE)$(DEBUG),,2> /dev/null) \
&& printenv \
|awk -F '=' 'NR == FNR { if($$1 !~ /^(#|$$)/) { A[$$1]; next } } !($$1 in A)' - $(env_dist) \
|cat $(env_over) - \
|awk 'BEGIN {split("$(MAKE_CMD_VARS)",vars," "); for (var in vars) {print vars[var]"="ENVIRON[vars[var]]};} {print}' \