Skip to content

Commit 555bd7d

Browse files
committed
Add rolling deploy simcore makefile targets
1. Automatically copy assets (dask certs) 2. Deploy simcore can now be easily reproduced manually 3. Implement Rolling dask cert update Related issues: * #984 * #934
1 parent 611900c commit 555bd7d

File tree

5 files changed

+71
-25
lines changed

5 files changed

+71
-25
lines changed

scripts/common.Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,18 @@ endef
297297
298298
endif
299299
300+
# Check that given variables are set and all have non-empty values,
301+
# die with an error otherwise.
302+
#
303+
# Params:
304+
# 1. Variable name(s) to test.
305+
# 2. (optional) Error message to print.
306+
guard-%:
307+
@ if [ "${${*}}" = "" ]; then \
308+
echo "Argument '$*' is missing. TIP: make <rule> $*=<value>"; \
309+
exit 1; \
310+
fi
311+
300312
# Gracefully use defaults and potentially overwrite them, via https://stackoverflow.com/a/49804748
301313
%: %-default
302314
@ true

scripts/deployments/prepare_simcore_stack.bash

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,5 @@ cd "$repo_basedir"
4545
log_info "Creating stack.yml file..."
4646
scripts/deployments/compose_stack_yml.bash
4747

48-
log_info "Ensuring dask secrets are relative to the stack file"
49-
# Check if the dask_tls_cert secret exists and update its file path if it does.
50-
if ./yq eval '.secrets.dask_tls_cert' stack.yml >/dev/null; then
51-
./yq eval --inplace '.secrets.dask_tls_cert.file = "./dask-sidecar/.dask-certificates/dask-cert.pem"' stack.yml
52-
else
53-
log_warning "The 'dask_tls_cert' secret does not exist. Skipping this step."
54-
fi
55-
56-
# Check if the dask_tls_key secret exists and update its file path if it does.
57-
if ./yq eval '.secrets.dask_tls_key' stack.yml >/dev/null; then
58-
./yq eval --inplace '.secrets.dask_tls_key.file = "./dask-sidecar/.dask-certificates/dask-key.pem"' stack.yml
59-
else
60-
log_warning "The 'dask_tls_key' secret does not exist. Skipping this step."
61-
fi
62-
6348
log_info "Adding prefix $PREFIX_STACK_NAME to all services..."
6449
./yq "with(.services; with_entries(.key |= \"${PREFIX_STACK_NAME}_\" + .))" stack.yml >"$this_script_dir"/stack_with_prefix.yml

