Consolidate dockerfiles
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
.git
|
||||
**/node_modules
|
||||
**/.env
|
||||
**/.DS_Store
|
||||
frontend/dist
|
||||
backend/target
|
||||
@@ -6,6 +6,7 @@ on:
|
||||
|
||||
env:
|
||||
REGISTRY: gitea.coracle.social
|
||||
IMAGE: coracle/caravel
|
||||
|
||||
jobs:
|
||||
build-and-push-image:
|
||||
@@ -14,16 +15,6 @@ jobs:
|
||||
contents: read
|
||||
packages: write
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- component: frontend
|
||||
image: coracle/caravel-frontend
|
||||
context: frontend
|
||||
- component: backend
|
||||
image: coracle/caravel-backend
|
||||
context: backend
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
@@ -39,7 +30,7 @@ jobs:
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: ${{ env.REGISTRY }}/${{ matrix.image }}
|
||||
images: ${{ env.REGISTRY }}/${{ env.IMAGE }}
|
||||
tags: |
|
||||
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/master' }}
|
||||
|
||||
@@ -52,7 +43,7 @@ jobs:
|
||||
id: push
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: ${{ matrix.context }}
|
||||
context: .
|
||||
push: true
|
||||
platforms: linux/amd64,linux/arm64
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
# syntax=docker/dockerfile:1
|
||||
|
||||
# ---------- Build the Rust backend (compiled here, in the build stage) ----------
|
||||
FROM rust:1.94-bookworm AS backend-build
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends \
|
||||
pkg-config \
|
||||
libsqlite3-dev \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
COPY backend/Cargo.toml backend/Cargo.lock ./
|
||||
COPY backend/src ./src
|
||||
COPY backend/migrations ./migrations
|
||||
|
||||
RUN cargo build --release
|
||||
|
||||
# ---------- Runtime: prebuilt backend + frontend built at startup ----------
|
||||
# The frontend is built in this (run) stage, not at image-build time, so VITE_*
|
||||
# values provided when the container starts are inlined into the bundle.
|
||||
# node:20-slim is bookworm-based, so it is ABI-compatible with the backend binary.
|
||||
FROM node:20-slim
|
||||
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends \
|
||||
ca-certificates \
|
||||
libsqlite3-0 \
|
||||
&& rm -rf /var/lib/apt/lists/* \
|
||||
&& npm install -g bun serve
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Install frontend deps as a cached image layer. The actual `vite build` runs at
|
||||
# startup (see the entrypoint below) so it can pick up runtime env vars.
|
||||
COPY frontend/package.json frontend/bun.lock ./frontend/
|
||||
RUN cd frontend && bun install
|
||||
|
||||
COPY frontend ./frontend
|
||||
|
||||
# Prebuilt backend binary from the build stage.
|
||||
COPY --from=backend-build /app/target/release/backend /app/backend
|
||||
|
||||
# Single entrypoint: build the frontend with the runtime config, then run both
|
||||
# processes and exit (so the orchestrator restarts us) if either one dies.
|
||||
RUN cat > /app/entrypoint.sh <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
echo "Building frontend with runtime configuration..."
|
||||
(cd /app/frontend && bun run build)
|
||||
|
||||
echo "Starting backend (:2892) and frontend (:3000)..."
|
||||
/app/backend &
|
||||
backend_pid=$!
|
||||
serve -s /app/frontend/dist -l 3000 &
|
||||
serve_pid=$!
|
||||
|
||||
trap 'kill -TERM "$backend_pid" "$serve_pid" 2>/dev/null || true' TERM INT
|
||||
|
||||
# Exit as soon as either process exits.
|
||||
wait -n
|
||||
EOF
|
||||
RUN chmod +x /app/entrypoint.sh
|
||||
|
||||
EXPOSE 2892 3000
|
||||
|
||||
CMD ["/app/entrypoint.sh"]
|
||||
@@ -1,31 +0,0 @@
|
||||
FROM rust:1.85-bookworm AS build
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends \
|
||||
pkg-config \
|
||||
libsqlite3-dev \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
COPY Cargo.toml Cargo.lock ./
|
||||
COPY src ./src
|
||||
COPY migrations ./migrations
|
||||
|
||||
RUN cargo build --release
|
||||
|
||||
FROM debian:bookworm-slim
|
||||
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends \
|
||||
ca-certificates \
|
||||
libsqlite3-0 \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY --from=build /app/target/release/backend /app/backend
|
||||
|
||||
EXPOSE 2892
|
||||
|
||||
CMD ["/app/backend"]
|
||||
@@ -1,23 +0,0 @@
|
||||
FROM node:20-slim
|
||||
|
||||
RUN npm install -g bun
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY package.json bun.lock ./
|
||||
RUN bun install
|
||||
|
||||
COPY . .
|
||||
|
||||
ARG VITE_API_URL
|
||||
ARG VITE_RELAY_DOMAIN
|
||||
ARG VITE_PLATFORM_NAME
|
||||
ENV VITE_API_URL=$VITE_API_URL
|
||||
ENV VITE_RELAY_DOMAIN=$VITE_RELAY_DOMAIN
|
||||
ENV VITE_PLATFORM_NAME=$VITE_PLATFORM_NAME
|
||||
|
||||
RUN bun run build
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
CMD ["npx", "serve", "dist", "-s"]
|
||||
Reference in New Issue
Block a user