feat: add the landing page to Flow Platform

Welcome :)
This commit is contained in:
Dan Anglin 2023-08-24 15:30:14 +01:00
parent 5a757d2ed5
commit 4eba300480
Signed by: dananglin
GPG key ID: 0C1D44CFBEE68638
8 changed files with 70 additions and 23 deletions

2
config

@ -1 +1 @@
Subproject commit d17177a0636e3e1b89cb2e3891aed2d6e5a1ed12 Subproject commit 46b27c4c2bda5d2109a4dbe9b84bb6efe881da7d

View file

@ -17,6 +17,7 @@ type config struct {
Forgejo forgejoConfig `json:"forgejo"` Forgejo forgejoConfig `json:"forgejo"`
GoToSocial gotosocialConfig `json:"gotosocial"` GoToSocial gotosocialConfig `json:"gotosocial"`
Woodpecker woodpeckerConfig `json:"woodpecker"` Woodpecker woodpeckerConfig `json:"woodpecker"`
Landing landingConfig `json:"landing"`
} }
type traefikConfig struct { type traefikConfig struct {
@ -95,6 +96,21 @@ type woodpeckerConfig struct {
ForgejoClientSecret string `json:"forgejoClientSecret"` 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) { func newConfig(path string) (config, error) {
var c config var c config

View file

@ -34,7 +34,7 @@ func Download(name string) error {
return fmt.Errorf("an error occurred whilst getting the packages for Woodpecker; %w", err) return fmt.Errorf("an error occurred whilst getting the packages for Woodpecker; %w", err)
} }
default: 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 return nil

View file

@ -95,6 +95,16 @@ func render(cfg config, component string) error {
templateDirName := filepath.Join(rootTemplatesDir, component) 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) files, err := os.ReadDir(templateDirName)
if err != nil { if err != nil {
return fmt.Errorf("unable to read files from %s; %w ", templateDirName, err) return fmt.Errorf("unable to read files from %s; %w ", templateDirName, err)
@ -140,10 +150,14 @@ func render(cfg config, component string) error {
func copyAssets(service string) error { func copyAssets(service string) error {
assetsDirName := filepath.Join(rootAssetsDir, service) assetsDirName := filepath.Join(rootAssetsDir, service)
if _, err := os.Stat(assetsDirName); err != nil { if _, err := os.Stat(assetsDirName); err != nil {
log.Printf("There's no assets directory for %s.\n", service) if os.IsNotExist(err) {
fmt.Printf("There's no assets directory for %q.\n", service)
return nil return nil
} }
return err
}
buildDirName := filepath.Join(rootBuildDir, service, "assets") buildDirName := filepath.Join(rootBuildDir, service, "assets")
walkDirFunc := func(path string, d fs.DirEntry, err error) error { walkDirFunc := func(path string, d fs.DirEntry, err error) error {

View file

@ -143,3 +143,23 @@ services:
- type: "bind" - type: "bind"
source: "{{ .Woodpecker.DataHostDirectory }}" source: "{{ .Woodpecker.DataHostDirectory }}"
target: "{{ .Woodpecker.DataContainerDirectory }}" 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" }}

View file

@ -2,7 +2,7 @@ FROM traefik:{{ .Traefik.Version }}
ADD traefik.yaml /flow/traefik/ 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 / ADD entrypoint.sh /

View file

@ -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 }}"

View file

@ -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