feat: Implement initial full-stack application structure including frontend pages, components, hooks, API integration, and backend services for account pooling and management.
This commit is contained in:
109
Dockerfile
Normal file
109
Dockerfile
Normal file
@@ -0,0 +1,109 @@
|
||||
# =============================================================================
|
||||
# Codex Pool Multi-Stage Dockerfile
|
||||
# =============================================================================
|
||||
# Stage 1: Build frontend
|
||||
# Stage 2: Build Go backend with embedded frontend
|
||||
# Stage 3: Final minimal image with Chromium
|
||||
# =============================================================================
|
||||
|
||||
ARG NODE_IMAGE=node:20-alpine
|
||||
ARG GOLANG_IMAGE=golang:1.23-alpine
|
||||
ARG ALPINE_IMAGE=alpine:3.20
|
||||
ARG GOPROXY=https://goproxy.cn,direct
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Stage 1: Frontend Builder
|
||||
# -----------------------------------------------------------------------------
|
||||
FROM ${NODE_IMAGE} AS frontend-builder
|
||||
|
||||
WORKDIR /app/frontend
|
||||
|
||||
# Install dependencies first (better caching)
|
||||
COPY frontend/package*.json ./
|
||||
RUN npm ci
|
||||
|
||||
# Copy frontend source and build
|
||||
COPY frontend/ ./
|
||||
RUN npm run build
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Stage 2: Backend Builder
|
||||
# -----------------------------------------------------------------------------
|
||||
FROM ${GOLANG_IMAGE} AS backend-builder
|
||||
|
||||
ARG GOPROXY
|
||||
|
||||
ENV GOPROXY=${GOPROXY}
|
||||
|
||||
# Install build dependencies
|
||||
RUN apk add --no-cache git gcc musl-dev
|
||||
|
||||
WORKDIR /app/backend
|
||||
|
||||
# Copy go mod files first (better caching)
|
||||
COPY backend/go.mod backend/go.sum ./
|
||||
RUN go mod download
|
||||
|
||||
# Copy backend source
|
||||
COPY backend/ ./
|
||||
|
||||
# Copy frontend dist from previous stage
|
||||
COPY --from=frontend-builder /app/frontend/dist ./internal/web/dist
|
||||
|
||||
# Build the binary with embed tag
|
||||
RUN CGO_ENABLED=1 GOOS=linux go build \
|
||||
-tags embed \
|
||||
-ldflags="-s -w" \
|
||||
-o /app/codex-pool \
|
||||
./cmd/main.go
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Stage 3: Final Runtime Image with Chromium
|
||||
# -----------------------------------------------------------------------------
|
||||
FROM ${ALPINE_IMAGE}
|
||||
|
||||
# Labels
|
||||
LABEL maintainer="Codex Pool"
|
||||
LABEL description="Codex Pool - Team Account Management"
|
||||
|
||||
# Install runtime dependencies including Chromium
|
||||
RUN apk add --no-cache \
|
||||
chromium \
|
||||
chromium-chromedriver \
|
||||
ca-certificates \
|
||||
tzdata \
|
||||
curl \
|
||||
&& rm -rf /var/cache/apk/*
|
||||
|
||||
# Chromedp configuration
|
||||
ENV CHROME_BIN=/usr/bin/chromium-browser
|
||||
ENV CHROME_PATH=/usr/bin/chromium-browser
|
||||
|
||||
# Create non-root user
|
||||
RUN addgroup -g 1000 codexpool && \
|
||||
adduser -u 1000 -G codexpool -s /bin/sh -D codexpool
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /app
|
||||
|
||||
# Copy binary from builder
|
||||
COPY --from=backend-builder /app/codex-pool /app/codex-pool
|
||||
|
||||
# Create data directory
|
||||
RUN mkdir -p /app/data && chown -R codexpool:codexpool /app
|
||||
|
||||
# Default config path
|
||||
ENV CONFIG_PATH=/app/data/config.yaml
|
||||
|
||||
# Switch to non-root user
|
||||
USER codexpool
|
||||
|
||||
# Expose port
|
||||
EXPOSE 8848
|
||||
|
||||
# Health check
|
||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \
|
||||
CMD curl -f http://localhost:8848/api/health || exit 1
|
||||
|
||||
# Run the application
|
||||
ENTRYPOINT ["/app/codex-pool"]
|
||||
Reference in New Issue
Block a user