This commit is contained in:
aynic.os 2021-06-01 01:50:11 +02:00
parent f510f626ab
commit 8661d103e5
12 changed files with 44 additions and 51 deletions

View File

@ -26,11 +26,11 @@ build-env: bootstrap
build-init:
$(ECHO) rm -rf build && $(ECHO) mkdir -p build
# target build-$(SHARED): Create shared folder in docker $(SERVICE) to deploy
.PHONY: build-$(SHARED)
build-$(SHARED): SERVICE ?= $(DOCKER_SERVICE)
build-$(SHARED): bootstrap
$(call docker-compose-exec,$(SERVICE),mkdir -p /$(SHARED) && $(foreach folder,$(SHARED_FOLDERS),rm -rf $(folder) && mkdir -p $(dir $(folder)) && ln -s /$(SHARED)/$(notdir $(folder)) $(folder) &&) true)
# target build-shared: Create shared folder in docker $(SERVICE) to deploy
.PHONY: build-shared
build-shared: SERVICE ?= $(DOCKER_SERVICE)
build-shared: bootstrap
$(call docker-compose-exec,$(SERVICE),mkdir -p /$(notdir $(SHARED)) && $(foreach folder,$(SHARED_FOLDERS),rm -rf $(folder) && mkdir -p $(dir $(folder)) && ln -s /$(notdir $(SHARED))/$(notdir $(folder)) $(folder) &&) true)
# target rebuild: Rebuild application docker images on local host
.PHONY: rebuild

View File

@ -142,7 +142,7 @@ define docker-stack-update
$(eval version := $(or $(2),$(if $(findstring :,$(stack)),$(lastword $(subst :, ,$(stack))),latest)))
$(eval path := $(patsubst %/,%,$(or $(3),$(if $(findstring /,$(1)),$(if $(wildcard stack/$(1) stack/$(1).yml),stack/$(if $(findstring .yml,$(1)),$(dir $(1)),$(if $(wildcard stack/$(1).yml),$(dir $(1)),$(1))),$(dir $(1)))),stack/$(name))))
$(eval COMPOSE_FILE += $(wildcard $(path)/$(name).yml $(path)/$(name).$(ENV).yml $(path)/$(name).$(ENV).$(version).yml $(path)/$(name).$(version).yml))
$(if $(wildcard $(path)/.env.dist),$(call .env,,$(path)/.env.dist,$(wildcard ../$(PARAMETERS)/$(ENV)/$(APP)/.env $(path)/.env.$(ENV) .env)))
$(if $(wildcard $(path)/.env.dist),$(call .env,,$(path)/.env.dist,$(wildcard $(PARAMETERS)/$(ENV)/$(APP)/.env $(path)/.env.$(ENV) .env)))
endef
define docker-tag
$(eval service := $(or $(1),$(DOCKER_SERVICE)))

View File

@ -3,5 +3,5 @@ define install-parameters
$(eval file:=$(or $(2),$(DOCKER_SERVICE)/parameters.yml))
$(eval dest:=$(or $(3),app/config))
$(eval env:=$(or $(4),$(ENV)))
$(if $(wildcard $(dest)/$(file)),,$(if $(wildcard ../$(PARAMETERS)/$(env)/$(path)/$(file)),$(ECHO) cp -a ../$(PARAMETERS)/$(env)/$(path)/$(file) $(dest)))
$(if $(wildcard $(dest)/$(file)),,$(if $(wildcard $(PARAMETERS)/$(env)/$(path)/$(file)),$(ECHO) cp -a $(PARAMETERS)/$(env)/$(path)/$(file) $(dest)))
endef

View File

@ -15,4 +15,3 @@ ENV_VARS += APP_DIR APP_DOMAIN APP_HOST APP_PATH APP_URL
MOUNT_NFS ?= false
NFS_CONFIG ?= addr=$(NFS_HOST),actimeo=3,intr,noacl,noatime,nocto,nodiratime,nolock,soft,rsize=32768,wsize=32768,tcp,rw,vers=3
NFS_HOST ?= host.docker.internal
PARAMETERS ?= ../parameters

View File

@ -2,7 +2,7 @@ CMDS += ssh-run
COMPOSE_IGNORE_ORPHANS := true
ENV_VARS += COMPOSE_IGNORE_ORPHANS DOCKER_IMAGE_CLI DOCKER_IMAGE_SSH DOCKER_NAME_CLI DOCKER_NAME_SSH
HOME ?= /home/$(USER)
NFS_DISK ?= $(NFS_HOST):/$(SHARED)
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))
SHELL ?= /bin/sh

