Makefile, Dockerfile & docker-compose.yml
Build, containerize, and run the full stack.
Makefile
.PHONY: build run test lint clean
APP_NAME := bookmarks
BUILD_DIR := ./bin
build:
go build -o $(BUILD_DIR)/$(APP_NAME) .
run: build
export $$(cat .env | xargs) && $(BUILD_DIR)/$(APP_NAME)
test:
go test -v -race ./...
lint:
go vet ./...
clean:
rm -rf $(BUILD_DIR)Dockerfile
FROM golang:1.24-alpine AS builder
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 go build -o /bin/bookmarks .
FROM alpine:3.21
COPY --from=builder /bin/bookmarks /bookmarks
COPY templates/ /templates/
COPY static/ /static/
EXPOSE 8080
ENTRYPOINT ["/bookmarks"]docker-compose.yml
services:
db:
image: postgres:17-alpine
environment:
POSTGRES_DB: bookmarks
POSTGRES_USER: bookmarks
POSTGRES_PASSWORD: localdev
ports:
- "5432:5432"
volumes:
- pgdata:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U bookmarks"]
interval: 5s
timeout: 3s
retries: 5
api:
build: .
ports:
- "8080:8080"
environment:
PORT: "8080"
DATABASE_URL: "postgres://bookmarks:localdev@db:5432/bookmarks?sslmode=disable"
depends_on:
db:
condition: service_healthy
volumes:
pgdata:.env (for local development without Docker)
PORT=8080
DATABASE_URL=postgres://bookmarks:localdev@localhost:5432/bookmarks?sslmode=disable
LOG_LEVEL=debug