Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.dockerignore
.git
.idea
.vscode
*.md
*.test
bin/
dist/
vendor/
.DS_Store
Ticket_Allocation.postman_collection.json
database_structure.sql
34 changes: 34 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# syntax=docker/dockerfile:1

FROM golang:1.25-alpine AS builder

WORKDIR /src

RUN apk add --no-cache git ca-certificates

COPY go.mod go.sum ./
RUN go mod download

COPY . .

RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="-s -w" -o /out/server ./cmd/server

FROM alpine:3.21

RUN apk add --no-cache ca-certificates wget \
&& adduser -D -H -u 10001 appuser

WORKDIR /app

COPY --from=builder /out/server /app/server

USER appuser

EXPOSE 3000

ENV PORT=3000

HEALTHCHECK --interval=5s --timeout=3s --start-period=5s --retries=10 \
CMD wget -qO- http://127.0.0.1:3000/_health >/dev/null || exit 1

ENTRYPOINT ["/app/server"]
32 changes: 32 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
.PHONY: generate local run test test-integration bench-purchase docker-up docker-down

DATABASE_URL ?= postgres://ticket:ticket@localhost:5432/ticket_allocation?sslmode=disable
PORT ?= 3000

generate:
go generate ./internal/api/v1/...

# Build and run the full stack (Postgres + API) on the docker network.
local:
docker compose up --build -d --wait
@echo "API listening on http://localhost:3000"
@echo "Health: curl -s http://localhost:3000/_health"

docker-up:
docker compose up -d --wait postgres

docker-down:
docker compose down -v

# Run the API on the host against compose Postgres.
run: docker-up
DATABASE_URL="$(DATABASE_URL)" PORT="$(PORT)" go run ./cmd/server

test:
go test ./... -race -count=1

test-integration: docker-up
TEST_DATABASE_URL="$(DATABASE_URL)" go test ./internal/store/postgres/... -tags=integration -race -count=1 -timeout=120s

bench-purchase: docker-up
TEST_DATABASE_URL="$(DATABASE_URL)" go test ./internal/store/postgres/... -tags=integration -run=^$$ -bench=BenchmarkCreatePurchaseContention -benchmem -count=3 -timeout=180s
Loading