Skip to content

Commit a9dcd36

Browse files
committed
feat: run container as non-root
- also update gha setup to reflect this change - differentiate between build and test of the container Signed-off-by: Robert Waffen <[email protected]>
1 parent 39a197d commit a9dcd36

File tree

2 files changed

+48
-10
lines changed

2 files changed

+48
-10
lines changed

.github/workflows/ci.yaml

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,15 @@ jobs:
3737
- name: Checkout repository
3838
uses: actions/checkout@v4
3939

40+
- name: Set up Docker Buildx
41+
uses: docker/setup-buildx-action@v3
42+
4043
- name: Build image
4144
uses: docker/build-push-action@v6
4245
with:
4346
tags: 'ci/voxbox-${{ matrix.rubygem_puppet }}:${{ github.sha }}'
4447
push: false
48+
outputs: type=docker,dest=/tmp/voxbox-${{ matrix.rubygem_puppet }}_${{ github.sha }}.tar
4549
build-args: |
4650
BASE_IMAGE=${{ matrix.base_image }}
4751
RUBYGEM_PUPPET=${{ matrix.rubygem_puppet }}
@@ -53,6 +57,12 @@ jobs:
5357
RUBYGEM_OVERCOMMIT=${{ matrix.rubygem_overcommit }}
5458
RUBYGEM_MODULESYNC=${{ matrix.rubygem_modulesync }}
5559
60+
- name: Upload voxbox-${{ matrix.rubygem_puppet }}_${{ github.sha }}.tar
61+
uses: actions/upload-artifact@v4
62+
with:
63+
name: voxbox-${{ matrix.rubygem_puppet }}_${{ github.sha }}
64+
path: /tmp/voxbox-${{ matrix.rubygem_puppet }}_${{ github.sha }}.tar
65+
5666
- name: Login to Docker Hub
5767
uses: docker/login-action@v3
5868
with:
@@ -64,36 +74,61 @@ jobs:
6474
uses: docker/scout-action@v1
6575
with:
6676
command: cves
67-
image: 'local://ci/voxbox-${{ matrix.rubygem_puppet }}:${{ github.sha }}'
77+
image: 'archive:///tmp/voxbox-${{ matrix.rubygem_puppet }}_${{ github.sha }}.tar'
6878
sarif-file: sarif.output.${{ matrix.rubygem_puppet }}.${{ github.sha }}.json
6979
summary: true
7080

7181
- name: Upload SARIF result
7282
id: upload-sarif
7383
uses: github/codeql-action/upload-sarif@v3
7484
with:
85+
category: ${{ matrix.rubygem_puppet }}
7586
sarif_file: sarif.output.${{ matrix.rubygem_puppet }}.${{ github.sha }}.json
7687

88+
test_ci_container:
89+
name: 'Test CI container'
90+
runs-on: ubuntu-latest
91+
needs:
92+
- setup-matrix
93+
- build_test_container
94+
strategy:
95+
matrix: ${{ fromJson(needs.setup-matrix.outputs.matrix) }}
96+
steps:
97+
- name: Set up Docker Buildx
98+
uses: docker/setup-buildx-action@v3
99+
100+
- name: Download artifact
101+
uses: actions/download-artifact@v4
102+
with:
103+
name: voxbox-${{ matrix.rubygem_puppet }}_${{ github.sha }}
104+
path: /tmp
105+
106+
- name: Load Docker image
107+
run: |
108+
docker load --input /tmp/voxbox-${{ matrix.rubygem_puppet }}_${{ github.sha }}.tar
109+
docker image ls -a
110+
77111
- name: Clone voxpupuli/puppet-example repository
78112
uses: actions/checkout@v4
79113
with:
80114
repository: voxpupuli/puppet-example
81115

82116
- name: Test container
83117
run: |
84-
docker run --rm -v $(pwd):/repo ci/voxbox-${{ matrix.rubygem_puppet }}:${{ github.sha }} -f /Rakefile -T
85-
docker run --rm -v $(pwd):/repo ci/voxbox-${{ matrix.rubygem_puppet }}:${{ github.sha }} -f /Rakefile lint
86-
docker run --rm -v $(pwd):/repo ci/voxbox-${{ matrix.rubygem_puppet }}:${{ github.sha }} -f /Rakefile metadata_lint
87-
docker run --rm -v $(pwd):/repo ci/voxbox-${{ matrix.rubygem_puppet }}:${{ github.sha }} -f /Rakefile strings:validate:reference
88-
docker run --rm -v $(pwd):/repo ci/voxbox-${{ matrix.rubygem_puppet }}:${{ github.sha }} -f /Rakefile rubocop
89-
docker run --rm -v $(pwd):/repo ci/voxbox-${{ matrix.rubygem_puppet }}:${{ github.sha }} -f /Rakefile syntax
90-
docker run --rm -v $(pwd):/repo ci/voxbox-${{ matrix.rubygem_puppet }}:${{ github.sha }} -f /Rakefile spec
91-
docker run --rm -v $(pwd):/repo ci/voxbox-${{ matrix.rubygem_puppet }}:${{ github.sha }} -f /Rakefile r10k:syntax
92-
docker run --rm -v $(pwd):/repo ci/voxbox-${{ matrix.rubygem_puppet }}:${{ github.sha }} -f /Rakefile r10k:dependencies
118+
docker run --user 1001 --rm -v $(pwd):/repo ci/voxbox-${{ matrix.rubygem_puppet }}:${{ github.sha }} -f /Rakefile -T
119+
docker run --user 1001 --rm -v $(pwd):/repo ci/voxbox-${{ matrix.rubygem_puppet }}:${{ github.sha }} -f /Rakefile lint
120+
docker run --user 1001 --rm -v $(pwd):/repo ci/voxbox-${{ matrix.rubygem_puppet }}:${{ github.sha }} -f /Rakefile metadata_lint
121+
docker run --user 1001 --rm -v $(pwd):/repo ci/voxbox-${{ matrix.rubygem_puppet }}:${{ github.sha }} -f /Rakefile strings:validate:reference
122+
docker run --user 1001 --rm -v $(pwd):/repo ci/voxbox-${{ matrix.rubygem_puppet }}:${{ github.sha }} -f /Rakefile rubocop
123+
docker run --user 1001 --rm -v $(pwd):/repo ci/voxbox-${{ matrix.rubygem_puppet }}:${{ github.sha }} -f /Rakefile syntax
124+
docker run --user 1001 --rm -v $(pwd):/repo ci/voxbox-${{ matrix.rubygem_puppet }}:${{ github.sha }} -f /Rakefile spec
125+
docker run --user 1001 --rm -v $(pwd):/repo ci/voxbox-${{ matrix.rubygem_puppet }}:${{ github.sha }} -f /Rakefile r10k:syntax
126+
docker run --user 1001 --rm -v $(pwd):/repo ci/voxbox-${{ matrix.rubygem_puppet }}:${{ github.sha }} -f /Rakefile r10k:dependencies
93127
94128
tests:
95129
needs:
96130
- build_test_container
131+
- test_ci_container
97132
runs-on: ubuntu-latest
98133
name: Test suite
99134
steps:

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,8 @@ RUN apk update \
6060

6161
WORKDIR /repo
6262

63+
RUN addgroup -S voxbox && adduser -S voxbox -G voxbox
64+
USER voxbox
65+
6366
ENTRYPOINT [ "rake" ]
6467
CMD [ "-f", "/Rakefile", "-T" ]

0 commit comments

Comments
 (0)