Skip to content

Commit c9cea34

Browse files
committed
[#121] Improve CI speed
1 parent 700417a commit c9cea34

10 files changed

Lines changed: 105 additions & 104 deletions

File tree

.gitlab/ci/build_app.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ app-web-image:
5858
- !reference [.release-workflow, rules]
5959
image:
6060
name: moby/buildkit:rootless
61-
entrypoint: ['']
61+
entrypoint: [""]
6262
before_script:
6363
- mkdir -p ~/.docker
6464
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > ~/.docker/config.json
@@ -71,8 +71,9 @@ app-web-image:
7171
--local dockerfile=./apps/polycentric \
7272
--opt build-arg:EXPO_PUBLIC_POLYCENTRIC_SEED_SERVERS=$EXPO_PUBLIC_POLYCENTRIC_SEED_SERVERS \
7373
--opt build-arg:SKIP_WORKSPACE_BUILD=1 \
74-
--import-cache type=registry,ref=$CI_REGISTRY_IMAGE/app:$CI_COMMIT_SHA-cache \
75-
--export-cache type=registry,ref=$CI_REGISTRY_IMAGE/app:$CI_COMMIT_SHA-cache,mode=max \
74+
--import-cache type=registry,ref=$CI_REGISTRY_IMAGE/app:cache-$CI_DEFAULT_BRANCH \
75+
--import-cache type=registry,ref=$CI_REGISTRY_IMAGE/app:cache-$CI_COMMIT_REF_SLUG \
76+
--export-cache type=registry,ref=$CI_REGISTRY_IMAGE/app:cache-$CI_COMMIT_REF_SLUG,mode=max \
7677
--output type=image,name=$CI_REGISTRY_IMAGE/app:$CI_COMMIT_SHA,push=true
7778
7879
.app-build-expo:

.gitlab/ci/build_js_sdks.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,17 @@
1818

1919
.js-sdks-base:
2020
extends: .js-sdk-workflow
21+
variables:
22+
PNPM_STORE_DIR: ${CI_PROJECT_DIR}/.pnpm-store
23+
cache:
24+
key: js-sdks-pnpm-${CI_COMMIT_REF_SLUG}
25+
fallback_keys:
26+
- js-sdks-pnpm-${CI_DEFAULT_BRANCH}
27+
paths:
28+
- .pnpm-store
2129
before_script:
2230
- npm install -g pnpm@10
31+
- pnpm config set store-dir ${PNPM_STORE_DIR}
2332
- pnpm config set @polycentric:registry https://${CI_SERVER_HOST}/api/v4/projects/${CI_PROJECT_ID}/packages/npm/
2433
- pnpm install
2534

.gitlab/ci/build_rn_sdk.yml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,16 @@ rn-android-build:
2525
- !reference [.app-workflow, rules]
2626
- !reference [.release-workflow, rules]
2727
cache:
28-
- key:
29-
files:
30-
- packages/rs-core/Cargo.lock
31-
prefix: rs-core-cargo-deps
28+
- key: rs-core-cargo-deps-${CI_COMMIT_REF_SLUG}
29+
fallback_keys:
30+
- rs-core-cargo-deps-${CI_DEFAULT_BRANCH}
3231
paths:
3332
- .cargo/registry/index
3433
- .cargo/registry/cache
3534
- .cargo/git/db
36-
- key:
37-
files:
38-
- packages/rs-core/Cargo.lock
39-
- pnpm-lock.yaml
40-
prefix: rs-core-target-${CI_JOB_NAME}
35+
- key: rs-core-target-${CI_JOB_NAME}-${CI_COMMIT_REF_SLUG}
36+
fallback_keys:
37+
- rs-core-target-${CI_JOB_NAME}-${CI_DEFAULT_BRANCH}
4138
paths:
4239
- target
4340
script:

.gitlab/ci/build_rs_core.yml

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,16 @@
2020
variables:
2121
RUST_CORE_PATH: packages/rs-core
2222
cache:
23-
- key:
24-
files:
25-
- packages/rs-core/Cargo.lock
26-
prefix: rs-core-cargo-deps
23+
- key: rs-core-cargo-deps-${CI_COMMIT_REF_SLUG}
24+
fallback_keys:
25+
- rs-core-cargo-deps-${CI_DEFAULT_BRANCH}
2726
paths:
2827
- .cargo/registry/index
2928
- .cargo/registry/cache
3029
- .cargo/git/db
31-
- key:
32-
files:
33-
- packages/rs-core/Cargo.lock
34-
prefix: rs-core-target-${CI_JOB_NAME}
30+
- key: rs-core-target-${CI_JOB_NAME}-${CI_COMMIT_REF_SLUG}
31+
fallback_keys:
32+
- rs-core-target-${CI_JOB_NAME}-${CI_DEFAULT_BRANCH}
3533
paths:
3634
- target
3735

@@ -92,22 +90,6 @@ rs-core-uniffi-web-build:
9290
- !reference [.rn-sdk-workflow, rules]
9391
- !reference [.app-workflow, rules]
9492
- !reference [.release-workflow, rules]
95-
cache:
96-
- key:
97-
files:
98-
- packages/rs-core/Cargo.lock
99-
prefix: rs-core-cargo-deps
100-
paths:
101-
- .cargo/registry/index
102-
- .cargo/registry/cache
103-
- .cargo/git/db
104-
- key:
105-
files:
106-
- packages/rs-core/Cargo.lock
107-
- pnpm-lock.yaml
108-
prefix: rs-core-target-${CI_JOB_NAME}
109-
paths:
110-
- target
11193
script:
11294
- cd packages/rs-core-uniffi-web
11395
- |

.gitlab/ci/build_services.yml

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1-
21
.service-rust-base:
32
image: ${RUST_IMAGE}
43
stage: check
4+
cache:
5+
key: ${CI_JOB_NAME}-${CI_COMMIT_REF_SLUG}
6+
fallback_keys:
7+
- ${CI_JOB_NAME}-${CI_DEFAULT_BRANCH}
8+
- ${CI_JOB_NAME}
9+
paths:
10+
- .cargo/registry/index/
11+
- .cargo/registry/cache/
12+
- .cargo/git/db/
13+
- target/
514

615
.service-format-check:
716
extends: .service-rust-base
@@ -20,20 +29,10 @@
2029
script:
2130
- cargo test --package ${SERVICE_NAME}
2231

23-
.service-build:
24-
extends: .service-rust-base
25-
stage: build
26-
script:
27-
- cargo build --release --package ${SERVICE_NAME}
28-
artifacts:
29-
paths:
30-
- target/release/${SERVICE_NAME}
31-
expire_in: 1 week
32-
3332
.service-image:
3433
image:
3534
name: moby/buildkit:rootless
36-
entrypoint: ['']
35+
entrypoint: [""]
3736
before_script:
3837
- mkdir -p ~/.docker
3938
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > ~/.docker/config.json
@@ -44,8 +43,9 @@
4443
--frontend dockerfile.v0 \
4544
--local context=. \
4645
--local dockerfile=./services/${SERVICE_DIR} \
47-
--import-cache type=registry,ref=$CI_REGISTRY_IMAGE/${SERVICE_NAME}:$CI_COMMIT_SHA-cache \
48-
--export-cache type=registry,ref=$CI_REGISTRY_IMAGE/${SERVICE_NAME}:$CI_COMMIT_SHA-cache,mode=max \
46+
--import-cache type=registry,ref=$CI_REGISTRY_IMAGE/${SERVICE_NAME}:cache-$CI_DEFAULT_BRANCH \
47+
--import-cache type=registry,ref=$CI_REGISTRY_IMAGE/${SERVICE_NAME}:cache-$CI_COMMIT_REF_SLUG \
48+
--export-cache type=registry,ref=$CI_REGISTRY_IMAGE/${SERVICE_NAME}:cache-$CI_COMMIT_REF_SLUG,mode=max \
4949
--output type=image,name=$CI_REGISTRY_IMAGE/${SERVICE_NAME}:$CI_COMMIT_SHA,push=true
5050
5151
########################################################################
@@ -90,11 +90,6 @@ server-clippy:
9090
- .server-workflow
9191
- .service-clippy
9292

93-
server-build:
94-
extends:
95-
- .server-workflow
96-
- .service-build
97-
9893
server-image:
9994
extends:
10095
- .server-workflow
@@ -145,11 +140,6 @@ moderation-clippy:
145140
- .moderation-workflow
146141
- .service-clippy
147142

148-
moderation-build:
149-
extends:
150-
- .moderation-workflow
151-
- .service-build
152-
153143
moderation-image:
154144
extends:
155145
- .moderation-workflow
@@ -203,11 +193,6 @@ push-notifications-test:
203193
- .push-notifications-workflow
204194
- .service-test
205195

206-
push-notifications-build:
207-
extends:
208-
- .push-notifications-workflow
209-
- .service-build
210-
211196
push-notifications-image:
212197
extends:
213198
- .push-notifications-workflow

.gitlab/ci/scan_dependencies.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ trivy:
1818
# Console output
1919
- trivy filesystem --scanners misconfig,vuln --exit-code 1 --severity CRITICAL .
2020
cache:
21+
key: trivy-${CI_COMMIT_REF_SLUG}
22+
fallback_keys:
23+
- trivy-${CI_DEFAULT_BRANCH}
2124
paths:
2225
- .trivycache/
2326
artifacts:

apps/polycentric/Dockerfile

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,17 @@ COPY packages packages
2626
COPY tools tools
2727
RUN pnpm install --frozen-lockfile
2828
RUN if [ -z "$SKIP_WORKSPACE_BUILD" ]; then pnpm run build; fi
29-
RUN cd apps/polycentric && npx expo export --platform web
3029
# Non symlinked packages and node_modules
3130
RUN pnpm --filter polycentric-app --prod --legacy deploy /deploy
31+
RUN cd /deploy && npx expo export --platform web
3232

3333
# Stage 3: Run
3434
FROM base AS runner
3535
WORKDIR /app
3636
ENV NODE_ENV=production
3737
ENV PORT=8080
3838

39-
COPY --from=build /deploy/node_modules ./node_modules
40-
COPY --from=build /deploy/package.json ./package.json
41-
COPY --from=build /app/apps/polycentric/dist ./dist
42-
COPY --from=build /app/apps/polycentric/server.js ./server.js
39+
COPY --from=build /deploy .
4340

4441
EXPOSE 8080
4542
CMD ["node", "server.js"]

services/moderation/Dockerfile

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,32 @@
1-
FROM rust:1.96-slim AS build
2-
1+
FROM rust:1.96-slim AS chef
32
WORKDIR /app
3+
COPY services/common/build-deps.sh build-deps.sh
4+
RUN sh build-deps.sh
5+
RUN cargo install cargo-chef --locked
46

5-
COPY Cargo.toml Cargo.toml
6-
COPY Cargo.lock Cargo.lock
7-
COPY protos protos
7+
FROM chef AS planner
8+
COPY Cargo.toml Cargo.lock ./
89
COPY packages packages
910
COPY services services
1011
COPY tools tools
12+
RUN cargo chef prepare --recipe-path recipe.json
1113

12-
RUN services/common/build-deps.sh
13-
14-
RUN cargo build --release --package moderation-service
15-
RUN cargo build --release --package moderation-migration
14+
FROM chef AS builder
15+
COPY --from=planner /app/recipe.json recipe.json
16+
COPY protos protos
17+
RUN cargo chef cook --release --recipe-path recipe.json
18+
COPY Cargo.toml Cargo.lock ./
19+
COPY packages packages
20+
COPY services services
21+
COPY tools tools
22+
RUN cargo build --release \
23+
--package moderation-service \
24+
--package moderation-migration
1625

1726
FROM rust:1.96-slim
1827
WORKDIR /app
1928
COPY services/common/runtime-deps.sh runtime-deps.sh
2029
RUN sh runtime-deps.sh
21-
COPY --from=build /app/target/release/moderation-service /app/moderation-service
22-
COPY --from=build /app/target/release/moderation-migration /app/moderation-migration
23-
CMD ["/app/moderation-service"]
30+
COPY --from=builder /app/target/release/moderation-service /app/moderation-service
31+
COPY --from=builder /app/target/release/moderation-migration /app/moderation-migration
32+
CMD ["/app/moderation-service"]
Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,32 @@
1-
FROM rust:1.96-slim AS build
2-
1+
FROM rust:1.96-slim AS chef
32
WORKDIR /app
3+
COPY services/common/build-deps.sh build-deps.sh
4+
RUN sh build-deps.sh
5+
RUN cargo install cargo-chef --locked
46

5-
COPY Cargo.toml Cargo.toml
6-
COPY Cargo.lock Cargo.lock
7-
COPY protos protos
7+
FROM chef AS planner
8+
COPY Cargo.toml Cargo.lock ./
89
COPY packages packages
910
COPY services services
1011
COPY tools tools
12+
RUN cargo chef prepare --recipe-path recipe.json
1113

12-
RUN services/common/build-deps.sh
13-
14-
RUN cargo build --release --package push-notifications-service
15-
RUN cargo build --release --package push-notifications-migration
14+
FROM chef AS builder
15+
COPY --from=planner /app/recipe.json recipe.json
16+
COPY protos protos
17+
RUN cargo chef cook --release --recipe-path recipe.json
18+
COPY Cargo.toml Cargo.lock ./
19+
COPY packages packages
20+
COPY services services
21+
COPY tools tools
22+
RUN cargo build --release \
23+
--package push-notifications-service \
24+
--package push-notifications-migration
1625

1726
FROM rust:1.96-slim
1827
WORKDIR /app
1928
COPY services/common/runtime-deps.sh runtime-deps.sh
2029
RUN sh runtime-deps.sh
21-
COPY --from=build /app/target/release/push-notifications-service /app/push-notifications-service
22-
COPY --from=build /app/target/release/push-notifications-migration /app/push-notifications-migration
30+
COPY --from=builder /app/target/release/push-notifications-service /app/push-notifications-service
31+
COPY --from=builder /app/target/release/push-notifications-migration /app/push-notifications-migration
2332
CMD ["/app/push-notifications-service"]

services/server/Dockerfile

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,32 @@
1-
FROM rust:1.96-slim AS build
2-
1+
FROM rust:1.96-slim AS chef
32
WORKDIR /app
3+
COPY services/common/build-deps.sh build-deps.sh
4+
RUN sh build-deps.sh
5+
RUN cargo install cargo-chef --locked
46

5-
COPY Cargo.toml Cargo.toml
6-
COPY Cargo.lock Cargo.lock
7-
COPY protos protos
7+
FROM chef AS planner
8+
COPY Cargo.toml Cargo.lock ./
89
COPY packages packages
910
COPY services services
1011
COPY tools tools
12+
RUN cargo chef prepare --recipe-path recipe.json
1113

12-
RUN services/common/build-deps.sh
13-
14-
RUN cargo build --release --package server
15-
RUN cargo build --release --package migration
14+
FROM chef AS builder
15+
COPY --from=planner /app/recipe.json recipe.json
16+
COPY protos protos
17+
RUN cargo chef cook --release --recipe-path recipe.json
18+
COPY Cargo.toml Cargo.lock ./
19+
COPY packages packages
20+
COPY services services
21+
COPY tools tools
22+
RUN cargo build --release \
23+
--package server \
24+
--package migration
1625

1726
FROM rust:1.96-slim
1827
WORKDIR /app
1928
COPY services/common/runtime-deps.sh runtime-deps.sh
2029
RUN sh runtime-deps.sh
21-
COPY --from=build /app/target/release/server /app/server
22-
COPY --from=build /app/target/release/migration /app/migration
30+
COPY --from=builder /app/target/release/server /app/server
31+
COPY --from=builder /app/target/release/migration /app/migration
2332
CMD ["/app/server"]

0 commit comments

Comments
 (0)