feat(devops): improve Docker build caching and add dev workflow targets

- Optimize Dockerfile layer caching with --mount=type=cache for Go modules and npm
- Reorganize Dockerfile layers for better cache hit rates
- Improve .dockerignore organization with categorized comments
- Add Makefile targets: up, down, rebuild-app, restart, ps
- Enhance Makefile help output with categorized sections
This commit is contained in:
2026-02-22 18:40:16 -05:00
parent 48937e9777
commit 55440e0dc8
3 changed files with 82 additions and 30 deletions
+20 -21
View File
@@ -3,40 +3,39 @@ FROM golang:1.25-alpine AS builder
WORKDIR /app
# Install Node.js, npm, and curl for Tailwind CSS building
RUN apk add --no-cache nodejs npm curl
# Install system tools (cached well)
RUN apk add --no-cache nodejs npm curl git
# Install sqlc
RUN go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest
# Install Go tools (cached well)
RUN --mount=type=cache,target=/root/go/pkg/mod \
go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest && \
go install github.com/a-h/templ/cmd/templ@latest
# Install templ
RUN go install github.com/a-h/templ/cmd/templ@latest
# Copy package files and install npm dependencies
# Copy package files and install npm dependencies (cached unless package.json changes)
COPY package*.json ./
RUN npm install
RUN --mount=type=cache,target=/root/.npm \
npm ci
# Copy source code
# Copy Go mod files (cached unless go.mod changes)
COPY go.mod go.sum ./
RUN --mount=type=cache,target=/root/go/pkg/mod \
go mod download
# Copy source code (this layer changes frequently)
COPY . .
# Download dependencies
RUN go mod tidy
# Generate sqlc code
# Generate code (only these rebuild on source changes)
RUN cd internal/database && sqlc generate
# Generate templ code
RUN cd templates && templ generate
# Build Tailwind CSS and download htmx
# Build frontend assets (only these rebuild on web/ changes)
RUN npm run build:css:prod
RUN npm run postinstall
# Build TypeScript to JavaScript
RUN npm run build:ts
# Build the application
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main ./cmd/server
# Build Go binary (cached unless Go files or generated code changes)
RUN --mount=type=cache,target=/root/go/pkg/mod \
CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main ./cmd/server
# Test runner stage - includes Go runtime and test dependencies
# This stage is ONLY used for running tests, never deployed to production