Skip to content

Commit 5cb7718

Browse files
committed
Merge #1872: chore(container): exclude irrelevant workspace members from nextest archive
baf6c8d chore(container): fix misleading cook-stage comment; clarify T2 task scope (Jose Celano) bf5bfe4 chore(container): exclude irrelevant workspace members from nextest archive (Jose Celano) Pull request description: Closes #1868. Add `--exclude workspace-coupling --exclude torrust-tracker-torrent-repository-benchmarking` to all four `cargo nextest archive` commands in the Containerfile (pre-link warm-up × 2 and final archive × 2, covering both debug and release builds). `cargo chef prepare` and `cargo chef cook` do not expose an `--exclude` flag (cargo-chef CLI limitation). The COPY/stub lines for the excluded packages are retained in the recipe stage because `cargo chef prepare` invokes `cargo metadata` internally, which requires every workspace member's manifest to be present on disk. This limitation and its rationale are documented in Containerfile comments. ## Changes - `Containerfile`: added `--exclude` flags to 4 `cargo nextest archive` commands; added explanatory comments to cook and recipe stages - `docs/issues/open/1868-…/ISSUE.md`: T1–T3 marked DONE, AC4 marked DONE, automatic verification checkpoint checked ## Verification - `linter all` → passed - `cargo machete` → passed - `cargo test --doc --workspace` → passed - Pre-commit hook → SUCCESS Remaining: AC1–AC3 require a full CI run (build timing and image correctness). ACKs for top commit: josecelano: ACK baf6c8d Tree-SHA512: 440b33bf1aff4c9f364f8d0a3727865421e551f38f7194bb17a3de1edb3aa3b0b3b5fcea42dc9a163d072495e5c9a2c8a30fbe6fe0b81483b043e529ea2a46e4
2 parents cbaa726 + baf6c8d commit 5cb7718

2 files changed

Lines changed: 50 additions & 21 deletions

File tree

  • docs/issues/open/1868-1840-workflow-performance-exclude-irrelevant-workspace-members

Containerfile

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ WORKDIR /build/src
5252
COPY Cargo.toml Cargo.lock ./
5353
COPY console/tracker-client/Cargo.toml console/tracker-client/
5454
COPY contrib/bencode/Cargo.toml contrib/bencode/
55+
# workspace-coupling and torrust-tracker-torrent-repository-benchmarking are
56+
# excluded from cargo nextest archive (see Cook and Build stages below), but
57+
# their Cargo.toml manifests and stub source files must still be present here
58+
# because `cargo chef prepare` uses `cargo metadata` internally to enumerate
59+
# all workspace members, and `cargo metadata` aborts if any member's manifest
60+
# or declared target file is missing. `cargo chef prepare` has no `--exclude`
61+
# flag (only `--bin`), so these stubs cannot be omitted from the recipe stage.
5562
COPY contrib/dev-tools/analysis/workspace-coupling/Cargo.toml contrib/dev-tools/analysis/workspace-coupling/
5663
COPY packages/axum-health-check-api-server/Cargo.toml packages/axum-health-check-api-server/
5764
COPY packages/axum-http-server/Cargo.toml packages/axum-http-server/
@@ -185,34 +192,55 @@ RUN cargo chef prepare --recipe-path /build/recipe.json
185192
FROM chef AS dependencies_debug
186193
WORKDIR /build/src
187194
COPY --from=recipe /build/recipe.json /build/recipe.json
195+
# Note: `cargo chef cook` does not support `--exclude` (the cargo-chef CLI only
196+
# exposes `--workspace` and `--package`, not `--exclude`). The two irrelevant
197+
# workspace members (workspace-coupling and torrust-tracker-torrent-repository-
198+
# benchmarking) are therefore still compiled as part of the cook skeleton
199+
# (their Cargo.toml manifests are in the recipe, so cargo-chef cooks them).
200+
# The build-time savings come from the archive/build stages: `cargo nextest
201+
# archive` below is passed `--exclude` so those packages are not compiled from
202+
# real source in the final archive. See Cook (release) and Build stages.
188203
RUN cargo chef cook --tests --workspace --all-features --recipe-path /build/recipe.json
189204
# Pre-link warm-up: Create and discard a nextest archive to warm up the linker
190205
# before final compilation. This improves incremental build cache efficiency
191206
# by pre-faulting the linker phases, avoiding redundant linking work in later stages.
192-
RUN cargo nextest archive --tests --workspace --all-features --archive-file /build/temp.tar.zst && rm -f /build/temp.tar.zst
207+
RUN cargo nextest archive --tests --workspace --all-features \
208+
--exclude workspace-coupling \
209+
--exclude torrust-tracker-torrent-repository-benchmarking \
210+
--archive-file /build/temp.tar.zst && rm -f /build/temp.tar.zst
193211

