mirror of
https://github.com/Xevion/Pac-Man.git
synced 2025-12-14 08:12:20 -06:00
refactor(docker): move frontend build into multi-stage Docker build
- Remove frontend build steps from GitHub Actions workflow - Add frontend-builder stage using oven/bun:1 in Dockerfile - Build frontend inside Docker for better consistency and portability - Copy built frontend from frontend-builder stage to runtime image - Simplify CI/CD pipeline by consolidating build steps
This commit is contained in:
25
.github/workflows/deploy.yaml
vendored
25
.github/workflows/deploy.yaml
vendored
@@ -81,31 +81,8 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# ========== Frontend Build ==========
|
|
||||||
- name: Install web dependencies
|
|
||||||
shell: bash
|
|
||||||
run: bun install
|
|
||||||
working-directory: web
|
|
||||||
|
|
||||||
- name: Build web frontend
|
|
||||||
shell: bash
|
|
||||||
run: bun run build
|
|
||||||
working-directory: web
|
|
||||||
env:
|
|
||||||
# API URL is relative (/api) since frontend and backend are on same domain
|
|
||||||
VITE_API_URL: /api
|
|
||||||
|
|
||||||
- name: Verify frontend build output
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
if [ ! -d "web/dist/client" ]; then
|
|
||||||
echo "::error::Frontend build output not found at web/dist/client"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
echo "Frontend build successful, files ready for Docker image"
|
|
||||||
ls -la web/dist/client
|
|
||||||
|
|
||||||
# ========== Docker Build and Push ==========
|
# ========== Docker Build and Push ==========
|
||||||
|
# Note: Frontend is now built inside Docker using multi-stage build
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,21 @@ FROM chef AS planner
|
|||||||
COPY . .
|
COPY . .
|
||||||
RUN cargo chef prepare --bin pacman-server --recipe-path recipe.json
|
RUN cargo chef prepare --bin pacman-server --recipe-path recipe.json
|
||||||
|
|
||||||
# -- Builder stage --
|
# -- Frontend builder stage --
|
||||||
|
FROM oven/bun:1 AS frontend-builder
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy frontend package files first for layer caching
|
||||||
|
COPY web/package.json web/bun.lock* ./
|
||||||
|
RUN bun install --frozen-lockfile
|
||||||
|
|
||||||
|
# Copy all frontend source including public directory (contains WASM files)
|
||||||
|
COPY web/ ./
|
||||||
|
|
||||||
|
# Build the frontend (Vite will copy public/ contents to dist/client/)
|
||||||
|
RUN bun run build
|
||||||
|
|
||||||
|
# -- Backend builder stage --
|
||||||
FROM chef AS builder
|
FROM chef AS builder
|
||||||
COPY --from=planner /app/recipe.json recipe.json
|
COPY --from=planner /app/recipe.json recipe.json
|
||||||
RUN cargo chef cook --release --bin pacman-server --recipe-path recipe.json
|
RUN cargo chef cook --release --bin pacman-server --recipe-path recipe.json
|
||||||
@@ -26,9 +40,8 @@ FROM debian:bookworm-slim AS runtime
|
|||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY --from=builder /app/target/release/pacman-server /usr/local/bin/pacman-server
|
COPY --from=builder /app/target/release/pacman-server /usr/local/bin/pacman-server
|
||||||
|
|
||||||
# Copy frontend static files (built by GitHub Actions)
|
# Copy frontend static files from frontend-builder stage
|
||||||
# These files should be in web/dist/client/ in the build context
|
COPY --from=frontend-builder /app/dist/client /app/static
|
||||||
COPY web/dist/client /app/static
|
|
||||||
|
|
||||||
# Install runtime dependencies
|
# Install runtime dependencies
|
||||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
|
|||||||
Reference in New Issue
Block a user