precompile rust components

This commit is contained in:
Lily Cohen 2023-06-07 11:43:32 -06:00 committed by Namekuji
parent 90ad37c3a3
commit 48f58feae6
No known key found for this signature in database
GPG key ID: B541BD6E646CABC7
5 changed files with 33 additions and 7 deletions

View file

@ -13,6 +13,9 @@ node_modules
**/node_modules
report.*.json
# Rust
packages/backend/native-utils/target/*
# Cypress
cypress/screenshots
cypress/videos

View file

@ -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", "--" ]

View file

@ -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

View file

@ -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",

View file

@ -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",