services/simcore/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
.env
22
docker-compose.deploy.yml
33
dask-sidecar/**
4+
assets/
5+
docker-compose.yml

services/simcore/Makefile

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,44 @@
11
.DEFAULT_GOAL := help
22

33
# Internal VARIABLES ------------------------------------------------
4-
# STACK_NAME defaults to name of the current directory. Should not to be changed if you follow GitOps operating procedures.
5-
STACK_NAME = $(notdir $(shell pwd))
6-
TEMP_COMPOSE=docker-compose.deploy.yml
74

8-
# TARGETS --------------------------------------------------
95
REPO_BASE_DIR := $(shell git rev-parse --show-toplevel)
6+
SIMCORE_REPO_DIR ?= $(abspath $(REPO_BASE_DIR)/../osparc-simcore)
7+
8+
STACK_NAME = $(notdir $(shell pwd))
9+
TEMP_COMPOSE=docker-compose.deploy.yml
1010

1111
# TARGETS --------------------------------------------------
1212
include ${REPO_BASE_DIR}/scripts/common.Makefile
1313

14+
$(SIMCORE_REPO_DIR):
15+
$(error $@ repo not found. Please clone this repo manually)
16+
17+
.PHONY: stack_with_prefix.yml
18+
stack_with_prefix.yml: $(SIMCORE_REPO_DIR) $(REPO_CONFIG_LOCATION) guard-DOCKER_IMAGE_TAG
19+
# generating $@
20+
@DOCKER_IMAGE_TAG=$(DOCKER_IMAGE_TAG) \
21+
$(REPO_BASE_DIR)/scripts/deployments/prepare_simcore_stack.bash
22+
@mv $(REPO_BASE_DIR)/scripts/deployments/stack_with_prefix.yml $@
23+
24+
# We don't want to generate stack file automatically here.
25+
# In CI we validate stack file generated in plan_simcore stage
26+
# We want to be sure that exactly this file is going to be deployed
27+
# So we pass this file as STACK_FILE argument and use as is
28+
#
29+
# USAGE:
30+
#
31+
# make stack_with_prefix.yml DOCKER_IMAGE_TAG=v1.81.0
32+
# make up STACK_FILE=stack_with_prefix.yml
33+
#
34+
.PHONY: up
35+
up: guard-STACK_FILE assets/dask-certificates prune-docker-stack-secrets
36+
# deploying simcore stack ...
37+
@set -a && source $(REPO_CONFIG_LOCATION) && set +a && \
38+
docker stack deploy --with-registry-auth -c $(STACK_FILE) $$SIMCORE_STACK_NAME
39+
1440
.PHONY: up-local
15-
up-local:
41+
up-local: prune-docker-stack-secrets
1642
@${REPO_BASE_DIR}/scripts/deployments/start_simcore_locally.bash
1743

1844
.PHONY: compose-local
@@ -36,6 +62,18 @@ compose-aws: .env ${TEMP_COMPOSE}-aws ## Create docker-compose.deploy for AWS
3662
.PHONY: compose-master
3763
compose-master: .env ${TEMP_COMPOSE}-master ## Create docker-compose.deploy for Master
3864

65+
assets/dask-certificates:
66+
$(eval CONFIG_DIR=$(shell dirname ${REPO_CONFIG_LOCATION}))
67+
@if [ -d $(CONFIG_DIR)/assets/dask-certificates ]; then \
68+
mkdir assets &> /dev/null || true; \
69+
cp -r $(CONFIG_DIR)/assets/dask-certificates $@; \
70+
else \
71+
echo "Error: $(CONFIG_DIR)/assets/dask-certificates dir does not exist" >&2; \
72+
exit 1; \
73+
fi
74+
75+
docker-compose.yml: docker-compose.yml.j2 .venv .env assets/dask-certificates
76+
@$(call jinja, $<, .env, $@)
3977

4078
.PHONY: ${TEMP_COMPOSE}-local
4179
${TEMP_COMPOSE}-local: docker-compose.yml docker-compose.deploy.local.yml

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ services:
5353
agent:
5454
networks:
5555
- monitored
56-
hostname: "{{.Node.Hostname}}-{{.Service.Name}}"
56+
hostname: "{% raw %}{{.Node.Hostname}}-{{.Service.Name}}{% endraw %}"
5757
volumes:
5858
- /var/run/docker.sock:/var/run/docker.sock
5959
environment:
@@ -272,7 +272,7 @@ services:
272272

273273

274274
wb-db-event-listener:
275-
hostname: "{{.Service.Name}}"
275+
hostname: "{% raw %}{{.Service.Name}}{% endraw %}"
276276
environment:
277277
- WEBSERVER_LOGLEVEL=${WEBSERVER_LOGLEVEL}
278278
networks:
@@ -311,7 +311,7 @@ services:
311311
- default
312312
- interactive_services_subnet
313313
- monitored
314-
hostname: "{{.Service.Name}}"
314+
hostname: "{% raw %}{{.Service.Name}}{% endraw %}"
315315
deploy:
316316
update_config:
317317
parallelism: 2
@@ -560,7 +560,7 @@ services:
560560
cpus: '0.1'
561561
562562
efs-guardian:
563-
hostname: "{{.Service.Name}}"
563+
hostname: "{% raw %}{{.Service.Name}}{% endraw %}"
564564
networks:
565565
- monitored
566566
deploy:
@@ -668,7 +668,7 @@ services:
668668
networks:
669669
- monitored
670670
- public
671-
hostname: "{{.Service.Name}}"
671+
hostname: "{% raw %}{{.Service.Name}}{% endraw %}"
672672
deploy:
673673
# NOTE: https://github.com/ITISFoundation/osparc-simcore/pull/4286
674674
# NOTE: this MUSTN'T change, or weird things might happen
@@ -921,6 +921,7 @@ services:
921921
volumes:
922922
rabbit_data:
923923
name: ${SWARM_STACK_NAME}_rabbit_data
924+
924925
networks:
925926
public:
926927
external: true
@@ -940,3 +941,11 @@ networks:
940941
interactive_services_subnet:
941942
name: ${SWARM_STACK_NAME}_interactive_services_subnet
942943
external: true
944+
945+
secrets:
946+
dask_tls_key:
947+
file: ./assets/dask-certificates/dask-key.pem
948+
name: ${SWARM_STACK_NAME}_dask_tls_key_{{ "./assets/dask-certificates/dask-key.pem" | sha256file | substring(0,10) }}
949+
dask_tls_cert:
950+
file: ./assets/dask-certificates/dask-cert.pem
951+
name: ${SWARM_STACK_NAME}_dask_tls_cert_{{ "./assets/dask-certificates/dask-cert.pem" | sha256file | substring(0,10) }}

0 commit comments

Comments
 (0)