194212
## Cook (release)
195213
FROM chef AS dependencies
196214
WORKDIR /build/src
197215
COPY --from=recipe /build/recipe.json /build/recipe.json
216+
# Note: `cargo chef cook` does not support `--exclude` — see Cook (debug) above.
198217
RUN cargo chef cook --tests --workspace --all-features --recipe-path /build/recipe.json --release
199218
# Pre-link warm-up: Create and discard a nextest archive to warm up the linker
200219
# before final compilation. This improves incremental build cache efficiency
201220
# by pre-faulting the linker phases, avoiding redundant linking work in later stages.
202-
RUN cargo nextest archive --tests --workspace --all-features --archive-file /build/temp.tar.zst --release && rm -f /build/temp.tar.zst
221+
RUN cargo nextest archive --tests --workspace --all-features \
222+
--exclude workspace-coupling \
223+
--exclude torrust-tracker-torrent-repository-benchmarking \
224+
--archive-file /build/temp.tar.zst --release && rm -f /build/temp.tar.zst
203225

204226

205227
## Build Archive (debug)
206228
FROM dependencies_debug AS build_debug
207229
WORKDIR /build/src
208230
COPY . /build/src
209-
RUN cargo nextest archive --tests --workspace --all-features --archive-file /build/torrust-tracker-debug.tar.zst
231+
RUN cargo nextest archive --tests --workspace --all-features \
232+
--exclude workspace-coupling \
233+
--exclude torrust-tracker-torrent-repository-benchmarking \
234+
--archive-file /build/torrust-tracker-debug.tar.zst
210235

211236
## Build Archive (release)
212237
FROM dependencies AS build
213238
WORKDIR /build/src
214239
COPY . /build/src
215-
RUN cargo nextest archive --tests --workspace --all-features --archive-file /build/torrust-tracker.tar.zst --release
240+
RUN cargo nextest archive --tests --workspace --all-features \
241+
--exclude workspace-coupling \
242+
--exclude torrust-tracker-torrent-repository-benchmarking \
243+
--archive-file /build/torrust-tracker.tar.zst --release
216244

217245

218246
# Extract and Test (debug)

docs/issues/open/1868-1840-workflow-performance-exclude-irrelevant-workspace-members/ISSUE.md

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@ significantly.
9292

9393
Status values: `TODO`, `IN_PROGRESS`, `BLOCKED`, `DONE`.
9494

95-
| ID | Status | Task | Notes / Expected Output |
96-
| --- | ------ | --------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
97-
| T1 | TODO | Verify `cargo nextest archive` supports `--exclude` | Confirm the flag works for cargo-nextest; check docs and local test. |
98-
| T2 | TODO | Add `--exclude` flags to all Containerfile cargo commands | Six commands: `cargo chef cook` × 2 and `cargo nextest archive` × 4. Both excluded packages named explicitly. |
99-
| T3 | TODO | Decide on `cargo chef prepare` exclusion | Determine if `--exclude` is supported/needed for `cargo chef prepare`. If yes, remove the COPY/stub entries for the two packages from the recipe stage. If no, document why the COPY/stub lines must stay. |
100-
| T4 | TODO | Run full CI build and record timing evidence | CI log showing build time after exclusion. Compare against pre-fix baseline (19m03s build step, 38m total). |
95+
| ID | Status | Task | Notes / Expected Output |
96+
| --- | ------ | ------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
97+
| T1 | DONE | Verify `cargo nextest archive` supports `--exclude` | Confirmed: `--exclude` is standard Cargo package-selection syntax; `cargo nextest archive` passes it through to Cargo. Verified by inspecting cargo-nextest behaviour and Cargo docs. |
98+
| T2 | DONE | Add `--exclude` flags to all `cargo nextest archive` commands in Containerfile | Applied to all 4 `cargo nextest archive` commands. `cargo chef cook` does **not** support `--exclude` (cargo-chef CLI limitation; see T3). Documented with comments in the Containerfile. |
99+
| T3 | DONE | Decide on `cargo chef prepare` exclusion | Neither `cargo chef prepare` nor `cargo chef cook` exposes an `--exclude` flag. The COPY/stub lines for both excluded packages **must stay** so that `cargo metadata` (invoked by `prepare`) can resolve the workspace without missing manifest files. See Containerfile comment and AC4. |
100+
| T4 | TODO | Run full CI build and record timing evidence | CI log showing build time after exclusion. Compare against pre-fix baseline (19m03s build step, 38m total). |
101101

