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:
+16
-1
@@ -1,10 +1,25 @@
|
|||||||
|
# Git
|
||||||
.git
|
.git
|
||||||
.gitignore
|
.gitignore
|
||||||
|
|
||||||
|
# Documentation
|
||||||
README.md
|
README.md
|
||||||
*.md
|
*.md
|
||||||
.env
|
.env.example
|
||||||
|
.editorconfig
|
||||||
|
|
||||||
|
# IDE
|
||||||
.DS_Store
|
.DS_Store
|
||||||
.vscode
|
.vscode
|
||||||
.idea
|
.idea
|
||||||
|
|
||||||
|
# Build artifacts (don't copy into container)
|
||||||
tmp/
|
tmp/
|
||||||
logs/
|
logs/
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# Dependencies (install fresh in container)
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# Environment
|
||||||
|
.env
|
||||||
+20
-21
@@ -3,40 +3,39 @@ FROM golang:1.25-alpine AS builder
|
|||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Install Node.js, npm, and curl for Tailwind CSS building
|
# Install system tools (cached well)
|
||||||
RUN apk add --no-cache nodejs npm curl
|
RUN apk add --no-cache nodejs npm curl git
|
||||||
|
|
||||||
# Install sqlc
|
# Install Go tools (cached well)
|
||||||
RUN go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest
|
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
|
# Copy package files and install npm dependencies (cached unless package.json changes)
|
||||||
RUN go install github.com/a-h/templ/cmd/templ@latest
|
|
||||||
|
|
||||||
# Copy package files and install npm dependencies
|
|
||||||
COPY package*.json ./
|
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 . .
|
COPY . .
|
||||||
|
|
||||||
# Download dependencies
|
# Generate code (only these rebuild on source changes)
|
||||||
RUN go mod tidy
|
|
||||||
|
|
||||||
# Generate sqlc code
|
|
||||||
RUN cd internal/database && sqlc generate
|
RUN cd internal/database && sqlc generate
|
||||||
|
|
||||||
# Generate templ code
|
|
||||||
RUN cd templates && templ generate
|
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 build:css:prod
|
||||||
RUN npm run postinstall
|
RUN npm run postinstall
|
||||||
|
|
||||||
# Build TypeScript to JavaScript
|
|
||||||
RUN npm run build:ts
|
RUN npm run build:ts
|
||||||
|
|
||||||
# Build the application
|
# Build Go binary (cached unless Go files or generated code changes)
|
||||||
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main ./cmd/server
|
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
|
# Test runner stage - includes Go runtime and test dependencies
|
||||||
# This stage is ONLY used for running tests, never deployed to production
|
# This stage is ONLY used for running tests, never deployed to production
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
.PHONY: help test test-integration test-all build build-force clean rebuild logs test-env-up test-env-down verify-guidelines verify-quick
|
.PHONY: help test test-integration test-all build build-force clean rebuild rebuild-app restart up down logs ps test-env-up test-env-down verify-guidelines verify-quick
|
||||||
|
|
||||||
# Include .env file for environment variables (single source of truth)
|
# Include .env file for environment variables (single source of truth)
|
||||||
# Ignore if .env doesn't exist yet
|
# Ignore if .env doesn't exist yet
|
||||||
@@ -10,16 +10,30 @@ endif
|
|||||||
# Default target
|
# Default target
|
||||||
help:
|
help:
|
||||||
@echo "Available targets:"
|
@echo "Available targets:"
|
||||||
|
@echo ""
|
||||||
|
@echo "Development:"
|
||||||
|
@echo " make up - Start containers (if already built)"
|
||||||
|
@echo " make build - Build and start all containers"
|
||||||
|
@echo " make rebuild-app - Rebuild app container only (fast, for development)"
|
||||||
|
@echo " make restart - Restart app container (preserves db)"
|
||||||
|
@echo " make down - Stop all containers"
|
||||||
|
@echo " make rebuild - Clean, rebuild, and start all containers"
|
||||||
|
@echo " make build-force - Force rebuild without cache (slow, use if needed)"
|
||||||
|
@echo ""
|
||||||
|
@echo "Status & Logs:"
|
||||||
|
@echo " make ps - Show container status"
|
||||||
|
@echo " make logs - Show container logs (follow mode)"
|
||||||
|
@echo ""
|
||||||
|
@echo "Testing:"
|
||||||
@echo " make test - Run unit tests (from host, fast)"
|
@echo " make test - Run unit tests (from host, fast)"
|
||||||
@echo " make test-integration - Run integration tests (in containers, matches prod)"
|
@echo " make test-integration - Run integration tests (in containers, matches prod)"
|
||||||
@echo " make test-all - Run all tests (unit + integration)"
|
@echo " make test-all - Run all tests (unit + integration)"
|
||||||
@echo " make build - Build and start containers"
|
|
||||||
@echo " make build-force - Force rebuild and start containers"
|
|
||||||
@echo " make clean - Stop and remove containers"
|
|
||||||
@echo " make rebuild - Clean, rebuild, and start containers"
|
|
||||||
@echo " make logs - Show container logs"
|
|
||||||
@echo " make test-env-up - Start containers with test mode enabled"
|
@echo " make test-env-up - Start containers with test mode enabled"
|
||||||
@echo " make test-env-down - Stop test environment"
|
@echo " make test-env-down - Stop test environment"
|
||||||
|
@echo ""
|
||||||
|
@echo "Verification:"
|
||||||
|
@echo " make verify-guidelines - Run comprehensive guidelines check"
|
||||||
|
@echo " make verify-quick - Run quick guidelines check"
|
||||||
|
|
||||||
# Run unit tests locally (fast, no containers)
|
# Run unit tests locally (fast, no containers)
|
||||||
test:
|
test:
|
||||||
@@ -56,7 +70,7 @@ test-all: test test-integration
|
|||||||
build:
|
build:
|
||||||
podman compose up --build -d
|
podman compose up --build -d
|
||||||
|
|
||||||
# Force rebuild without cache
|
# Force rebuild without cache (slow, use if needed)
|
||||||
build-force:
|
build-force:
|
||||||
podman compose build --no-cache
|
podman compose build --no-cache
|
||||||
podman compose up -d
|
podman compose up -d
|
||||||
@@ -68,6 +82,30 @@ clean:
|
|||||||
# Clean rebuild (remove volumes, rebuild, start)
|
# Clean rebuild (remove volumes, rebuild, start)
|
||||||
rebuild: clean build
|
rebuild: clean build
|
||||||
|
|
||||||
|
# Quick start (if already built)
|
||||||
|
up:
|
||||||
|
podman compose up -d
|
||||||
|
|
||||||
|
# Stop all containers (alias for clean)
|
||||||
|
down:
|
||||||
|
podman compose down
|
||||||
|
|
||||||
|
# Rebuild app container only (fast, for development)
|
||||||
|
rebuild-app:
|
||||||
|
@echo "Rebuilding app container only (database stays running)..."
|
||||||
|
podman compose up --build -d app
|
||||||
|
@echo "✓ App container rebuilt"
|
||||||
|
|
||||||
|
# Restart app container (preserves database)
|
||||||
|
restart:
|
||||||
|
@echo "Restarting app container (database stays running)..."
|
||||||
|
podman compose restart app
|
||||||
|
@echo "✓ App container restarted"
|
||||||
|
|
||||||
|
# Show container status
|
||||||
|
ps:
|
||||||
|
podman compose ps
|
||||||
|
|
||||||
# Show container logs
|
# Show container logs
|
||||||
logs:
|
logs:
|
||||||
podman compose logs -f
|
podman compose logs -f
|
||||||
|
|||||||
Reference in New Issue
Block a user