mirror of
https://github.com/zix99/traefik-lazyload.git
synced 2025-12-21 11:35:00 +01:00
Fix and release a docker build
This commit is contained in:
16
Dockerfile
16
Dockerfile
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
14
assets.go
14
assets.go
@@ -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")),
|
||||
}
|
||||
}
|
||||
|
||||
6
main.go
6
main.go
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user