Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/workflows/docker-build-manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,12 @@ jobs:
file: ./backend/Dockerfile
push: true
outputs: type=registry,name=ghcr.io/${{ steps.repo.outputs.image_name }}-backend,push-by-digest=true
cache-from: type=gha,scope=backend-${{ matrix.arch }}
cache-to: type=gha,mode=max,scope=backend-${{ matrix.arch }}
cache-from: |
type=gha,scope=backend-${{ matrix.arch }}
type=registry,ref=ghcr.io/${{ steps.repo.outputs.image_name }}-backend:buildcache-${{ matrix.arch }}
cache-to: |
type=gha,mode=max,scope=backend-${{ matrix.arch }}
type=registry,ref=ghcr.io/${{ steps.repo.outputs.image_name }}-backend:buildcache-${{ matrix.arch }},mode=max
platforms: ${{ matrix.platform }}
provenance: false

Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/main-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,12 @@ jobs:
file: ./backend/Dockerfile
push: true
outputs: type=registry,name=ghcr.io/${{ steps.repo.outputs.image_name }}-backend,push-by-digest=true
cache-from: type=gha,scope=backend-${{ matrix.arch }}
cache-to: type=gha,mode=max,scope=backend-${{ matrix.arch }}
cache-from: |
type=gha,scope=backend-${{ matrix.arch }}
type=registry,ref=ghcr.io/${{ steps.repo.outputs.image_name }}-backend:buildcache-${{ matrix.arch }}
cache-to: |
type=gha,mode=max,scope=backend-${{ matrix.arch }}
type=registry,ref=ghcr.io/${{ steps.repo.outputs.image_name }}-backend:buildcache-${{ matrix.arch }},mode=max
platforms: ${{ matrix.platform }}
provenance: false

Expand Down
46 changes: 20 additions & 26 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,43 +1,37 @@
# Multi-stage build for FinanceVault Backend (with embedded frontend proxy)

###################
# Backend Build Stage
# Chef Stage - Prepare Recipe
###################
FROM rust:latest AS backend-builder

FROM rust:latest AS chef
RUN cargo install cargo-chef
WORKDIR /usr/src/app

###################
# Planner Stage - Analyze Dependencies
###################
FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json

###################
# Backend Build Stage
###################
FROM chef AS backend-builder

# Install system dependencies
RUN apt-get update && apt-get install -y \
pkg-config \
libssl-dev \
sqlite3 \
&& rm -rf /var/lib/apt/lists/*

# Copy workspace Cargo files
COPY Cargo.toml ./
COPY migration/Cargo.toml ./migration/
COPY entity/Cargo.toml ./entity/

# Create dummy source files for dependency caching
RUN mkdir -p src && \
echo "fn main() {}" > src/main.rs && \
mkdir -p migration/src && \
echo "pub use sea_orm_migration::prelude::*; pub struct Migrator; impl MigratorTrait for Migrator { fn migrations() -> Vec<Box<dyn MigrationTrait>> { vec![] } }" > migration/src/lib.rs && \
mkdir -p entity/src && \
echo "pub mod entities; pub mod prelude; pub use entities::*;" > entity/src/lib.rs && \
mkdir -p entity/src/entities && \
echo "pub mod prelude { pub use super::*; }" > entity/src/entities/mod.rs

# Build dependencies (this will be cached)
RUN cargo build --release || true

# Copy all source code
COPY migration/src ./migration/src
COPY entity/src ./entity/src
COPY src ./src
# Build dependencies first (cached layer)
COPY --from=planner /usr/src/app/recipe.json recipe.json
RUN cargo chef cook --release --recipe-path recipe.json

# Build the actual application
# Copy source code and build application
COPY . .
RUN cargo build --release

###################
Expand Down
Loading