Skip to content

Commit f13cf98

Browse files
authored
Refactor services makefile ⚠️ 🚨 DEVOPS (#1314)
* Refactor servivces makefile Use `up` target to deploy service independent of deployment. Remove unused code Related issue/s * #1310 * further refactoring * update metabase makefile * Add help commands * Improve default target comments * Move config/secret to service makefile * Remove stale comments * Further refactoring * further clean up * Add comment * Fix doc string
1 parent 1c5d1df commit f13cf98

31 files changed

+408
-551
lines changed

scripts/common-services.Makefile

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,47 @@
33
STACK_NAME = $(notdir $(shell pwd))
44
TEMP_COMPOSE=.stack.${STACK_NAME}.yaml
55
REPO_BASE_DIR := $(shell git rev-parse --show-toplevel)
6+
7+
MAKEFLAGS += --no-print-directory
8+
9+
#
10+
# Common targets
11+
#
12+
13+
.PHONY: up-default
14+
up-default: ## Deploy stack (usage: `make up`)
15+
@# By default run .up target with flavor (e.g. `.up-local`, .`up-aws`)
16+
@# If no flavor available, override by defining `up` target
17+
@set -a && source $(REPO_CONFIG_LOCATION) && set +a && \
18+
$(MAKE) .up-$$OSPARC_DEPLOYMENT_TARGET
19+
20+
.PHONY: down-default
21+
down-default: ## Remove stack (usage: `make down`)
22+
@echo "${STACK_NAME}"
23+
@docker stack rm --detach=false ${STACK_NAME}
24+
25+
.PHONY: prune-docker-stack-configs-default
26+
prune-docker-stack-configs-default: ## Clean all unused stack configs
27+
@# Since the introduction of rolling docker config updates old
28+
@# [docker config] versions are kept. This target removes them
29+
@# https://github.com/docker/cli/issues/203
30+
@#
31+
@# This should be run before stack update in order to
32+
@# keep previous config version for potential rollback
33+
@#
34+
@# This will not clean "external" configs. To achieve this extend
35+
@# this target in related Makefiles.
36+
@#
37+
@# Long live Kubernetes ConfigMaps!
38+
39+
@for id in $$(docker config ls --filter "label=com.docker.stack.namespace=${STACK_NAME}" --format '{{.ID}}'); do \
40+
docker config rm "$$id" >/dev/null 2>&1 || true; \
41+
done
42+
43+
.PHONY: prune-docker-stack-secrets-default
44+
prune-docker-stack-secrets-default: ## Clean all unused stack secrets
45+
@# Same as for configs
46+
47+
@for id in $$(docker secret ls --filter "label=com.docker.stack.namespace=${STACK_NAME}" --format '{{.ID}}'); do \
48+
docker secret rm "$$id" >/dev/null 2>&1 || true; \
49+
done

scripts/common.Makefile

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,6 @@ help:
193193
@awk --posix 'BEGIN {FS = ":.*?## "} /^[[:alpha:][:space:]_-]+:.*?## / {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
194194
@echo ""
195195
196-
.PHONY: down-default
197-
down-default: ## Removes the stack from the swarm
198-
@echo "${STACK_NAME}"
199-
@docker stack rm --detach=false ${STACK_NAME}
200-
201196
.PHONY: leave
202197
leave: ## Leaves swarm stopping all services in it
203198
-@docker swarm leave -f
@@ -226,36 +221,6 @@ clean-default: .check_clean ## Cleans all outputs
226221
set +o allexport; \
227222
envsubst < $< > .env
228223
229-
ifdef STACK_NAME
230-
231-
.PHONY: prune-docker-stack-configs-default
232-
prune-docker-stack-configs-default: ## Clean all unused stack configs
233-
@# Since the introduction of rolling docker config updates old
234-
@# [docker config] versions are kept. This target removes them
235-
@# https://github.com/docker/cli/issues/203
236-
@#
237-
@# This should be run before stack update in order to
238-
@# keep previous config version for potential rollback
239-
@#
240-
@# This will not clean "external" configs. To achieve this extend
241-
@# this target in related Makefiles.
242-
@#
243-
@# Long live Kubernetes ConfigMaps!
244-
245-
@for id in $$(docker config ls --filter "label=com.docker.stack.namespace=${STACK_NAME}" --format '{{.ID}}'); do \
246-
docker config rm "$$id" >/dev/null 2>&1 || true; \
247-
done
248-
249-
.PHONY: prune-docker-stack-secrets-default
250-
prune-docker-stack-secrets-default: ## Clean all unused stack secrets
251-
@# Same as for configs
252-
253-
@for id in $$(docker secret ls --filter "label=com.docker.stack.namespace=${STACK_NAME}" --format '{{.ID}}'); do \
254-
docker secret rm "$$id" >/dev/null 2>&1 || true; \
255-
done
256-
257-
endif
258-
259224
# Helpers -------------------------------------------------
260225
.PHONY: .init
261226
.init: ## initializeds swarm cluster

services/admin-panels/Makefile

Lines changed: 29 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,53 @@
11
REPO_BASE_DIR := $(shell git rev-parse --show-toplevel)
22

33
include ${REPO_BASE_DIR}/scripts/common-services.Makefile
4-
# common-services.Makefile should be included first as common.Makefile
5-
# relies on STACK_NAME var which is defined in common-services.Makefile
64
include ${REPO_BASE_DIR}/scripts/common.Makefile
75

8-
# Helpers --------------------------------------------------
6+
#
7+
# Helpers
8+
#
9+
910
define custom-jinja
1011
@${VENV_BIN}/j2 --format=json $(1) $(2) -o $(3) \
1112
--filters $(REPO_BASE_DIR)/scripts/j2cli_global_filters.py
1213
endef
1314

14-
.PHONY: .data.json
15-
.data.json:
16-
@$(_tree) -J ${PWD}/data | jq ".[0]" > .data.json
17-
18-
.PHONY: docker-compose.yml
19-
docker-compose.yml: docker-compose.yml.j2 venv .data.json .env jupyter_server_config.py
20-
$(call custom-jinja, $<, .data.json, tmp.yml)
21-
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash tmp.yml > $@
22-
@rm tmp.yml
23-
24-
.PHONY: up
25-
up: .init ${TEMP_COMPOSE} prune-docker-stack-configs ## Deploys jaeger stack
26-
@docker stack deploy --with-registry-auth --prune --compose-file ${TEMP_COMPOSE} ${STACK_NAME}
27-
28-
.PHONY: up-letsencrypt-http
29-
up-letsencrypt-http: .init ${TEMP_COMPOSE}-letsencrypt-http prune-docker-stack-configs ## Deploys jaeger stack using let's encrypt http challenge
30-
@docker stack deploy --with-registry-auth --prune --compose-file ${TEMP_COMPOSE}-letsencrypt-http ${STACK_NAME}
31-
32-
.PHONY: up-letsencrypt-dns
33-
up-letsencrypt-dns: .init ${TEMP_COMPOSE}-letsencrypt-dns prune-docker-stack-configs ## Deploys jaeger stack using let's encrypt dns challenge
34-
@docker stack deploy --with-registry-auth --prune --compose-file ${TEMP_COMPOSE}-letsencrypt-dns ${STACK_NAME}
15+
#
16+
# Targets
17+
#
3518

36-
.PHONY: up-dalco ## Deploys jaeger stack for Dalco Cluster
37-
up-dalco: .init ${TEMP_COMPOSE}-dalco prune-docker-stack-configs
19+
.PHONY: .up-dalco
20+
.up-dalco: ${TEMP_COMPOSE}-dalco prune-docker-stack-configs
3821
@docker stack deploy --with-registry-auth --prune --compose-file ${TEMP_COMPOSE}-dalco ${STACK_NAME}
3922

40-
.PHONY: up-aws
41-
up-aws: .init ${TEMP_COMPOSE}-aws prune-docker-stack-configs ## Deploys jaeger stack in aws
23+
.PHONY: .up-aws
24+
.up-aws: ${TEMP_COMPOSE}-aws prune-docker-stack-configs
4225
@docker stack deploy --with-registry-auth --prune --compose-file ${TEMP_COMPOSE}-aws ${STACK_NAME}
4326

44-
.PHONY: up-master
45-
up-master: .init ${TEMP_COMPOSE}-master prune-docker-stack-configs
27+
.PHONY: .up-master
28+
.up-master: ${TEMP_COMPOSE}-master prune-docker-stack-configs
4629
@docker stack deploy --with-registry-auth --prune --compose-file ${TEMP_COMPOSE}-master ${STACK_NAME}
4730

48-
.PHONY: up-local
49-
up-local: up
50-
51-
.PHONY: up-public
52-
up-public: up-dalco
31+
.PHONY: .up-local
32+
.up-local: ${TEMP_COMPOSE} prune-docker-stack-configs
33+
@docker stack deploy --with-registry-auth --prune --compose-file ${TEMP_COMPOSE} ${STACK_NAME}
5334

54-
# Helpers -------------------------------------------------
35+
.PHONY: .up-public
36+
.up-public: .up-dalco
5537

38+
#
39+
# Artifacts
40+
#
5641

57-
.PHONY: ${TEMP_COMPOSE}-letsencrypt-http
58-
${TEMP_COMPOSE}-letsencrypt-http: docker-compose.yml docker-compose.letsencrypt.http.yml .env
59-
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< docker-compose.letsencrypt.http.yml > $@
42+
.PHONY: .data.json
43+
.data.json:
44+
@$(_tree) -J ${PWD}/data | jq ".[0]" > .data.json
6045

61-
.PHONY: ${TEMP_COMPOSE}-letsencrypt-dns
62-
${TEMP_COMPOSE}-letsencrypt-dns: docker-compose.yml docker-compose.letsencrypt.dns.yml .env
63-
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< docker-compose.letsencrypt.dns.yml > $@
46+
.PHONY: docker-compose.yml
47+
docker-compose.yml: docker-compose.yml.j2 venv .data.json .env jupyter_server_config.py
48+
$(call custom-jinja, $<, .data.json, tmp.yml)
49+
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash tmp.yml > $@
50+
@rm tmp.yml
6451

6552
.PHONY: ${TEMP_COMPOSE}-dalco
6653
${TEMP_COMPOSE}-dalco: docker-compose.yml .env

services/admin-panels/docker-compose.letsencrypt.dns.yml

Lines changed: 0 additions & 6 deletions
This file was deleted.

services/admin-panels/docker-compose.letsencrypt.http.yml

Lines changed: 0 additions & 6 deletions
This file was deleted.

services/adminer/Makefile

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,47 @@
11
REPO_BASE_DIR := $(shell git rev-parse --show-toplevel)
22

33
include ${REPO_BASE_DIR}/scripts/common-services.Makefile
4-
# common-services.Makefile should be included first as common.Makefile
5-
# relies on STACK_NAME var which is defined in common-services.Makefile
64
include ${REPO_BASE_DIR}/scripts/common.Makefile
75

8-
.PHONY: up
9-
up: .init .env ${TEMP_COMPOSE} ## Deploys adminer stack
10-
@docker stack deploy --with-registry-auth --prune --compose-file ${TEMP_COMPOSE} ${STACK_NAME}
11-
12-
.PHONY: up-letsencrypt-http
13-
up-letsencrypt-http: .init .env ${TEMP_COMPOSE}-letsencrypt-http ## Deploys adminer stack using let's encrypt http challenge
14-
@docker stack deploy --with-registry-auth --prune --compose-file ${TEMP_COMPOSE}-letsencrypt-http ${STACK_NAME}
15-
16-
.PHONY: up-letsencrypt-dns
17-
up-letsencrypt-dns: .init .env ${TEMP_COMPOSE}-letsencrypt-dns ## Deploys adminer stack using let's encrypt dns challenge
18-
@docker stack deploy --with-registry-auth --prune --compose-file ${TEMP_COMPOSE}-letsencrypt-dns ${STACK_NAME}
6+
#
7+
# Targets
8+
#
199

20-
.PHONY: up-dalco ## Deploys adminer stack for Dalco Cluster
21-
up-dalco: .init .env ${TEMP_COMPOSE}-dalco
10+
.PHONY: .up-dalco
11+
.up-dalco: ${TEMP_COMPOSE}-dalco
2212
@docker stack deploy --with-registry-auth --prune --compose-file ${TEMP_COMPOSE}-dalco ${STACK_NAME}
2313

24-
.PHONY: up-aws
25-
up-aws: .init .env ${TEMP_COMPOSE}-aws ## Deploys adminer stack using let's encrypt dns challenge
14+
.PHONY: .up-aws
15+
.up-aws: ${TEMP_COMPOSE}-aws
2616
@docker stack deploy --with-registry-auth --prune --compose-file ${TEMP_COMPOSE}-aws ${STACK_NAME}
2717

28-
.PHONY: up-local
29-
up-local: up
18+
.PHONY: .up-local
19+
.up-local: ${TEMP_COMPOSE}
20+
@docker stack deploy --with-registry-auth --prune --compose-file ${TEMP_COMPOSE} ${STACK_NAME}
3021

31-
.PHONY: up-master ## Deploys adminer stack for master Cluster
32-
up-master: .init .env ${TEMP_COMPOSE}-master
22+
.PHONY: .up-master
23+
.up-master: ${TEMP_COMPOSE}-master
3324
@docker stack deploy --with-registry-auth --prune --compose-file ${TEMP_COMPOSE}-master ${STACK_NAME}
3425

26+
.PHONY: .up-public
27+
.up-public: .up-dalco
3528

36-
.PHONY: up-public
37-
up-public: up-dalco
38-
39-
# Helpers -------------------------------------------------
29+
#
30+
# Artifacts
31+
#
4032

4133
.PHONY: ${TEMP_COMPOSE}
42-
${TEMP_COMPOSE}: docker-compose.yml
34+
${TEMP_COMPOSE}: docker-compose.yml .env
4335
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< > $@
4436

4537
.PHONY: ${TEMP_COMPOSE}-dalco
46-
${TEMP_COMPOSE}-dalco: docker-compose.yml docker-compose.dalco.yml
38+
${TEMP_COMPOSE}-dalco: docker-compose.yml docker-compose.dalco.yml .env
4739
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< docker-compose.dalco.yml > $@
4840

4941
.PHONY: ${TEMP_COMPOSE}-master
50-
${TEMP_COMPOSE}-master: docker-compose.yml docker-compose.master.yml
42+
${TEMP_COMPOSE}-master: docker-compose.yml docker-compose.master.yml .env
5143
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< docker-compose.master.yml > $@
5244

5345
.PHONY: ${TEMP_COMPOSE}-aws
54-
${TEMP_COMPOSE}-aws: docker-compose.yml docker-compose.aws.yml
46+
${TEMP_COMPOSE}-aws: docker-compose.yml docker-compose.aws.yml .env
5547
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< docker-compose.aws.yml > $@

services/adminer/docker-compose.letsencrypt.dns.yml

Lines changed: 0 additions & 6 deletions
This file was deleted.

services/adminer/docker-compose.letsencrypt.http.yml

Lines changed: 0 additions & 6 deletions
This file was deleted.

services/appmotion_gateway/Makefile

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,59 @@
11
REPO_BASE_DIR := $(shell git rev-parse --show-toplevel)
22

33
include ${REPO_BASE_DIR}/scripts/common-services.Makefile
4-
# common-services.Makefile should be included first as common.Makefile
5-
# relies on STACK_NAME var which is defined in common-services.Makefile
64
include ${REPO_BASE_DIR}/scripts/common.Makefile
75

6+
#
7+
# Vars
8+
#
9+
810
DOCKER_STACK_DEPLOY_COMMON_DEPENDENCIES = .api_env.secret \
911
prune-docker-stack-configs \
1012
prune-docker-stack-secrets
1113

12-
# TARGETS --------------------------------------------------
13-
include ${REPO_BASE_DIR}/scripts/common.Makefile
14+
#
15+
# Targets
16+
#
1417

15-
.PHONY: up-aws ## Deploys stack on aws
16-
up-aws: .init .env ${TEMP_COMPOSE}-aws ${DOCKER_STACK_DEPLOY_COMMON_DEPENDENCIES}
18+
.PHONY: .up-aws
19+
.up-aws: ${TEMP_COMPOSE}-aws ${DOCKER_STACK_DEPLOY_COMMON_DEPENDENCIES}
1720
@docker stack deploy --with-registry-auth --prune --compose-file ${TEMP_COMPOSE}-aws ${STACK_NAME}
1821

19-
.PHONY: up-master ## Deploys stack on master
20-
up-master: .init .env ${TEMP_COMPOSE}-master ${DOCKER_STACK_DEPLOY_COMMON_DEPENDENCIES}
22+
.PHONY: .up-master
23+
.up-master: ${TEMP_COMPOSE}-master ${DOCKER_STACK_DEPLOY_COMMON_DEPENDENCIES}
2124
@docker stack deploy --with-registry-auth --prune --compose-file ${TEMP_COMPOSE}-master ${STACK_NAME}
2225

23-
.PHONY: up-dalco ## Deploys stack on dalco
24-
up-dalco: .init .env ${TEMP_COMPOSE}-dalco ${DOCKER_STACK_DEPLOY_COMMON_DEPENDENCIES}
26+
.PHONY: .up-dalco
27+
.up-dalco: ${TEMP_COMPOSE}-dalco ${DOCKER_STACK_DEPLOY_COMMON_DEPENDENCIES}
2528
@docker stack deploy --with-registry-auth --prune --compose-file ${TEMP_COMPOSE}-dalco ${STACK_NAME}
2629

27-
.PHONY: up-local ## Deploys stack on local
28-
up-local: .init .env ${TEMP_COMPOSE}-local ${DOCKER_STACK_DEPLOY_COMMON_DEPENDENCIES}
30+
.PHONY: .up-local
31+
.up-local: ${TEMP_COMPOSE}-local ${DOCKER_STACK_DEPLOY_COMMON_DEPENDENCIES}
2932
@docker stack deploy --with-registry-auth --prune --compose-file ${TEMP_COMPOSE}-local ${STACK_NAME}
3033

31-
# Helpers -------------------------------------------------
34+
#
35+
# Artifacts
36+
#
3237

3338
docker-compose.yml: .env .api_env.secret venv
3439
@$(call jinja, docker-compose.yml.j2, .env, docker-compose.yml.unlinted) && \
3540
$(_yq) docker-compose.yml.unlinted > docker-compose.yml; \
3641
rm docker-compose.yml.unlinted >/dev/null 2>&1;
3742

3843
.PHONY: ${TEMP_COMPOSE}-aws
39-
${TEMP_COMPOSE}-aws: docker-compose.yml docker-compose.aws.yml
44+
${TEMP_COMPOSE}-aws: docker-compose.yml docker-compose.aws.yml .env
4045
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< docker-compose.aws.yml > $@
4146

4247
.PHONY: ${TEMP_COMPOSE}-master
43-
${TEMP_COMPOSE}-master: docker-compose.yml docker-compose.master.yml
48+
${TEMP_COMPOSE}-master: docker-compose.yml docker-compose.master.yml .env
4449
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< docker-compose.master.yml > $@
4550

4651
.PHONY: ${TEMP_COMPOSE}-dalco
47-
${TEMP_COMPOSE}-dalco: docker-compose.yml docker-compose.dalco.yml
52+
${TEMP_COMPOSE}-dalco: docker-compose.yml docker-compose.dalco.yml .env
4853
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< docker-compose.dalco.yml > $@
4954

5055
.PHONY: ${TEMP_COMPOSE}-local
51-
${TEMP_COMPOSE}-local: docker-compose.yml docker-compose.local.yml
56+
${TEMP_COMPOSE}-local: docker-compose.yml docker-compose.local.yml .env
5257
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< docker-compose.local.yml > $@
5358

5459
.api_env.secret: .env template.api_env ## resolves '.api_env.secret' using '.env'

0 commit comments

Comments
 (0)