Skip to content

Commit dda6e01

Browse files
committed
Merge remote-tracking branch 'upstream/main'
2 parents ed8d479 + e4ba1db commit dda6e01

18 files changed

+93
-76
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,13 @@ jobs:
88

99
steps:
1010
- name: Checkout repository
11-
uses: actions/checkout@v3
11+
uses: actions/checkout@v4
1212

13-
- name: Define python
14-
run: echo "PYTHON_VERSION=$(cat .python-version)" >> $GITHUB_ENV
15-
16-
- name: Install python version
17-
uses: gabrielfalcao/pyenv-action@v11
18-
with:
19-
default: "${{ env.PYTHON_VERSION }}"
20-
command: pip install -U pip
13+
- name: Set up Python
14+
uses: actions/setup-python@v5 # defaults to .python-version
2115

2216
- name: Show python version
2317
run: python --version
2418

25-
- name: Install dependencies
26-
run: |
27-
pip install pre-commit
28-
pre-commit install
29-
3019
- name: Run pre-commit
31-
run: pre-commit run --all-files
20+
uses: pre-commit/[email protected]

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ repos:
3939
- id: pyupgrade
4040
name: upgrade code
4141
- repo: https://github.com/hadialqattan/pycln
42-
rev: v2.2.2
42+
rev: v2.5.0 # https://github.com/hadialqattan/pycln/issues/249
4343
hooks:
4444
- id: pycln
4545
args: [--all, --expand-stars]

scripts/common.Makefile

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,39 @@ clean-default: .check_clean ## Cleans all outputs
207207
export DEPLOYMENT_API_DOMAIN_TESTING_CAPTURE_TRAEFIK_RULE='${DEPLOYMENT_API_DOMAIN_TESTING_CAPTURE_TRAEFIK_RULE}'; \
208208
export DEPLOYMENT_FQDNS_CAPTURE_INVITATIONS='${DEPLOYMENT_FQDNS_CAPTURE_INVITATIONS}'; \
209209
export DOLLAR='$$'; \
210+
$(if $(STACK_NAME),export STACK_NAME='$(STACK_NAME)';) \
210211
set +o allexport; \
211212
envsubst < $< > .env
212213
214+
ifdef STACK_NAME
215+
216+
.PHONY: prune-docker-stack-configs-default
217+
prune-docker-stack-configs-default: ## Clean all unused stack configs
218+
@# Since the introduction of rolling docker config updates old
219+
@# [docker config] versions are kept. This target removes them
220+
@# https://github.com/docker/cli/issues/203
221+
@#
222+
@# This should be run before stack update in order to
223+
@# keep previous config version for potential rollback
224+
@#
225+
@# This will not clean "external" configs. To achieve this extend
226+
@# this target in related Makefiles.
227+
@#
228+
@# Long live Kubernetes ConfigMaps!
229+
230+
@for id in $$(docker config ls --filter "label=com.docker.stack.namespace=${STACK_NAME}" --format '{{.ID}}'); do \
231+
docker config rm "$$id" >/dev/null 2>&1 || true; \
232+
done
233+
234+
.PHONY: prune-docker-stack-secrets-default
235+
prune-docker-stack-secrets-default: ## Clean all unused stack secrets
236+
@# Same as for configs
237+
238+
@for id in $$(docker secret ls --filter "label=com.docker.stack.namespace=${STACK_NAME}" --format '{{.ID}}'); do \
239+
docker secret rm "$$id" >/dev/null 2>&1 || true; \
240+
done
241+
242+
endif
213243
214244
# Helpers -------------------------------------------------
215245
.PHONY: .init
@@ -253,13 +283,16 @@ venv: $(REPO_BASE_DIR)/.venv/bin/activate ## Creates a python virtual environmen
253283
ifeq ($(shell test -f j2cli_customization.py && echo -n yes),yes)
254284
255285
define jinja
256-
$(REPO_BASE_DIR)/.venv/bin/j2 --format=env $(1) $(2) -o $(3) --customize j2cli_customization.py
286+
$(REPO_BASE_DIR)/.venv/bin/j2 --format=env $(1) $(2) -o $(3) \
287+
--filters $(REPO_BASE_DIR)/scripts/j2cli_global_filters.py \
288+
--customize j2cli_customization.py
257289
endef
258290
259291
else
260292
261293
define jinja
262-
$(REPO_BASE_DIR)/.venv/bin/j2 --format=env $(1) $(2) -o $(3)
294+
$(REPO_BASE_DIR)/.venv/bin/j2 --format=env $(1) $(2) -o $(3) \
295+
--filters $(REPO_BASE_DIR)/scripts/j2cli_global_filters.py
263296
endef
264297
265298
endif

