diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..08a392d --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +.git +.idea +debug +uploads +.env diff --git a/Dockerfile b/Dockerfile index e1790bd..90de275 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,6 +8,8 @@ RUN CGO_ENABLED=0 GOOS=linux go build -o server ./cmd/main.go FROM alpine:3.18 RUN apk add --no-cache ca-certificates tzdata WORKDIR /app -COPY --from=builder /app/server . +RUN mkdir -p /app/uploads/images +COPY --from=builder /app/server ./server EXPOSE 8080 +EXPOSE 50051 CMD ["./server"] diff --git a/debug/docker-compose.yml b/debug/docker-compose.yml new file mode 100644 index 0000000..5b1e042 --- /dev/null +++ b/debug/docker-compose.yml @@ -0,0 +1,33 @@ +services: + postgres: + image: postgres:16 + container_name: backend-postgres + restart: unless-stopped + ports: + - "${DB_PORT:-5432}:5432" + environment: + POSTGRES_DB: ${DB_NAME:-game_admin} + POSTGRES_USER: ${DB_USER:-game_admin_user} + POSTGRES_PASSWORD: ${DB_PASSWORD:-game_admin_password} + volumes: + - postgres_data:/var/lib/postgresql/data + healthcheck: + test: ["CMD-SHELL", "pg_isready -U ${DB_USER:-game_admin_user} -d ${DB_NAME:-game_admin}"] + interval: 10s + timeout: 5s + retries: 10 + start_period: 15s + + adminer: + image: adminer:4 + container_name: backend-adminer + restart: unless-stopped + depends_on: + - postgres + ports: + - "${ADMINER_PORT:-8081}:8080" + environment: + ADMINER_DEFAULT_SERVER: postgres + +volumes: + postgres_data: diff --git a/docker-compose.yml b/docker-compose.yml index 5b1e042..c759c51 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,33 +1,14 @@ services: - postgres: - image: postgres:16 - container_name: backend-postgres + app: + build: + context: . + dockerfile: Dockerfile + container_name: backend-app restart: unless-stopped + env_file: + - .env ports: - - "${DB_PORT:-5432}:5432" - environment: - POSTGRES_DB: ${DB_NAME:-game_admin} - POSTGRES_USER: ${DB_USER:-game_admin_user} - POSTGRES_PASSWORD: ${DB_PASSWORD:-game_admin_password} + - "${SERVER_PORT:-8080}:8080" + - "${GRPC_PORT:-50051}:50051" volumes: - - postgres_data:/var/lib/postgresql/data - healthcheck: - test: ["CMD-SHELL", "pg_isready -U ${DB_USER:-game_admin_user} -d ${DB_NAME:-game_admin}"] - interval: 10s - timeout: 5s - retries: 10 - start_period: 15s - - adminer: - image: adminer:4 - container_name: backend-adminer - restart: unless-stopped - depends_on: - - postgres - ports: - - "${ADMINER_PORT:-8081}:8080" - environment: - ADMINER_DEFAULT_SERVER: postgres - -volumes: - postgres_data: + - ./uploads:/app/${UPLOAD_DIR:-uploads}