launch app-% target when APP

This commit is contained in:
2025-12-18 00:47:53 +01:00
parent 4cd1aae963
commit 9f80ab9220
11 changed files with 8 additions and 13 deletions
+3 -1
View File
@@ -234,7 +234,9 @@ docker-run-%: docker-build-%
.PHONY: docker-stack-%
docker-stack-%: MAKE_VARS += DOCKER_COMPOSE_DOWN_OPTIONS
docker-stack-%:
$(foreach stack, $(STACK), $(call make,docker-compose-$* STACK=$(stack) APP_NAME=$(subst _,,$(subst -,,$(subst .,,$(call LOWERCASE,$(firstword $(subst /, ,$(stack)))))))))
$(if $(filter-out myos,$(filter $(APP),$(STACK))), \
$(call make,app-$(APP)-$*) \
, $(foreach stack, $(STACK), $(call make,docker-compose-$* STACK=$(stack) APP_NAME=$(subst _,,$(subst -,,$(subst .,,$(call LOWERCASE,$(firstword $(subst /, ,$(stack))))))))))
# target docker-tag: Call docker-tag for each SERVICES
.PHONY: docker-tag
+103
View File
@@ -0,0 +1,103 @@
##
# COMMON
# target build: Fire APPS target
.PHONY: build
build: $(APPS) ## Build applications
# target build@%: Fire APPS target
.PHONY: build@%
build@%: $(APPS);
# target clean: Fire APPS target
.PHONY: clean
clean: $(APPS) ## Clean applications
# target clean@%: Fire APPS target
.PHONY: clean@%
clean@%: $(APPS);
# target config: Fire APPS target
.PHONY: config
config: $(APPS)
# target copy: Copy files and folders to all APPS
.PHONY: copy
copy:
$(foreach app,$(APPS),$(foreach file,$(ARGS),$(if $(wildcard $(file)),$(RUN) $(if $(filter Linux,$(SYSTEM)),cp -a --parents $(file) $(app)/,rsync -a $(file) $(app)/$(file)) &&)) true &&) true
# target deploy: Fire APPS target
.PHONY: deploy
deploy: $(APPS) ## Deploy applications
# target deploy@%: Fire APPS target
.PHONY: deploy@%
deploy@%: $(APPS);
# target down: Fire APPS target
.PHONY: down
down: $(APPS) ## Remove applications dockers
# target install: Fire APPS target
.PHONY: install
install: $(APPS) ## Install applications
# target ps: Fire APPS target
.PHONY: ps
ps: $(APPS)
# target rebuild: Fire APPS target
.PHONY: rebuild
rebuild: $(APPS) ## Rebuild applications
# target recreate: Fire APPS target
.PHONY: recreate
recreate: $(APPS) ## Recreate applications
# target reinstall: Fire APPS target
.PHONY: reinstall
reinstall: $(APPS) ## Reinstall applications
# target release: Fire release-create target
.PHONY: release
release: release-create ## Create release VERSION
# target restart: Fire APPS target
.PHONY: restart
restart: $(APPS) ## Restart applications
# target start: Fire APPS target
.PHONY: start
start: $(APPS) ## Start applications
# target stop: Fire APPS target
.PHONY: stop
stop: $(APPS) ## Stop applications
# target tests: Fire APPS target
.PHONY: tests
tests: $(APPS) ## Test applications
# target up: Fire APPS target
.PHONY: up
up: $(APPS) ## Create applications dockers
# target update: Fire update-apps target
.PHONY: update
update: update-apps ## Update applications files
# target upgrade: Fire upgrade-apps and release-upgrade targets
.PHONY: upgrade
upgrade: upgrade-apps release-upgrade ## Upgrade applications
# target $(APPS): Call targets MAKECMDGOALS in folder $@
.PHONY: $(APPS)
$(APPS):
$(if $(wildcard $@/Makefile), \
$(call make,$(patsubst apps-%,%,$(MAKECMDGOALS)) STATUS=0,$(patsubst %/,%,$@),APP_PATH_PREFIX), \
$(call WARNING,no,Makefile,available in app,$@) \
)
# target apps-%: Fire $(APPS) target to call target % in $(APPS)
.PHONY: apps-%
apps-%: $(APPS) ;
+14
View File
@@ -0,0 +1,14 @@
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)^ 2>/dev/null)
endif
APPS_IMPACTED := $(shell git diff --name-only $(COMMIT_BEFORE) $(COMMIT_AFTER) 2>/dev/null |awk -F '/' 'NF>1 && !seen[$$1]++ {print $$1}')
APPS := $(or $(APPS_IMPACTED),$(APPS))
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
+6
View File
@@ -0,0 +1,6 @@
CONTEXT += APPS DOMAIN RELEASE
DIRS ?= $(CONFIG) $(MAKE_DIR) $(SHARED)
MAKECMDARGS += copy master-tag release release-check release-create release-finish subrepo-push subrepo-update
RELEASE_UPGRADE ?= $(filter v%, $(shell git tag -l 2>/dev/null |sort -V |awk '/$(RELEASE)/,0'))
RELEASE_VERSION ?= $(firstword $(subst -, ,$(VERSION)))
SUBREPOS ?= $(filter subrepo/%, $(shell git remote 2>/dev/null))
+49
View File
@@ -0,0 +1,49 @@
##
# RELEASE
# target release-check: Define RELEASE_BRANCH and 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))
# target release-create: Create release VERSION from upstream/develop branch
.PHONY: release-create
release-create: release-check git-stash
$(call make,git-branch-create-upstream-develop BRANCH=$(RELEASE_BRANCH))
$(call make,git-unstash,,STATUS)
# target release-finish: Merge release VERSION in master branch
.PHONY: release-finish
release-finish: release-check git-stash
$(call make,git-branch-merge-upstream-master BRANCH=$(RELEASE_BRANCH))
$(call make,subrepos-update)
$(call make,git-tag-create-upstream-master TAG=$(RELEASE_VERSION))
$(call make,subrepos-tag-create-master TAG=$(RELEASE_VERSION))
$(call make,git-tag-merge-upstream-develop TAG=$(RELEASE_VERSION))
$(call make,git-branch-delete BRANCH=$(RELEASE_BRANCH))
$(call make,subrepos-branch-delete BRANCH=$(RELEASE_BRANCH))
$(call make,git-unstash,,STATUS)
# target release-update: Update RELEASE with RELEASE_VERSION in .env
.PHONY: release-update
release-update:
$(RUN) awk -v s=RELEASE=$(RELEASE_VERSION) '/^RELEASE=/{$$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
# target release-upgrade: Run migration targets to upgrade specific releases
.PHONY: release-upgrade
release-upgrade: $(patsubst %,release-upgrade-from-%,$(RELEASE_UPGRADE)) release-update ## Upgrade release
# target release-upgrade-from-%: Sample of catch-all release migration target
.PHONY: release-upgrade-from-%
release-upgrade-from-%:
printf 'Upgrading from release: $*\n'
+91
View File
@@ -0,0 +1,91 @@
##
# SUBREPO
# target subrepo-branch-delete: Delete branch $(BRANCH) on remote $(SUBREPO)
.PHONY: subrepo-branch-delete
subrepo-branch-delete: myos-user subrepo-check
ifneq ($(words $(BRANCH)),0)
[ $$(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
.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))
# target subrepo-git-diff: Check if monorepo is up to date with subrepo
# subrepo-push saves the parent commit in file subrepo/.gitrepo
## it gets parent commit in .gitrepo : awk '$1 == "parent" {print $3}' subrepo/.gitrepo
## it gets child of parent commit : git rev-list --ancestry-path parent..HEAD |tail -n 1
## it compares child commit with our tree : git diff --quiet child -- subrepo
.PHONY: subrepo-git-diff
subrepo-git-diff: myos-user subrepo-check
$(eval IGNORE_DRYRUN := true)
$(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-user subrepo-check
$(RUN) git fetch --prune $(REMOTE)
# target subrepo-tag-create-%: Create tag TAG to reference branch REMOTE/%
.PHONY: subrepo-tag-create-%
subrepo-tag-create-%: myos-user subrepo-check subrepo-git-fetch
ifneq ($(words $(TAG)),0)
[ $$(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
.PHONY: subrepo-push
subrepo-push: myos-user subrepo-check subrepo-git-fetch subrepo-git-diff
# update .gitrepo only on master branch
ifeq ($(BRANCH),master)
$(eval UPDATE_SUBREPO_OPTIONS += -u)
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 sh -c 'git ls-remote --heads $(REMOTE) $(BRANCH) |wc -l') )
$(eval IGNORE_DRYRUN := false)
else
$(eval DELETE = 0)
endif
if [ $(DIFF) -eq 0 ]; then \
$(call INFO,subrepo $(SUBREPO) already up to date); \
else \
if [ $(DELETE) -eq 1 ]; then \
$(RUN) git push $(REMOTE) :$(BRANCH); \
$(RUN) git push $(REMOTE) refs/remotes/$(REMOTE)/master:refs/heads/$(BRANCH); \
fi; \
$(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
.PHONY: subrepos-branch-delete
subrepos-branch-delete: $(APPS) ;
# target subrepos-tag-create-%: Fire APPS target
.PHONY: subrepos-tag-create-%
subrepos-tag-create-%: $(APPS) ;
# target subrepos-update: Fire APPS target and push updates to upstream
.PHONY: subrepos-update
subrepos-update: myos-user git-stash $(APPS) git-unstash ## Update subrepos
$(RUN) git push upstream $(BRANCH)
# target subrepo-update-%: Call subrepo-update target in folder %
.PHONY: subrepo-update-%
subrepo-update-%:
$(if $(wildcard $*/Makefile),$(call make,subrepo-update,$*))