102102
## Progress Tracking
103103

@@ -107,8 +107,8 @@ Status values: `TODO`, `IN_PROGRESS`, `BLOCKED`, `DONE`.
107107
- [x] Spec reviewed and approved by user/maintainer
108108
- [x] GitHub issue created and issue number added to this spec
109109
- [ ] (Optional, recommended for complex issues) Spec-only PR merged into `develop` before implementation
110-
- [ ] Implementation completed
111-
- [ ] Automatic verification completed (`linter all`, relevant tests, and any pre-push checks)
110+
- [x] Implementation completed
111+
- [x] Automatic verification completed (`linter all`, relevant tests, and any pre-push checks)
112112
- [ ] Manual verification scenarios executed and recorded (status + evidence)
113113
- [ ] Acceptance criteria reviewed after implementation and updated with evidence
114114
- [ ] Reviewer validated acceptance criteria and updated checkboxes
@@ -119,15 +119,16 @@ Status values: `TODO`, `IN_PROGRESS`, `BLOCKED`, `DONE`.
119119

120120
- 2026-06-03 00:00 UTC - GitHub Copilot - Drafted issue spec based on post-merge CI analysis of #1853 - draft file created
121121
- 2026-06-03 00:00 UTC - GitHub Copilot - Narrowed scope to `--exclude` fix only; layer split analysis moved to dependency-layer-cache-reuse draft - draft updated
122+
- 2026-06-03 00:00 UTC - GitHub Copilot - Implemented: added `--exclude workspace-coupling --exclude torrust-tracker-torrent-repository-benchmarking` to all 4 `cargo nextest archive` commands in Containerfile; investigated and documented that `cargo chef cook` and `cargo chef prepare` do not support `--exclude` (cargo-chef CLI limitation); COPY/stub lines for excluded packages retained in recipe stage because `cargo chef prepare` invokes `cargo metadata` which requires all workspace manifests to be present
122123

123124
## Acceptance Criteria
124125

125126
- [ ] AC1: `workspace-coupling` and `torrust-tracker-torrent-repository-benchmarking` do not appear in the container build compilation output.
126127
- [ ] AC2: The final `cargo nextest archive` step in the CI build completes in measurably less time than the 19m03s baseline recorded after #1853.
127128
- [ ] AC3: The tracker runtime image is produced correctly and all unit tests still pass inside the container build.
128-
- [ ] AC4: The decision on `cargo chef prepare` exclusion is documented with rationale (either in the Containerfile comments or in this spec).
129-
- [ ] `linter all` exits with code `0`
130-
- [ ] Relevant tests pass
129+
- [x] AC4: The decision on `cargo chef prepare` and `cargo chef cook` exclusion is documented: neither tool exposes `--exclude` in its CLI (cargo-chef limitation). `cargo chef prepare` uses `cargo metadata` internally, which requires every workspace member's manifest to exist on disk — the COPY/stub lines for the excluded packages are therefore retained in the recipe stage. `cargo chef cook` similarly has no `--exclude` flag; the exclusion is achieved entirely through the 4 `cargo nextest archive` commands where standard Cargo `--exclude` is supported. This is documented in Containerfile comments.
130+
- [x] `linter all` exits with code `0`
131+
- [x] Relevant tests pass
131132
- [ ] Manual verification scenarios are executed and documented (status + evidence)
132133
- [ ] Acceptance criteria are re-reviewed after implementation and reflect actual behavior
133134
- [ ] Documentation is updated when behavior/workflow changes
@@ -154,12 +155,12 @@ Status values: `TODO`, `IN_PROGRESS`, `DONE`, `FAILED`, `BLOCKED`.
154155

155156
### Acceptance Verification
156157

157-
| AC ID | Status (`TODO`/`DONE`) | Evidence |
158-
| ----- | ---------------------- | ------------------------------------ |
159-
| AC1 | TODO | {CI log link} |
160-
| AC2 | TODO | {timing comparison} |
161-
| AC3 | TODO | {CI test stage log} |
162-
| AC4 | TODO | {Containerfile comment or spec note} |
158+
| AC ID | Status (`TODO`/`DONE`) | Evidence |
159+
| ----- | ---------------------- | ----------------------------------------------------------------------------------- |
160+
| AC1 | TODO | {CI log link} |
161+
| AC2 | TODO | {timing comparison} |
162+
| AC3 | TODO | {CI test stage log} |
163+
| AC4 | DONE | See AC4 text above and Containerfile comments in the Cook (debug) and recipe stages |
163164

164165
## Risks and Trade-offs
165166

0 commit comments

Comments
 (0)