diff --git a/config b/config index d17177a..46b27c4 160000 --- a/config +++ b/config @@ -1 +1 @@ -Subproject commit d17177a0636e3e1b89cb2e3891aed2d6e5a1ed12 +Subproject commit 46b27c4c2bda5d2109a4dbe9b84bb6efe881da7d diff --git a/magefiles/config.go b/magefiles/config.go index dc04c83..1539460 100644 --- a/magefiles/config.go +++ b/magefiles/config.go @@ -17,6 +17,7 @@ type config struct { Forgejo forgejoConfig `json:"forgejo"` GoToSocial gotosocialConfig `json:"gotosocial"` Woodpecker woodpeckerConfig `json:"woodpecker"` + Landing landingConfig `json:"landing"` } type traefikConfig struct { @@ -95,6 +96,21 @@ type woodpeckerConfig struct { ForgejoClientSecret string `json:"forgejoClientSecret"` } +type landingConfig struct { + Version string `json:"version"` + ContainerIpv4Address string `json:"containerIpv4Address"` + Services []landingConfigLinks `json:"services"` + Profiles []landingConfigLinks `json:"profiles"` + Port int32 `json:"port"` + ImageDigest string `json:"imageDigest"` +} + +type landingConfigLinks struct { + Title string + URL string + Rel string +} + func newConfig(path string) (config, error) { var c config diff --git a/magefiles/download.go b/magefiles/download.go index f3ef03d..8a6e445 100644 --- a/magefiles/download.go +++ b/magefiles/download.go @@ -34,7 +34,7 @@ func Download(name string) error { return fmt.Errorf("an error occurred whilst getting the packages for Woodpecker; %w", err) } default: - fmt.Printf("'%s' has no files to download.\n", name) + fmt.Printf("There's no files to download for %q.\n", name) } return nil diff --git a/magefiles/prepare.go b/magefiles/prepare.go index 35732b2..5f3a616 100644 --- a/magefiles/prepare.go +++ b/magefiles/prepare.go @@ -95,6 +95,16 @@ func render(cfg config, component string) error { templateDirName := filepath.Join(rootTemplatesDir, component) + _, err := os.Stat(templateDirName) + if err != nil { + if os.IsNotExist(err) { + fmt.Printf("There's no template directory for %q.\n", component) + return nil + } + + return err + } + files, err := os.ReadDir(templateDirName) if err != nil { return fmt.Errorf("unable to read files from %s; %w ", templateDirName, err) @@ -140,8 +150,12 @@ func render(cfg config, component string) error { func copyAssets(service string) error { assetsDirName := filepath.Join(rootAssetsDir, service) if _, err := os.Stat(assetsDirName); err != nil { - log.Printf("There's no assets directory for %s.\n", service) - return nil + if os.IsNotExist(err) { + fmt.Printf("There's no assets directory for %q.\n", service) + return nil + } + + return err } buildDirName := filepath.Join(rootBuildDir, service, "assets") diff --git a/templates/compose/docker-compose.yaml.gotmpl b/templates/compose/docker-compose.yaml.gotmpl index 2b09f11..ad81d45 100644 --- a/templates/compose/docker-compose.yaml.gotmpl +++ b/templates/compose/docker-compose.yaml.gotmpl @@ -143,3 +143,23 @@ services: - type: "bind" source: "{{ .Woodpecker.DataHostDirectory }}" target: "{{ .Woodpecker.DataContainerDirectory }}" + # -- Landing Page -- + landing: + container_name: "landing-page" + command: + - --address={{ .Landing.ContainerIpv4Address }}:{{ .Landing.Port }} + {{ range .Landing.Services -}} + - --service=title={{ .Title }},url={{ .URL }}{{ if gt (len .Rel) 0 }},rel={{ .Rel }}{{ end }} + {{ end -}} + {{ range .Landing.Profiles -}} + - --profile=title={{ .Title }},url={{ .URL }}{{ if gt (len .Rel) 0 }},rel={{ .Rel }}{{ end }} + {{ end -}} + image: "codeflow.dananglin.me.uk/flow/landing:v{{ .Landing.Version }}@{{ .Landing.ImageDigest }}" + expose: + - "{{ .Landing.Port }}" + networks: + flow: + ipv4_address: "{{ .Landing.ContainerIpv4Address }}" + restart: "always" + volumes: + {{- template "defaultVolumes" }} diff --git a/templates/traefik/Dockerfile.gotmpl b/templates/traefik/Dockerfile.gotmpl index b94ed21..7a9a249 100644 --- a/templates/traefik/Dockerfile.gotmpl +++ b/templates/traefik/Dockerfile.gotmpl @@ -2,7 +2,7 @@ FROM traefik:{{ .Traefik.Version }} ADD traefik.yaml /flow/traefik/ -ADD dynamic_root_domain_redirect.yaml /tmp/dynamic_root_domain_redirect.yaml +ADD dynamic_landing_page.yaml /tmp/dynamic_landing_page.yaml ADD entrypoint.sh / diff --git a/templates/traefik/dynamic_landing_page.yaml.gotmpl b/templates/traefik/dynamic_landing_page.yaml.gotmpl new file mode 100644 index 0000000..64b09b6 --- /dev/null +++ b/templates/traefik/dynamic_landing_page.yaml.gotmpl @@ -0,0 +1,15 @@ +--- +http: + routers: + landing-page: + entryPoints: + - "https" + rule: "Host(`{{ .RootDomain }}`)" + service: landing-page + tls: + certResolver: resolver + services: + landing-page: + loadBalancer: + servers: + - url: "http://{{ .Landing.ContainerIpv4Address }}:{{ .Landing.Port }}" diff --git a/templates/traefik/dynamic_root_domain_redirect.yaml.gotmpl b/templates/traefik/dynamic_root_domain_redirect.yaml.gotmpl deleted file mode 100644 index b82b1ea..0000000 --- a/templates/traefik/dynamic_root_domain_redirect.yaml.gotmpl +++ /dev/null @@ -1,18 +0,0 @@ ---- -http: - routers: - root-domain: - entryPoints: - - "https" - rule: "Host(`{{ .RootDomain }}`)" - middlewares: - - "redirect-root-to-freeflow" - service: noop@internal - tls: - certResolver: resolver - middlewares: - redirect-root-to-freeflow: - redirectRegex: - regex: "^(.*)" - replacement: "https://{{ .GoToSocial.Subdomain }}.{{ .RootDomain }}/@{{ .GoToSocial.LandingPageUser }}" - permanent: true