add dockerfile for backend && update docker-compose.yml
This commit is contained in:
@@ -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"]
|
||||||
|
|||||||
@@ -1,4 +1,36 @@
|
|||||||
services:
|
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
|
# Development service with hot reload
|
||||||
frontend-dev:
|
frontend-dev:
|
||||||
image: node:20-alpine
|
image: node:20-alpine
|
||||||
@@ -22,7 +54,10 @@ services:
|
|||||||
target: production
|
target: production
|
||||||
ports:
|
ports:
|
||||||
- "8080:80"
|
- "8080:80"
|
||||||
|
depends_on:
|
||||||
|
- backend
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
node_modules:
|
node_modules:
|
||||||
|
postgres_data:
|
||||||
|
|||||||
Reference in New Issue
Block a user