From ba9a865b550d084d7c748471ccf2b71bcfb6b020 Mon Sep 17 00:00:00 2001 From: Dan Anglin Date: Sat, 26 Aug 2023 13:25:41 +0100 Subject: [PATCH] chore(traefik): remove mounted shared directory The mounted shared directory is no longer needed for now so it will removed from all containers that are mounting it. Changes for Traefik: - Build all dynamic configurations inside the Traefik container. - Remove the mount point for the shared directory. --- config | 2 +- magefiles/config.go | 22 +++++++------- templates/compose/docker-compose.yaml.gotmpl | 4 --- templates/traefik/Dockerfile.gotmpl | 19 ++++--------- templates/traefik/entrypoint.sh.gotmpl | 30 -------------------- templates/traefik/traefik.yaml.gotmpl | 2 +- 6 files changed, 19 insertions(+), 60 deletions(-) delete mode 100644 templates/traefik/entrypoint.sh.gotmpl diff --git a/config b/config index a360553..40b13ab 160000 --- a/config +++ b/config @@ -1 +1 @@ -Subproject commit a36055337246e8ddd83811c982769fab1d555748 +Subproject commit 40b13ab1b1b52d617851f56d89c4017e0360c3b3 diff --git a/magefiles/config.go b/magefiles/config.go index 1539460..c352362 100644 --- a/magefiles/config.go +++ b/magefiles/config.go @@ -21,16 +21,18 @@ type config struct { } type traefikConfig struct { - Version string `json:"version"` - CheckNewVersion bool `json:"checkNewVersion"` - ExternalSSHPort int32 `json:"externalSSHPort"` - LogLevel string `json:"logLevel"` - SendAnonymousUsage bool `json:"sendAnonymousUsage"` - ContainerIpv4Address string `json:"containerIpv4Address"` - AcmeEmail string `json:"acmeEmail"` - SharedMountPoint string `json:"sharedMountPoint"` - TlsHostDirectory string `json:"tlsHostDirectory"` - TlsContainerDirectory string `json:"tlsContainerDirectory"` + Version string `json:"version"` + CheckNewVersion bool `json:"checkNewVersion"` + ExternalSSHPort int32 `json:"externalSSHPort"` + LogLevel string `json:"logLevel"` + SendAnonymousUsage bool `json:"sendAnonymousUsage"` + ContainerIpv4Address string `json:"containerIpv4Address"` + AcmeEmail string `json:"acmeEmail"` + SharedMountPoint string `json:"sharedMountPoint"` + TlsHostDirectory string `json:"tlsHostDirectory"` + TlsContainerDirectory string `json:"tlsContainerDirectory"` + StaticConfigDirectory string `json:"staticConfigDirectory"` + DynamicConfigDirectory string `json:"dynamicConfigDirectory"` } type forgejoConfig struct { diff --git a/templates/compose/docker-compose.yaml.gotmpl b/templates/compose/docker-compose.yaml.gotmpl index ad81d45..2a8281b 100644 --- a/templates/compose/docker-compose.yaml.gotmpl +++ b/templates/compose/docker-compose.yaml.gotmpl @@ -49,10 +49,6 @@ services: restart: "always" volumes: {{- template "defaultVolumes" }} - # Shared volume - - type: "volume" - source: "traefik-shared" - target: "{{ .Traefik.SharedMountPoint }}" # Traefik TLS volume - type: "bind" source: "{{ .Traefik.TlsHostDirectory }}" diff --git a/templates/traefik/Dockerfile.gotmpl b/templates/traefik/Dockerfile.gotmpl index 9a5905e..f4dfb0c 100644 --- a/templates/traefik/Dockerfile.gotmpl +++ b/templates/traefik/Dockerfile.gotmpl @@ -1,18 +1,9 @@ # syntax=docker/dockerfile:1 FROM traefik:{{ .Traefik.Version }} -ADD traefik.yaml /flow/traefik/ +RUN --mount=type=bind,source=.,target=/packages \ + mkdir -p {{ .Traefik.StaticConfigDirectory }} {{ .Traefik.DynamicConfigDirectory }} \ + && cp /packages/traefik.yaml {{ .Traefik.StaticConfigDirectory }}/traefik.yaml \ + && cp /packages/dynamic_*.yaml {{ .Traefik.DynamicConfigDirectory }}/ -ADD dynamic_landing_page.yaml /tmp/dynamic_landing_page.yaml - -ADD dynamic_gotosocial.yaml /tmp/dynamic_gotosocial.yaml - -ADD dynamic_woodpecker.yaml /tmp/dynamic_woodpecker.yaml - -ADD dynamic_forgejo.yaml /tmp/dynamic_forgejo.yaml - -ADD entrypoint.sh / - -RUN chmod +x /entrypoint.sh - -CMD ["--configfile=/flow/traefik/traefik.yaml"] +CMD ["--configfile={{ .Traefik.StaticConfigDirectory }}/traefik.yaml"] diff --git a/templates/traefik/entrypoint.sh.gotmpl b/templates/traefik/entrypoint.sh.gotmpl deleted file mode 100644 index 9a5cbca..0000000 --- a/templates/traefik/entrypoint.sh.gotmpl +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/sh - -set -e - -# Create the dynamic config directory in the shared volume. -mkdir -p {{ .Traefik.SharedMountPoint }}/dynamic -chgrp {{ .FlowGID }} {{ .Traefik.SharedMountPoint }}/dynamic -chmod a-rwx,u+rwx,g+rwx {{ .Traefik.SharedMountPoint }}/dynamic - -# Move any dynamic config to the new directory. -for f in $( find /tmp -mindepth 1 -maxdepth 1 -type f -iname 'dynamic*.yaml' -exec basename {} \; ); do - echo "INFO: Moving /tmp/${f} to {{ .Traefik.SharedMountPoint }}/dynamic/${f}..." - mv -f /tmp/${f} {{ .Traefik.SharedMountPoint }}/dynamic/${f} -done - -# first arg is `-f` or `--some-option` -if [ "${1#-}" != "$1" ]; then - set -- traefik "$@" -fi - -# if our command is a valid Traefik subcommand, let's invoke it through Traefik instead -# (this allows for "docker run traefik version", etc) -if traefik "$1" --help >/dev/null 2>&1 -then - set -- traefik "$@" -else - echo "= '$1' is not a Traefik command: assuming shell execution." 1>&2 -fi - -exec "$@" diff --git a/templates/traefik/traefik.yaml.gotmpl b/templates/traefik/traefik.yaml.gotmpl index ec3fc04..f83b5c8 100644 --- a/templates/traefik/traefik.yaml.gotmpl +++ b/templates/traefik/traefik.yaml.gotmpl @@ -22,7 +22,7 @@ entryPoints: providers: file: watch: true - directory: "{{ .Traefik.SharedMountPoint }}/dynamic" + directory: "{{ .Traefik.DynamicConfigDirectory }}" certificatesResolvers: resolver: acme: