Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
{
"matchManagers": ["custom.regex"],
"groupName": "Docker build tooling"
},
{
"matchFileNames": ["actions/docker/test-image/tooling.json"],
"groupName": "Container test tooling"
}
],
"customManagers": [
Expand All @@ -21,6 +25,21 @@
"matchStrings": [
"# renovate: datasource=(?<datasource>\\S+) depName=(?<depName>\\S+) versioning=(?<versioning>\\S+)\\s+default: \"(?:[^\"\\s]+:)?(?<currentValue>[^\"\\s]+)\""
]
},
{
"customType": "regex",
"managerFilePatterns": ["/^actions/docker/test-image/tooling\\.json$/"],
"matchStrings": [
"\"(?:nodeRunner|reaper)\":\\s*\"(?<depName>[^\"@]+):(?<currentValue>[^\"@:]+)@(?<currentDigest>sha256:[a-f0-9]+)\""
],
"datasourceTemplate": "docker"
},
{
"customType": "regex",
"managerFilePatterns": ["/^actions/docker/test-image/tooling\\.json$/"],
"matchStrings": ["\"gossVersion\":\\s*\"(?<currentValue>v[0-9.]+)\""],
"datasourceTemplate": "github-releases",
"depNameTemplate": "goss-org/goss"
}
]
}
11 changes: 11 additions & 0 deletions .github/workflows/__shared-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ jobs:
pull-requests: write
security-events: write

test-action-docker-test-image:
needs: lint
uses: $/.github/workflows/__test-action-docker-test-image.yml
permissions:
contents: read
id-token: write
packages: read
pull-requests: write
security-events: write

test-action-docker-build-image:
needs: lint
uses: $/.github/workflows/__test-action-docker-build-image.yml
Expand Down Expand Up @@ -262,6 +272,7 @@ jobs:
- test-action-helm-release-chart
- test-action-docker-promote-images
- test-action-docker-verify-images
- test-action-docker-test-image
- test-action-docker-prune-pull-requests-image-tags
if: always()
uses: hoverkraft-tech/ci-github-common/.github/workflows/ci-reports.yml@d606f77fad305ef07dfde3db5270f5e324019c97 # 4.2.4
Expand Down
180 changes: 180 additions & 0 deletions .github/workflows/__test-action-docker-test-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
---
name: Test for "docker/test-image" action
run-name: Test for "docker/test-image" action

on: # yamllint disable-line rule:truthy
workflow_call:

permissions: {}

jobs:
continuous-integration:
uses: hoverkraft-tech/ci-github-nodejs/.github/workflows/continuous-integration.yml@191d7230d57982bfc11d57f68b005f386a6d7fbf # 3.1.1
permissions:
contents: read
id-token: write
packages: read
pull-requests: write
security-events: write
with:
working-directory: actions/docker/test-image
build: ""
lint: ""
code-ql: '{"languages":"typescript","config-file":".github/codeql/config.yml"}'
test: '{"comment":false,"report-group":"test-action-docker-test-image"}'

integration:
name: Native ${{ matrix.engine }} lifecycle and reporting
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
packages: read
strategy:
fail-fast: false
matrix:
engine: [testcontainers-node, goss]
env:
IMAGE: ghcr.io/hoverkraft-tech/ci-github-container/application-test:0.1.0@sha256:e5cc91762bc2b09276ab2b56d88583dd11522cc80b61e63dac7b4ac0f0d04c77
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- uses: $/actions/docker/setup
with:
setup-docker: false
setup-buildx: false
oci-registry-username: ${{ github.actor }}
oci-registry-password: ${{ secrets.GITHUB_TOKEN }}

- name: Arrange native suites and a caller-owned container
id: arrange
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
env:
ENGINE: ${{ matrix.engine }}
with:
script: |
const fs = require('node:fs');
const path = require('node:path');
const id = require('node:crypto').randomUUID();
const root = path.join(process.env.GITHUB_WORKSPACE, '.cache/agent-work', `container-tests-${id}`);
core.setOutput('root', root);
core.setOutput('caller', `caller-${id}`);
fs.mkdirSync(root, {recursive: true});
for (const mode of ['success', 'failure', 'timeout']) {
const directory = path.join(root, mode);
fs.cpSync(`tests/container-image/${process.env.ENGINE}`, directory, {recursive: true});
if (mode === 'success') continue;
if (process.env.ENGINE === 'testcontainers-node') fs.writeFileSync(path.join(directory, mode), '');
else {
const command = JSON.stringify(mode === 'failure' ? 'false' : 'sleep 60');
fs.appendFileSync(path.join(directory, 'goss.yaml'),
` fixture-${mode}:\n exec: ${command}\n exit-status: 0\n timeout: 90000\n`);
}
}
await exec.exec('docker', ['pull', process.env.IMAGE]);
const image = await exec.getExecOutput('docker', ['image', 'inspect', '--format', '{{.Id}}', process.env.IMAGE]);
core.setOutput('image-id', image.stdout.trim());
await exec.exec('docker', ['create', '--name', `caller-${id}`, '--label', `org.testcontainers.session-id=${id}`, image.stdout.trim()]);

- name: Act - Validate registry candidate
id: passing
uses: $/actions/docker/test-image
with:
image: ${{ env.IMAGE }}
working-directory: ${{ steps.arrange.outputs.root }}/success
report-group: test-action-docker-test-image

- name: Act - Retain native reports after a failing assertion
id: failing
continue-on-error: true
uses: $/actions/docker/test-image
with:
image: ${{ steps.arrange.outputs.image-id }}
working-directory: ${{ steps.arrange.outputs.root }}/failure
report-group: fixture-container-negative

- name: Act - Bound execution and clean resources after timeout
id: timeout
continue-on-error: true
uses: $/actions/docker/test-image
with:
image: ${{ steps.arrange.outputs.image-id }}
working-directory: ${{ steps.arrange.outputs.root }}/timeout
timeout: "10"
report-group: fixture-container-negative

- name: Act - Reject a short-lived image with Goss
id: incompatible
if: matrix.engine == 'goss'
continue-on-error: true
uses: $/actions/docker/test-image
with:
image: docker.io/library/hello-world:latest@sha256:1e4c05b897a751332ce85c7e9449da2d93514ea2dea6dbb0e2753c9e949b2bfa
working-directory: ${{ steps.arrange.outputs.root }}/success
timeout: "10"
report-group: fixture-container-negative

- name: Download failed test reports
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
artifact-ids: ${{ steps.failing.outputs.report-artifact-id }}
path: ${{ steps.arrange.outputs.root }}/download

- name: Assert public results, retained failures and resource ownership
if: ${{ !cancelled() && steps.arrange.outcome == 'success' }}
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
env:
ENGINE: ${{ matrix.engine }}
ROOT: ${{ steps.arrange.outputs.root }}
CALLER: ${{ steps.arrange.outputs.caller }}
PASSING: ${{ steps.passing.outputs.validation }}
PASS_REPORT: ${{ steps.passing.outputs.report-artifact-id }}
FAIL_REPORT: ${{ steps.failing.outputs.report-artifact-id }}
FAIL_RESULT: ${{ steps.failing.outputs.validation }}
FAIL_OUTCOME: ${{ steps.failing.outcome }}
TIMEOUT_RESULT: ${{ steps.timeout.outputs.validation }}
TIMEOUT_OUTCOME: ${{ steps.timeout.outcome }}
TIMEOUT_LOGS: ${{ steps.timeout.outputs.diagnostic-artifact-id }}
INCOMPATIBLE_RESULT: ${{ steps.incompatible.outputs.validation }}
INCOMPATIBLE_OUTCOME: ${{ steps.incompatible.outcome }}
INCOMPATIBLE_LOGS: ${{ steps.incompatible.outputs.diagnostic-artifact-id }}
with:
script: |
const assert = require('node:assert/strict');
const path = require('node:path');
const { pathToFileURL } = require('node:url');
const { Reports } = await import(pathToFileURL(path.resolve('actions/docker/test-image/dist/index.js')));
const result = JSON.parse(process.env.PASSING);
assert.equal(result.image, process.env.IMAGE);
assert.equal(result['identity-kind'], 'registry');
assert.equal(result.engine, process.env.ENGINE);
assert.ok(result.tests.executed > 0);
assert.equal(process.env.FAIL_OUTCOME, 'failure');
assert.equal(process.env.TIMEOUT_OUTCOME, 'failure');
assert.equal(process.env.FAIL_RESULT, '');
assert.equal(process.env.TIMEOUT_RESULT, '');
assert.ok(process.env.PASS_REPORT && process.env.FAIL_REPORT && process.env.TIMEOUT_LOGS);
assert.notEqual(process.env.PASS_REPORT, process.env.FAIL_REPORT);
if (process.env.ENGINE === 'goss') {
assert.equal(process.env.INCOMPATIBLE_OUTCOME, 'failure');
assert.equal(process.env.INCOMPATIBLE_RESULT, '');
assert.ok(process.env.INCOMPATIBLE_LOGS);
}
const files = await glob.create(`${process.env.ROOT}/download/**/*.xml`);
assert.ok((await files.glob()).some(file => new Reports(file).inspect().failed > 0));
await exec.exec('docker', ['container', 'inspect', process.env.CALLER]);
const containers = await exec.getExecOutput('docker', ['container', 'ls', '-aq', '--filter', 'label=io.hoverkraft.container-test']);
assert.equal(containers.stdout.trim(), '');

- name: Clean caller fixture
if: ${{ always() && steps.arrange.outputs.root != '' }}
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
env:
ROOT: ${{ steps.arrange.outputs.root }}
CALLER: ${{ steps.arrange.outputs.caller }}
with:
script: |
await exec.exec('docker', ['container', 'rm', '-f', process.env.CALLER], {ignoreReturnCode: true});
require('node:fs').rmSync(process.env.ROOT, {recursive: true, force: true});
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ _Actions that operate on OCI images across their build, metadata, and lifecycle

#### - [Sign images](actions/docker/sign-images/README.md)

#### - [Test image](actions/docker/test-image/README.md)

#### - [Verify images](actions/docker/verify-images/README.md)

### Helm
Expand Down
Loading
Loading