Skip to content

Commit d2803d9

Browse files
committed
Allow providing own certificates for dev cluster
1 parent 7774748 commit d2803d9

8 files changed

+119
-9
lines changed

.gitignore

+4-3
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,10 @@ src/Apps/*/dist/
247247
**/integration_tests_secrets.sh
248248
**/dist
249249

250-
dev/proxy/*.pem
251-
dev/proxy/*.crt
252-
dev/proxy/*.key
250+
**/*.pem
251+
**/*.crt
252+
**/*.cert
253+
**/*.key
253254

254255
!dev/**/.env
255256
!release/

.template.config/template.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,11 @@
117117
{
118118
"actionId": "CB9A6CF3-4F5C-4860-B9D2-03A574959774",
119119
"args": {
120-
"+x": ["./backend/dev/*/*.sh", "./dev-cluster/*.sh"]
120+
"+x": ["./backend/dev/*/*.sh", "./dev-cluster/*.sh", "./dev-cluster/*/*.sh"]
121121
},
122122
"manualInstructions": [
123123
{
124-
"text": "Run 'chmod +x ./backend/dev/*/*.sh ./dev-cluster/*.sh'"
124+
"text": "Run 'chmod +x ./backend/dev/*/*.sh ./dev-cluster/*.sh ./dev-cluster/*/*.sh'"
125125
}
126126
]
127127
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM traefik
2+
3+
COPY --chmod=0644 local.lncd.pl.cert local.lncd.pl.key /certs/
4+
COPY config.toml /config/config.toml
5+
COPY dynamic.toml /config/dynamic/main.toml
6+
7+
CMD ["--configFile=/config/config.toml"]

dev-cluster/apps/config.toml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[global]
2+
checkNewVersion = true
3+
sendAnonymousUsage = false
4+
[log]
5+
level = "DEBUG"
6+
[api]
7+
dashboard = true
8+
insecure = true
9+
debug = true
10+
11+
[provieders]
12+
[providers.docker]
13+
exposedByDefault = true
14+
[providers.file]
15+
directory = "/config/dynamic"
16+
watch = true
17+
18+
[entryPoints]
19+
[entryPoints.web]
20+
address = ":80"
21+
[entryPoints.web.http]
22+
[entryPoints.web.http.redirections]
23+
[entryPoints.web.http.redirections.entryPoint]
24+
to = ":443"
25+
scheme = "https"
26+
[entryPoints.websecure]
27+
address = ":443"

dev-cluster/apps/generate_certs.sh

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
if command -v apk 2>/dev/null
6+
then
7+
apk add --no-cache openssl
8+
fi
9+
10+
NAME=local.lncd.pl
11+
SUBJ="
12+
C=PL
13+
O=LeanCode DEV
14+
commonName=*.$NAME
15+
organizationalUnitName=LeanCode DEV
16+
17+
SUBJ="$(echo "$SUBJ" | tr '\n' '/')"
18+
PASSWD=Passwd1!
19+
20+
if ! test -f CA.key || ! test -f CA.pem
21+
then
22+
openssl genrsa -des3 -out CA.key -passout pass:"$PASSWD" 2048
23+
openssl req -x509 -new -nodes -subj "$SUBJ" -key CA.key -passin pass:"$PASSWD" -sha256 -days 825 -out CA.pem
24+
fi
25+
26+
if ! test -f "$NAME.key" || ! test -f "$NAME.cert"
27+
then
28+
openssl genrsa -out "$NAME.key" 2048
29+
openssl req -new -subj "$SUBJ" -key "$NAME.key" -out "$NAME.csr"
30+
cat > "$NAME.ext" <<-EOF
31+
authorityKeyIdentifier=keyid,issuer
32+
basicConstraints=CA:FALSE
33+
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
34+
subjectAltName = @alt_names
35+
[alt_names]
36+
DNS.1 = $NAME # Be sure to include the domain name here because Common Name is not so commonly honoured by itself
37+
DNS.2 = *.$NAME # Optionally, add additional domains (I've added a subdomain here)
38+
EOF
39+
40+
openssl x509 -req -in "$NAME.csr" -CA CA.pem -CAkey CA.key -CAcreateserial \
41+
-out "$NAME.cert" -days 825 -sha256 -extfile "$NAME.ext" -passin pass:"$PASSWD"
42+
fi
43+
44+
chmod 666 -- CA.key CA.pem "$NAME.key" "$NAME.cert" || true
45+
rm -f -- "$NAME.ext" "$NAME.csr" CA.srl

dev-cluster/deploy.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ cd "${0:A:h}"
66
k3d cluster delete exampleapp || true
77
k3d registry delete k3d-exampleapp-registry.local.lncd.pl || true
88
rm *.tfstate* || true
9+
docker rm exampleapp-certificates || true
910

1011
# Docker provider will not be able to use the token
11-
az acr login -n leancode
12-
docker pull leancode.azurecr.io/traefik-proxy
12+
az acr login -n leancode && docker pull leancode.azurecr.io/traefik-proxy || true
1313

1414
# We depend on these charts
1515
helm repo add traefik https://helm.traefik.io/traefik || true

dev-cluster/traefik.tf

+27-2
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,45 @@ locals {
44
traefik_image = "${local.traefik_image_name}:${local.traefik_image_version}"
55

66
traefik_triggers = {
7-
dockerfile_trigger = filemd5("./apps/Dockerfile.traefik")
7+
dockerfile_trigger = filemd5(var.traefik_self_signed ? "./apps/Dockerfile.traefik-self-signed" : "./apps/Dockerfile.traefik")
88
dynamic_toml_trigger = filemd5("./apps/dynamic.toml")
99
}
1010
}
1111

12+
resource "docker_image" "alpine" {
13+
name = "docker.io/library/alpine:latest"
14+
keep_locally = true
15+
}
16+
17+
resource "docker_container" "certificates" {
18+
image = docker_image.alpine.image_id
19+
name = "exampleapp-certificates"
20+
21+
start = true
22+
attach = true
23+
wait = true
24+
rm = true
25+
working_dir = "/mnt"
26+
command = ["./generate_certs.sh"]
27+
28+
mounts {
29+
type = "bind"
30+
source = abspath("${path.module}/apps")
31+
target = "/mnt"
32+
}
33+
}
34+
1235
resource "docker_image" "traefik" {
1336
name = local.traefik_image
1437

1538
build {
1639
context = "./apps"
17-
dockerfile = "Dockerfile.traefik"
40+
dockerfile = var.traefik_self_signed ? "Dockerfile.traefik-self-signed" : "Dockerfile.traefik"
1841
}
1942

2043
triggers = local.traefik_triggers
44+
45+
depends_on = [docker_container.certificates]
2146
}
2247

2348
resource "docker_registry_image" "traefik" {

dev-cluster/variables.tf

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
variable "traefik_self_signed" {
2+
type = bool
3+
default = true
4+
}
5+
16
variable "metabase" {
27
type = bool
38
default = false

0 commit comments

Comments
 (0)