import files
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
##
|
||||
# COMMON
|
||||
|
||||
.PHONY: build
|
||||
build: $(APPS) ## Build applications
|
||||
|
||||
.PHONY: build@%
|
||||
build@%: $(APPS);
|
||||
|
||||
.PHONY: clean
|
||||
clean: $(APPS) ## Clean applications
|
||||
|
||||
.PHONY: clean@%
|
||||
clean@%: $(APPS);
|
||||
|
||||
.PHONY: config
|
||||
config: $(APPS)
|
||||
|
||||
.PHONY: copy
|
||||
copy:
|
||||
$(foreach app,$(APPS),$(foreach file,$(ARGS),$(if $(wildcard $(file)),$(ECHO) $(if $(filter LINUX,$(HOST_SYSTEM)),cp -a --parents $(file) $(app)/,rsync -a $(file) $(app)/$(file)) &&)) true &&) true
|
||||
|
||||
.PHONY: deploy
|
||||
deploy: $(APPS) ## Deploy applications
|
||||
|
||||
.PHONY: deploy@%
|
||||
deploy@%: $(APPS);
|
||||
|
||||
.PHONY: down
|
||||
down: $(APPS) ## Remove application dockers
|
||||
|
||||
.PHONY: ps
|
||||
ps: $(APPS)
|
||||
|
||||
.PHONY: rebuild
|
||||
rebuild: $(APPS) ## Rebuild applications
|
||||
|
||||
.PHONY: recreate
|
||||
recreate: $(APPS) ## Recreate applications
|
||||
|
||||
.PHONY: reinstall
|
||||
reinstall: $(APPS) ## Reinstall applications
|
||||
|
||||
.PHONY: restart
|
||||
restart: $(APPS) ## Restart applications
|
||||
|
||||
.PHONY: start
|
||||
start: $(APPS) ## Start applications
|
||||
|
||||
.PHONY: stop
|
||||
stop: $(APPS) ## Stop applications
|
||||
|
||||
.PHONY: tests
|
||||
tests: $(APPS) ## Test applications
|
||||
|
||||
.PHONY: up
|
||||
up: $(APPS) ## Create application dockers
|
||||
|
||||
.PHONY: $(APPS)
|
||||
$(APPS):
|
||||
$(if $(wildcard $@/Makefile), \
|
||||
$(call make,-o install-infra $(patsubst apps-%,%,$(MAKECMDGOALS)) STATUS=0,$(patsubst %/,%,$@),ENV_SUFFIX), \
|
||||
printf "${COLOR_BROWN}WARNING${COLOR_RESET}: ${COLOR_GREEN}no app available in folder${COLOR_RESET} $@.\n" >&2)
|
||||
|
||||
# run targets in $(APPS)
|
||||
.PHONY: apps-%
|
||||
apps-%: $(APPS) ; ## run % targets in $(APPS)
|
||||
@@ -0,0 +1,15 @@
|
||||
ifneq (,$(filter true,$(DRONE)))
|
||||
# limit to APPS impacted by the commit
|
||||
ifneq (,$(filter $(DRONE_BUILD_EVENT),pull_request push))
|
||||
COMMIT_AFTER := $(DRONE_COMMIT_AFTER)
|
||||
COMMIT_BEFORE := $(if $(filter 0000000000000000000000000000000000000000,$(DRONE_COMMIT_BEFORE)),upstream/master,$(DRONE_COMMIT_BEFORE))
|
||||
endif
|
||||
ifneq (,$(filter $(DRONE_BUILD_EVENT),tag))
|
||||
COMMIT_AFTER := $(DRONE_TAG)
|
||||
COMMIT_BEFORE := $(shell git describe --abbrev=0 --tags $(DRONE_TAG)^)
|
||||
endif
|
||||
APPS_IMPACTED := $(shell git diff --name-only $(COMMIT_BEFORE) $(COMMIT_AFTER) 2>/dev/null |awk -F '/' 'NF>1 && !seen[$$1]++ {print $$1}')
|
||||
# prevent drone to make down in infra
|
||||
APPS := $(if $(filter-out down,$(MAKECMDGOALS)),$(filter $(INFRA),$(APPS_IMPACTED))) $(sort $(filter-out $(DIRS) $(INFRA),$(APPS_IMPACTED)))
|
||||
CONTEXT += DRONE_BRANCH DRONE_BUILD_EVENT DRONE_BUILD_NUMBER DRONE_COMMIT_AFTER DRONE_COMMIT_AUTHOR DRONE_COMMIT_AUTHOR_EMAIL DRONE_COMMIT_BEFORE DRONE_COMMIT_REF GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME
|
||||
endif
|
||||
@@ -0,0 +1,8 @@
|
||||
APPS ?= $(INFRA) $(sort $(filter-out $(DIRS) $(INFRA), $(patsubst %/,%,$(wildcard */)) ))
|
||||
APPS_NAME ?= $(foreach app,$(APPS),$(or $(shell awk -F '=' '$$1 == "APP" {print $$2}' $(or $(wildcard $(app)/.env),$(wildcard $(app)/.env.$(ENV)),$(app)/.env.dist) 2>/dev/null),$(app)))
|
||||
CMDS += copy master-tag release release-check release-create release-finish subrepo-push update-subrepo
|
||||
CONTEXT += APPS APPS_NAME ENV RELEASE_INSTALL
|
||||
DIRS ?= $(MAKE_DIR) $(PARAMETERS) $(SHARED)
|
||||
RELEASE_UPGRADE ?= $(filter v%, $(shell git tag -l |sort -V |awk '/$(RELEASE_INSTALL)/,0'))
|
||||
RELEASE_VERSION ?= $(firstword $(subst -, ,$(VERSION)))
|
||||
SUBREPOS ?= $(filter subrepo/%, $(shell git remote))
|
||||
@@ -0,0 +1,85 @@
|
||||
##
|
||||
# GIT
|
||||
|
||||
## Check if monorepo is up to date with subrepo. subrepo-push saves the parent commit in .gitrepo
|
||||
.PHONY: git-diff-subrepo
|
||||
git-diff-subrepo: infra-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: infra-base subrepo-check
|
||||
$(call exec,git fetch --prune $(REMOTE))
|
||||
|
||||
.PHONY: git-stash
|
||||
git-stash: infra-base git-status
|
||||
if [ ! $(STATUS) -eq 0 ]; then \
|
||||
$(call exec,git stash); \
|
||||
fi
|
||||
|
||||
.PHONY: git-status
|
||||
git-status: infra-base
|
||||
$(eval DRYRUN_IGNORE := true)
|
||||
$(eval STATUS := $(shell $(call exec,git status -uno --porcelain 2>/dev/null |wc -l)))
|
||||
$(eval DRYRUN_IGNORE := false)
|
||||
|
||||
.PHONY: git-unstash
|
||||
git-unstash: infra-base
|
||||
$(eval STATUS ?= 0)
|
||||
if [ ! $(STATUS) -eq 0 ]; then \
|
||||
$(call exec,git stash pop); \
|
||||
fi
|
||||
|
||||
# Create branch $(BRANCH) from upstream/$* branch
|
||||
.PHONY: branch-create-upstream-%
|
||||
branch-create-upstream-%: infra-base update-upstream
|
||||
$(call exec,git fetch --prune upstream)
|
||||
$(call exec,git rev-parse --verify $(BRANCH) >/dev/null 2>&1 && echo Unable to create $(BRANCH). || git branch $(BRANCH) upstream/$*)
|
||||
$(call exec,[ $$(git ls-remote --heads upstream $(BRANCH) |wc -l) -eq 0 ] && git push upstream $(BRANCH) || echo Unable to create branch $(BRANCH) on remote upstream.)
|
||||
$(call exec,git checkout $(BRANCH))
|
||||
|
||||
# Delete branch $(BRANCH)
|
||||
.PHONY: branch-delete
|
||||
branch-delete: infra-base update-upstream
|
||||
$(call exec,git rev-parse --verify $(BRANCH) >/dev/null 2>&1 && git branch -d $(BRANCH) || echo Unable to delete branch $(BRANCH).)
|
||||
$(foreach remote,upstream, $(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).) &&) true
|
||||
|
||||
# Merge branch $(BRANCH) into upstream/$* branch
|
||||
.PHONY: branch-merge-upstream-%
|
||||
branch-merge-upstream-%: infra-base update-upstream
|
||||
$(call exec,git rev-parse --verify $(BRANCH) >/dev/null 2>&1)
|
||||
$(call exec,git checkout $(BRANCH))
|
||||
$(call exec,git pull --ff-only upstream $(BRANCH))
|
||||
$(call exec,git push upstream $(BRANCH))
|
||||
$(call exec,git checkout $*)
|
||||
$(call exec,git pull --ff-only upstream $*)
|
||||
$(call exec,git merge --no-ff --no-edit $(BRANCH))
|
||||
$(call exec,git push upstream $*)
|
||||
|
||||
# Create $(TAG) tag to reference upstream/$* branch
|
||||
.PHONY: tag-create-upstream-%
|
||||
tag-create-upstream-%: infra-base update-upstream
|
||||
ifneq ($(words $(TAG)),0)
|
||||
$(call exec,git checkout $*)
|
||||
$(call exec,git pull --tags --prune upstream $*)
|
||||
$(call sed,s/^##\? $(TAG).*/## $(TAG) - $(shell date +%Y-%m-%d)/,CHANGELOG.md)
|
||||
$(call exec,[ $$(git diff CHANGELOG.md 2>/dev/null |wc -l) -eq 0 ] || git commit -m "$$(cat CHANGELOG.md |sed -n '\''/$(TAG)/,/^$$/{s/##\(.*\)/release\1\n/;p;}'\'')" CHANGELOG.md)
|
||||
$(call exec,[ $$(git tag -l $(TAG) |wc -l) -eq 0 ] || git tag -d $(TAG))
|
||||
$(call exec,git tag $(TAG))
|
||||
$(call exec,[ $$(git ls-remote --tags upstream $(TAG) |wc -l) -eq 0 ] || git push upstream :refs/tags/$(TAG))
|
||||
$(call exec,git push --tags upstream $*)
|
||||
endif
|
||||
|
||||
# Merge tag $(TAG) into upstream/$* branch
|
||||
.PHONY: tag-merge-upstream-%
|
||||
tag-merge-upstream-%: infra-base update-upstream
|
||||
ifneq ($(words $(TAG)),0)
|
||||
$(call exec,git fetch --tags -u --prune upstream $*:$*)
|
||||
$(call exec,git checkout $*)
|
||||
$(call exec,git merge --ff --no-edit $(TAG))
|
||||
$(call exec,git push upstream $*)
|
||||
endif
|
||||
@@ -0,0 +1,11 @@
|
||||
##
|
||||
# INSTALL
|
||||
|
||||
.PHONY: install-infra
|
||||
install-infra: infra-install
|
||||
|
||||
.PHONY: install-$(SHARED)
|
||||
install-$(SHARED): $(SHARED)
|
||||
|
||||
$(SHARED):
|
||||
$(ECHO) mkdir -p $(SHARED)
|
||||
@@ -0,0 +1,35 @@
|
||||
##
|
||||
# RELEASE
|
||||
|
||||
.PHONY: release
|
||||
release: release-create # Create release [version]
|
||||
|
||||
.PHONY: release-check
|
||||
release-check:
|
||||
ifneq ($(words $(ARGS)),0)
|
||||
$(eval RELEASE_VERSION := $(word 1, $(ARGS)))
|
||||
$(eval RELEASE_BRANCH := release/$(RELEASE_VERSION))
|
||||
else
|
||||
ifneq ($(findstring $(firstword $(subst /, ,$(BRANCH))),release),)
|
||||
$(eval RELEASE_BRANCH := $(BRANCH))
|
||||
$(eval RELEASE_VERSION := $(word 2, $(subst /, ,$(BRANCH))))
|
||||
endif
|
||||
endif
|
||||
$(if $(filter VERSION=%,$(MAKEFLAGS)), $(eval RELEASE_VERSION:=$(VERSION)) $(eval RELEASE_BRANCH := release/$(RELEASE_VERSION)))
|
||||
$(if $(findstring $(firstword $(subst /, ,$(RELEASE_BRANCH))),release),,$(error Please provide a VERSION or a release BRANCH))
|
||||
|
||||
.PHONY: release-create
|
||||
release-create: release-check git-stash ## Create release [version]
|
||||
$(call make,branch-create-upstream-develop BRANCH=$(RELEASE_BRANCH))
|
||||
$(call make,git-unstash,,STATUS)
|
||||
|
||||
.PHONY: release-finish
|
||||
release-finish: release-check git-stash ## Finish release [version]
|
||||
$(call make,branch-merge-upstream-master BRANCH=$(RELEASE_BRANCH))
|
||||
$(call make,update-subrepos)
|
||||
$(call make,tag-create-upstream-master TAG=$(RELEASE_VERSION))
|
||||
$(call make,subrepos-tag-create-master TAG=$(RELEASE_VERSION))
|
||||
$(call make,tag-merge-upstream-develop TAG=$(RELEASE_VERSION))
|
||||
$(call make,branch-delete BRANCH=$(RELEASE_BRANCH))
|
||||
$(call make,subrepos-branch-delete BRANCH=$(RELEASE_BRANCH))
|
||||
$(call make,git-unstash,,STATUS)
|
||||
@@ -0,0 +1,59 @@
|
||||
##
|
||||
# SUBREPO
|
||||
|
||||
.PHONY: subrepo-check
|
||||
subrepo-check:
|
||||
ifeq ($(words $(ARGS)), 0)
|
||||
ifeq ($(words $(SUBREPO)), 0)
|
||||
$(error Please provide a SUBREPO)
|
||||
endif
|
||||
endif
|
||||
$(eval SUBREPO ?= $(word 1, $(ARGS)))
|
||||
$(eval REMOTE := subrepo/$(SUBREPO))
|
||||
|
||||
## Delete branch $(BRANCH) on $(SUBREPO) remote
|
||||
.PHONY: subrepo-branch-delete
|
||||
subrepo-branch-delete: infra-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-tag-create-%
|
||||
subrepo-tag-create-%: infra-base subrepo-check git-fetch-subrepo ## 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))
|
||||
endif
|
||||
|
||||
## Push to subrepo.
|
||||
.PHONY: subrepo-push
|
||||
subrepo-push: infra-base subrepo-check git-fetch-subrepo git-diff-subrepo
|
||||
# update .gitrepo only on master branch
|
||||
ifeq ($(BRANCH),master)
|
||||
$(eval UPDATE_SUBREPO_OPTIONS += -u)
|
||||
endif
|
||||
# if release|story|hotfix branch, delete remote branch before push and recreate it from master
|
||||
ifneq ($(findstring $(firstword $(subst /, ,$(BRANCH))),release story hotfix),)
|
||||
$(eval DRYRUN_IGNORE := true)
|
||||
$(eval DELETE = $(shell $(call exec,git ls-remote --heads $(REMOTE) $(BRANCH) |wc -l)) )
|
||||
$(eval DRYRUN_IGNORE := false)
|
||||
else
|
||||
$(eval DELETE = 0)
|
||||
endif
|
||||
if [ $(DIFF) -eq 0 ]; then \
|
||||
echo subrepo $(SUBREPO) already up to date.; \
|
||||
else \
|
||||
if [ $(DELETE) -eq 1 ]; then \
|
||||
$(call exec,git push $(REMOTE) :$(BRANCH)); \
|
||||
$(call exec,git push $(REMOTE) refs/remotes/$(REMOTE)/master:refs/heads/$(BRANCH)); \
|
||||
fi; \
|
||||
$(call exec,git subrepo fetch $(SUBREPO) -b $(BRANCH)); \
|
||||
$(call exec,git subrepo push $(SUBREPO) -b $(BRANCH) $(UPDATE_SUBREPO_OPTIONS)); \
|
||||
$(call exec,git subrepo clean $(SUBREPO)); \
|
||||
fi
|
||||
|
||||
.PHONY: subrepos-branch-delete
|
||||
subrepos-branch-delete: $(APPS) ;
|
||||
|
||||
.PHONY: subrepos-tag-create-%
|
||||
subrepos-tag-create-%: $(APPS) ;
|
||||
@@ -0,0 +1,47 @@
|
||||
##
|
||||
# UPDATE
|
||||
|
||||
## Update /etc/hosts
|
||||
.PHONY: update-hosts
|
||||
update-hosts:
|
||||
ifneq (,$(filter $(ENV),local))
|
||||
cat */.env 2>/dev/null |grep -Eo 'urlprefix-[^/]+' |sed 's/urlprefix-//' |while read host; do grep $$host /etc/hosts >/dev/null 2>&1 || { echo "Adding $$host to /etc/hosts"; echo 127.0.0.1 $$host |$(ECHO) sudo tee -a /etc/hosts >/dev/null; }; done
|
||||
endif
|
||||
|
||||
.PHONY: update-$(PARAMETERS)
|
||||
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): infra-base
|
||||
$(call exec,[ -d $(PARAMETERS) ] && cd $(PARAMETERS) && git pull --quiet || git clone --quiet $(GIT_PARAMETERS_REPOSITORY))
|
||||
|
||||
## Update release version number in .env
|
||||
.PHONY: update-release
|
||||
update-release:
|
||||
$(ECHO) awk -v s=RELEASE_INSTALL=$(RELEASE_VERSION) '/^RELEASE_INSTALL=/{$$0=s;f=1} {a[++n]=$$0} END{if(!f)a[++n]=s;for(i=1;i<=n;i++)print a[i]>ARGV[1]}' .env
|
||||
|
||||
## Update remotes
|
||||
.PHONY: update-remotes
|
||||
update-remotes: infra-base
|
||||
$(call exec,git fetch --all --prune --tags -u)
|
||||
|
||||
.PHONY: update-remote-%
|
||||
update-remote-%: infra-base
|
||||
$(call exec,git fetch --prune --tags -u $*)
|
||||
|
||||
## Update subrepos
|
||||
.PHONY: update-subrepos
|
||||
update-subrepos: infra-base git-stash $(APPS) git-unstash ## Update subrepos
|
||||
$(call exec,git push upstream $(BRANCH))
|
||||
|
||||
.PHONY: update-subrepo-%
|
||||
update-subrepo-%:
|
||||
$(if $(wildcard $*/Makefile),$(call make,update-subrepo,$*))
|
||||
|
||||
.PHONY: update-upstream
|
||||
update-upstream: infra-base .git/refs/remotes/upstream/master
|
||||
$(call exec,git fetch --tags upstream)
|
||||
|
||||
.git/refs/remotes/upstream/master: infra-base
|
||||
$(call exec,git remote add upstream $(GIT_UPSTREAM_REPOSITORY) 2>/dev/null ||:)
|
||||
@@ -0,0 +1,9 @@
|
||||
##
|
||||
# UPGRADE
|
||||
|
||||
.PHONY: upgrade
|
||||
upgrade: $(patsubst %,upgrade-from-release-%,$(RELEASE_UPGRADE)) update-release ## Update monorepo version
|
||||
|
||||
.PHONY: upgrade-from-release-%
|
||||
upgrade-from-release-%:
|
||||
# echo "Upgrading from release: $*"
|
||||
Reference in New Issue
Block a user