This commit is contained in:
aynic.os 2021-06-07 22:39:57 +02:00
parent 3a9ddae015
commit 11916a1bc3
3 changed files with 33 additions and 7 deletions

View File

@ -1,7 +1,6 @@
APP_DIR ?= $(CURDIR)
APP_DOMAIN ?= $(ENV)$(addprefix .,$(DOMAIN))
APP_HOST ?= $(APP)$(addprefix .,$(APP_DOMAIN))
APP_PARAMETERS_REPOSITORY ?= $(GIT_PARAMETERS_REPOSITORY)
APP_PARENT ?= $(MONOREPO)
APP_PARENT_DIR ?= $(MONOREPO_DIR)
APP_PATH ?= /$(APP_PATH_PREFIX)
@ -11,7 +10,7 @@ APP_UPSTREAM_REPOSITORY ?= $(or $(shell git config --get remote.upstream
APP_URI ?= $(APP_HOST)$(APP_PATH)
APP_URL ?= $(APP_SCHEME)://$(APP_URI)
BUILD_ENV_VARS ?= APP BRANCH COMMIT DEPLOY_HOOK_URL ENV VERSION
CONTEXT_DEBUG += APP_DIR APP_DOMAIN APP_HOST APP_PATH APP_URL APP_REPOSITORY APP_UPSTREAM_REPOSITORY APP_PARAMETERS_REPOSITORY CONSUL_HTTP_TOKEN SERVICES
CONTEXT_DEBUG += APP_DIR APP_DOMAIN APP_HOST APP_PATH APP_URL APP_REPOSITORY APP_UPSTREAM_REPOSITORY CONSUL_HTTP_TOKEN SERVICES
ENV_DEPLOY ?= $(shell ls .git/refs/heads/)
ENV_VARS += APP_DIR APP_DOMAIN APP_HOST APP_PATH APP_URL CONSUL_HTTP_TOKEN $(if $(filter true,$(MOUNT_NFS)),NFS_CONFIG)
MOUNT_NFS ?= false

View File

@ -8,7 +8,7 @@ APP_TYPE ?= $(if $(SUBREPO),subrepo) $(if $(filter .,$(MY
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 ?= $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null)
CMDS ?= exec exec:% exec@% run run:% run@%
CMDS ?= exec exec:% exec@% install-app install-apps run run:% run@%
COMMIT ?= $(shell git rev-parse $(BRANCH) 2>/dev/null)
CONTEXT ?= $(if $(APP),APP BRANCH VERSION) $(shell awk 'BEGIN {FS="="}; $$1 !~ /^(\#|$$)/ {print $$1}' .env.dist 2>/dev/null)
CONTEXT_DEBUG ?= MAKEFILE_LIST env APPS GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME LOG_LEVEL MAKE_DIR MAKE_SUBDIRS MAKE_CMD_ARGS MAKE_ENV_ARGS MONOREPO_DIR UID USER
@ -27,7 +27,6 @@ ENV_VARS ?= APP BRANCH ENV HOSTNAME GID GIT_AUTHOR_EMAIL
GID ?= $(shell id -g 2>/dev/null)
GIT_AUTHOR_EMAIL ?= $(shell git config user.email 2>/dev/null)
GIT_AUTHOR_NAME ?= $(shell git config user.name 2>/dev/null)
GIT_PARAMETERS_REPOSITORY ?= $(call pop,$(GIT_UPSTREAM_REPOSITORY))/$(notdir $(PARAMETERS))
GIT_REPOSITORY ?= $(if $(SUBREPO),$(shell awk -F ' = ' '$$1 ~ /^[[\s\t]]*remote$$/ {print $$2}' .gitrepo 2>/dev/null),$(shell git config --get remote.origin.url 2>/dev/null))
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))
@ -48,6 +47,7 @@ MONOREPO ?= $(if $(filter myos,$(MYOS)),$(notdir $(CURDIR
MONOREPO_DIR ?= $(if $(MONOREPO),$(if $(filter myos,$(MYOS)),$(realpath $(CURDIR)),$(if $(APP),$(realpath $(CURDIR)/..))))
MYOS ?= $(if $(filter $(MAKE_DIR),$(call pop,$(MAKE_DIR))),.,$(call pop,$(MAKE_DIR)))
PARAMETERS ?= $(RELATIVE)parameters
PARAMETERS_REPOSITORY ?= $(call pop,$(GIT_UPSTREAM_REPOSITORY))/$(notdir $(PARAMETERS))
QUIET ?= $(if $(filter false,$(VERBOSE)),--quiet)
RECURSIVE ?= true
RELATIVE ?= $(if $(filter myos,$(MYOS)),./,../)
@ -170,6 +170,23 @@ pop = $(patsubst %$(or $(2),/)$(lastword $(subst $(or $(2),/), ,$(1))),%,$(1))
# macro sed: Exec sed script 1 on file 2
sed = $(call exec,sed -i $(SED_SUFFIX) '\''$(1)'\'' $(2))
# function install-app: Exec 'git clone url 1 dir 2'
## it installs application source files
define install-app
$(eval url := $(or $(1), $(APP_REPOSITORY)))
$(eval dir := $(or $(2), $(RELATIVE)$(lastword $(subst /, ,$(url)))))
[ -d $(dir) ] || $(call exec,$(ECHO) git clone $(QUIET) $(url) $(dir))
endef
# function update-app: Exec 'cd dir 1 && git pull'
## it updates application source files
define update-app
$(eval dir := $(or $(1), $(APP_DIR)))
$(eval url := $(or $(2), $(APP_REPOSITORY)))
$(call install-app,$(url),$(dir))
[ -d $(dir) ] && $(call exec,cd $(dir) && $(ECHO) git pull $(QUIET))
endef
# function TARGET:ENV: Create a new target ending with :env
## it sets ENV, ENV_FILE and calls original target
define TARGET:ENV

View File

@ -1,6 +1,16 @@
##
# UPDATE
# target install-app install-apps: Call install-app for each ARGS
.PHONY: install-app install-apps
install-app install-apps:
$(foreach url,$(ARGS),$(call install-app,$(url)))
# target install-app-%: Call install-app for %
.PHONY: install-app-%
install-app-%:
$(call install-app,$*)
# target update-apps: Call update-app target for each APPS
.PHONY: update-apps
update-apps:
@ -14,11 +24,11 @@ update-app: update-app-$(APP_NAME) ;
.PHONY: update-app-%
update-app-%: myos-base % ;
# target $(APP): Clone or pull application files
# target $(APP): Call update-app
.PHONY: $(APP)
$(APP): APP_DIR := $(RELATIVE)$(APP)
$(APP):
$(call exec,[ -d $(APP_DIR) ] && cd $(APP_DIR) && git pull $(QUIET) origin $(BRANCH) || git clone $(QUIET) $(APP_REPOSITORY) $(APP_DIR))
$(call update-app)
# target update-hosts: Update /etc/hosts
# on local host
@ -38,7 +48,7 @@ update-parameters: $(PARAMETERS)
$(PARAMETERS): SSH_PUBLIC_HOST_KEYS := $(PARAMETERS_REMOTE_HOST) $(SSH_BASTION_HOSTNAME) $(SSH_REMOTE_HOSTS)
$(PARAMETERS): MAKE_VARS += SSH_BASTION_HOSTNAME SSH_BASTION_USERNAME SSH_PRIVATE_IP_RANGE SSH_PUBLIC_HOST_KEYS
$(PARAMETERS): myos-base
$(call exec,[ -d $(PARAMETERS) ] && cd $(PARAMETERS) && git pull --quiet || git clone --quiet $(APP_PARAMETERS_REPOSITORY))
$(call update-app,$(PARAMETERS),$(PARAMETERS_REPOSITORY))
# target update-remote-%: fetch git remote %
.PHONY: update-remote-%