fix(dockerfile): add templ

This commit is contained in:
maotovisk 2025-08-09 02:35:09 -03:00
parent 84bd8355d6
commit ba21c71835

View file

@ -1,30 +1,64 @@
# syntax=docker/dockerfile:1
############################
# Build stage
############################
FROM golang:1.24-alpine AS builder FROM golang:1.24-alpine AS builder
RUN apk add --no-cache git build-base sqlite-dev # You can still override these if you want
ARG TAILWIND_VERSION=v4.1.11
# deps for CGO + curl
RUN apk add --no-cache git build-base sqlite-dev curl
WORKDIR /app WORKDIR /app
# Cache go deps
COPY go.mod go.sum ./ COPY go.mod go.sum ./
RUN go mod download RUN go mod download
# ---- templ CLI: install the SAME version as in go.mod ----
# Read the templ module version from go.mod, then install matching CLI
RUN set -eux; \
TEMPL_VER="$(go list -m -f '{{.Version}}' github.com/a-h/templ)"; \
echo "Installing templ CLI @$TEMPL_VER"; \
go install "github.com/a-h/templ/cmd/templ@${TEMPL_VER}"
# ---- Tailwind v4 standalone ----
RUN curl -fsSL -o /usr/local/bin/tailwindcss \
"https://github.com/tailwindlabs/tailwindcss/releases/download/${TAILWIND_VERSION}/tailwindcss-linux-x64-musl" \
&& chmod +x /usr/local/bin/tailwindcss
# App source
COPY . . COPY . .
RUN go build -o maot-shortner ./cmd/maot-shortner # 1) Generate templ -> .go (now CLI matches module, so parsing works)
RUN templ generate
FROM alpine:latest # 2) Build Tailwind (v4) no --clean in v4
RUN mkdir -p ./web/static/css
RUN tailwindcss -i ./web/resources/css/input.css -o ./web/static/css/output.css --minify
# 3) Build Go binary (CGO for SQLite)
ENV CGO_ENABLED=1
RUN go build -ldflags="-s -w" -o /app/maot-shortner ./cmd/maot-shortner
############################
# Runtime stage
############################
FROM alpine:3.20
RUN apk add --no-cache ca-certificates sqlite-libs RUN apk add --no-cache ca-certificates sqlite-libs
WORKDIR /app WORKDIR /app
COPY --from=builder /app/maot-shortner . COPY --from=builder /app/maot-shortner .
COPY --from=builder /app/web/static ./web/static COPY --from=builder /app/web/static ./web/static
RUN mkdir -p /app/data RUN mkdir -p /app/data
EXPOSE 3032 EXPOSE 3032
ENV DATABASE_PATH=/app/data/shortener.db ENV DATABASE_PATH=/app/data/shortener.db
VOLUME ["/app/data"] VOLUME ["/app/data"]
CMD ["./maot-shortner"] CMD ["./maot-shortner"]