This commit is contained in:
aynic.os
2021-05-31 03:45:39 +02:00
parent c9821467de
commit 0996e2a355
24 changed files with 176 additions and 211 deletions
+15 -12
View File
@@ -7,8 +7,11 @@ APP_DIR ?= $(if $(APP),$(CURDIR))
APP_DOMAIN ?= $(if $(APP),$(ENV)$(addprefix .,$(DOMAIN)))
APP_HOST ?= $(if $(APP),$(APP)$(addprefix .,$(APP_DOMAIN)))
APP_NAME ?= $(APP)
APP_PARAMETERS_REPOSITORY ?= $(GIT_PARAMETERS_REPOSITORY)
APP_PATH ?= /$(APP_PATH_PREFIX)
APP_SCHEME ?= https
APP_TYPE ?= $(if $(SUBREPO),subrepo) $(if $(MYOS),,myos)
APP_UPSTREAM_REPOSITORY ?= $(GIT_UPSTREAM_REPOSITORY)
APP_URI ?= $(if $(APP),$(APP_HOST)$(APP_PATH))
APP_URL ?= $(if $(APP),$(APP_SCHEME)://$(APP_URI))
APPS ?= $(if $(MONOREPO),$(sort $(patsubst $(MONOREPO_DIR)/%/.git,%,$(wildcard $(MONOREPO_DIR)/*/.git))))
@@ -26,9 +29,9 @@ DRYRUN ?= false
DRYRUN_IGNORE ?= false
DRYRUN_RECURSIVE ?= false
ENV ?= dist
ENV_DEPLOY ?= preprod prod
ENV_DEPLOY ?= $(if $(APP),$(shell ls .git/refs/heads/))
ENV_FILE ?= $(wildcard ../$(PARAMETERS)/$(ENV)/$(APP)/.env) .env
ENV_LIST ?= local dev tests preprod prod #TODO: staging develop
ENV_LIST ?= debug local tests release master #TODO: staging develop
ENV_RESET ?= false
ENV_VARS ?= APP APP_DIR APP_DOMAIN BRANCH ENV HOSTNAME GID MONOREPO MONOREPO_DIR TAG UID USER VERSION
GID ?= $(shell id -g 2>/dev/null)
@@ -37,9 +40,9 @@ GIT_REPOSITORY ?= $(if $(SUBREPO),$(shell awk -F ' = ' '$$1 ~ /
GIT_UPSTREAM_REPOSITORY ?= $(if $(findstring ://,$(GIT_REPOSITORY)),$(call pop,$(call pop,$(GIT_REPOSITORY)))/,$(call pop,$(GIT_REPOSITORY),:):)$(GIT_UPSTREAM_USER)/$(lastword $(subst /, ,$(GIT_REPOSITORY)))
GIT_UPSTREAM_USER ?= $(or $(MONOREPO),$(USER))
HOSTNAME ?= $(shell hostname 2>/dev/null |sed 's/\..*//')
MAKE_ARGS ?= $(foreach var,$(MAKE_VARS),$(if $($(var)),$(var)='$($(var))'))
MAKE_VARS ?= ENV
MAKE_SUBDIRS ?= $(if $(filter myos,$(MYOS)),monorepo,$(if $(SUBREPO),subrepo )$(if $(APP),apps $(foreach type,$(APP_TYPE),$(if $(wildcard $(MAKE_DIR)/apps/$(type)),apps/$(type)))))
MAKE_ENV_ARGS ?= $(foreach var,$(MAKE_ENV_VARS),$(if $($(var)),$(var)='$($(var))'))
MAKE_ENV_VARS ?= ENV
MAKE_SUBDIRS ?= $(if $(filter myos,$(MYOS)),monorepo,$(if $(APP),apps $(foreach type,$(APP_TYPE),$(if $(wildcard $(MAKE_DIR)/apps/$(type)),apps/$(type)))))
MAKECMDARGS ?= $(foreach var,$(MAKECMDVARS),$(var)='$($(var))')
MAKECMDVARS ?= $(strip $(foreach var, $(filter-out .VARIABLES,$(.VARIABLES)), $(if $(filter command\ line,$(origin $(var))),$(var))))
MAKEENVVARS ?= $(strip $(foreach var, $(filter-out .VARIABLES,$(.VARIABLES)), $(if $(filter environment,$(origin $(var))),$(var))))
@@ -140,8 +143,8 @@ gid = $(shell grep '^$(1):' /etc/group 2>/dev/null |awk -F: '{print $$3}')
# 2nd arg: directory to call make from
# 3rd arg: list of variables to pass to make (ENV by default)
# 4th arg: path to .env file with additional arguments to call make with (file must exist when calling make)
# add list of VARIABLE=VALUE from vars to MAKE_ARGS
# add list of arguments from file to MAKE_ARGS
# add list of VARIABLE=VALUE from vars to MAKE_ENV_ARGS
# add list of arguments from file to MAKE_ENV_ARGS
# eval MAKE_DIR option to -C $(2) if $(2) given
# add current target to MAKE_OLDFILE (list of already fired targets)
# print command that will be run if VERBOSE mode
@@ -152,13 +155,13 @@ define make
$(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"'\''"}')))
$(if $(vars),$(eval MAKE_ENV_ARGS += $(foreach var,$(vars),$(if $($(var)),$(var)='$($(var))'))))
$(if $(wildcard $(file)),$(eval MAKE_ENV_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), $^))
$(if $(filter $(VERBOSE),true),printf '${COLOR_GREEN}Running${COLOR_RESET} "'"make $(MAKE_ARGS) $(cmd)"'" $(if $(dir),${COLOR_BLUE}in folder${COLOR_RESET} $(dir) )\n')
$(ECHO) $(MAKE) $(MAKE_DIR) $(patsubst %,-o %,$(MAKE_OLDFILE)) MAKE_OLDFILE="$(MAKE_OLDFILE)" $(MAKE_ARGS) $(cmd)
$(if $(filter $(DRYRUN_RECURSIVE),true),$(MAKE) $(MAKE_DIR) $(patsubst %,-o %,$(MAKE_OLDFILE)) MAKE_OLDFILE="$(MAKE_OLDFILE)" DRYRUN=$(DRYRUN) RECURSIVE=$(RECURSIVE) $(MAKE_ARGS) $(cmd))
$(if $(filter $(VERBOSE),true),printf '${COLOR_GREEN}Running${COLOR_RESET} "'"make $(MAKE_ENV_ARGS) $(cmd)"'" $(if $(dir),${COLOR_BLUE}in folder${COLOR_RESET} $(dir) )\n')
$(ECHO) $(MAKE) $(MAKE_DIR) $(patsubst %,-o %,$(MAKE_OLDFILE)) MAKE_OLDFILE="$(MAKE_OLDFILE)" $(MAKE_ENV_ARGS) $(cmd)
$(if $(filter $(DRYRUN_RECURSIVE),true),$(MAKE) $(MAKE_DIR) $(patsubst %,-o %,$(MAKE_OLDFILE)) MAKE_OLDFILE="$(MAKE_OLDFILE)" DRYRUN=$(DRYRUN) RECURSIVE=$(RECURSIVE) $(MAKE_ENV_ARGS) $(cmd))
endef
pop = $(patsubst %$(or $(2),/)$(lastword $(subst $(or $(2),/), ,$(1))),%,$(1))