Fix and release a docker build

This commit is contained in:
Christopher LaPointe
2023-06-03 21:38:44 -04:00
parent 6c8e52d24e
commit 895f7ff440
4 changed files with 29 additions and 10 deletions

View File

@@ -1,11 +1,19 @@
FROM golang:1.18
# BUILD
FROM golang:1.18-alpine3.17 AS build
EXPOSE 8080
WORKDIR /opt/app
COPY go.* .
WORKDIR /opt/src
COPY go.* ./
RUN go mod download
COPY . .
RUN go build .
# Make the final image
FROM alpine:latest
EXPOSE 8080
WORKDIR /opt/app
COPY --from=build /opt/src/traefik-lazyload .
COPY config.yaml .
CMD ./traefik-lazyload

View File

@@ -40,7 +40,8 @@ services:
# Lazy-loader manager
lazyloader:
build: .
#build: . # Uncomment to build from source
image: ghcr.io/zix99/traefik-lazyload:1
labels:
- traefik.enable=true
- "traefik.http.routers.lazyload.priority=-100" # Lower router priority. Would only be hit if the app isn't running

View File

@@ -19,8 +19,6 @@ type SplashModel struct {
Hostname string
}
var splashTemplate = template.Must(template.ParseFS(httpAssets, path.Join("assets", config.Model.Splash)))
type StatusPageModel struct {
Active []*service.ContainerState
Qualifying []containers.Wrapper
@@ -28,4 +26,14 @@ type StatusPageModel struct {
RuntimeMetrics string
}
var statusPageTemplate = template.Must(template.ParseFS(httpAssets, "assets/status.html"))
type assetTemplates struct {
splash *template.Template
status *template.Template
}
func LoadTemplates() *assetTemplates {
return &assetTemplates{
splash: template.Must(template.ParseFS(httpAssets, path.Join("assets", config.Model.Splash))),
status: template.Must(template.ParseFS(httpAssets, "assets/status.html")),
}
}

View File

@@ -19,6 +19,7 @@ import (
)
type controller struct {
assets assetTemplates
core *service.Core
discovery *containers.Discovery
}
@@ -55,6 +56,7 @@ func main() {
}
controller := controller{
*LoadTemplates(),
core,
discovery,
}
@@ -110,7 +112,7 @@ func (s *controller) ContainerHandler(w http.ResponseWriter, r *http.Request) {
}
} else {
w.WriteHeader(http.StatusAccepted)
renderErr := splashTemplate.Execute(w, SplashModel{
renderErr := s.assets.splash.Execute(w, SplashModel{
Hostname: host,
ContainerState: sOpts,
})
@@ -129,7 +131,7 @@ func (s *controller) StatusHandler(w http.ResponseWriter, r *http.Request) {
qualifying, _ := s.discovery.QualifyingContainers(r.Context())
providers, _ := s.discovery.ProviderContainers(r.Context())
statusPageTemplate.Execute(w, StatusPageModel{
s.assets.status.Execute(w, StatusPageModel{
Active: s.core.ActiveContainers(),
Qualifying: qualifying,
Providers: providers,