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/src
WORKDIR /opt/app COPY go.* ./
COPY go.* .
RUN go mod download RUN go mod download
COPY . . COPY . .
RUN go build . 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 CMD ./traefik-lazyload

View File

@@ -40,7 +40,8 @@ services:
# Lazy-loader manager # Lazy-loader manager
lazyloader: lazyloader:
build: . #build: . # Uncomment to build from source
image: ghcr.io/zix99/traefik-lazyload:1
labels: labels:
- traefik.enable=true - traefik.enable=true
- "traefik.http.routers.lazyload.priority=-100" # Lower router priority. Would only be hit if the app isn't running - "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 Hostname string
} }
var splashTemplate = template.Must(template.ParseFS(httpAssets, path.Join("assets", config.Model.Splash)))
type StatusPageModel struct { type StatusPageModel struct {
Active []*service.ContainerState Active []*service.ContainerState
Qualifying []containers.Wrapper Qualifying []containers.Wrapper
@@ -28,4 +26,14 @@ type StatusPageModel struct {
RuntimeMetrics string 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 { type controller struct {
assets assetTemplates
core *service.Core core *service.Core
discovery *containers.Discovery discovery *containers.Discovery
} }
@@ -55,6 +56,7 @@ func main() {
} }
controller := controller{ controller := controller{
*LoadTemplates(),
core, core,
discovery, discovery,
} }
@@ -110,7 +112,7 @@ func (s *controller) ContainerHandler(w http.ResponseWriter, r *http.Request) {
} }
} else { } else {
w.WriteHeader(http.StatusAccepted) w.WriteHeader(http.StatusAccepted)
renderErr := splashTemplate.Execute(w, SplashModel{ renderErr := s.assets.splash.Execute(w, SplashModel{
Hostname: host, Hostname: host,
ContainerState: sOpts, ContainerState: sOpts,
}) })
@@ -129,7 +131,7 @@ func (s *controller) StatusHandler(w http.ResponseWriter, r *http.Request) {
qualifying, _ := s.discovery.QualifyingContainers(r.Context()) qualifying, _ := s.discovery.QualifyingContainers(r.Context())
providers, _ := s.discovery.ProviderContainers(r.Context()) providers, _ := s.discovery.ProviderContainers(r.Context())
statusPageTemplate.Execute(w, StatusPageModel{ s.assets.status.Execute(w, StatusPageModel{
Active: s.core.ActiveContainers(), Active: s.core.ActiveContainers(),
Qualifying: qualifying, Qualifying: qualifying,
Providers: providers, Providers: providers,