scripts/j2cli_global_filters.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
def sha256file(filepath):
2+
import hashlib
3+
4+
_hash = hashlib.sha256()
5+
6+
# https://stackoverflow.com/a/22058673/12124525
7+
with open(filepath, "rb") as f:
8+
while True:
9+
data = f.read(65536)
10+
if not data:
11+
break
12+
13+
_hash.update(data)
14+
15+
return _hash.hexdigest()
16+
17+
18+
def substring(value, start, end):
19+
return value[start:end]

services/admin-panels/docker-compose.yml.j2

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ services:
8989
- traefik.http.services.adminpanels.loadbalancer.server.port=8888
9090
- traefik.http.routers.adminpanels.rule=Host(`${ADMINPANELS_DOMAIN}`)
9191
- traefik.http.routers.adminpanels.entrypoints=https
92-
- traefik.http.routers.adminpanels.priority=1
9392
- traefik.http.routers.adminpanels.tls=true
9493
- traefik.http.routers.adminpanels.middlewares=ops_whitelist_ips@swarm, ops_gzip@swarm
9594
placement:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
!docker-compose.yml
1+
docker-compose.yml
22
*.secret
Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,37 @@
11
.DEFAULT_GOAL := help
22

3-
4-
53
# Internal VARIABLES ------------------------------------------------
64
# STACK_NAME defaults to name of the current directory. Should not to be changed if you follow GitOps operating procedures.
75
STACK_NAME = $(notdir $(shell pwd))
86
TEMP_COMPOSE=.stack.${STACK_NAME}.yaml
97
REPO_BASE_DIR := $(shell git rev-parse --show-toplevel)
108

9+
DOCKER_STACK_DEPLOY_COMMON_DEPENDENCIES = .api_env.secret \
10+
prune-docker-stack-configs \
11+
prune-docker-stack-secrets
12+
1113
# TARGETS --------------------------------------------------
1214
include ${REPO_BASE_DIR}/scripts/common.Makefile
1315

1416
.PHONY: up-aws ## Deploys stack on aws
15-
up-aws: .init .env ${TEMP_COMPOSE}-aws .api_env.secret
17+
up-aws: .init .env ${TEMP_COMPOSE}-aws ${DOCKER_STACK_DEPLOY_COMMON_DEPENDENCIES}
1618
@docker stack deploy --with-registry-auth --prune --compose-file ${TEMP_COMPOSE}-aws ${STACK_NAME}
1719

1820
.PHONY: up-master ## Deploys stack on master
19-
up-master: .init .env ${TEMP_COMPOSE}-master .api_env.secret
21+
up-master: .init .env ${TEMP_COMPOSE}-master ${DOCKER_STACK_DEPLOY_COMMON_DEPENDENCIES}
2022
@docker stack deploy --with-registry-auth --prune --compose-file ${TEMP_COMPOSE}-master ${STACK_NAME}
2123

2224
.PHONY: up-local ## Deploys stack on local
23-
up-local: .init .env ${TEMP_COMPOSE}-local .api_env.secret
25+
up-local: .init .env ${TEMP_COMPOSE}-local ${DOCKER_STACK_DEPLOY_COMMON_DEPENDENCIES}
2426
@docker stack deploy --with-registry-auth --prune --compose-file ${TEMP_COMPOSE}-local ${STACK_NAME}
2527

2628
# Helpers -------------------------------------------------
2729

30+
docker-compose.yml: .env .api_env.secret
31+
@$(call jinja, docker-compose.yml.j2, .env, docker-compose.yml.unlinted) && \
32+
$(_yq) docker-compose.yml.unlinted > docker-compose.yml; \
33+
rm docker-compose.yml.unlinted >/dev/null 2>&1;
34+
2835
.PHONY: ${TEMP_COMPOSE}-aws
2936
${TEMP_COMPOSE}-aws: docker-compose.yml docker-compose.aws.yml
3037
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< docker-compose.aws.yml > $@
@@ -37,6 +44,5 @@ ${TEMP_COMPOSE}-master: docker-compose.yml docker-compose.master.yml
3744
${TEMP_COMPOSE}-local: docker-compose.yml docker-compose.local.yml
3845
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< docker-compose.local.yml > $@
3946

40-
4147
.api_env.secret: .env template.api_env ## resolves '.api_env.secret' using '.env'
4248
@set -o allexport; source $<; set +o allexport; envsubst < $(word 2,$^) > $@

