chore: add Docker multi-stage build and Docker Compose stack

This commit is contained in:
2026-06-05 23:37:57 +07:00
parent e19fcd5417
commit 68e6c8c46e
2 changed files with 74 additions and 0 deletions
+33
View File
@@ -0,0 +1,33 @@
# Build stage
FROM rust:1.82-slim AS builder
RUN apt-get update && apt-get install -y \
pkg-config \
libssl-dev \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY Cargo.toml Cargo.lock ./
RUN mkdir src && echo 'fn main(){}' > src/main.rs
RUN cargo build --release
RUN rm src/main.rs
COPY src ./src
RUN touch src/main.rs && cargo build --release
# Runtime stage
FROM debian:bookworm-slim AS runtime
RUN apt-get update && apt-get install -y \
ca-certificates \
libssl3 \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY --from=builder /app/target/release/openai-proxy /usr/local/bin/openai-proxy
EXPOSE 8080
ENTRYPOINT ["openai-proxy"]
+41
View File
@@ -0,0 +1,41 @@
version: "3.9"
services:
postgres:
image: postgres:16-alpine
restart: unless-stopped
environment:
POSTGRES_USER: proxy
POSTGRES_PASSWORD: proxy
POSTGRES_DB: proxydb
volumes:
- postgres_data:/var/lib/postgresql/data
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
ports:
- "5432:5432"
healthcheck:
test: ["CMD-SHELL", "pg_isready -U proxy -d proxydb"]
interval: 5s
timeout: 5s
retries: 5
proxy:
build:
context: .
dockerfile: Dockerfile
restart: unless-stopped
depends_on:
postgres:
condition: service_healthy
environment:
DATABASE_URL: postgres://proxy:proxy@postgres:5432/proxydb
UPSTREAM_URL: ${UPSTREAM_URL:-https://api.openai.com}
UPSTREAM_API_KEY: ${UPSTREAM_API_KEY}
BIND_ADDR: 0.0.0.0
PORT: 8080
RUST_LOG: ${RUST_LOG:-info}
ports:
- "${PORT:-8080}:8080"
volumes:
postgres_data: