diff --git a/backend/Dockerfile b/backend/Dockerfile index e69de29..53a13bf 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -0,0 +1,34 @@ +# Stage 1: Builder +FROM golang:1.25-alpine AS builder + +WORKDIR /app + +# Install git and build dependencies +RUN apk add --no-cache git + +# Copy go mod files +COPY go.mod go.sum ./ +RUN go mod download + +# Copy source code +COPY . . + +# Build the application +RUN CGO_ENABLED=0 GOOS=linux go build -o api ./cmd/api + +# Stage 2: Production +FROM alpine:latest AS production + +RUN apk --no-cache add ca-certificates + +WORKDIR /app + +# Copy binary from builder +COPY --from=builder /app/api . + +# Copy migrations +COPY internal/db/migrations ./migrations + +EXPOSE 8080 + +CMD ["./api"] diff --git a/docker-compose.yml b/docker-compose.yml index 53a30f4..289afc6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,36 @@ services: + # PostgreSQL database + postgres: + image: postgres:16-alpine + environment: + POSTGRES_USER: egor + POSTGRES_PASSWORD: barsik + POSTGRES_DB: delivery_tracker + volumes: + - postgres_data:/var/lib/postgresql/data + ports: + - "5432:5432" + healthcheck: + test: ["CMD-SHELL", "pg_isready -U egor -d delivery_tracker"] + interval: 5s + timeout: 5s + retries: 5 + + # Backend API + backend: + build: + context: ./backend + dockerfile: Dockerfile + target: production + environment: + DATABASE_URL: postgres://egor:barsik@postgres:5432/delivery_tracker?sslmode=disable + ports: + - "8081:8080" + depends_on: + postgres: + condition: service_healthy + restart: unless-stopped + # Development service with hot reload frontend-dev: image: node:20-alpine @@ -22,7 +54,10 @@ services: target: production ports: - "8080:80" + depends_on: + - backend restart: unless-stopped volumes: node_modules: + postgres_data: