From ff0d9ac476c6ef3e3a06b4493616b961687fe71c Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Fri, 4 Aug 2023 20:35:24 +0200 Subject: [PATCH] Improve docker builds --- Dockerfile | 33 +++++++--------------- packages/backend/native-utils/package.json | 2 +- 2 files changed, 11 insertions(+), 24 deletions(-) diff --git a/Dockerfile b/Dockerfile index ee94a68f6..a45686b53 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,22 +6,6 @@ WORKDIR /iceshrimp # Install compilation dependencies RUN apk add --no-cache --no-progress git alpine-sdk vips-dev python3 nodejs-current npm rust cargo vips -# Collect sccache args -ARG SCCACHE_VERSION=v0.5.4 -ARG SCCACHE_ARCHITECTURE=x86_64 -ARG SCCACHE_MEMORY_LIMIT=10G - -# Download and initialize sccache -RUN wget https://github.com/mozilla/sccache/releases/download/${SCCACHE_VERSION}/sccache-${SCCACHE_VERSION}-${SCCACHE_ARCHITECTURE}-unknown-linux-musl.tar.gz && \ - tar xzf sccache-${SCCACHE_VERSION}-${SCCACHE_ARCHITECTURE}-unknown-linux-musl.tar.gz && \ - mv sccache-${SCCACHE_VERSION}-${SCCACHE_ARCHITECTURE}-unknown-linux-musl/sccache /usr/local/bin && \ - rm -rf sccache-${SCCACHE_VERSION}-${SCCACHE_ARCHITECTURE}-unknown-linux-musl* - -# Set sccache as the Rust compiler, set default dir, and set cache memory limit -ENV RUSTC_WRAPPER=sccache -ENV SCCACHE_DIR=/tmp/sccache -ENV SCCACHE_CACHE_SIZE=${SCCACHE_MEMORY_LIMIT} - # Copy only the cargo dependency-related files first, to cache efficiently COPY packages/backend/native-utils/Cargo.toml packages/backend/native-utils/Cargo.toml COPY packages/backend/native-utils/Cargo.lock packages/backend/native-utils/Cargo.lock @@ -53,15 +37,18 @@ RUN corepack enable && corepack prepare yarn@stable --activate && yarn # Save yarn cache RUN --mount=type=cache,target=/iceshrimp/.yarncache rm -rf .yarncache/* && cp -Tr .yarn .yarncache -# Copy in the rest of the native-utils rust files -COPY packages/backend/native-utils packages/backend/native-utils/ - -# Compile native-utils utilising sccache -RUN --mount=type=cache,target=/root/.cargo --mount=type=cache,target=/tmp/sccache --mount=type=cache,target=/iceshrimp/packages/backend/native-utils/migration/target yarn workspace native-utils build - # Copy in the rest of the files to compile COPY . ./ -RUN env NODE_ENV=production sh -c "yarn workspace iceshrimp-js run build && yarn workspaces foreach --exclude native-utils --include sw --include client --include backend --include megalodon run build && yarn gulp" + +# Fix napi-rs jank +RUN --mount=type=cache,target=/iceshrimp/.napi_buildcache cp -Tr /iceshrimp/.napi_buildcache /iceshrimp/packages/backend/native-utils/built +RUN --mount=type=cache,target=/iceshrimp/packages/backend/native-utils/target if [[ ! -f /iceshrimp/packages/backend/native-utils/built/index.js ]]; then rm -rf /iceshrimp/packages/backend/native-utils/target/release; fi + +# Build the thing +RUN --mount=type=cache,target=/root/.cargo --mount=type=cache,target=/iceshrimp/packages/backend/native-utils/target env NODE_ENV=production sh -c "yarn build && yarn gulp" + +# Fix napi-rs jank (part 2) +RUN --mount=type=cache,target=/iceshrimp/.napi_buildcache cp -Tr /iceshrimp/packages/backend/native-utils/built /iceshrimp/.napi_buildcache # Prepare yarn cache (production) RUN --mount=type=cache,target=/iceshrimp/.yarncache_prod cp -Tr .yarncache_prod .yarn diff --git a/packages/backend/native-utils/package.json b/packages/backend/native-utils/package.json index bc23e9e88..05623cc1f 100644 --- a/packages/backend/native-utils/package.json +++ b/packages/backend/native-utils/package.json @@ -36,7 +36,7 @@ "artifacts": "napi artifacts", "build": "yarn build:napi && yarn build:migration", "build:napi": "napi build --features napi --platform --release ./built/", - "build:migration": "cargo build --locked --profile release-no-lto -p migration --target-dir migration/target && cp ./migration/target/release-no-lto/migration ./built/migration", + "build:migration": "cargo build --locked --profile release-no-lto -p migration && cp ./target/release-no-lto/migration ./built/migration", "build:debug": "napi build --platform ./built/ && cargo build -p migration", "prepublishOnly": "napi prepublish -t npm", "test": "yarn cargo:test && yarn build:napi && ava",