2021-02-09 17:05:00 +01:00
|
|
|
##
|
|
|
|
# COMMON
|
|
|
|
|
2021-06-02 00:54:33 +02:00
|
|
|
# target bootstrap: Update application files and start dockers
|
|
|
|
# on local host
|
2022-05-09 02:32:23 +02:00
|
|
|
.PHONY: bootstrap app-bootstrap
|
|
|
|
bootstrap: bootstrap-app app-bootstrap ## Update application files and start dockers
|
2021-02-09 17:05:00 +01:00
|
|
|
|
2022-05-07 15:04:44 +02:00
|
|
|
# target bootstrap-app: Fire install-bin-git
|
|
|
|
.PHONY: bootstrap-app
|
|
|
|
bootstrap-app: install-bin-git
|
|
|
|
|
2021-06-02 00:54:33 +02:00
|
|
|
# target build: Build application docker images to run
|
|
|
|
# on local host
|
|
|
|
.PHONY: build
|
|
|
|
build: docker-compose-build ## Build application docker images
|
|
|
|
|
2021-06-13 02:09:57 +02:00
|
|
|
# target build@%: Build application docker images of % ENV
|
2021-06-02 00:54:33 +02:00
|
|
|
# on local host
|
|
|
|
.PHONY: build@% app-build
|
2022-05-07 15:04:44 +02:00
|
|
|
build@%: myos-user
|
2021-06-02 00:54:33 +02:00
|
|
|
$(eval docker_images += $(foreach service,$(SERVICES),$(if $(shell docker images -q $(DOCKER_REPOSITORY)/$(service):$(DOCKER_IMAGE_TAG) 2>/dev/null),$(service))))
|
|
|
|
$(eval build_app := $(or $(filter $(DOCKER_BUILD_CACHE),false),$(filter-out $(docker_images),$(SERVICES))))
|
|
|
|
$(if $(build_app), \
|
|
|
|
$(call make,build-init app-build), \
|
2021-06-14 12:52:48 +02:00
|
|
|
$(foreach service,$(SERVICES), \
|
2021-06-14 14:32:14 +02:00
|
|
|
$(or $(call INFO,docker image $(DOCKER_REPOSITORY)/$(service):$(DOCKER_IMAGE_TAG) has id $(shell docker images -q $(DOCKER_REPOSITORY)/$(service):$(DOCKER_IMAGE_TAG) 2>/dev/null)), true) && \
|
2021-06-14 12:52:48 +02:00
|
|
|
) true \
|
2021-06-02 00:54:33 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
# target clean: Clean application and docker images
|
|
|
|
# on local host
|
|
|
|
.PHONY: clean app-clean
|
2021-06-16 13:19:52 +02:00
|
|
|
clean: app-clean docker-rm docker-images-rm docker-volume-rm .env-clean ## Clean application and docker stuffs
|
2021-06-02 00:54:33 +02:00
|
|
|
|
|
|
|
# target clean@%: Clean deployed application and docker images of % ENV
|
|
|
|
# on local host
|
|
|
|
.PHONY: clean@%
|
2021-06-13 02:09:57 +02:00
|
|
|
clean@%: docker-rm docker-image-rm docker-volume-rm;
|
2021-06-02 00:54:33 +02:00
|
|
|
|
|
|
|
# target config: View application docker compose file
|
|
|
|
# on local host
|
2021-02-09 17:05:00 +01:00
|
|
|
.PHONY: config
|
2021-06-02 00:54:33 +02:00
|
|
|
config: docker-compose-config ## View application docker compose file
|
2021-02-09 17:05:00 +01:00
|
|
|
|
2021-06-02 00:54:33 +02:00
|
|
|
# target connect: Connect to docker SERVICE
|
|
|
|
# on local host
|
2021-02-09 17:05:00 +01:00
|
|
|
.PHONY: connect
|
2021-06-02 00:54:33 +02:00
|
|
|
connect: docker-compose-connect ## Connect to docker SERVICE
|
2021-02-09 17:05:00 +01:00
|
|
|
|
2021-06-02 00:54:33 +02:00
|
|
|
# target connect@%: Connect to docker SERVICE of % ENV
|
|
|
|
# on first remote host
|
2021-02-09 17:05:00 +01:00
|
|
|
.PHONY: connect@%
|
|
|
|
connect@%: SERVICE ?= $(DOCKER_SERVICE)
|
2021-06-02 00:54:33 +02:00
|
|
|
connect@%:
|
2021-05-17 03:40:02 +02:00
|
|
|
$(call make,ssh-connect,$(MYOS),APP SERVICE)
|
2021-02-09 17:05:00 +01:00
|
|
|
|
2021-06-06 16:29:54 +02:00
|
|
|
# target deploy: Fire deploy@% for ENV
|
2021-06-02 00:54:33 +02:00
|
|
|
.PHONY: deploy
|
2021-07-12 21:04:06 +02:00
|
|
|
deploy: $(if $(filter $(ENV),$(ENV_DEPLOY)),deploy-localhost,deploy@$(ENV)) ## Deploy application dockers
|
2021-06-02 00:54:33 +02:00
|
|
|
|
|
|
|
# target down: Remove application dockers
|
|
|
|
# on local host
|
2021-02-09 17:05:00 +01:00
|
|
|
.PHONY: down
|
|
|
|
down: docker-compose-down ## Remove application dockers
|
|
|
|
|
2021-06-06 16:29:54 +02:00
|
|
|
# target exec: Exec ARGS in docker SERVICE
|
2021-06-02 00:54:33 +02:00
|
|
|
# on local host
|
2021-02-09 17:05:00 +01:00
|
|
|
.PHONY: exec
|
2021-06-02 00:54:33 +02:00
|
|
|
exec: ## Exec command in docker SERVICE
|
2021-02-09 17:05:00 +01:00
|
|
|
ifneq (,$(filter $(ENV),$(ENV_DEPLOY)))
|
2021-06-14 12:52:48 +02:00
|
|
|
$(RUN) $(call exec,$(ARGS))
|
2021-02-09 17:05:00 +01:00
|
|
|
else
|
|
|
|
$(call make,docker-compose-exec,,ARGS)
|
|
|
|
endif
|
|
|
|
|
2021-06-06 16:29:54 +02:00
|
|
|
# target exec@%: Exec ARGS in docker SERVICE of % ENV
|
2021-06-02 00:54:33 +02:00
|
|
|
# on all remote hosts
|
2021-02-09 17:05:00 +01:00
|
|
|
.PHONY: exec@%
|
|
|
|
exec@%: SERVICE ?= $(DOCKER_SERVICE)
|
2021-06-02 00:54:33 +02:00
|
|
|
exec@%:
|
2021-05-17 03:40:02 +02:00
|
|
|
$(call make,ssh-exec,$(MYOS),APP ARGS SERVICE)
|
2021-02-09 17:05:00 +01:00
|
|
|
|
2022-07-06 23:27:41 +02:00
|
|
|
# target force-%: Fire targets %, stack-user-% and stack-node-%
|
2022-06-30 23:37:10 +02:00
|
|
|
# on local host
|
|
|
|
.PHONY: force-%
|
2022-07-06 23:27:41 +02:00
|
|
|
force-%: % stack-user-% stack-node-%;
|
2022-06-30 23:37:10 +02:00
|
|
|
|
2021-06-02 00:54:33 +02:00
|
|
|
# target install app-install: Install application
|
|
|
|
# on local host
|
|
|
|
.PHONY: install app-install
|
2021-06-16 13:19:52 +02:00
|
|
|
install: bootstrap app-install ## Install application
|
2021-06-02 00:54:33 +02:00
|
|
|
|
|
|
|
# target logs: Display application dockers logs
|
|
|
|
# on local host
|
2021-02-09 17:05:00 +01:00
|
|
|
.PHONY: logs
|
|
|
|
logs: docker-compose-logs ## Display application dockers logs
|
|
|
|
|
2021-06-02 00:54:33 +02:00
|
|
|
# target ps: List application dockers
|
|
|
|
# on local host
|
2021-02-09 17:05:00 +01:00
|
|
|
.PHONY: ps
|
|
|
|
ps: docker-compose-ps ## List application dockers
|
|
|
|
|
2021-06-02 00:54:33 +02:00
|
|
|
# target rebuild: Rebuild application docker images
|
|
|
|
# on local host
|
|
|
|
.PHONY: rebuild
|
|
|
|
rebuild: docker-compose-rebuild ## Rebuild application dockers images
|
|
|
|
|
|
|
|
# target rebuild@%: Rebuild application docker images
|
|
|
|
# on local host
|
|
|
|
.PHONY: rebuild@%
|
|
|
|
rebuild@%:
|
|
|
|
$(call make,build@$* DOCKER_BUILD_CACHE=false)
|
|
|
|
|
|
|
|
# target recreate: Recreate application dockers
|
|
|
|
# on local host
|
2021-02-09 17:05:00 +01:00
|
|
|
.PHONY: recreate
|
2021-05-31 03:45:39 +02:00
|
|
|
recreate: docker-compose-recreate app-start ## Recreate application dockers
|
2021-02-09 17:05:00 +01:00
|
|
|
|
2021-06-06 16:29:54 +02:00
|
|
|
# target reinstall: Fire clean, Call .env target, Call install target
|
2021-06-02 00:54:33 +02:00
|
|
|
# on local host
|
2021-02-09 17:05:00 +01:00
|
|
|
.PHONY: reinstall
|
|
|
|
reinstall: clean ## Reinstall application
|
|
|
|
$(call make,.env)
|
|
|
|
$(call make,install)
|
|
|
|
|
2021-06-02 00:54:33 +02:00
|
|
|
# target release: Fire release-create
|
|
|
|
.PHONY: release
|
|
|
|
release: release-create ## Create release VERSION
|
|
|
|
|
|
|
|
# target restart: Restart application dockers
|
|
|
|
# on local host
|
2021-02-09 17:05:00 +01:00
|
|
|
.PHONY: restart
|
2021-05-31 03:45:39 +02:00
|
|
|
restart: docker-compose-restart app-start ## Restart application
|
2021-02-09 17:05:00 +01:00
|
|
|
|
2021-06-06 16:29:54 +02:00
|
|
|
# target run: Run command ARGS in a new docker SERVICE
|
2021-06-02 00:54:33 +02:00
|
|
|
# on local host
|
2021-02-09 17:05:00 +01:00
|
|
|
.PHONY: run
|
|
|
|
run: ## Run a command in a new docker
|
|
|
|
ifneq (,$(filter $(ENV),$(ENV_DEPLOY)))
|
|
|
|
$(call run,$(ARGS))
|
|
|
|
else
|
|
|
|
$(call make,docker-compose-run,,ARGS)
|
|
|
|
endif
|
|
|
|
|
2021-06-06 16:29:54 +02:00
|
|
|
# target run@%: Run command ARGS in a new docker SERVICE of % ENV
|
2021-06-02 00:54:33 +02:00
|
|
|
# on all remote hosts
|
2021-02-09 17:05:00 +01:00
|
|
|
.PHONY: run@%
|
|
|
|
run@%: SERVICE ?= $(DOCKER_SERVICE)
|
2021-06-02 00:54:33 +02:00
|
|
|
run@%:
|
2021-05-17 03:40:02 +02:00
|
|
|
$(call make,ssh-run,$(MYOS),APP ARGS)
|
2021-02-09 17:05:00 +01:00
|
|
|
|
2021-06-02 00:54:33 +02:00
|
|
|
# target scale: Scale SERVICE application to NUM dockers
|
|
|
|
# on local host
|
2021-02-09 17:05:00 +01:00
|
|
|
.PHONY: scale
|
2021-06-02 00:54:33 +02:00
|
|
|
scale: docker-compose-scale ## Scale SERVICE application to NUM dockers
|
2021-02-09 17:05:00 +01:00
|
|
|
|
2022-06-30 23:37:10 +02:00
|
|
|
# target shutdown: remove application, node and user dockers
|
|
|
|
# on local host
|
|
|
|
.PHONY: shutdown
|
|
|
|
shutdown: force-down ## Shutdown all dockers
|
|
|
|
|
2021-06-02 00:54:33 +02:00
|
|
|
# target ssh@%: Connect to % ENV
|
|
|
|
# on first remote host
|
2021-02-09 17:05:00 +01:00
|
|
|
.PHONY: ssh@%
|
2021-06-02 00:54:33 +02:00
|
|
|
ssh@%:
|
2021-05-17 03:40:02 +02:00
|
|
|
$(call make,ssh,$(MYOS),APP)
|
2021-02-09 17:05:00 +01:00
|
|
|
|
2021-06-02 00:54:33 +02:00
|
|
|
# target stack: Call docker-stack for each STACK
|
|
|
|
## it updates COMPOSE_FILE with all .yml files of the current stack
|
2021-02-09 17:05:00 +01:00
|
|
|
.PHONY: stack
|
2022-07-06 23:27:41 +02:00
|
|
|
stack:
|
2021-02-09 17:05:00 +01:00
|
|
|
$(foreach stackz,$(STACK),$(call docker-stack,$(stackz)))
|
|
|
|
|
2021-06-06 16:29:54 +02:00
|
|
|
# target stack-%: Call docker-compose-% target on STACK
|
2021-06-02 00:54:33 +02:00
|
|
|
## it splits % on dashes and extracts stack from the beginning and command from
|
|
|
|
## the last part of %
|
2022-05-09 02:32:23 +02:00
|
|
|
## ex: stack-node-up will fire the docker-compose-up target in the node stack
|
2021-02-09 17:05:00 +01:00
|
|
|
.PHONY: stack-%
|
|
|
|
stack-%:
|
|
|
|
$(eval stack := $(subst -$(lastword $(subst -, ,$*)),,$*))
|
|
|
|
$(eval command := $(lastword $(subst -, ,$*)))
|
|
|
|
$(if $(findstring -,$*), \
|
2022-05-07 15:04:44 +02:00
|
|
|
$(if $(filter $(command),$(filter-out %-%,$(patsubst docker-compose-%,%,$(filter docker-compose-%,$(MAKE_TARGETS))))), \
|
2022-06-30 23:37:10 +02:00
|
|
|
$(call make,docker-compose-$(command) STACK="$(stack)",,ARGS COMPOSE_IGNORE_ORPHANS SERVICE User node)))
|
2021-02-09 17:05:00 +01:00
|
|
|
|
2021-06-06 16:29:54 +02:00
|
|
|
# target start app-start: Start application dockers
|
2021-06-02 00:54:33 +02:00
|
|
|
# on local host
|
2021-06-06 16:29:54 +02:00
|
|
|
.PHONY: start app-start
|
2021-02-09 17:05:00 +01:00
|
|
|
start: docker-compose-start ## Start application dockers
|
|
|
|
|
2021-06-02 00:54:33 +02:00
|
|
|
# target stop: Stop application dockers
|
|
|
|
# on local host
|
2021-02-09 17:05:00 +01:00
|
|
|
.PHONY: stop
|
|
|
|
stop: docker-compose-stop ## Stop application dockers
|
|
|
|
|
2021-06-02 00:54:33 +02:00
|
|
|
# target tests app-tests: Test application
|
|
|
|
# on local host
|
2021-02-09 17:05:00 +01:00
|
|
|
.PHONY: tests app-tests
|
|
|
|
tests: app-tests ## Test application
|
|
|
|
|
2021-06-02 00:54:33 +02:00
|
|
|
# target up: Create and start application dockers
|
|
|
|
# on local host
|
2021-02-09 17:05:00 +01:00
|
|
|
.PHONY: up
|
2022-07-06 23:27:41 +02:00
|
|
|
up: docker-compose-up app-start ## Create application dockers
|
2021-02-09 17:05:00 +01:00
|
|
|
|
2021-06-02 00:54:33 +02:00
|
|
|
# target update app-update: Update application files
|
|
|
|
# on local host
|
2021-02-09 17:05:00 +01:00
|
|
|
.PHONY: update app-update
|
2021-06-02 00:54:33 +02:00
|
|
|
update: update-app app-update ## Update application files
|
|
|
|
|
|
|
|
# target upgrade app-upgrade: Upgrade application
|
|
|
|
# on local host
|
|
|
|
.PHONY: upgrade app-upgrade
|
|
|
|
upgrade: update app-upgrade release-upgrade ## Upgrade application
|
2021-02-09 17:05:00 +01:00
|
|
|
|
|
|
|
# target %: Always fired target
|
2021-06-02 00:54:33 +02:00
|
|
|
## it fires the stack and %-rule-exists targets everytime
|
2021-02-09 17:05:00 +01:00
|
|
|
%: FORCE stack %-rule-exists ;
|
|
|
|
|
2021-06-02 00:54:33 +02:00
|
|
|
# target %-rule-exists: Print a warning message if % target does not exists
|
2021-02-09 17:05:00 +01:00
|
|
|
%-rule-exists:
|
2021-07-11 09:56:03 +02:00
|
|
|
$(if $(filter $*,$(MAKECMDGOALS)),$(if $(filter-out $*,$(MAKE_TARGETS)),$(call WARNING,target,$*,unavailable in app,$(APP))))
|