Skip to content

Commit cc61f25

Browse files
Copilotneilime
andcommitted
Add structure-test stage to Dockerfile for local builds
Co-authored-by: neilime <[email protected]> Signed-off-by: Emilien Escalle <[email protected]>
1 parent b6d8c26 commit cc61f25

File tree

6 files changed

+121
-80
lines changed

6 files changed

+121
-80
lines changed

.github/workflows/continuous-integration.md

Lines changed: 87 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# GitHub Reusable Workflow: Continuous Integration
44

55
<div align="center">
6-
<img src="https://opengraph.githubassets.com/9565476f005871806c94e4706c94afdf476b35461ae854e19f08f3eb4fcacbfb/hoverkraft-tech/docker-base-images" width="60px" align="center" alt="Continuous Integration" />
6+
<img src="https://opengraph.githubassets.com/191c96d965ceddaf21e28c8a52675eacb1b222318078b5d408067303106d0b60/hoverkraft-tech/docker-base-images" width="60px" align="center" alt="Continuous Integration" />
77
</div>
88

99
---
@@ -42,6 +42,42 @@ A comprehensive CI workflow that performs linting, builds Docker images, and run
4242
- **`statuses`**: `write`
4343

4444
<!-- overview:end -->
45+
46+
## Testing
47+
48+
Tests are defined in `images/<image-name>/container-structure-test.yaml` using [container-structure-test](https://github.com/GoogleContainerTools/container-structure-test).
49+
50+
### Test Configuration
51+
52+
Each image can have a `container-structure-test.yaml` file with:
53+
54+
- `commandTests` - Verify commands run correctly in the container
55+
- `fileExistenceTests` - Check files/directories exist
56+
- `fileContentTests` - Verify file contents
57+
- `metadataTest` - Validate container metadata (env vars, user, workdir, etc.)
58+
59+
### Example Test Configuration
60+
61+
```yaml
62+
schemaVersion: "2.0.0"
63+
64+
commandTests:
65+
- name: "helm is installed"
66+
command: "helm"
67+
args: ["version"]
68+
exitCode: 0
69+
70+
fileExistenceTests:
71+
- name: "script exists"
72+
path: "/usr/local/bin/script.sh"
73+
shouldExist: true
74+
isExecutableBy: "any"
75+
76+
metadataTest:
77+
user: "appuser"
78+
workdir: "/app"
79+
```
80+
4581
<!-- usage:start -->
4682
4783
## Usage
@@ -54,22 +90,13 @@ on:
5490
- main
5591
permissions: {}
5692
jobs:
57-
ci:
58-
uses: hoverkraft-tech/docker-base-images/.github/workflows/continuous-integration.yml@main
59-
permissions:
60-
actions: read
61-
contents: read
62-
id-token: write
63-
issues: read
64-
packages: write
65-
pull-requests: write
66-
security-events: write
67-
statuses: write
93+
continuous-integration:
94+
uses: hoverkraft-tech/docker-base-images/.github/workflows/continuous-integration.yml@67e15e3bc73162a931c72f3eb1e16c862b338e16 # 0.1.3
95+
permissions: {}
6896
secrets:
69-
# Password or GitHub token (packages:read and packages:write scopes)
70-
# used to log against the OCI registry.
97+
# Password or GitHub token (packages:read and packages:write scopes) used to log against the OCI registry.
7198
# Defaults to GITHUB_TOKEN if not provided.
72-
oci-registry-password: ${{ github.token }}
99+
oci-registry-password: ""
73100
with:
74101
# JSON array of runner(s) to use.
75102
# See https://docs.github.com/en/actions/using-jobs/choosing-the-runner-for-a-job.
@@ -82,6 +109,8 @@ jobs:
82109
oci-registry: ghcr.io
83110

84111
# JSON array of platforms to build images for.
112+
# See https://docs.docker.com/buildx/working-with-buildx/#build-multi-platform-images.
113+
#
85114
# Default: `["linux/amd64","linux/arm64"]`
86115
platforms: '["linux/amd64","linux/arm64"]'
87116

@@ -92,100 +121,70 @@ jobs:
92121
```
93122
94123
<!-- usage:end -->
95-
<!--
96-
// jscpd:ignore-start
97-
-->
98124
<!-- inputs:start -->
99125
100126
## Inputs
101127
102128
### Workflow Call Inputs
103129
104-
| **Input** | **Description** | **Required** | **Type** | **Default** |
105-
| ------------------ | --------------------------------------------------------------------------------------------- | ------------ | ---------- | ------------------------------- |
106-
| **`runs-on`** | JSON array of runner(s) to use. | **false** | **string** | `["ubuntu-latest"]` |
107-
| | See <https://docs.github.com/en/actions/using-jobs/choosing-the-runner-for-a-job>. | | | |
108-
| **`oci-registry`** | OCI registry where to pull and push images. | **false** | **string** | `ghcr.io` |
109-
| **`platforms`** | JSON array of platforms to build images for. | **false** | **string** | `["linux/amd64","linux/arm64"]` |
110-
| | See <https://docs.docker.com/buildx/working-with-buildx/#build-multi-platform-images>. | | | |
111-
| **`images`** | JSON array of images to build. If not provided, all available images will be considered. | **false** | **string** | |
130+
| **Input** | **Description** | **Required** | **Type** | **Default** |
131+
| ------------------ | -------------------------------------------------------------------------------------- | ------------ | ---------- | ------------------------------- |
132+
| **`runs-on`** | JSON array of runner(s) to use. | **false** | **string** | `["ubuntu-latest"]` |
133+
| | See <https://docs.github.com/en/actions/using-jobs/choosing-the-runner-for-a-job>. | | | |
134+
| **`oci-registry`** | OCI registry where to pull and push images. | **false** | **string** | `ghcr.io` |
135+
| **`platforms`** | JSON array of platforms to build images for. | **false** | **string** | `["linux/amd64","linux/arm64"]` |
136+
| | See <https://docs.docker.com/buildx/working-with-buildx/#build-multi-platform-images>. | | | |
137+
| **`images`** | JSON array of images to build. | **false** | **string** | - |
138+
| | If not provided, all available images will be considered. | | | |
139+
| | Example: `["php-8", "nodejs-24"]` | | | |
112140

113141
<!-- inputs:end -->
142+
143+
<!--
144+
// jscpd:ignore-start
145+
-->
146+
114147
<!-- secrets:start -->
115148

116149
## Secrets
117150

118-
| **Secret** | **Description** | **Required** |
119-
| --------------------------- | -------------------------------------------------------------------------------------------- | ------------ |
120-
| **`oci-registry-password`** | Password or GitHub token (packages:read and packages:write scopes) for OCI registry access. | **false** |
121-
| | Defaults to GITHUB_TOKEN if not provided. | |
151+
| **Secret** | **Description** | **Required** |
152+
| --------------------------- | -------------------------------------------------------------------------------------------------------- | ------------ |
153+
| **`oci-registry-password`** | Password or GitHub token (packages:read and packages:write scopes) used to log against the OCI registry. | **false** |
154+
| | Defaults to GITHUB_TOKEN if not provided. | |
122155

123156
<!-- secrets:end -->
124157
<!-- outputs:start -->
125158

126159
## Outputs
127160

128-
| **Output** | **Description** |
129-
| ------------------ | --------------------------------------------------------------------------------------------- |
130-
| **`built-images`** | Built images data. See docker-build-images.md for the format. |
161+
| **Output** | **Description** |
162+
| ------------------ | ------------------------------------------------------------------------------------------------------------------------ |
163+
| **`built-images`** | Built images data. |
164+
| | See <https://github.com/hoverkraft-tech/ci-github-container/blob/main/.github/workflows/docker-build-images.md#outputs>. |
131165

132166
<!-- outputs:end -->
133167

134-
## Testing
135-
136-
Tests are defined in `images/<image-name>/container-structure-test.yaml` using [container-structure-test](https://github.com/GoogleContainerTools/container-structure-test).
137-
138-
### Test Configuration
139-
140-
Each image can have a `container-structure-test.yaml` file with:
141-
142-
- `commandTests` - Verify commands run correctly in the container
143-
- `fileExistenceTests` - Check files/directories exist
144-
- `fileContentTests` - Verify file contents
145-
- `metadataTest` - Validate container metadata (env vars, user, workdir, etc.)
146-
147-
### Example Test Configuration
148-
149-
```yaml
150-
schemaVersion: "2.0.0"
151-
152-
commandTests:
153-
- name: "helm is installed"
154-
command: "helm"
155-
args: ["version"]
156-
exitCode: 0
157-
158-
fileExistenceTests:
159-
- name: "script exists"
160-
path: "/usr/local/bin/script.sh"
161-
shouldExist: true
162-
isExecutableBy: "any"
163-
164-
metadataTest:
165-
user: "appuser"
166-
workdir: "/app"
167-
```
168-
169-
### Running Tests Locally
170-
171-
```bash
172-
# Test a specific image
173-
make test ci-helm
168+
<!--
169+
// jscpd:ignore-end
170+
-->
174171

175-
# Test all images
176-
make test-all
177-
```
172+
<!-- examples:start -->
173+
<!-- examples:end -->
178174

179175
<!--
180-
// jscpd:ignore-end
176+
// jscpd:ignore-start
181177
-->
178+
182179
<!-- contributing:start -->
183180

184181
## Contributing
185182

186183
Contributions are welcome! Please see the [contributing guidelines](https://github.com/hoverkraft-tech/docker-base-images/blob/main/CONTRIBUTING.md) for more details.
187184

188185
<!-- contributing:end -->
186+
<!-- security:start -->
187+
<!-- security:end -->
189188
<!-- license:start -->
190189

191190
## License
@@ -199,3 +198,14 @@ Copyright © 2025 hoverkraft-tech
199198
For more details, see the [license](http://choosealicense.com/licenses/mit/).
200199

201200
<!-- license:end -->
201+
<!-- generated:start -->
202+
203+
---
204+
205+
This documentation was automatically generated by [CI Dokumentor](https://github.com/hoverkraft-tech/ci-dokumentor).
206+
207+
<!-- generated:end -->
208+
209+
<!--
210+
// jscpd:ignore-end
211+
-->

.github/workflows/continuous-integration.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# A comprehensive CI workflow that performs linting, builds Docker images, and runs tests against the built images using [container-structure-test](https://github.com/GoogleContainerTools/container-structure-test).
2+
#
3+
# ### Jobs
4+
#
5+
# 1. **linter**: Runs code linting using the shared linter workflow
6+
# 2. **build-images**: Builds Docker images (depends on linter)
7+
# 3. **prepare-test-matrix**: Prepares the matrix for test jobs
8+
# 4. **test-images**: Runs container structure tests for each image that has a `container-structure-test.yaml` file
9+
110
---
211
name: Continuous Integration
312

.github/workflows/prepare-release.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ jobs:
9595
<!-- outputs:end -->
9696
<!-- examples:start -->
9797
<!-- examples:end -->
98+
<!--
99+
// jscpd:ignore-start
100+
-->
98101
<!-- contributing:start -->
99102

100103
## Contributing
@@ -124,3 +127,6 @@ For more details, see the [license](http://choosealicense.com/licenses/mit/).
124127
This documentation was automatically generated by [CI Dokumentor](https://github.com/hoverkraft-tech/ci-dokumentor).
125128

126129
<!-- generated:end -->
130+
<!--
131+
// jscpd:ignore-end
132+
-->

.github/workflows/release.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ jobs:
6363
```
6464
6565
<!-- usage:end -->
66+
67+
<!--
68+
// jscpd:ignore-start
69+
-->
70+
6671
<!-- inputs:start -->
6772
6873
## Inputs
@@ -79,6 +84,11 @@ jobs:
7984
| **`prerelease`** | Whether the release is a prerelease | **false** | **boolean** | `false` |
8085

8186
<!-- inputs:end -->
87+
88+
<!--
89+
// jscpd:ignore-end
90+
-->
91+
8292
<!-- secrets:start -->
8393

8494
## Secrets

Dockerfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ghcr.io/super-linter/super-linter:slim-v8.0.0
1+
FROM ghcr.io/super-linter/super-linter:slim-v8.0.0 AS linter
22

33
HEALTHCHECK --interval=5m --timeout=10s --start-period=30s --retries=3 CMD ["/bin/sh","-c","test -d /github/home"]
44
ARG UID=1000
@@ -10,3 +10,7 @@ ENV RUN_LOCAL=true
1010
ENV USE_FIND_ALGORITHM=true
1111
ENV LOG_LEVEL=WARN
1212
ENV LOG_FILE="/github/home/logs"
13+
14+
FROM ghcr.io/googlecontainertools/container-structure-test:1.22.0 AS structure-test
15+
16+
HEALTHCHECK --interval=5m --timeout=10s --start-period=30s --retries=3 CMD ["container-structure-test", "version"]

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ define run_linter
3636
DEFAULT_WORKSPACE="$(CURDIR)"; \
3737
LINTER_IMAGE="linter:latest"; \
3838
VOLUME="$$DEFAULT_WORKSPACE:$$DEFAULT_WORKSPACE"; \
39-
docker build --build-arg UID=$(shell id -u) --build-arg GID=$(shell id -g) --tag $$LINTER_IMAGE .; \
39+
docker build --target linter --build-arg UID=$(shell id -u) --build-arg GID=$(shell id -g) --tag $$LINTER_IMAGE .; \
4040
docker run \
4141
-e DEFAULT_WORKSPACE="$$DEFAULT_WORKSPACE" \
4242
-e FILTER_REGEX_INCLUDE="$(filter-out $@,$(MAKECMDGOALS))" \
@@ -61,11 +61,13 @@ define run_tests
6161
fi; \
6262
echo "Building image $$IMAGE_NAME..."; \
6363
docker buildx build -t "$$IMAGE_NAME:test" "$$IMAGE_DIR" || exit 1; \
64+
echo "Building structure-test image..."; \
65+
docker build --target structure-test --tag structure-test:latest . || exit 1; \
6466
echo "Running tests for $$IMAGE_NAME..."; \
6567
docker run --rm \
6668
-v /var/run/docker.sock:/var/run/docker.sock \
6769
-v "$$IMAGE_DIR:/workspace" \
68-
ghcr.io/googlecontainertools/container-structure-test:v1.22.0 \
70+
structure-test:latest \
6971
test --image "$$IMAGE_NAME:test" --config /workspace/container-structure-test.yaml
7072
endef
7173

0 commit comments

Comments
 (0)