diff --git a/.dockerignore b/.dockerignore index 8aa17c3a8..4a75603f7 100644 --- a/.dockerignore +++ b/.dockerignore @@ -13,6 +13,9 @@ node_modules **/node_modules report.*.json +# Rust +packages/backend/native-utils/target/* + # Cypress cypress/screenshots cypress/videos diff --git a/Dockerfile b/Dockerfile index 29922af4f..cbdf7407e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,6 +5,16 @@ WORKDIR /calckey # Install compilation dependencies RUN apk add --no-cache --no-progress git alpine-sdk python3 rust cargo vips +# 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/migration/Cargo.toml packages/backend/native-utils/migration/Cargo.toml +COPY packages/backend/native-utils/src/*.rs packages/backend/native-utils/src/ + +# Install cargo dependencies +RUN cd packages/backend && \ + cargo fetch --locked --manifest-path ./native-utils/migration/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 @@ -22,13 +32,26 @@ RUN corepack prepare pnpm@latest --activate # Install dev mode dependencies for compilation RUN 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/src packages/backend/native-utils/src +COPY packages/backend/native-utils/migration packages/backend/native-utils/migration +COPY packages/backend/native-utils/tests packages/backend/native-utils/tests +COPY packages/backend/native-utils/*.rs packages/backend/native-utils/ + +# native-utils cargo build +RUN pnpm run build:cargo + # Copy in the rest of the files, to compile from TS to JS COPY . ./ -RUN pnpm run build +RUN pnpm run build:recursive +RUN pnpm run gulp # Trim down the dependencies to only the prod deps RUN pnpm i --prod --frozen-lockfile +# Clean up the cargo deps +RUN rm -rf /calckey/packages/backend/native-utils/target/release/deps ## Runtime container FROM node:20-alpine @@ -51,7 +74,7 @@ COPY --from=build /calckey/built /calckey/built COPY --from=build /calckey/packages/backend/built /calckey/packages/backend/built COPY --from=build /calckey/packages/backend/assets/instance.css /calckey/packages/backend/assets/instance.css COPY --from=build /calckey/packages/backend/native-utils/built /calckey/packages/backend/native-utils/built -COPY --from=build /calckey/packages/backend/native-utils/target /calckey/packages/backend/native-utils/target +COPY --from=build /calckey/packages/backend/native-utils/target/release /calckey/packages/backend/native-utils/target/release RUN corepack enable ENTRYPOINT [ "/sbin/tini", "--" ] diff --git a/docker-compose.yml b/docker-compose.yml index d6ad26a05..abb1882ea 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -19,8 +19,6 @@ services: environment: NODE_ENV: production volumes: - - ./.cargo-cache:/root/.cargo - - ./.cargo-target:/calckey/packages/backend/native-utils/target - ./files:/calckey/files - ./.config:/calckey/.config:ro diff --git a/package.json b/package.json index 42a18a33c..a6de546ff 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,9 @@ "private": true, "scripts": { "rebuild": "pnpm run clean && pnpm -r run build && pnpm run gulp", - "build": "pnpm -r run build && pnpm run gulp", + "build": "pnpm -r run build:cargo && pnpm -r run build:recursive && pnpm run gulp", + "build:recursive": "pnpm -r run build", + "build:cargo": "pnpm --filter backend run build:cargo", "start": "pnpm --filter backend run start", "start:test": "pnpm --filter backend run start:test", "init": "pnpm run migrate", diff --git a/packages/backend/package.json b/packages/backend/package.json index 2a19b916c..90b1e1e41 100644 --- a/packages/backend/package.json +++ b/packages/backend/package.json @@ -8,10 +8,10 @@ "start:test": "NODE_ENV=test pnpm node ./built/index.js", "migrate": "pnpm run migrate:typeorm && pnpm run migrate:cargo", "migrate:typeorm": "typeorm migration:run -d ormconfig.js", - "migrate:cargo": "cargo run --manifest-path ./native-utils/migration/Cargo.toml -- up", + "migrate:cargo": "./native-utils/target/release/migration up", "revertmigration": "pnpm run revertmigration:cargo && pnpm run revertmigration:typeorm", "revertmigration:typeorm": "typeorm migration:revert -d ormconfig.js", - "revertmigration:cargo": "cargo run --manifest-path ./native-utils/migration/Cargo.toml -- down", + "revertmigration:cargo": "./native-utils/target/release/migration down", "check:connect": "node ./check_connect.js", "build": "pnpm swc src -d built -D", "watch": "pnpm swc src -d built -D -w",