container: reorder build operations to use cargo build cache on deps updates
This commit is contained in:
parent
aa266d91e0
commit
b07dc87af6
1 changed files with 22 additions and 19 deletions
41
Dockerfile
41
Dockerfile
|
@ -7,7 +7,12 @@ RUN apk update && apk add --no-cache build-base linux-headers curl ca-certificat
|
||||||
RUN curl --proto '=https' --tlsv1.2 --silent --show-error --fail https://sh.rustup.rs | sh -s -- -y
|
RUN curl --proto '=https' --tlsv1.2 --silent --show-error --fail https://sh.rustup.rs | sh -s -- -y
|
||||||
ENV PATH="/root/.cargo/bin:${PATH}"
|
ENV PATH="/root/.cargo/bin:${PATH}"
|
||||||
|
|
||||||
# Copy only the cargo dependency-related files first, to cache efficiently
|
# Copy only backend-rs dependency-related files first, to cache efficiently
|
||||||
|
COPY package.json pnpm*.yaml ./
|
||||||
|
COPY packages/backend-rs/package.json packages/backend-rs/package.json
|
||||||
|
COPY packages/backend-rs/npm/linux-x64-musl/package.json packages/backend-rs/npm/linux-x64-musl/package.json
|
||||||
|
COPY packages/backend-rs/npm/linux-arm64-musl/package.json packages/backend-rs/npm/linux-arm64-musl/package.json
|
||||||
|
|
||||||
COPY Cargo.toml Cargo.toml
|
COPY Cargo.toml Cargo.toml
|
||||||
COPY Cargo.lock Cargo.lock
|
COPY Cargo.lock Cargo.lock
|
||||||
COPY packages/backend-rs/Cargo.toml packages/backend-rs/Cargo.toml
|
COPY packages/backend-rs/Cargo.toml packages/backend-rs/Cargo.toml
|
||||||
|
@ -15,23 +20,10 @@ COPY packages/backend-rs/src/lib.rs packages/backend-rs/src/
|
||||||
COPY packages/macro-rs/Cargo.toml packages/macro-rs/Cargo.toml
|
COPY packages/macro-rs/Cargo.toml packages/macro-rs/Cargo.toml
|
||||||
COPY packages/macro-rs/src/lib.rs packages/macro-rs/src/
|
COPY packages/macro-rs/src/lib.rs packages/macro-rs/src/
|
||||||
|
|
||||||
# Install cargo dependencies
|
# Configure pnpm, and install backend-rs dependencies
|
||||||
|
RUN corepack enable && corepack prepare pnpm@latest --activate && pnpm --filter backend-rs install --frozen-lockfile
|
||||||
RUN cargo fetch --locked --manifest-path /firefish/packages/backend-rs/Cargo.toml
|
RUN cargo fetch --locked --manifest-path /firefish/packages/backend-rs/Cargo.toml
|
||||||
|
|
||||||
# Copy only the dependency-related files first, to cache efficiently
|
|
||||||
COPY package.json pnpm*.yaml ./
|
|
||||||
COPY packages/backend/package.json packages/backend/package.json
|
|
||||||
COPY packages/client/package.json packages/client/package.json
|
|
||||||
COPY packages/sw/package.json packages/sw/package.json
|
|
||||||
COPY packages/firefish-js/package.json packages/firefish-js/package.json
|
|
||||||
COPY packages/megalodon/package.json packages/megalodon/package.json
|
|
||||||
COPY packages/backend-rs/package.json packages/backend-rs/package.json
|
|
||||||
COPY packages/backend-rs/npm/linux-x64-musl/package.json packages/backend-rs/npm/linux-x64-musl/package.json
|
|
||||||
COPY packages/backend-rs/npm/linux-arm64-musl/package.json packages/backend-rs/npm/linux-arm64-musl/package.json
|
|
||||||
|
|
||||||
# Configure pnpm, and install dev mode dependencies for compilation
|
|
||||||
RUN corepack enable && corepack prepare pnpm@latest --activate && pnpm install --frozen-lockfile
|
|
||||||
|
|
||||||
# Copy in the rest of the rust files
|
# Copy in the rest of the rust files
|
||||||
COPY packages/backend-rs packages/backend-rs/
|
COPY packages/backend-rs packages/backend-rs/
|
||||||
# COPY packages/macro-rs packages/macro-rs/
|
# COPY packages/macro-rs packages/macro-rs/
|
||||||
|
@ -42,10 +34,21 @@ RUN NODE_ENV='production' pnpm run --filter backend-rs build
|
||||||
# Copy/Overwrite index.js to mitigate the bug in napi-rs codegen
|
# Copy/Overwrite index.js to mitigate the bug in napi-rs codegen
|
||||||
COPY packages/backend-rs/index.js packages/backend-rs/built/index.js
|
COPY packages/backend-rs/index.js packages/backend-rs/built/index.js
|
||||||
|
|
||||||
# Copy in the rest of the files to compile
|
# Copy only the dependency-related files first, to cache efficiently
|
||||||
|
COPY packages/backend/package.json packages/backend/package.json
|
||||||
|
COPY packages/client/package.json packages/client/package.json
|
||||||
|
COPY packages/sw/package.json packages/sw/package.json
|
||||||
|
COPY packages/firefish-js/package.json packages/firefish-js/package.json
|
||||||
|
COPY packages/megalodon/package.json packages/megalodon/package.json
|
||||||
|
|
||||||
|
# Install dev mode dependencies for compilation
|
||||||
|
RUN pnpm install --frozen-lockfile
|
||||||
|
|
||||||
|
# Copy in the rest of the files to build
|
||||||
COPY . ./
|
COPY . ./
|
||||||
RUN NODE_ENV='production' pnpm run --filter firefish-js build
|
|
||||||
RUN NODE_ENV='production' pnpm run --recursive --parallel --filter '!backend-rs' --filter '!firefish-js' build && pnpm run build:assets
|
# Build other workspaces
|
||||||
|
RUN NODE_ENV='production' pnpm run --recursive --filter '!backend-rs' build && pnpm run build:assets
|
||||||
|
|
||||||
# Trim down the dependencies to only those for production
|
# Trim down the dependencies to only those for production
|
||||||
RUN find . -path '*/node_modules/*' -delete && pnpm install --prod --frozen-lockfile
|
RUN find . -path '*/node_modules/*' -delete && pnpm install --prod --frozen-lockfile
|
||||||
|
|
Loading…
Reference in a new issue