From 36da212aaa580a2a1c2c4d6af04cd8f4c2946057 Mon Sep 17 00:00:00 2001 From: Namekuji Date: Thu, 22 Jun 2023 13:16:59 -0400 Subject: [PATCH] cache native-utils --- .dockerignore | 4 +--- Dockerfile | 23 +++++++++++++------ .../backend/native-utils/migration/Cargo.toml | 6 ++--- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/.dockerignore b/.dockerignore index 4a75603f7..90d15ddd9 100644 --- a/.dockerignore +++ b/.dockerignore @@ -28,9 +28,6 @@ coverage !/.config/example.yml !/.config/docker_example.env -#docker dev config -/dev/docker-compose.yml - # misskey built db @@ -50,3 +47,4 @@ packages/backend/assets/instance.css # dockerignore custom .git Dockerfile +docker-compose.yml diff --git a/Dockerfile b/Dockerfile index 47452be3f..e11cb2bf4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,12 +8,12 @@ RUN apk add --no-cache --no-progress git alpine-sdk python3 nodejs-current npm r # 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 +COPY packages/backend/native-utils/src/lib.rs packages/backend/native-utils/src/ COPY packages/backend/native-utils/migration/Cargo.toml packages/backend/native-utils/migration/Cargo.toml -COPY packages/backend/native-utils/src/*.rs packages/backend/native-utils/src/ +COPY packages/backend/native-utils/migration/src/lib.rs packages/backend/native-utils/migration/src/ # Install cargo dependencies -RUN cd packages/backend && \ - cargo fetch --locked --manifest-path ./native-utils/migration/Cargo.toml +RUN cargo fetch --locked --manifest-path /calckey/packages/backend/native-utils/Cargo.toml # Copy only the dependency-related files first, to cache efficiently COPY package.json pnpm*.yaml ./ @@ -28,12 +28,21 @@ COPY packages/backend/native-utils/npm/linux-arm64-musl/package.json packages/ba # Configure corepack and pnpm, and install dev mode dependencies for compilation RUN corepack enable && corepack prepare pnpm@latest --activate && pnpm i --frozen-lockfile +# Copy in the rest of the native-utils rust files +COPY packages/backend/native-utils/.cargo packages/backend/native-utils/.cargo +COPY packages/backend/native-utils/build.rs packages/backend/native-utils/ +COPY packages/backend/native-utils/src packages/backend/native-utils/src/ +COPY packages/backend/native-utils/migration/src packages/backend/native-utils/migration/src/ + +# Compile native-utils +RUN pnpm run --filter native-utils build + # Copy in the rest of the files to compile COPY . ./ -RUN env NODE_ENV=production pnpm run build +RUN env NODE_ENV=production sh -c "pnpm run --filter '!native-utils' build && pnpm run gulp" -# Trim down the artifacts and dependencies to only the prod deps -RUN cargo clean --manifest-path /calckey/packages/backend/native-utils/Cargo.toml && pnpm i --prod --frozen-lockfile +# Trim down the dependencies to only those for production +RUN pnpm i --prod --frozen-lockfile ## Runtime container FROM alpine:3.18 @@ -59,6 +68,6 @@ COPY --from=build /calckey/packages/backend/native-utils/built /calckey/packages RUN corepack enable && corepack prepare pnpm@latest --activate ENV NODE_ENV=production -VOLUME [ "/calckey/files" ] +VOLUME "/calckey/files" ENTRYPOINT [ "/sbin/tini", "--" ] CMD [ "pnpm", "run", "migrateandstart" ] diff --git a/packages/backend/native-utils/migration/Cargo.toml b/packages/backend/native-utils/migration/Cargo.toml index 4dee156ef..7ed9fd5f0 100644 --- a/packages/backend/native-utils/migration/Cargo.toml +++ b/packages/backend/native-utils/migration/Cargo.toml @@ -10,14 +10,14 @@ path = "src/lib.rs" [features] default = [] -convert = ["dep:native-utils"] +convert = ["dep:native-utils", "dep:indicatif", "dep:futures"] [dependencies] serde_json = "1.0.96" native-utils = { path = "../", optional = true } -indicatif = { version = "0.17.4", features = ["tokio"] } +indicatif = { version = "0.17.4", features = ["tokio"], optional = true } tokio = { version = "1.28.2", features = ["full"] } -futures = "0.3.28" +futures = { version = "0.3.28", optional = true } serde_yaml = "0.9.21" serde = { version = "1.0.163", features = ["derive"] } urlencoding = "2.1.2"