Skip to content

Commit a5d3ec4

Browse files
authored
🌱 Setup CI workflow to use same container as Dockerfile (#1804)
Lookup the "FROM .* as builder" image from the project's Dockerfile, and use that image to run the CI unit-test job. This will ensure the unit-test job is using the same container image that the image builds will be using. A problem with the container should show up quickly in the unit-testing. Signed-off-by: Scott J Dickerson <[email protected]>
1 parent 14f4fc6 commit a5d3ec4

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

.github/workflows/ci-repo.yml

+22-13
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,40 @@ on:
1010
- "main"
1111
- "release-*"
1212

13-
env:
14-
# Note: This should match the node version(s) used in the base Dockerfile
15-
node-version: "18"
16-
1713
jobs:
14+
unit-test-lookup-image:
15+
runs-on: ubuntu-latest
16+
outputs:
17+
builder-image: ${{ steps.grepBuilder.outputs.builder }}
18+
steps:
19+
- uses: actions/checkout@v4
20+
- name: Lookup builder image from the project's Dockerfile
21+
id: grepBuilder
22+
run: |
23+
builder=$(grep 'as builder' Dockerfile | sed -e 's/^FROM \(.*\) as builder$/\1/')
24+
echo "Builder image: \`$builder\`" >> "$GITHUB_STEP_SUMMARY"
25+
echo "builder=$builder" >> "$GITHUB_OUTPUT"
26+
1827
unit-test:
1928
runs-on: ubuntu-latest
29+
needs: unit-test-lookup-image
30+
31+
# Use the same container as the Dockerfile's "FROM * as builder"
32+
container: ${{ needs.unit-test-lookup-image.outputs.builder-image }}
2033

2134
steps:
2235
- uses: actions/checkout@v4
2336

24-
- name: Use Node.js (version "${{ env.node-version }}")
25-
uses: actions/setup-node@v4
26-
with:
27-
node-version: ${{ env.node-version }}
28-
cache: "npm"
29-
30-
- name: Force install npm@9 to match Dockerfile build container ubi9/nodejs-18:1-88
31-
run: npm install -g npm@9
37+
# TODO: Setup a cache for npm so it could install faster
38+
# follow actions/setup-node@v4 techniques
3239

3340
- name: Verify package-lock.json
3441
run: ./scripts/verify_lock.mjs
3542

3643
- name: Install
37-
run: npm clean-install --ignore-scripts
44+
run: |
45+
npm version
46+
npm clean-install --ignore-scripts
3847
3948
- name: Lint sources
4049
run: npm run lint

0 commit comments

Comments
 (0)