The application can now be built, tailwind is built, AND templ components are generated! Which means, we can no longer push the tailwind generated CSS file OR the templ generated go files! Plus, this is the first step towards deployment and CI/CD!
55 lines
959 B
Docker
55 lines
959 B
Docker
# Fetch stage
|
|
FROM golang:latest AS fetch-stage
|
|
|
|
COPY go.mod go.sum /app
|
|
|
|
WORKDIR /app
|
|
|
|
RUN go mod download
|
|
|
|
|
|
# Generate stage
|
|
FROM ghcr.io/a-h/templ:latest AS generate-stage
|
|
|
|
COPY --chown=65532:65532 . /app
|
|
|
|
WORKDIR /app
|
|
|
|
RUN ["templ", "generate"]
|
|
|
|
# Generate stage two
|
|
|
|
FROM node:lts-alpine AS tailwind-build-stage
|
|
|
|
COPY --from=generate-stage /app /app
|
|
|
|
WORKDIR /app
|
|
|
|
RUN npm install tailwindcss @tailwindcss/cli && npx @tailwindcss/cli -i ./web/static/css/main.css -o ./web/static/css/tailwind.css --minify -c ./tailwind.config.js
|
|
|
|
|
|
# Build stage
|
|
FROM golang:1.24 AS build-stage
|
|
|
|
COPY --from=tailwind-build-stage /app /app
|
|
|
|
WORKDIR /app
|
|
|
|
RUN CGO_ENABLED=0 GOOS=linux go build -o /entrypoint /app/cmd/web/main.go
|
|
|
|
# Deploy.
|
|
FROM gcr.io/distroless/static-debian11 AS release-stage
|
|
|
|
WORKDIR /
|
|
|
|
COPY --from=build-stage /entrypoint /entrypoint
|
|
|
|
COPY --from=build-stage /app/web/static /web/static
|
|
|
|
|
|
EXPOSE 3000
|
|
|
|
USER nonroot:nonroot
|
|
|
|
ENTRYPOINT ["/entrypoint"]
|