ansible
This commit is contained in:
+4
-13
@@ -9,20 +9,11 @@ bootstrap: bootstrap-git bootstrap-docker app-bootstrap ## Update application fi
|
||||
# target bootstrap-docker: Build and start application dockers
|
||||
# on local host
|
||||
.PHONY: boostrap-docker
|
||||
bootstrap-docker: docker-network-create
|
||||
$(call make,docker-compose-up)
|
||||
bootstrap-docker: install-bin-docker docker-network-create
|
||||
|
||||
# target bootstrap-git: Fire update-app
|
||||
.PHONY: bootstrap-git
|
||||
bootstrap-git: update-app
|
||||
|
||||
# target bootstrap-git-%: Clone GIT_REPOSITORY in folder %
|
||||
# on local host
|
||||
.PHONY: bootstrap-git-%
|
||||
bootstrap-git-%:
|
||||
if ! git config remote.origin.url > /dev/null ; \
|
||||
then git clone $(QUIET) $(GIT_REPOSITORY) $*; \
|
||||
fi
|
||||
bootstrap-git: install-bin-git
|
||||
|
||||
# target build: Build application docker images to run
|
||||
# on local host
|
||||
@@ -45,7 +36,7 @@ build@%: myos-base
|
||||
# target clean: Clean application and docker images
|
||||
# on local host
|
||||
.PHONY: clean app-clean
|
||||
clean: app-clean docker-rm docker-image-rm docker-volume-rm .env-clean ## Clean application and docker stuffs
|
||||
clean: app-clean docker-rm docker-images-rm docker-volume-rm .env-clean ## Clean application and docker stuffs
|
||||
|
||||
# target clean@%: Clean deployed application and docker images of % ENV
|
||||
# on local host
|
||||
@@ -98,7 +89,7 @@ exec@%:
|
||||
# target install app-install: Install application
|
||||
# on local host
|
||||
.PHONY: install app-install
|
||||
install: update-app app-install ## Install application
|
||||
install: bootstrap app-install ## Install application
|
||||
|
||||
# target logs: Display application dockers logs
|
||||
# on local host
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
BUILD_AUTHOR ?= $(DOCKER_AUTHOR)
|
||||
BUILD_DATE ?= $(shell TZ=UTC date "+%Y%m%dT%H%M%SZ" 2>/dev/null)
|
||||
BUILD_DESCRIPTION ?= Lot of Love
|
||||
BUILD_DOCUMENTATION ?= $(if $(wildcard README.md),$(APP_REPOSITORY)/blob/$(COMMIT)/README.md)
|
||||
BUILD_ENV_VARS ?= APP BRANCH BUILD_DATE BUILD_STATUS COMMIT DEPLOY_HOOK_URL ENV VERSION
|
||||
BUILD_DOCUMENTATION ?= $(if $(wildcard README.md),$(APP_REPOSITORY_URL)/blob/$(COMMIT)/README.md)
|
||||
BUILD_ENV_VARS ?= APP BRANCH BUILD_DATE BUILD_STATUS COMMIT DEPLOY_HOOK_URL ENV UID USER VERSION
|
||||
BUILD_LABEL_VARS ?= org.label-schema.% org.opencontainers.% os.my.%
|
||||
BUILD_LABEL_ARGS ?= $(foreach var,$(filter $(BUILD_LABEL_VARS),$(MAKE_FILE_VARS)),$(if $($(var)),$(var)='$($(var))'))
|
||||
BUILD_LICENSE ?= GPL-3.0
|
||||
@@ -19,17 +19,17 @@ org.label-schema.schema-version ?= 1.0
|
||||
org.label-schema.url ?= $(APP_URL)
|
||||
org.label-schema.usage ?= $(BUILD_DOCUMENTATION)
|
||||
org.label-schema.vcs-ref ?= $(COMMIT)
|
||||
org.label-schema.vcs-url ?= $(APP_REPOSITORY)
|
||||
org.label-schema.vcs-url ?= $(APP_REPOSITORY_URL)
|
||||
org.label-schema.vendor ?= $(BUILD_AUTHOR)
|
||||
org.label-schema.version ?= $(VERSION)
|
||||
org.opencontainers.image.created ?= $(BUILD_DATE)
|
||||
org.opencontainers.image.revision ?= $(COMMIT)
|
||||
org.opencontainers.image.source ?= $(APP_REPOSITORY)
|
||||
org.opencontainers.image.source ?= $(APP_REPOSITORY_URL)
|
||||
org.opencontainers.image.url ?= $(APP_URL)
|
||||
org.opencontainers.image.vendor ?= $(BUILD_AUTHOR)
|
||||
org.opencontainers.image.version ?= $(VERSION)
|
||||
org.opencontainers.image.url ?= $(APP_URL)
|
||||
org.opencontainers.image.source ?= $(APP_REPOSITORY)
|
||||
org.opencontainers.image.source ?= $(APP_REPOSITORY_URL)
|
||||
org.opencontainers.image.version ?= $(VERSION)
|
||||
org.opencontainers.image.revision ?= $(COMMIT)
|
||||
org.opencontainers.image.vendor ?= $(BUILD_AUTHOR)
|
||||
|
||||
@@ -47,7 +47,7 @@ DOCKER_SERVICES ?= $(eval IGNORE_DRYRUN := true)$(shell $(call d
|
||||
DOCKER_SHELL ?= $(SHELL)
|
||||
ENV_VARS += COMPOSE_PROJECT_NAME COMPOSE_SERVICE_NAME DOCKER_BUILD_TARGET DOCKER_GID DOCKER_IMAGE_TAG DOCKER_REGISTRY DOCKER_REPOSITORY DOCKER_SHELL
|
||||
|
||||
ifeq ($(DOCKER), true)
|
||||
ifneq ($(DOCKER_RUN),)
|
||||
DOCKER_COMPOSE ?= docker/compose:$(COMPOSE_VERSION)
|
||||
else
|
||||
DOCKER_COMPOSE ?= $(or $(shell docker compose >/dev/null 2>&1 && printf 'docker compose\n'),docker-compose)
|
||||
|
||||
+9
-3
@@ -5,13 +5,19 @@ APP_HOST ?= $(APP)$(addprefix .,$(APP_DOMAIN))
|
||||
APP_INSTALLED ?= $(APPS)
|
||||
APP_PARENT ?= $(MONOREPO)
|
||||
APP_PARENT_DIR ?= $(MONOREPO_DIR)
|
||||
APP_PATH ?= /$(APP_PATH_PREFIX)
|
||||
APP_REPOSITORY ?= $(GIT_REPOSITORY)
|
||||
APP_PATH += $(APP_PATH_PREFIX)
|
||||
APP_REPOSITORY ?= $(APP_REPOSITORY_URL)
|
||||
APP_REPOSITORY_HOST ?= $(shell printf '$(APP_REPOSITORY_URI)\n' |sed 's|/.*||;s|.*@||')
|
||||
APP_REPOSITORY_PATH ?= $(shell printf '$(APP_REPOSITORY_URI)\n' |sed 's|[^/]*/||;')
|
||||
APP_REPOSITORY_SCHEME ?= $(shell printf '$(APP_REPOSITORY_URL)\n' |sed 's|://.*||;')
|
||||
APP_REPOSITORY_URI ?= $(shell printf '$(APP_REPOSITORY_URL)\n' |sed 's|.*://||;')
|
||||
APP_REPOSITORY_URL ?= $(GIT_REPOSITORY)
|
||||
APP_REQUIRED ?= $(APP_REPOSITORY)
|
||||
APP_SCHEME ?= https
|
||||
APP_UPSTREAM_REPOSITORY ?= $(or $(shell git config --get remote.upstream.url 2>/dev/null),$(GIT_UPSTREAM_REPOSITORY))
|
||||
APP_URI ?= $(APP_HOST)$(APP_PATH)
|
||||
APP_URI ?= $(APP_HOST)/$(APP_PATH)
|
||||
APP_URL ?= $(APP_SCHEME)://$(APP_URI)
|
||||
CONTEXT += APP APPS BRANCH DOMAIN VERSION RELEASE
|
||||
CONTEXT_DEBUG += APP_DIR APP_URL APP_REPOSITORY APP_UPSTREAM_REPOSITORY ENV_DEPLOY
|
||||
ENV_DEPLOY ?= $(shell ls .git/refs/remotes/origin/ 2>/dev/null)
|
||||
ENV_VARS += APP_DIR APP_DOMAIN APP_HOST APP_PATH APP_URL CONSUL_HTTP_TOKEN $(if $(filter true,$(MOUNT_NFS)),NFS_CONFIG)
|
||||
|
||||
+13
-6
@@ -122,7 +122,7 @@ docker-images-rm:
|
||||
docker-images-rm-%:
|
||||
docker images |awk '$$1 ~ /^$(subst /,\/,$*)/ {print $$3}' |sort -u |while read image; do $(RUN) docker rmi -f $$image; done
|
||||
|
||||
# target docker-login: Exec 'docker login'
|
||||
# target docker-login: Run 'docker login'
|
||||
.PHONY: docker-login
|
||||
docker-login: myos-base
|
||||
$(RUN) docker login
|
||||
@@ -131,7 +131,7 @@ docker-login: myos-base
|
||||
.PHONY: docker-network-create
|
||||
docker-network-create: docker-network-create-$(DOCKER_NETWORK)
|
||||
|
||||
# target docker-network-create-%: Exec 'docker network create %'
|
||||
# target docker-network-create-%: Run 'docker network create %'
|
||||
.PHONY: docker-network-create-%
|
||||
docker-network-create-%:
|
||||
if [ -z "$(shell docker network ls -q --filter name='^$*$$' 2>/dev/null)" ]; then \
|
||||
@@ -142,18 +142,25 @@ docker-network-create-%:
|
||||
.PHONY: docker-network-rm
|
||||
docker-network-rm: docker-network-rm-$(DOCKER_NETWORK)
|
||||
|
||||
# target docker-network-rm-%: Remove docker network %
|
||||
# target docker-network-rm-%: Run 'docker network rm %'
|
||||
.PHONY: docker-network-rm-%
|
||||
docker-network-rm-%:
|
||||
if [ -n "$(shell docker network ls -q --filter name='^$*$$' 2>/dev/null)" ]; then \
|
||||
$(RUN) docker network rm $* >/dev/null \
|
||||
&& $(or $(call INFO,docker network $* removed), true); fi \
|
||||
|
||||
# target docker-plugin-install: Exec 'docker plugin install DOCKER_PLUGIN_OPTIONS DOCKER_PLUGIN'
|
||||
# target docker-plugin-install: Run 'docker plugin install DOCKER_PLUGIN_OPTIONS DOCKER_PLUGIN'
|
||||
.PHONY: docker-plugin-install
|
||||
docker-plugin-install:
|
||||
$(eval docker_plugin_state := $(shell docker plugin ls | awk '$$2 == "$(DOCKER_PLUGIN)" {print $$NF}') )
|
||||
$(if $(docker_plugin_state),$(if $(filter $(docker_plugin_state),false),printf "Enabling docker plugin $(DOCKER_PLUGIN) ... " && $(RUN) docker plugin enable $(DOCKER_PLUGIN) >/dev/null 2>&1 && printf "done\n" || printf "ERROR\n"),printf "Installing docker plugin $(DOCKER_PLUGIN) ... " && $(RUN) docker plugin install $(DOCKER_PLUGIN_OPTIONS) $(DOCKER_PLUGIN) $(DOCKER_PLUGIN_ARGS) >/dev/null 2>&1 && printf "done\n" || printf "ERROR\n")
|
||||
$(if $(docker_plugin_state),\
|
||||
$(if $(filter $(docker_plugin_state),false),\
|
||||
$(RUN) docker plugin enable $(DOCKER_PLUGIN) >/dev/null 2>&1 \
|
||||
&& $(or $(call INFO,docker plugin $(DOCKER_PLUGIN) enabled), true) \
|
||||
), \
|
||||
$(RUN) docker plugin install $(DOCKER_PLUGIN_OPTIONS) $(DOCKER_PLUGIN) $(DOCKER_PLUGIN_ARGS) >/dev/null 2>&1 \
|
||||
&& $(or $(call INFO,docker plugin $(DOCKER_PLUGIN) installed), true) \
|
||||
)
|
||||
|
||||
# target docker-push: Call docker-push for each SERVICES
|
||||
.PHONY: docker-push
|
||||
@@ -205,7 +212,7 @@ docker-run-%: docker-build-%
|
||||
$(eval path := $(patsubst %/,%,$*))
|
||||
$(eval image := $(DOCKER_REPOSITORY)/$(lastword $(subst /, ,$(path)))$(if $(findstring :,$*),,:$(DOCKER_IMAGE_TAG)))
|
||||
$(eval image_id := $(shell docker images -q $(image) 2>/dev/null))
|
||||
$(call docker-run,$(command),$(if $(image_id),$(image),$(path)))
|
||||
$(call docker-run,$(RUN) $(command),$(if $(image_id),$(image),$(path)))
|
||||
|
||||
# target docker-tag: Call docker-tag for each SERVICES
|
||||
.PHONY: docker-tag
|
||||
|
||||
@@ -9,11 +9,11 @@
|
||||
.PHONY: install-mysql-database-%
|
||||
install-mysql-database-%: $(if $(DOCKER_RUN),myos-base)
|
||||
$(call exec,mysql -h mysql -u root -proot $* -e "use $*" >/dev/null 2>&1) \
|
||||
|| $(RUN) $(call exec,mysql -h mysql -u root -proot mysql -e "create database $* character set utf8 collate utf8_unicode_ci;")
|
||||
|| $(call exec,$(RUN) mysql -h mysql -u root -proot mysql -e "create database $* character set utf8 collate utf8_unicode_ci;")
|
||||
$(call exec,mysql -h mysql -u $* -p$* $* -e "use $*" >/dev/null 2>&1) \
|
||||
|| $(RUN) $(call exec,mysql -h mysql -u root -proot mysql -e "grant all privileges on $*.* to '$*'@'%' identified by '$*'; flush privileges;")
|
||||
|| $(call exec,$(RUN) mysql -h mysql -u root -proot mysql -e "grant all privileges on $*.* to '$*'@'%' identified by '$*'; flush privileges;")
|
||||
$(call exec,sh -c '[ $$(mysql -h mysql -u $* -p$* $* -e "show tables" 2>/dev/null |wc -l) -eq 0 ] && [ -f "${APP_DIR}/$*.mysql.gz" ]') \
|
||||
&& $(RUN) $(call exec,sh -c 'gzip -cd "${APP_DIR}/$*.mysql.gz" |mysql -h mysql -u root -proot $*') \
|
||||
&& $(call exec,$(RUN) sh -c 'gzip -cd "${APP_DIR}/$*.mysql.gz" |mysql -h mysql -u root -proot $*') \
|
||||
||:
|
||||
|
||||
# target install-pgsql-database-%: Import %.pgsql.gz to database %
|
||||
@@ -24,14 +24,14 @@ install-mysql-database-%: $(if $(DOCKER_RUN),myos-base)
|
||||
.PHONY: install-pgsql-database-%
|
||||
install-pgsql-database-%: myos-base
|
||||
$(call exec,PGPASSWORD=$* psql -h postgres -U $* template1 -c "\q" >/dev/null 2>&1) \
|
||||
|| $(RUN) $(call exec,PGPASSWORD=postgres psql -h postgres -U postgres -c "create user $* with createdb password '$*';")
|
||||
|| $(call exec,$(RUN) PGPASSWORD=postgres psql -h postgres -U postgres -c "create user $* with createdb password '$*';")
|
||||
$(call exec,PGPASSWORD=$* psql -h postgres -U $* -d $* -c "" >/dev/null 2>&1) \
|
||||
|| $(RUN) $(call exec,PGPASSWORD=postgres psql -h postgres -U postgres -c "create database $* owner $* ;")
|
||||
|| $(call exec,$(RUN) PGPASSWORD=postgres psql -h postgres -U postgres -c "create database $* owner $* ;")
|
||||
$(call exec,[ $$(PGPASSWORD=$* psql -h postgres -U $* -d $* -c "\d" 2>/dev/null |wc -l) -eq 0 ] && [ -f "${APP_DIR}/$*.pgsql.gz" ]) \
|
||||
&& $(RUN) $(call exec,sh -c 'gzip -cd "${APP_DIR}/$*.pgsql.gz" |PGPASSWORD="postgres" psql -h postgres -U postgres -d $*') \
|
||||
&& $(call exec,$(RUN) sh -c 'gzip -cd "${APP_DIR}/$*.pgsql.gz" |PGPASSWORD="postgres" psql -h postgres -U postgres -d $*') \
|
||||
||:
|
||||
$(call exec,[ $$(PGPASSWORD=$* psql -h postgres -U $* -d $* -c "\d" 2>/dev/null |wc -l) -eq 0 ] && [ -f "${APP_DIR}/$*.pgsql" ]) \
|
||||
&& $(RUN) $(call exec,sh -c 'PGPASSWORD="postgres" psql -h postgres -U postgres -c "ALTER ROLE $* WITH SUPERUSER" && PGPASSWORD="postgres" pg_restore -h postgres --no-owner --role=$* -U postgres -d $* ${APP_DIR}/$*.pgsql && PGPASSWORD="postgres" psql -h postgres -U postgres -c "ALTER ROLE $* WITH NOSUPERUSER"') \
|
||||
&& $(call exec,$(RUN) sh -c 'PGPASSWORD="postgres" psql -h postgres -U postgres -c "ALTER ROLE $* WITH SUPERUSER" && PGPASSWORD="postgres" pg_restore -h postgres --no-owner --role=$* -U postgres -d $* ${APP_DIR}/$*.pgsql && PGPASSWORD="postgres" psql -h postgres -U postgres -c "ALTER ROLE $* WITH NOSUPERUSER"') \
|
||||
||:
|
||||
|
||||
# target install-build-config: Call install-config with file * and dest build
|
||||
|
||||
@@ -4,6 +4,6 @@ ENV_VARS += COMPOSE_IGNORE_ORPHANS DOCKER_IMAGE_CLI DOCKE
|
||||
HOME ?= /home/$(USER)
|
||||
NFS_DISK ?= $(NFS_HOST):/$(notdir $(SHARED))
|
||||
NFS_OPTIONS ?= rw,rsize=8192,wsize=8192,bg,hard,intr,nfsvers=3,noatime,nodiratime,actimeo=3
|
||||
NFS_PATH ?= /srv/$(subst :,,$(NFS_DISK))
|
||||
NFS_PATH ?= /srv/$(subst $(space),/,$(strip $(call reverse,$(subst ., ,$(NFS_HOST)))))$(subst ..,,$(SHARED))
|
||||
SHELL ?= /bin/sh
|
||||
STACK ?= base
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
DOCKER_BUILD_VARS += $(SSH_ENV_VARS)
|
||||
ENV_VARS += $(SSH_ENV_VARS)
|
||||
SSH_AUTHORIZED_KEYS ?= $(SSH_GITHUB_AUTHORIZED_KEYS)
|
||||
SSH_BASTION_HOSTNAME ?=
|
||||
SSH_BASTION_USERNAME ?=
|
||||
SSH_ENV_VARS ?= SSH_BASTION_HOSTNAME SSH_BASTION_USERNAME SSH_PUBLIC_HOST_KEYS SSH_PRIVATE_IP_RANGE
|
||||
SSH_PUBLIC_HOST_KEYS ?= $(SSH_REMOTE_HOSTS) $(SSH_BASTION_HOSTNAME)
|
||||
SSH_BASTION_USERNAME ?= $(SSH_USER)
|
||||
SSH_ENV_VARS ?= SSH_BASTION_HOSTNAME SSH_BASTION_USERNAME SSH_PUBLIC_HOSTS SSH_PRIVATE_IP_RANGE SSH_USER
|
||||
SSH_GITHUB_AUTHORIZED_KEYS ?= $(patsubst %,https://github.com/%,$(patsubst %,%.keys,$(SSH_USER)))
|
||||
SSH_PUBLIC_HOSTS ?= $(CONFIG_REPOSITORY_HOST) $(SSH_BASTION_HOSTNAME) $(SSH_REMOTE_HOSTS)
|
||||
SSH_PRIVATE_IP_RANGE ?=
|
||||
SSH_PRIVATE_KEYS ?= $(wildcard $(SSH_DIR)/id_rsa)
|
||||
SSH_REMOTE_HOSTS ?= github.com gitlab.com
|
||||
SSH_USER ?= $(call slugify,$(GIT_USER))
|
||||
|
||||
# function ssh-connect: Exec command 2 on remote hosts 1 with tty
|
||||
define ssh-connect
|
||||
|
||||
+16
-8
@@ -17,6 +17,11 @@ install-app install-apps: myos-base install-app-required
|
||||
install-app-required: myos-base
|
||||
$(foreach url,$(APP_REQUIRED),$(call install-app,$(url)))
|
||||
|
||||
# target install-bin-%; Call ansible-run-localhost when bin % is not available
|
||||
.PHONY: install-bin-%
|
||||
install-bin-%:;
|
||||
$(if $(shell type $* 2>/dev/null),,$(call make,ansible-run-localhost))
|
||||
|
||||
# target $(SHARED): Create SHARED folder
|
||||
$(SHARED):
|
||||
$(RUN) mkdir -p $(SHARED)
|
||||
@@ -36,8 +41,6 @@ update-app-%: % ;
|
||||
|
||||
# target update-config: Update config files
|
||||
.PHONY: update-config
|
||||
update-config: SSH_PUBLIC_HOST_KEYS := $(CONFIG_REMOTE_HOST) $(SSH_BASTION_HOSTNAME) $(SSH_REMOTE_HOSTS)
|
||||
update-config: MAKE_VARS += SSH_BASTION_HOSTNAME SSH_BASTION_USERNAME SSH_PRIVATE_IP_RANGE SSH_PUBLIC_HOST_KEYS
|
||||
update-config: myos-base
|
||||
$(call update-app,$(CONFIG_REPOSITORY),$(CONFIG))
|
||||
|
||||
@@ -47,27 +50,32 @@ update-config: myos-base
|
||||
.PHONY: update-hosts
|
||||
update-hosts:
|
||||
ifneq (,$(filter $(ENV),local))
|
||||
cat .env */.env 2>/dev/null |grep -Eo 'urlprefix-[^/]+' |sed 's/urlprefix-//' |while read host; do grep $$host /etc/hosts >/dev/null 2>&1 || { printf "Adding $$host to /etc/hosts\n"; printf "127.0.0.1 $$host\n" |$(RUN) sudo tee -a /etc/hosts >/dev/null; }; done
|
||||
cat .env */.env 2>/dev/null |grep -Eo 'urlprefix-[^/]+' |sed 's/urlprefix-//' |while read host; do \
|
||||
grep $$host /etc/hosts >/dev/null 2>&1 || { \
|
||||
printf "Adding $$host to /etc/hosts\n"; \
|
||||
printf "127.0.0.1 $$host\n" |$(RUN) sudo tee -a /etc/hosts >/dev/null; \
|
||||
}; \
|
||||
done
|
||||
endif
|
||||
|
||||
# target update-remote-%: fetch git remote %
|
||||
.PHONY: update-remote-%
|
||||
update-remote-%: myos-base
|
||||
$(RUN) $(call exec,git fetch --prune --tags $*)
|
||||
$(RUN) git fetch --prune --tags $*
|
||||
|
||||
# target update-remotes: fetch all git remotes
|
||||
.PHONY: update-remotes
|
||||
update-remotes: myos-base
|
||||
$(RUN) $(call exec,git fetch --all --prune --tags)
|
||||
$(RUN) git fetch --all --prune --tags
|
||||
|
||||
# target update-upstream: fetch git remote upstream
|
||||
.PHONY: update-upstream
|
||||
update-upstream: myos-base .git/refs/remotes/upstream/master
|
||||
$(RUN) $(call exec,git fetch --prune --tags upstream)
|
||||
$(RUN) git fetch --prune --tags upstream
|
||||
|
||||
# target .git/refs/remotes/upstream/master: git add upstream APP_UPSTREAM_REPOSITORY
|
||||
# target .git/refs/remotes/upstream/master: add git upstream APP_UPSTREAM_REPOSITORY
|
||||
.git/refs/remotes/upstream/master:
|
||||
$(RUN) git remote add upstream $(APP_UPSTREAM_REPOSITORY) 2>/dev/null ||:
|
||||
$(RUN) git remote add upstream $(APP_UPSTREAM_REPOSITORY)
|
||||
|
||||
# target shared: Fire SHARED
|
||||
.PHONY: update-shared
|
||||
|
||||
+1
-2
@@ -14,7 +14,6 @@ DOCKER_NETWORK_PRIVATE ?= $(USER_ENV)
|
||||
DOCKER_NETWORK_PUBLIC ?= node
|
||||
DOCKER_REPOSITORY_MYOS ?= $(subst _,/,$(COMPOSE_PROJECT_NAME_MYOS))
|
||||
DOCKER_REPOSITORY_NODE ?= $(subst _,/,$(COMPOSE_PROJECT_NAME_NODE))
|
||||
DOCKER_RUN ?= $(filter true,$(DOCKER))
|
||||
# DOCKER_RUN_OPTIONS: default options of `docker run` command
|
||||
DOCKER_RUN_OPTIONS += --rm -it
|
||||
# DOCKER_RUN_VOLUME: options -v of `docker run` command to mount additionnal volumes
|
||||
@@ -33,7 +32,7 @@ else
|
||||
DOCKER_RUN_VOLUME += -v $(or $(APP_PARENT_DIR),$(APP_DIR),$(PWD)):$(or $(WORKSPACE_DIR),$(APP_PARENT_DIR),$(APP_DIR),$(PWD))
|
||||
endif
|
||||
|
||||
ifeq ($(DOCKER), true)
|
||||
ifneq ($(DOCKER_RUN),)
|
||||
|
||||
DOCKER_SSH_AUTH := -e SSH_AUTH_SOCK=/tmp/ssh-agent/socket -v $(DOCKER_VOLUME_SSH):/tmp/ssh-agent
|
||||
|
||||
|
||||
+48
-26
@@ -12,6 +12,10 @@ 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 ?= $(GIT_BRANCH)
|
||||
CMD_APK_INSTALL ?= $(if $(shell type -p apk),apk --no-cache --update add)
|
||||
CMD_APK_REMOVE ?= $(if $(shell type -p apk),apk --no-cache del)
|
||||
CMD_APT_INSTALL ?= $(if $(shell type -p apt-get),apt-get update && apt-get -fy install)
|
||||
CMD_APT_REMOVE ?= $(if $(shell type -p apt-get),apt-get -fy remove)
|
||||
CMDS ?= exec exec:% exec@% install-app install-apps run run:% run@%
|
||||
COLOR_INFO ?= $(COLOR_BROWN)
|
||||
COLOR_HIGHLIGHT ?= $(COLOR_GREEN)
|
||||
@@ -28,17 +32,24 @@ COLOR_CYAN ?= \033[36m
|
||||
COLOR_GRAY ?= \033[37m
|
||||
COMMIT ?= $(or $(SUBREPO_COMMIT),$(GIT_COMMIT))
|
||||
CONFIG ?= $(RELATIVE)config
|
||||
CONFIG_REPOSITORY ?= $(call pop,$(or $(APP_UPSTREAM_REPOSITORY),$(GIT_UPSTREAM_REPOSITORY)))/$(notdir $(CONFIG))
|
||||
CONTEXT ?= $(if $(APP),APP BRANCH DOMAIN VERSION) $(shell awk 'BEGIN {FS="="}; $$1 !~ /^(\#|$$)/ {print $$1}' .env.dist 2>/dev/null)
|
||||
CONFIG_REPOSITORY ?= $(CONFIG_REPOSITORY_URL)
|
||||
CONFIG_REPOSITORY_HOST ?= $(shell printf '$(CONFIG_REPOSITORY_URI)\n' |sed 's|/.*||;s|.*@||')
|
||||
CONFIG_REPOSITORY_PATH ?= $(shell printf '$(CONFIG_REPOSITORY_URI)\n' |sed 's|[^/]*/||;')
|
||||
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_DEBUG ?= MAKEFILE_LIST env env.docker APPS GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME MAKE_DIR MAKE_SUBDIRS MAKE_CMD_ARGS MAKE_ENV_ARGS UID USER
|
||||
DEBUG ?=
|
||||
DOCKER ?= $(if $(BUILD),false,true)
|
||||
DOCKER ?= $(shell type -p docker)
|
||||
DOCKER_RUN ?= $(if $(filter-out false False FALSE,$(DOCKER)),$(DOCKER))
|
||||
DOMAIN ?= localhost
|
||||
DRONE ?= false
|
||||
DRYRUN ?= false
|
||||
DRYRUN_RECURSIVE ?= false
|
||||
ELAPSED_TIME = $(shell $(call TIME))
|
||||
ENV ?= local
|
||||
ENV_ARGS = $(if $(DOCKER_RUN),$(env.docker.args) $(env.docker.dist),$(env.args) $(env.dist))
|
||||
ENV_FILE ?= $(wildcard $(CONFIG)/$(ENV)/$(APP)/.env .env)
|
||||
ENV_LIST ?= $(shell ls .git/refs/heads/ 2>/dev/null)
|
||||
ENV_RESET ?= false
|
||||
@@ -53,10 +64,14 @@ GIT_STATUS ?= $(shell git status -uno --porcelain 2>/dev/nu
|
||||
GIT_TAG ?= $(shell git tag -l --points-at $(BRANCH) 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 ?= $(lastword $(subst /, ,$(call pop,$(MYOS_REPOSITORY))))
|
||||
GIT_USER ?= $(GIT_AUTHOR_NAME)
|
||||
GIT_VERSION ?= $(shell git describe --tags $(BRANCH) 2>/dev/null || git rev-parse $(BRANCH) 2>/dev/null)
|
||||
HOSTNAME ?= $(shell hostname 2>/dev/null |sed 's/\..*//')
|
||||
IGNORE_DRYRUN ?= false
|
||||
IGNORE_VERBOSE ?= false
|
||||
INSTALL ?= $(SUDO) $(subst &&,&& $(SUDO),$(INSTALL_CMD))
|
||||
INSTALL_CMDS ?= APK_INSTALL APT_INSTALL
|
||||
$(foreach cmd,$(INSTALL_CMDS),$(if $(CMD_$(cmd)),$(eval INSTALL_CMD ?= $(CMD_$(cmd)))))
|
||||
LOG_LEVEL ?= $(if $(DEBUG),debug,$(if $(VERBOSE),info,error))
|
||||
MAKE_ARGS ?= $(foreach var,$(MAKE_VARS),$(if $($(var)),$(var)='$($(var))'))
|
||||
MAKE_SUBDIRS ?= $(if $(filter myos,$(MYOS)),monorepo,$(if $(APP),apps $(foreach type,$(APP_TYPE),$(if $(wildcard $(MAKE_DIR)/apps/$(type)),apps/$(type)))))
|
||||
@@ -83,6 +98,7 @@ SHARED ?= $(RELATIVE)shared
|
||||
SSH_DIR ?= ${HOME}/.ssh
|
||||
STATUS ?= $(GIT_STATUS)
|
||||
SUBREPO ?= $(if $(wildcard .gitrepo),$(notdir $(CURDIR)))
|
||||
SUDO ?= $(if $(filter-out 0,$(UID)),$(shell type -p sudo))
|
||||
TAG ?= $(GIT_TAG)
|
||||
UID ?= $(shell id -u 2>/dev/null)
|
||||
USER ?= $(shell id -nu 2>/dev/null)
|
||||
@@ -90,18 +106,13 @@ USER_ENV ?= $(USER)_$(ENV)
|
||||
VERBOSE ?= $(if $(DEBUG),true)
|
||||
VERSION ?= $(GIT_VERSION)
|
||||
|
||||
ifeq ($(DOCKER), true)
|
||||
ENV_ARGS = $(env.docker.args) $(env.docker.dist)
|
||||
else
|
||||
ENV_ARGS = $(env.args) $(env.dist)
|
||||
endif
|
||||
|
||||
ifneq ($(DEBUG),)
|
||||
CONTEXT += $(CONTEXT_DEBUG)
|
||||
else
|
||||
.SILENT:
|
||||
endif
|
||||
|
||||
# Guess RUN
|
||||
ifeq ($(DRYRUN),true)
|
||||
RUN = $(if $(filter-out true,$(IGNORE_DRYRUN)),echo)
|
||||
ifeq ($(RECURSIVE), true)
|
||||
@@ -124,14 +135,12 @@ HOST_SYSTEM := DARWIN
|
||||
endif
|
||||
endif
|
||||
|
||||
# include .env files
|
||||
include $(wildcard $(ENV_FILE))
|
||||
|
||||
ifeq ($(HOST_SYSTEM),DARWIN)
|
||||
ifneq ($(DOCKER),true)
|
||||
SED_SUFFIX := ''
|
||||
endif
|
||||
endif
|
||||
|
||||
# include .env files
|
||||
include $(wildcard $(ENV_FILE))
|
||||
|
||||
# function conf: Extract variable=value line from configuration files
|
||||
## it prints the line with variable 3 definition from block 2 in file 1
|
||||
@@ -165,7 +174,20 @@ endef
|
||||
# macro force: Run command 1 sine die
|
||||
## it starts command 1 if it is not already running
|
||||
## it returns never
|
||||
force = $$(while true; do [ $$(ps x |awk 'BEGIN {nargs=split("'"$$*"'",args)} $$field == args[1] { matched=1; for (i=1;i<=NF-field;i++) { if ($$(i+field) == args[i+1]) {matched++} } if (matched == nargs) {found++} } END {print found+0}' field=4) -eq 0 ] && $(RUN) $(1) || sleep 1; done)
|
||||
force = $$(while true; do \
|
||||
[ $$(ps x |awk '\
|
||||
BEGIN {nargs=split("'"$$*"'",args)} \
|
||||
$$field == args[1] { \
|
||||
matched=1; \
|
||||
for (i=1;i<=NF-field;i++) { \
|
||||
if ($$(i+field) == args[i+1]) {matched++} \
|
||||
} \
|
||||
if (matched == nargs) {found++} \
|
||||
} \
|
||||
END {print found+0}' field=4) -eq 0 \
|
||||
] \
|
||||
&& $(RUN) $(1) || sleep 1; done \
|
||||
)
|
||||
|
||||
# macro gid: Return GID of group 1
|
||||
gid = $(shell grep '^$(1):' /etc/group 2>/dev/null |awk -F: '{print $$3}')
|
||||
@@ -188,14 +210,14 @@ ${COLOR_HIGHLIGHT}$@${COLOR_RESET}:${COLOR_RESET} ' >&$(INFO_FD) \
|
||||
&& printf '\n' >&$(INFO_FD) \
|
||||
))
|
||||
|
||||
# function install-app: Exec 'git clone url 1 dir 2' or Call update-app with url 1 dir 2
|
||||
# function install-app: Run 'git clone url 1 dir 2' or Call update-app with url 1 dir 2
|
||||
define install-app
|
||||
$(call INFO,install-app,$(1)$(comma) $(2))
|
||||
$(eval url := $(or $(1), $(APP_REPOSITORY)))
|
||||
$(eval url := $(or $(1), $(APP_REPOSITORY_URL)))
|
||||
$(eval dir := $(or $(2), $(RELATIVE)$(lastword $(subst /, ,$(url)))))
|
||||
$(if $(wildcard $(dir)/.git), \
|
||||
$(call update-app,$(url),$(dir)), \
|
||||
$(RUN) $(call exec,git clone $(QUIET) $(url) $(dir)) \
|
||||
$(call update-app,$(url),$(dir)), \
|
||||
$(RUN) git clone $(QUIET) $(url) $(dir) \
|
||||
)
|
||||
endef
|
||||
|
||||
@@ -228,21 +250,21 @@ endef
|
||||
# macro pop: Return last word of string 1 according to separator 2
|
||||
pop = $(patsubst %$(or $(2),/)$(lastword $(subst $(or $(2),/), ,$(1))),%,$(1))
|
||||
|
||||
# macro sed: Exec sed script 1 on file 2
|
||||
sed = $(call env-exec,$(RUN) sed -i $(SED_SUFFIX) '$(1)' $(2))
|
||||
# macro sed: Run sed script 1 on file 2
|
||||
sed = $(RUN) sed -i $(SED_SUFFIX) '$(1)' $(2)
|
||||
|
||||
# macro TIME: Print time elapsed since unixtime 1
|
||||
TIME = awk '{printf "%02d:%02d:%02d\n",int($$1/3600),int(($$1%3600)/60),int($$1%60)}' \
|
||||
<<< $(shell bc <<< "$(or $(2),$(MAKE_UNIXTIME_CURRENT))-$(or $(1),$(MAKE_UNIXTIME_START))" 2>/dev/null)
|
||||
<<< $(shell awk 'BEGIN {current=$(or $(2),$(MAKE_UNIXTIME_CURRENT)); start=$(or $(1),$(MAKE_UNIXTIME_START)); print (current - start)}' 2>/dev/null)
|
||||
|
||||
# function update-app: Exec 'cd dir 1 && git pull' or Call install-app
|
||||
# function update-app: Run 'cd dir 1 && git pull' or Call install-app
|
||||
define update-app
|
||||
$(call INFO,update-app,$(1)$(comma) $(2))
|
||||
$(eval url := $(or $(1), $(APP_REPOSITORY)))
|
||||
$(eval url := $(or $(1), $(APP_REPOSITORY_URL)))
|
||||
$(eval dir := $(or $(2), $(APP_DIR)))
|
||||
$(if $(wildcard $(dir)/.git), \
|
||||
$(RUN) $(call exec,sh -c 'cd $(dir) && git pull $(QUIET)'), \
|
||||
$(call install-app,$(url),$(dir)) \
|
||||
$(RUN) sh -c 'cd $(dir) && git pull $(QUIET)', \
|
||||
$(call install-app,$(url),$(dir)) \
|
||||
)
|
||||
endef
|
||||
|
||||
|
||||
+1
-1
@@ -90,5 +90,5 @@ define .env_update
|
||||
awk '{while(match($$0,"[$$]{[^}]*}")) {var=substr($$0,RSTART+2,RLENGTH-3);gsub("[$$]{"var"}",ENVIRON[var])} print}') \
|
||||
|sed -e /^$$/d -e /^#/d \
|
||||
|sort \
|
||||
>> $(env_file)
|
||||
>> $(env_file);
|
||||
endef
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
CMDS += copy master-tag release release-check release-create release-finish subrepo-push subrepo-update
|
||||
CONTEXT += APPS ENV RELEASE
|
||||
CONTEXT += APPS DOMAIN RELEASE
|
||||
DIRS ?= $(CONFIG) $(MAKE_DIR) $(SHARED)
|
||||
RELEASE_UPGRADE ?= $(filter v%, $(shell git tag -l 2>/dev/null |sort -V |awk '/$(RELEASE)/,0'))
|
||||
RELEASE_VERSION ?= $(firstword $(subst -, ,$(VERSION)))
|
||||
|
||||
+15
-15
@@ -3,10 +3,10 @@
|
||||
|
||||
# target subrepo-branch-delete: Delete branch $(BRANCH) on remote $(SUBREPO)
|
||||
.PHONY: subrepo-branch-delete
|
||||
subrepo-branch-delete: $(if $(DOCKER_RUN),myos-base) subrepo-check
|
||||
subrepo-branch-delete: myos-base subrepo-check
|
||||
ifneq ($(words $(BRANCH)),0)
|
||||
$(call exec,[ $$(git ls-remote --heads $(REMOTE) $(BRANCH) 2>/dev/null |wc -l) -eq 1 ]) \
|
||||
&& $(call exec,$(RUN) git push $(REMOTE) :$(BRANCH))
|
||||
[ $$(git ls-remote --heads $(REMOTE) $(BRANCH) 2>/dev/null |wc -l) -eq 1 ] \
|
||||
&& $(RUN) git push $(REMOTE) :$(BRANCH)
|
||||
endif
|
||||
|
||||
# target subrepo-check: Define SUBREPO and REMOTE
|
||||
@@ -28,21 +28,21 @@ endif
|
||||
.PHONY: subrepo-git-diff
|
||||
subrepo-git-diff: myos-base subrepo-check
|
||||
$(eval IGNORE_DRYRUN := true)
|
||||
$(eval DIFF = $(shell $(call exec,git diff --quiet $(shell $(call exec,git rev-list --ancestry-path $(shell awk '$$1 == "parent" {print $$3}' $(SUBREPO)/.gitrepo)..HEAD |tail -n 1)) -- $(SUBREPO); printf '$$?\n')) )
|
||||
$(eval DIFF = $(shell git diff --quiet $(shell git rev-list --ancestry-path $(shell awk '$$1 == "parent" {print $$3}' $(SUBREPO)/.gitrepo)..HEAD |tail -n 1) -- $(SUBREPO); printf '$$?\n') )
|
||||
$(eval IGNORE_DRYRUN := false)
|
||||
|
||||
# target subrepo-git-fetch: Fetch git remote
|
||||
.PHONY: subrepo-git-fetch
|
||||
subrepo-git-fetch: myos-base subrepo-check
|
||||
$(call exec,$(RUN) git fetch --prune $(REMOTE))
|
||||
$(RUN) git fetch --prune $(REMOTE)
|
||||
|
||||
# target subrepo-tag-create-%: Create tag TAG to reference branch REMOTE/%
|
||||
.PHONY: subrepo-tag-create-%
|
||||
subrepo-tag-create-%: myos-base subrepo-check subrepo-git-fetch
|
||||
ifneq ($(words $(TAG)),0)
|
||||
$(call exec,[ $$(git ls-remote --tags $(REMOTE) $(TAG) |wc -l) -eq 0 ]) \
|
||||
|| $(call exec,$(RUN) git push $(REMOTE) :refs/tags/$(TAG))
|
||||
$(call exec,$(RUN) git push $(REMOTE) refs/remotes/subrepo/$(SUBREPO)/$*:refs/tags/$(TAG))
|
||||
[ $$(git ls-remote --tags $(REMOTE) $(TAG) |wc -l) -eq 0 ] \
|
||||
|| $(call exec,$(RUN) git push $(REMOTE) :refs/tags/$(TAG))
|
||||
$(RUN) git push $(REMOTE) refs/remotes/subrepo/$(SUBREPO)/$*:refs/tags/$(TAG)
|
||||
endif
|
||||
|
||||
# target subrepo-push: Push to subrepo
|
||||
@@ -55,7 +55,7 @@ endif
|
||||
# if specific branch name, delete remote branch before push and recreate it from master
|
||||
ifneq ($(findstring $(firstword $(subst /, ,$(BRANCH))),feature hotfix release story),)
|
||||
$(eval IGNORE_DRYRUN := true)
|
||||
$(eval DELETE = $(shell $(call exec,sh -c 'git ls-remote --heads $(REMOTE) $(BRANCH) |wc -l')) )
|
||||
$(eval DELETE = $(shell sh -c 'git ls-remote --heads $(REMOTE) $(BRANCH) |wc -l') )
|
||||
$(eval IGNORE_DRYRUN := false)
|
||||
else
|
||||
$(eval DELETE = 0)
|
||||
@@ -64,12 +64,12 @@ endif
|
||||
$(call INFO,subrepo $(SUBREPO) already up to date); \
|
||||
else \
|
||||
if [ $(DELETE) -eq 1 ]; then \
|
||||
$(call exec,$(RUN) git push $(REMOTE) :$(BRANCH)); \
|
||||
$(call exec,$(RUN) git push $(REMOTE) refs/remotes/$(REMOTE)/master:refs/heads/$(BRANCH)); \
|
||||
$(RUN) git push $(REMOTE) :$(BRANCH); \
|
||||
$(RUN) git push $(REMOTE) refs/remotes/$(REMOTE)/master:refs/heads/$(BRANCH); \
|
||||
fi; \
|
||||
$(call exec,$(RUN) git subrepo fetch $(SUBREPO) -b $(BRANCH)); \
|
||||
$(call exec,$(RUN) git subrepo push $(SUBREPO) -b $(BRANCH) $(UPDATE_SUBREPO_OPTIONS)); \
|
||||
$(call exec,$(RUN) git subrepo clean $(SUBREPO)); \
|
||||
$(RUN) git subrepo fetch $(SUBREPO) -b $(BRANCH); \
|
||||
$(RUN) git subrepo push $(SUBREPO) -b $(BRANCH) $(UPDATE_SUBREPO_OPTIONS); \
|
||||
$(RUN) git subrepo clean $(SUBREPO); \
|
||||
fi
|
||||
|
||||
# target subrepos-branch-delete: Fire APPS target
|
||||
@@ -83,7 +83,7 @@ subrepos-tag-create-%: $(APPS) ;
|
||||
# target subrepos-update: Fire APPS target and push updates to upstream
|
||||
.PHONY: subrepos-update
|
||||
subrepos-update: myos-base git-stash $(APPS) git-unstash ## Update subrepos
|
||||
$(call exec,$(RUN) git push upstream $(BRANCH))
|
||||
$(RUN) git push upstream $(BRANCH)
|
||||
|
||||
# target subrepo-update-%: Call subrepo-update target in folder %
|
||||
.PHONY: subrepo-update-%
|
||||
|
||||
@@ -69,6 +69,7 @@ reverse = $(if $(1),$(call reverse,$(wordlist 2,$(words $(1)),$(1))) $(firstword
|
||||
# and in rules. Particularly useful for VCS version strings, that can contain
|
||||
# slashes, colons (OK in filenames but not in rules), and spaces.
|
||||
sanitize = $(subst $(space),_,$(subst :,_,$(subst /,_,$(strip $(1)))))
|
||||
slugify = $(subst $(space),,$(subst :,,$(subst /,,$(subst .,,$(1)))))
|
||||
|
||||
# MESSAGE Macro -- display a message in bold type
|
||||
MESSAGE = echo "$(TERM_BOLD)>>> $($(PKG)_NAME) $($(PKG)_VERSION) $(call qstrip,$(1))$(TERM_RESET)"
|
||||
|
||||
Reference in New Issue
Block a user