feat: dockerization
This commit is contained in:
+54
@@ -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"]
|
||||||
@@ -2,13 +2,14 @@ package pages
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/internal/components/page"
|
"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"
|
"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/web/components"
|
||||||
)
|
)
|
||||||
|
|
||||||
templ Home(pages []page.PageHeader) {
|
templ Home(pages []page.PageHeader) {
|
||||||
for _, page := range pages {
|
for _, page := range pages {
|
||||||
@components.ImageTile("/images/" + page.CoverImageUID) {
|
@components.ImageTile("/images/" + page.CoverImageUID) {
|
||||||
<a class="flex items-center justify-center h-full " href={ "/" + page.UID } preload="mouseover">
|
<a class="flex items-center justify-center h-full " href={ translate.Path(ctx, page.UID) } preload="mouseover">
|
||||||
<h2
|
<h2
|
||||||
class="text-3xl font-bold text-white hover:underline text-shadow-lg"
|
class="text-3xl font-bold text-white hover:underline text-shadow-lg"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import templruntime "github.com/a-h/templ/runtime"
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/internal/components/page"
|
"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"
|
"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/web/components"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -52,9 +53,9 @@ func Home(pages []page.PageHeader) templ.Component {
|
|||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
var templ_7745c5c3_Var3 templ.SafeURL
|
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 {
|
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))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
@@ -67,7 +68,7 @@ func Home(pages []page.PageHeader) templ.Component {
|
|||||||
var templ_7745c5c3_Var4 string
|
var templ_7745c5c3_Var4 string
|
||||||
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(page.Title)
|
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(page.Title)
|
||||||
if templ_7745c5c3_Err != nil {
|
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))
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user