View File

@ -20,7 +20,7 @@ DRYRUN ?= false
DRYRUN_IGNORE ?= false
DRYRUN_RECURSIVE ?= false
ENV ?= dist
ENV_FILE ?= $(wildcard ../$(PARAMETERS)/$(ENV)/$(APP)/.env) .env
ENV_FILE ?= $(wildcard $(PARAMETERS)/$(ENV)/$(APP)/.env) .env
ENV_LIST ?= debug local tests release master #TODO: staging develop
ENV_RESET ?= false
ENV_VARS ?= APP BRANCH ENV HOSTNAME GID GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME MONOREPO MONOREPO_DIR TAG UID USER VERSION
@ -45,9 +45,11 @@ MAKE_VARS ?= ENV
MONOREPO ?= $(if $(filter myos,$(MYOS)),$(notdir $(CURDIR)),$(if $(APP),$(notdir $(realpath $(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
QUIET ?= $(if $(filter false,$(VERBOSE)),--quiet)
RECURSIVE ?= true
SHARED ?= shared
RELATIVE ?= $(if $(filter myos,$(MYOS)),,../)
SHARED ?= $(RELATIVE)shared
SSH_DIR ?= ${HOME}/.ssh
SUBREPO ?= $(if $(wildcard .gitrepo),$(notdir $(CURDIR)))
TAG ?= $(shell git tag -l --points-at $(BRANCH) 2>/dev/null)
@ -171,8 +173,8 @@ endef
# eval each target:$(env) targets
# override value of $(ENV) with $(env)
# override values of .env files with ../$(PARAMETERS)/$(env)/$(APP)/.env file
$(foreach env,$(ENV_LIST),$(eval TARGET := %\:$(env)) $(eval ASSIGN_ENV := ENV:=$(env)) $(eval ASSIGN_ENV_FILE := ENV_FILE+=$(wildcard ../$(PARAMETERS)/$(env)/$(APP)/.env)) $(eval $(TARGET:ENV)))
# override values of .env files with $(PARAMETERS)/$(env)/$(APP)/.env file
$(foreach env,$(ENV_LIST),$(eval TARGET := %\:$(env)) $(eval ASSIGN_ENV := ENV:=$(env)) $(eval ASSIGN_ENV_FILE := ENV_FILE+=$(wildcard $(PARAMETERS)/$(env)/$(APP)/.env)) $(eval $(TARGET:ENV)))
# set ENV=$(env) for each target ending with @$(env)
$(foreach env,$(ENV_LIST),$(eval %@$(env): ENV:=$(env)))

View File

@ -2,7 +2,7 @@
# target .env:
# update .env file when .env.dist file is newer
.env: .env.dist
$(call .env,,,$(wildcard ../$(PARAMETERS)/$(ENV)/$(APP)/.env .env.$(ENV)))
$(call .env,,,$(wildcard $(PARAMETERS)/$(ENV)/$(APP)/.env .env.$(ENV)))
.PHONY: .env-clean
.env-clean:

View File

@ -3,5 +3,4 @@ CONTEXT += APPS ENV RELEASE
DIRS ?= $(MAKE_DIR) $(PARAMETERS) $(SHARED)
RELEASE_UPGRADE ?= $(filter v%, $(shell git tag -l 2>/dev/null |sort -V |awk '/$(RELEASE)/,0'))
RELEASE_VERSION ?= $(firstword $(subst -, ,$(VERSION)))
PARAMETERS ?= parameters
SUBREPOS ?= $(filter subrepo/%, $(shell git remote 2>/dev/null))

View File

@ -1,16 +0,0 @@
##
# GIT
## Check if monorepo is up to date with subrepo. subrepo-push saves the parent commit in file subrepo/.gitrepo
.PHONY: git-diff-subrepo
git-diff-subrepo: myos-base subrepo-check
## Get parent commit in .gitrepo : awk '$1 == "parent" {print $3}' subrepo/.gitrepo
## Get child of parent commit : git rev-list --ancestry-path parent..HEAD |tail -n 1
## Compare child commit with our tree : git diff --quiet child -- subrepo
$(eval DRYRUN_IGNORE := 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); echo $$?)) )
$(eval DRYRUN_IGNORE := false)
.PHONY: git-fetch-subrepo
git-fetch-subrepo: myos-base subrepo-check
$(call exec,git fetch --prune $(REMOTE))

View File

@ -1,11 +0,0 @@
##
# INSTALL
.PHONY: install-myos
install-myos: myos-install
.PHONY: install-$(SHARED)
install-$(SHARED): $(SHARED)
$(SHARED):
$(ECHO) mkdir -p $(SHARED)

View File

@ -1,6 +1,13 @@
##
# SUBREPO
## Delete branch $(BRANCH) on $(SUBREPO) remote
.PHONY: subrepo-branch-delete
subrepo-branch-delete: myos-base subrepo-check
ifneq ($(words $(BRANCH)),0)
$(call exec,[ $$(git ls-remote --heads $(REMOTE) $(BRANCH) |wc -l) -eq 1 ] && git push $(REMOTE) :$(BRANCH) || echo Unable to delete branch $(BRANCH) on remote $(REMOTE).)
endif
.PHONY: subrepo-check
subrepo-check:
ifeq ($(words $(ARGS)), 0)
@ -11,15 +18,22 @@ endif
$(eval SUBREPO ?= $(word 1, $(ARGS)))
$(eval REMOTE := subrepo/$(SUBREPO))
## Delete branch $(BRANCH) on $(SUBREPO) remote
.PHONY: subrepo-branch-delete
subrepo-branch-delete: myos-base subrepo-check
ifneq ($(words $(BRANCH)),0)
$(call exec,[ $$(git ls-remote --heads $(REMOTE) $(BRANCH) |wc -l) -eq 1 ] && git push $(REMOTE) :$(BRANCH) || echo Unable to delete branch $(BRANCH) on remote $(REMOTE).)
endif
## Check if monorepo is up to date with subrepo. subrepo-push saves the parent commit in file subrepo/.gitrepo
.PHONY: subrepo-git-diff
subrepo-git-diff: myos-base subrepo-check
## Get parent commit in .gitrepo : awk '$1 == "parent" {print $3}' subrepo/.gitrepo
## Get child of parent commit : git rev-list --ancestry-path parent..HEAD |tail -n 1
## Compare child commit with our tree : git diff --quiet child -- subrepo
$(eval DRYRUN_IGNORE := 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); echo $$?)) )
$(eval DRYRUN_IGNORE := false)
.PHONY: subrepo-git-fetch
subrepo-git-fetch: myos-base subrepo-check
$(call exec,git fetch --prune $(REMOTE))
.PHONY: subrepo-tag-create-%
subrepo-tag-create-%: myos-base subrepo-check git-fetch-subrepo ## Create $(TAG) tag to reference $(REMOTE)/$* branch
subrepo-tag-create-%: myos-base subrepo-check subrepo-git-fetch ## Create $(TAG) tag to reference $(REMOTE)/$* branch
ifneq ($(words $(TAG)),0)
$(call exec,[ $$(git ls-remote --tags $(REMOTE) $(TAG) |wc -l) -eq 0 ] || git push $(REMOTE) :refs/tags/$(TAG))
$(call exec,git push $(REMOTE) refs/remotes/subrepo/$(SUBREPO)/$*:refs/tags/$(TAG))
@ -27,7 +41,7 @@ endif
## Push to subrepo.
.PHONY: subrepo-push
subrepo-push: myos-base subrepo-check git-fetch-subrepo git-diff-subrepo
subrepo-push: myos-base subrepo-check subrepo-git-fetch subrepo-git-diff
# update .gitrepo only on master branch
ifeq ($(BRANCH),master)
$(eval UPDATE_SUBREPO_OPTIONS += -u)

View File

@ -12,7 +12,7 @@ update-app: update-app-$(APP_NAME) ; ## Update application source files
update-app-%: myos-base % ;
.PHONY: $(APP)
$(APP): APP_DIR := $(if $(filter myos,$(MYOS)),,../)$(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))
@ -45,3 +45,9 @@ update-upstream: myos-base .git/refs/remotes/upstream/master
.git/refs/remotes/upstream/master: myos-base
$(call exec,git remote add upstream $(APP_UPSTREAM_REPOSITORY) 2>/dev/null ||:)
.PHONY: update-shared
update-shared: $(SHARED)
$(SHARED):
$(ECHO) mkdir -p $(SHARED)