services/appmotion_gateway/docker-compose.yml renamed to services/appmotion_gateway/docker-compose.yml.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ configs:
103103
# SEE https://docs.docker.com/compose/compose-file/05-services/#configs
104104
api_env_config:
105105
file: ./.api_env.secret
106+
name: ${STACK_NAME}_api_env_config_{{ "./.api_env.secret" | sha256file | substring(0,10) }} # rolling update on content change
106107

107108
volumes:
108109
# SEE https://docs.docker.com/compose/compose-file/07-volumes/

services/appmotion_gateway/template.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ DEPLOYMENT_FQDNS_APPMOTION_CAPTURE_TRAEFIK_RULE='${DEPLOYMENT_FQDNS_APPMOTION_CA
2020
APPMOTION_NETWORK=${APPMOTION_NETWORK}
2121
MONITORING_DOMAIN=${MONITORING_DOMAIN}
2222
PUBLIC_NETWORK=${PUBLIC_NETWORK}
23-
SWARM_STACK_NAME=${SWARM_STACK_NAME}
23+
STACK_NAME=${STACK_NAME}
2424
MACHINE_FQDN=${MACHINE_FQDN}

services/filestash/Makefile

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,50 +24,39 @@ up-letsencrypt-dns: .init .env filestash_config.json ${TEMP_COMPOSE}-letsencrypt
2424
@docker stack deploy --with-registry-auth --prune --compose-file ${TEMP_COMPOSE}-letsencrypt-dns ${STACK_NAME}
2525

2626
.PHONY: up-dalco ## Deploys stack for Dalco Cluster
27-
up-dalco: .init .env filestash_config.json ${TEMP_COMPOSE}-dalco
28-
@docker stack deploy --with-registry-auth --prune --compose-file ${TEMP_COMPOSE}-dalco ${STACK_NAME}
27+
up-dalco: up
2928

3029
.PHONY: up-aws ## Deploys stack on aws
3130
up-aws: .init .env ${TEMP_COMPOSE}-aws filestash_config.json ## Deploys stack in aws
3231
@docker stack deploy --with-registry-auth --prune --compose-file ${TEMP_COMPOSE}-aws ${STACK_NAME}
3332

3433
.PHONY: up-master ## Deploys stack for master Cluster
35-
up-master: .init .env filestash_config.json ${TEMP_COMPOSE}-master
36-
@docker stack deploy --with-registry-auth --prune --compose-file ${TEMP_COMPOSE}-master ${STACK_NAME}
34+
up-master: up
3735

3836
.PHONY: up-public ## Deploys stack on public
39-
up-public: up-dalco
37+
up-public: up
4038

4139
.PHONY: up-local ## Deploys stack on local deployment
4240
up-local: up
4341

4442
# Helpers -------------------------------------------------
4543

4644
.PHONY: ${TEMP_COMPOSE}
47-
${TEMP_COMPOSE}: docker-compose.yml
45+
${TEMP_COMPOSE}: docker-compose.yml .env
4846
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< > $@
4947

5048
.PHONY: ${TEMP_COMPOSE}-letsencrypt-http
51-
${TEMP_COMPOSE}-letsencrypt-http: docker-compose.yml docker-compose.letsencrypt.http.yml
49+
${TEMP_COMPOSE}-letsencrypt-http: docker-compose.yml docker-compose.letsencrypt.http.yml .env
5250
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< docker-compose.letsencrypt.http.yml > $@
5351

5452
.PHONY: ${TEMP_COMPOSE}-letsencrypt-dns
55-
${TEMP_COMPOSE}-letsencrypt-dns: docker-compose.yml docker-compose.letsencrypt.dns.yml
53+
${TEMP_COMPOSE}-letsencrypt-dns: docker-compose.yml docker-compose.letsencrypt.dns.yml .env
5654
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< docker-compose.letsencrypt.dns.yml > $@
5755

58-
.PHONY: ${TEMP_COMPOSE}-dalco
59-
${TEMP_COMPOSE}-dalco: docker-compose.yml docker-compose.dalco.yml
60-
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< docker-compose.dalco.yml > $@
61-
62-
.PHONY: ${TEMP_COMPOSE}-master
63-
${TEMP_COMPOSE}-master: docker-compose.yml docker-compose.master.yml
64-
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< docker-compose.master.yml > $@
65-
6656
.PHONY: ${TEMP_COMPOSE}-aws
67-
${TEMP_COMPOSE}-aws: docker-compose.yml docker-compose.aws.yml
57+
${TEMP_COMPOSE}-aws: docker-compose.yml docker-compose.aws.yml .env
6858
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< docker-compose.aws.yml > $@
6959

70-
7160
filestash_config.json: .env
7261
@set -o allexport; \
7362
source $(REPO_CONFIG_LOCATION); \

0 commit comments

Comments
 (0)