From affe5fa89830e699835e3eda37d21ceff6ae566d Mon Sep 17 00:00:00 2001 From: Nicholas Ferguson Date: Sat, 17 May 2025 16:37:00 -0400 Subject: [PATCH] Optimize Docker builds --- .dockerignore | 5 ++--- Dockerfile.backend | 13 +++++++++++-- Dockerfile.worker | 10 ++++++++-- frontend/Dockerfile.frontend | 16 +++++----------- 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/.dockerignore b/.dockerignore index fc20574..bea7113 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,9 +2,8 @@ frontend/node_modules frontend/dist -# Ignore debug build artifacts but allow release artifacts -**/target/debug -!**/target/release +# Ignore build artifacts +**/target # Rust/Cargo related **/Cargo.lock diff --git a/Dockerfile.backend b/Dockerfile.backend index 39ff7c0..bff54e5 100644 --- a/Dockerfile.backend +++ b/Dockerfile.backend @@ -5,8 +5,17 @@ RUN apt-get update && apt-get install -y \ && rm -rf /var/lib/apt/lists/* WORKDIR /app -COPY . . -RUN cargo build --release + +# cache dependencies +COPY Cargo.toml Cargo.lock ./ +RUN mkdir src && echo "fn main() {}" > src/main.rs \ + && cargo build --release --locked \ + && rm -r src + +COPY src ./src +COPY migrations ./migrations +COPY diesel.toml ./ +RUN cargo build --release --locked FROM debian:buster-slim diff --git a/Dockerfile.worker b/Dockerfile.worker index d949cfd..93087fe 100644 --- a/Dockerfile.worker +++ b/Dockerfile.worker @@ -9,11 +9,17 @@ RUN apt-get update && apt-get install -y \ WORKDIR /app -# Copy the worker application code +# cache dependencies for the worker +COPY worker_app/Cargo.toml ./worker_app/ +RUN mkdir -p worker_app/src && echo "fn main() {}" > worker_app/src/main.rs \ + && cd worker_app && cargo build --release --locked \ + && rm -r src + +# Copy the worker application source COPY worker_app /app/worker_app # Build the worker application -RUN cd worker_app && cargo build --release +RUN cd worker_app && cargo build --release --locked # Install FluentCLI RUN cargo install --force --git https://github.com/njfio/fluent_cli --branch v.0.5.5-feature-docker-image fluent diff --git a/frontend/Dockerfile.frontend b/frontend/Dockerfile.frontend index 4016684..c023f73 100644 --- a/frontend/Dockerfile.frontend +++ b/frontend/Dockerfile.frontend @@ -6,17 +6,11 @@ COPY package*.json ./ ENV PUPPETEER_SKIP_DOWNLOAD=true -# Clear npm cache -RUN npm cache clean --force - -# Install dependencies -RUN npm ci - -# Install Vuex (latest version compatible with Vue 3) -RUN npm install vuex@4 - -# Install dev dependencies including @types/node -RUN npm install --save-dev @types/node +# Clear npm cache and install dependencies +RUN npm cache clean --force \ + && npm ci \ + && npm install vuex@4 \ + && npm install --save-dev @types/node # Copy all project files COPY . .