From 7b600249352b39848bc7ac20e3bb0541e15bb123 Mon Sep 17 00:00:00 2001 From: schreifuchs Date: Mon, 2 Mar 2026 22:33:22 +0100 Subject: [PATCH] feat: dockerization --- Dockerfile | 54 ++++++++++++++++++++++++++++++++++++++++ web/pages/index.templ | 3 ++- web/pages/index_templ.go | 7 +++--- 3 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b2e91bc --- /dev/null +++ b/Dockerfile @@ -0,0 +1,54 @@ +# Stage 1: Build frontend assets +FROM node:24-alpine AS frontend-builder +WORKDIR /app + +# Enable pnpm via corepack +RUN corepack enable pnpm + +# Install dependencies +COPY package.json pnpm-lock.yaml ./ +RUN pnpm install --frozen-lockfile + +# Copy source and build assets +COPY . . +RUN pnpm run build:css && pnpm run build:js + +# Stage 2: Build Go binary +FROM golang:1.26-alpine AS go-builder +WORKDIR /app + +# Install git for potential private modules (though not strictly needed here) +RUN apk add --no-cache git + +# Download Go modules +COPY go.mod go.sum ./ +RUN go mod download + +# Copy source code +COPY . . + +# Copy built frontend assets from the previous stage +COPY --from=frontend-builder /app/web/static/css/output.css ./web/static/css/ +COPY --from=frontend-builder /app/web/static/js/htmx.min.js ./web/static/js/ + +# Generate templ files using the tool defined in go.mod +RUN go tool templ generate + +# Build the optimized binary +RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o /app/server ./cmd/schreifuchs-ch + +# Stage 3: Final minimal image +FROM alpine:latest +WORKDIR /app + +# Install root certificates and timezone data +RUN apk --no-cache add ca-certificates tzdata + +# Copy the compiled binary from the builder stage +COPY --from=go-builder /app/server . + +# Expose the application port +EXPOSE 8080 + +# Set the entrypoint +ENTRYPOINT ["/app/server"] diff --git a/web/pages/index.templ b/web/pages/index.templ index 50ec709..734bb0d 100644 --- a/web/pages/index.templ +++ b/web/pages/index.templ @@ -2,13 +2,14 @@ package pages import ( "git.schreifuchs.ch/schreifuchs/schreifuchs.ch/internal/components/page" + "git.schreifuchs.ch/schreifuchs/schreifuchs.ch/internal/components/translate" "git.schreifuchs.ch/schreifuchs/schreifuchs.ch/web/components" ) templ Home(pages []page.PageHeader) { for _, page := range pages { @components.ImageTile("/images/" + page.CoverImageUID) { - +

diff --git a/web/pages/index_templ.go b/web/pages/index_templ.go index 36b6e1d..67c630a 100644 --- a/web/pages/index_templ.go +++ b/web/pages/index_templ.go @@ -10,6 +10,7 @@ import templruntime "github.com/a-h/templ/runtime" import ( "git.schreifuchs.ch/schreifuchs/schreifuchs.ch/internal/components/page" + "git.schreifuchs.ch/schreifuchs/schreifuchs.ch/internal/components/translate" "git.schreifuchs.ch/schreifuchs/schreifuchs.ch/web/components" ) @@ -52,9 +53,9 @@ func Home(pages []page.PageHeader) templ.Component { return templ_7745c5c3_Err } var templ_7745c5c3_Var3 templ.SafeURL - templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinURLErrs("/" + page.UID) + templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinURLErrs(translate.Path(ctx, page.UID)) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `pages/index.templ`, Line: 11, Col: 76} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `pages/index.templ`, Line: 12, Col: 91} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3)) if templ_7745c5c3_Err != nil { @@ -67,7 +68,7 @@ func Home(pages []page.PageHeader) templ.Component { var templ_7745c5c3_Var4 string templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(page.Title) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `pages/index.templ`, Line: 15, Col: 17} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `pages/index.templ`, Line: 16, Col: 17} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4)) if templ_7745c5c3_Err != nil {