From 914c320799717d34a76ef8fa066bacfea3275b59 Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Sat, 21 Nov 2026 17:53:31 +0900 Subject: [PATCH 1/2] =?UTF-8?q?ci(main):=20NFS=20nightly=EA=B0=80=20nfs?= =?UTF-8?q?=C2=B7nfsd=20=EB=91=90=20=EB=AA=A8=EB=93=88=EC=9D=84=20?= =?UTF-8?q?=EB=B3=B4=EA=B3=A0=20=EC=8B=A4=ED=8C=A8=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EB=A5=BC=20=EB=82=A8=EA=B8=B4=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 문제: nightly `fileserver-nfs-ambiguity`의 호스트 확인 step은 `/proc/filesystems`에서 `nfsd`만 보고, 실패 안내도 `nfsd`만 올린다. 서버 이미지 erichough/nfs-server 2.2.1의 entrypoint (`init_runtime_assertions`)는 `nfs`와 `nfsd`를 둘 다 요구하고, `nfsd`를 올려도 `nfs`는 따라오지 않는다. 그래서 안내대로 한 호스트는 확인 step을 지나 compose에서 `exited (1)`로 빨강이 된다. 그 이유는 서버 컨테이너 로그에만 있는데, job에는 로그 step이 없고 `if: always()` 정리 step이 `down -v`로 컨테이너를 지운다(run 52·63에서 서버 출력 줄 0). 시험 step은 `--rerun` 없이 빌드 캐시를 쓰는데, `FILESERVER_NFS_TESTS`는 Java가 실행 중에 읽는 env라 태스크 입력이 아니다. fileserver 입력이 같은 두 번째 run은 `FROM-CACHE`로 NFS 없이 초록일 수 있다. 고친 것: - 확인 step이 `for module in nfs nfsd`로 둘 다 보고, 빠진 모듈 이름과 `modprobe -a nfs nfsd`(둘을 주려면 `-a`가 있어야 한다. 없으면 둘째가 첫째의 모듈 인자가 된다) 명령을 찍는다. 주석도 같은 명령. - 시험 step에 `--rerun`. - `if: failure()` step이 `down`보다 앞에서 compose 로그를 찍는다. - `docs/fileserver/storage-certification.md` 「네트워크 파일 시스템」에 호스트 모듈 줄과 `--rerun`(이유 한 줄). - `DeveloperExperienceContractTest`에 시험 셋(tag `repository-contract`, `.gitea/**`는 이미 이 lane의 입력이다): 확인 step의 모듈 목록과 안내 명령의 모듈 목록이 정확히 `nfs`·`nfsd`, 이 job의 Gradle step마다 `--rerun`, compose `logs`를 부르는 `failure()` step이 `down`보다 앞. step 번호나 Gradle을 어디서 부르는지에 기대지 않게 썼다. 버린 안: 확인 step을 지우고 이미지 메시지에 맡기기(로그 step이 생겨도 첫 step이 몇 초 만에 정확한 명령을 주는 편이 낫다). 확인을 scripts/ci/ 스크립트로 빼고 fixture로 시험하기(파일 둘이 늘고, 총괄이 고르지 않음). 위험·한계: job이 실제로 초록이 되는지, 고친 확인 step이 모듈을 올린 호스트에서 통과하는지는 소유자가 호스트에 모듈을 넣은 뒤 nightly에서만 볼 수 있다. compose.yml 머리 주석(11행)의 같은 명령에 `--rerun`이 없지만 그 주석은 QA-BE-0001 몫이라 두었다. 리뷰 반영(종류 B 1회, 렌즈 be-build-ci·be-testing·be-security): - `--rerun`을 shell 낱말로만 봐서 `bash -c "… --rerun"`에서 거짓 실패 → run 전체에서 `(?&2 - echo " echo nfsd | sudo tee /etc/modules-load.d/nfsd.conf && sudo modprobe nfsd" >&2 + missing="" + for module in nfs nfsd; do grep -qw "${module}" /proc/filesystems || missing="${missing} ${module}"; done + [ -z "${missing}" ] || { + echo "fileserver-nfs: the runner host kernel lacks:${missing}; load them on the host:" >&2 + echo " printf 'nfs\\nnfsd\\n' | sudo tee /etc/modules-load.d/nfsd.conf && sudo modprobe -a nfs nfsd" >&2 exit 1 } - uses: ./.gitea/actions/setup-java-gradle - run: docker compose -f src/adapter/outbound/fileserver/compose/nfs/compose.yml up -d --wait - - run: ./gradlew :adapter:outbound:fileserver:test --tests '*NfsAmbiguityIntegrationTest' + # --rerun: FILESERVER_NFS_TESTS is read at run time, not a task input, so without it an + # unchanged fileserver comes back FROM-CACHE and the job is green without touching NFS. + - run: ./gradlew :adapter:outbound:fileserver:test --tests '*NfsAmbiguityIntegrationTest' --rerun + # The compose step says only "exited (1)"; why the server or client stopped is in their logs, + # and the step below removes the containers. + - if: ${{ failure() }} + run: docker compose -f src/adapter/outbound/fileserver/compose/nfs/compose.yml logs --no-color --timestamps - if: ${{ always() }} run: docker compose -f src/adapter/outbound/fileserver/compose/nfs/compose.yml down -v diff --git a/docs/fileserver/storage-certification.md b/docs/fileserver/storage-certification.md index 34638589..7582a973 100644 --- a/docs/fileserver/storage-certification.md +++ b/docs/fileserver/storage-certification.md @@ -46,11 +46,18 @@ ## 네트워크 파일 시스템 +호스트 커널에 `nfs`·`nfsd` 모듈이 둘 다 올라와 있어야 한다. 서버 이미지는 둘 중 하나라도 없으면 바로 +끝나고, `nfsd`를 올려도 `nfs`는 따라오지 않는다. 올리는 명령은 `.gitea/workflows/main.yml` +`fileserver-nfs-ambiguity` job 주석과 같다. + ```bash docker compose -f src/adapter/outbound/fileserver/compose/nfs/compose.yml up -d -FILESERVER_NFS_TESTS=true ./gradlew :adapter:outbound:fileserver:test +FILESERVER_NFS_TESTS=true ./gradlew :adapter:outbound:fileserver:test --rerun ``` +`--rerun`을 붙이는 이유: `FILESERVER_NFS_TESTS`는 시험이 실행 중에 읽는 환경 변수라 태스크 입력이 아니다. env +없이 한 번 돈 뒤 env를 켜고 다시 돌면 태스크가 `UP-TO-DATE`로 끝나 NFS 시험이 돌지 않는다. + mount는 일부러 `hard`다. `soft` mount는 느린 서버를 짧게 끝난 쓰기로 바꾼다. 이 설계가 받아들이지 않는 바로 그 손상이다. diff --git a/src/bootstrap/app/src/test/java/dev/caskeleton/bootstrap/contract/DeveloperExperienceContractTest.java b/src/bootstrap/app/src/test/java/dev/caskeleton/bootstrap/contract/DeveloperExperienceContractTest.java index daba9568..e3c8fb63 100644 --- a/src/bootstrap/app/src/test/java/dev/caskeleton/bootstrap/contract/DeveloperExperienceContractTest.java +++ b/src/bootstrap/app/src/test/java/dev/caskeleton/bootstrap/contract/DeveloperExperienceContractTest.java @@ -41,6 +41,12 @@ class DeveloperExperienceContractTest { private static final String MAIN_WORKFLOW = ".gitea/workflows/main.yml"; private static final String RELEASE_WORKFLOW = ".gitea/workflows/release.yml"; + /** The nightly job that runs the fileserver tests against a real NFS server, and its Compose. */ + private static final String NFS_JOB = "fileserver-nfs-ambiguity"; + + private static final String NFS_COMPOSE = + "src/adapter/outbound/fileserver/compose/nfs/compose.yml"; + // The workflow-mutation fixtures that stood here are gone with the tests that used them: a // hex-escaped `uses:`, a line-continued action reference, a `run:` block impersonating a // validation step, a bare `if: always()` versus the guarded form, a gate-matrix step. Every one @@ -351,6 +357,92 @@ class DeveloperExperienceContractTest { .noneMatch(step -> step instanceof Map map && map.containsKey("uses")); } + @Test + @Tag("repository-contract") + @DisplayName("NFS nightly의 호스트 확인 step은 서버 이미지가 요구하는 nfs·nfsd 두 모듈을 다 보고, 둘 다 올리는 명령을 안내한다") + void nfsHostCheckLooksForBothModulesTheServerImageRequires() throws IOException { + // given + Pattern moduleLoop = Pattern.compile("\\bfor\\s+\\w+\\s+in\\s+([^;\\n]+?)\\s*;\\s*do\\b"); + Pattern loadHint = Pattern.compile("\\bmodprobe\\s+-a((?:\\s+[\\w-]+)+)"); + Pattern bootList = + Pattern.compile("\\bprintf\\s+'([^']*)'\\s*\\|\\s*sudo\\s+tee\\s+/etc/modules-load\\.d/"); + + // when + List checks = + nfsJobSteps().stream() + .map(DeveloperExperienceContractTest::stepRun) + .filter(run -> run.contains("/proc/filesystems")) + .toList(); + + // then + assertThat(checks) + .as("the one step that reads /proc/filesystems") + .singleElement() + .satisfies( + check -> { + assertThat(wordsMatchedBy(moduleLoop, check)) + .as("the modules the check looks for") + .containsExactlyInAnyOrder("nfs", "nfsd"); + assertThat(wordsMatchedBy(loadHint, check)) + .as("the modules the printed command loads now") + .containsExactlyInAnyOrder("nfs", "nfsd"); + assertThat(printfLines(groupMatchedBy(bootList, check))) + .as("the modules the printed command loads at every boot") + .containsExactlyInAnyOrder("nfs", "nfsd"); + }); + } + + @Test + @Tag("repository-contract") + @DisplayName( + "NFS nightly의 Gradle step은 --rerun으로 돈다: FILESERVER_NFS_TESTS는 태스크 입력이 아니어서, --rerun이 없으면 캐시가 NFS 없이 초록을 돌려준다") + void nfsJobRerunsItsTestsInsteadOfTakingThemFromTheBuildCache() throws IOException { + // The flag as a whole word anywhere in the script, so a Gradle call wrapped in a container's + // `bash -c "…"` still counts. + Pattern rerun = Pattern.compile("(? gradleRuns = + nfsJobSteps().stream() + .map(DeveloperExperienceContractTest::stepRun) + .filter(run -> run.contains("gradlew")) + .toList(); + + assertThat(gradleRuns) + .as("the steps that run the NFS tests with Gradle") + .isNotEmpty() + .allSatisfy(run -> assertThat(run).as(run).containsPattern(rerun)); + } + + @Test + @Tag("repository-contract") + @DisplayName("NFS nightly는 실패하면 컨테이너를 지우는 down step보다 먼저 compose 로그를 남긴다") + void nfsJobPrintsTheComposeLogsOnFailureBeforeRemovingTheContainers() throws IOException { + // given + List> composeSteps = + nfsJobSteps().stream() + .filter(step -> scriptWords(stepRun(step)).contains(NFS_COMPOSE)) + .toList(); + + // when + List subcommands = + composeSteps.stream().map(step -> composeSubcommand(stepRun(step))).toList(); + List logsConditions = + composeSteps.stream() + .filter(step -> composeSubcommand(stepRun(step)).equals("logs")) + .map(step -> String.valueOf(step.get("if"))) + .toList(); + + // then + assertThat(subcommands) + .as("what the job asks %s to do, in order", NFS_COMPOSE) + .containsSubsequence("logs", "down"); + assertThat(logsConditions) + .as("the logs step runs when an earlier step failed") + .singleElement() + .asString() + .contains("failure()"); + } + @Test @Tag("repository-contract") @DisplayName("compose 종료 유예 시간은 웹 drain, async 대기, preStop, 여유를 모두 더한 값 이상이다") @@ -601,6 +693,48 @@ class DeveloperExperienceContractTest { return (String) value; } + private static List> nfsJobSteps() throws IOException { + Map job = requireMap(requireMap(parseYamlMap(read(MAIN_WORKFLOW)), "jobs"), NFS_JOB); + return requireList(job, "steps").stream().>map(step -> (Map) step).toList(); + } + + /** A step's shell script, or "" for a step that uses an action. */ + private static String stepRun(Map step) { + return step.get("run") instanceof String run ? run : ""; + } + + /** The word after the NFS Compose file in a {@code docker compose -f } run. */ + private static String composeSubcommand(String run) { + List words = scriptWords(run); + int file = words.indexOf(NFS_COMPOSE); + return file >= 0 && file + 1 < words.size() ? words.get(file + 1) : ""; + } + + /** The first group the pattern captures in {@code text}; fails when it does not match. */ + private static String groupMatchedBy(Pattern pattern, String text) { + Matcher matcher = pattern.matcher(text); + assertThat(matcher.find()).as("%s in:%n%s", pattern, text).isTrue(); + return matcher.group(1); + } + + /** The shell words of the first group the pattern captures in {@code text}. */ + private static List wordsMatchedBy(Pattern pattern, String text) { + return shellWords(groupMatchedBy(pattern, text)); + } + + /** The lines a printf format prints, its {@code \n} written with one or more backslashes. */ + private static List printfLines(String format) { + return Pattern.compile("(?:\\\\+n|\\s)+") + .splitAsStream(format) + .filter(line -> !line.isEmpty()) + .toList(); + } + + /** The shell words of a step script, its backslash-newline continuations joined first. */ + private static List scriptWords(String run) { + return shellWords(run.replace("\\\n", " ")); + } + private static List shellWords(String arguments) { return Pattern.compile("\\s+") .splitAsStream(arguments.trim()) -- 2.54.0 From 2b1b162611f5fe1857db6ec3d03c2371af78f9e2 Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Sat, 21 Nov 2026 17:53:31 +0900 Subject: [PATCH 2/2] =?UTF-8?q?build(compose):=20nightly=EA=B0=80=20?= =?UTF-8?q?=EB=9D=84=EC=9A=B0=EB=8A=94=20NFS=20compose=20=EC=9D=B4?= =?UTF-8?q?=EB=AF=B8=EC=A7=80=EB=A5=BC=20digest=EB=A1=9C=20=EA=B3=A0?= =?UTF-8?q?=EC=A0=95=ED=95=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 문제: nightly `fileserver-nfs-ambiguity`가 `docker compose -f`로 띄우는 `src/adapter/outbound/fileserver/compose/nfs/compose.yml`의 이미지 둘이 digest 없는 tag다(`erichough/nfs-server:2.2.1`, `eclipse-temurin:21-jdk`). 둘 다 `privileged: true`다. runner dind는 캐시에 있는 tag를 다시 받지 않아서, 같은 commit에서도 캐시가 남은 runner와 새 runner가 다른 client를 띄운다(desktop dind의 21-jdk는 10-29 빌드, 레지스트리는 11-20 빌드). nfs-server는 제3자 개인 계정 이미지라 tag가 다시 push되면 캐시가 빈 뒤 첫 run에서 바뀐 이미지가 privileged로 뜬다. 또 `repositoryContractTest`의 입력에 `src/adapter/outbound/*/compose/**`가 없어서, 이 compose만 바꾼 PR은 그 lane이 main 캐시로 FROM-CACHE가 되어 시험이 돌지 않는다. 고친 것: - 두 이미지를 `tag@sha256:`로. 값은 레지스트리에서 읽었다 (2026-11-21 17:29 KST, desktop `docker buildx imagetools inspect`): nfs-server:2.2.1 `1efd4ece…`(manifest v2, 2020-02-07 뒤 그대로), 21-jdk `8ad118b1…`(OCI index). client는 tag를 바꾸지 않았다 (`-noble`은 OS가 24.04로 바뀐다). - `repositoryContractInputs`에 `src/adapter/outbound/*/compose/**`. - `DeveloperExperienceContractTest`에 시험 하나(tag `repository-contract`): `.gitea/workflows/*`·`.gitea/actions/*/action.yml` 의 step `run`에서 `docker compose`의 전역 옵션 `-f`/`--file`이 가리키는 파일마다 모든 `image:` 줄이 `@sha256:` 64자로 끝난다. 그런 파일이 하나도 없으면 실패한다(빈 범위로 초록이 되지 않게). 버린 안: 그대로 두기(제3자 privileged 이미지라 실행 뒤 digest를 남기는 행렬 예외에 맞지 않는다). Renovate 같은 자동 갱신(이 repo에 장치가 없다). 위험·한계: digest를 올리는 일은 사람이 한다. 스크립트가 띄우는 compose(redis 행렬), 루트 `compose.yaml`, compose-lanes의 tag는 이 시험 범위 밖이다. client 이미지를 `nfs-common`이 든 것으로 바꾸는 일은 QA-BE-0001 몫이고, 그때도 이 시험이 그 이미지에 digest를 요구한다. 리뷰 반영(종류 B 1회, 렌즈 be-build-ci·be-testing·be-security): - `docker compose \` 줄 이음 뒤 `-f`를 놓침 → compose 파일을 찾을 때도 백슬래시-줄바꿈을 먼저 잇는다. - `build.gradle` 주석 문구. 검증(desktop 공유 잠금, detached worktree): - RED: base 3bfefe69(트리 dfae7dc4) + 새 시험 파일(트리 fee22e62)에서 `./gradlew :app-bootstrap:repositoryContractTest --tests 'dev.caskeleton.bootstrap.contract.DeveloperExperienceContractTest' --no-build-cache` rc=1. digest 시험이 `19: image: erichough/nfs-server:2.2.1`·`39: image: eclipse-temurin:21-jdk`로 실패. - GREEN 트리 d8fc8e09: `:app-bootstrap:repositoryContractTest --no-build-cache` rc=0(65개, skip 1), `:app-bootstrap:testQualityCheck` rc=0. - 변이: `-f` 뒤에 줄 이음으로 `-f compose.yaml`을 더하면 rc=1(시험이 `compose.yaml`의 tag 이미지를 든다). - 빌드 캐시를 켜고(`--build-cache`) 이 트리로 lane을 한 번 돌려 채운 뒤 client 줄의 `@sha256:…`만 지우면 태스크가 실행되고 FAILED rc=1. 대조: include 한 줄을 뺀 트리에서 같은 순서면 `UP-TO-DATE` rc=0. - 트리 d8fc8e09: desktop `scripts/verify.sh leaf :app-bootstrap --no-cache` rc=0(334개), `scripts/verify.sh pr --no-cache` rc=0 (7343개, 실패 0, skip 35), 노트북 `scripts/verify.sh docs` rc=0. Refs: CI-BE-0008 --- .../fileserver/compose/nfs/compose.yml | 4 +- src/bootstrap/app/build.gradle | 2 + .../DeveloperExperienceContractTest.java | 121 ++++++++++++++++++ 3 files changed, 125 insertions(+), 2 deletions(-) diff --git a/src/adapter/outbound/fileserver/compose/nfs/compose.yml b/src/adapter/outbound/fileserver/compose/nfs/compose.yml index b34eba6f..e38c5dd8 100644 --- a/src/adapter/outbound/fileserver/compose/nfs/compose.yml +++ b/src/adapter/outbound/fileserver/compose/nfs/compose.yml @@ -16,7 +16,7 @@ services: nfs-server: - image: erichough/nfs-server:2.2.1 + image: erichough/nfs-server:2.2.1@sha256:1efd4ece380c5ba27479417585224ef857006daa46ab84560a28c1224bc71e9e container_name: fileserver-nfs-server privileged: true environment: @@ -36,7 +36,7 @@ services: retries: 10 nfs-client: - image: eclipse-temurin:21-jdk + image: eclipse-temurin:21-jdk@sha256:8ad118b146aa92da815b576441acd6b42b38236797ad0b6edc8c200b85bb0734 container_name: fileserver-nfs-client privileged: true depends_on: diff --git a/src/bootstrap/app/build.gradle b/src/bootstrap/app/build.gradle index e7e93770..16068210 100644 --- a/src/bootstrap/app/build.gradle +++ b/src/bootstrap/app/build.gradle @@ -376,6 +376,8 @@ def repositoryContractInputs = files( include 'src/bootstrap/app/compose-lanes/**' // The release data a capability leaf owns (readiness cards, release registries). include 'src/adapter/outbound/*/release/**' + // The Compose files outbound leaves keep; workflow steps start some with `-f` (digests). + include 'src/adapter/outbound/*/compose/**' exclude '**/*.md' exclude repositoryContractExcludes }) diff --git a/src/bootstrap/app/src/test/java/dev/caskeleton/bootstrap/contract/DeveloperExperienceContractTest.java b/src/bootstrap/app/src/test/java/dev/caskeleton/bootstrap/contract/DeveloperExperienceContractTest.java index e3c8fb63..44d552a1 100644 --- a/src/bootstrap/app/src/test/java/dev/caskeleton/bootstrap/contract/DeveloperExperienceContractTest.java +++ b/src/bootstrap/app/src/test/java/dev/caskeleton/bootstrap/contract/DeveloperExperienceContractTest.java @@ -9,10 +9,15 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.time.Duration; +import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Set; +import java.util.TreeMap; +import java.util.TreeSet; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.stream.Stream; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; @@ -47,6 +52,24 @@ class DeveloperExperienceContractTest { private static final String NFS_COMPOSE = "src/adapter/outbound/fileserver/compose/nfs/compose.yml"; + /** Compose's global options that take a value: the subcommand is the first word after them. */ + private static final Set COMPOSE_OPTIONS_WITH_A_VALUE = + Set.of( + "-f", + "--file", + "-p", + "--project-name", + "--project-directory", + "--env-file", + "--profile", + "--ansi", + "--progress", + "--parallel"); + + private static final Pattern COMPOSE_IMAGE_LINE = + Pattern.compile("^\\s*image:\\s*[\"']?([^\"'\\s#]+)"); + private static final Pattern IMAGE_DIGEST = Pattern.compile("@sha256:[0-9a-f]{64}$"); + // The workflow-mutation fixtures that stood here are gone with the tests that used them: a // hex-escaped `uses:`, a line-continued action reference, a `run:` block impersonating a // validation step, a bare `if: always()` versus the guarded form, a gate-matrix step. Every one @@ -443,6 +466,24 @@ class DeveloperExperienceContractTest { .contains("failure()"); } + @Test + @Tag("repository-contract") + @DisplayName("workflow step이 docker compose -f로 띄우는 compose 파일의 image는 모두 sha256 digest로 고정한다") + void composeFilesAWorkflowStepStartsPinEveryImageByDigest() throws IOException { + // given + Set composeFiles = composeFilesStartedByWorkflowSteps(); + + // when + Map> unpinned = imagesWithoutADigest(composeFiles); + + // then + assertThat(unpinned) + .as( + "the Compose files workflow steps start with -f, each with its image lines lacking a digest") + .isNotEmpty() + .allSatisfy((file, images) -> assertThat(images).as(file).isEmpty()); + } + @Test @Tag("repository-contract") @DisplayName("compose 종료 유예 시간은 웹 drain, async 대기, preStop, 여유를 모두 더한 값 이상이다") @@ -710,6 +751,86 @@ class DeveloperExperienceContractTest { return file >= 0 && file + 1 < words.size() ? words.get(file + 1) : ""; } + /** + * Every file a {@code docker compose -f } names in a step of {@code .gitea/workflows/*} or + * {@code .gitea/actions//action.yml}. Compose a script starts is not one of them. + */ + private static Set composeFilesStartedByWorkflowSteps() throws IOException { + List definitions = new ArrayList<>(); + try (Stream workflows = Files.list(REPOSITORY_ROOT.resolve(".gitea/workflows"))) { + workflows.filter(path -> path.toString().matches(".*\\.ya?ml")).forEach(definitions::add); + } + try (Stream actions = Files.list(REPOSITORY_ROOT.resolve(".gitea/actions"))) { + actions + .flatMap(action -> Stream.of(action.resolve("action.yml"), action.resolve("action.yaml"))) + .filter(Files::isRegularFile) + .forEach(definitions::add); + } + Set files = new TreeSet<>(); + for (Path definition : definitions) { + stepRuns(parseYamlMap(Files.readString(definition))) + .forEach(run -> files.addAll(composeFilesNamedIn(run))); + } + return files; + } + + /** Every {@code run:} script anywhere in a parsed workflow or action. */ + private static Stream stepRuns(Object node) { + if (node instanceof Map map) { + return map.entrySet().stream() + .flatMap( + entry -> + "run".equals(entry.getKey()) && entry.getValue() instanceof String run + ? Stream.of(run) + : stepRuns(entry.getValue())); + } + return node instanceof List list + ? list.stream().flatMap(DeveloperExperienceContractTest::stepRuns) + : Stream.empty(); + } + + /** The {@code -f}/{@code --file} values among the global options of each docker compose call. */ + private static List composeFilesNamedIn(String run) { + List words = scriptWords(run); + List files = new ArrayList<>(); + for (int docker = 0; docker + 1 < words.size(); docker++) { + if (!words.get(docker).equals("docker") || !words.get(docker + 1).equals("compose")) { + continue; + } + int next = docker + 2; + while (next < words.size() && words.get(next).startsWith("-")) { + String option = words.get(next++); + if (option.startsWith("--file=")) { + files.add(option.substring("--file=".length())); + } else if (COMPOSE_OPTIONS_WITH_A_VALUE.contains(option) && next < words.size()) { + String value = words.get(next++); + if (option.equals("-f") || option.equals("--file")) { + files.add(value); + } + } + } + } + return files; + } + + /** Per Compose file, its {@code image:} lines (numbered) whose reference has no digest. */ + private static Map> imagesWithoutADigest(Set composeFiles) + throws IOException { + Map> unpinned = new TreeMap<>(); + for (String file : composeFiles) { + List lines = read(file).lines().toList(); + List withoutDigest = new ArrayList<>(); + for (int line = 0; line < lines.size(); line++) { + Matcher image = COMPOSE_IMAGE_LINE.matcher(lines.get(line)); + if (image.find() && !IMAGE_DIGEST.matcher(image.group(1)).find()) { + withoutDigest.add((line + 1) + ": " + lines.get(line).trim()); + } + } + unpinned.put(file, withoutDigest); + } + return unpinned; + } + /** The first group the pattern captures in {@code text}; fails when it does not match. */ private static String groupMatchedBy(Pattern pattern, String text) { Matcher matcher = pattern.matcher(text); -- 2.54.0