From ba21c71835fe7c7a27c743a07eef92ea06273f99 Mon Sep 17 00:00:00 2001 From: maotovisk Date: Sat, 9 Aug 2025 02:35:09 -0300 Subject: [PATCH] fix(dockerfile): add templ --- Dockerfile | 44 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 07e2f08..de39d77 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,30 +1,64 @@ +# syntax=docker/dockerfile:1 + +############################ +# Build stage +############################ 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 +# Cache go deps COPY go.mod go.sum ./ 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 . . -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 WORKDIR /app COPY --from=builder /app/maot-shortner . - COPY --from=builder /app/web/static ./web/static RUN mkdir -p /app/data EXPOSE 3032 ENV DATABASE_PATH=/app/data/shortener.db - VOLUME ["/app/data"] CMD ["./maot-shortner"]