Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add imageid output and use metadata to set digest output #569

Merged
merged 1 commit into from Mar 14, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
158 changes: 87 additions & 71 deletions .github/workflows/ci.yml
Expand Up @@ -26,10 +26,6 @@ jobs:
uses: ./action
with:
file: ./test/Dockerfile
-
name: Dump context
if: always()
uses: crazy-max/ghaction-dump-context@v1

git-context:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -77,10 +73,6 @@ jobs:
echo "::error::Digest should not be empty"
exit 1
fi
-
name: Dump context
if: always()
uses: crazy-max/ghaction-dump-context@v1

git-context-secret:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -137,10 +129,6 @@ jobs:
echo "::error::Digest should not be empty"
exit 1
fi
-
name: Dump context
if: always()
uses: crazy-max/ghaction-dump-context@v1

path-context:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -192,10 +180,6 @@ jobs:
echo "::error::Digest should not be empty"
exit 1
fi
-
name: Dump context
if: always()
uses: crazy-max/ghaction-dump-context@v1

error:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -223,10 +207,6 @@ jobs:
echo "::error::Should have failed"
exit 1
fi
-
name: Dump context
if: always()
uses: crazy-max/ghaction-dump-context@v1

error-buildx:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -259,10 +239,6 @@ jobs:
echo "::error::Should have failed"
exit 1
fi
-
name: Dump context
if: always()
uses: crazy-max/ghaction-dump-context@v1

docker-driver:
runs-on: ubuntu-latest
Expand All @@ -284,10 +260,6 @@ jobs:
file: ./test/Dockerfile
push: true
tags: localhost:5000/name/app:latest
-
name: Dump context
if: always()
uses: crazy-max/ghaction-dump-context@v1

export-docker:
runs-on: ubuntu-latest
Expand All @@ -307,10 +279,6 @@ jobs:
name: Inspect
run: |
docker image inspect myimage:latest
-
name: Dump context
if: always()
uses: crazy-max/ghaction-dump-context@v1

network:
runs-on: ubuntu-latest
Expand All @@ -331,10 +299,6 @@ jobs:
context: ./test
tags: name/app:latest
network: host
-
name: Dump context
if: always()
uses: crazy-max/ghaction-dump-context@v1

shm-size:
runs-on: ubuntu-latest
Expand All @@ -357,10 +321,6 @@ jobs:
file: ./test/shmsize.Dockerfile
tags: name/app:latest
shm-size: 2g
-
name: Dump context
if: always()
uses: crazy-max/ghaction-dump-context@v1

ulimit:
runs-on: ubuntu-latest
Expand All @@ -385,10 +345,6 @@ jobs:
ulimit: |
nofile=1024:1024
nproc=3
-
name: Dump context
if: always()
uses: crazy-max/ghaction-dump-context@v1

cgroup-parent:
runs-on: ubuntu-latest
Expand All @@ -411,10 +367,6 @@ jobs:
file: ./test/cgroup.Dockerfile
tags: name/app:latest
cgroup-parent: foo
-
name: Dump context
if: always()
uses: crazy-max/ghaction-dump-context@v1

add-hosts:
runs-on: ubuntu-latest
Expand All @@ -435,10 +387,6 @@ jobs:
add-hosts: |
docker:10.180.0.1
foo:10.0.0.1
-
name: Dump context
if: always()
uses: crazy-max/ghaction-dump-context@v1

multi:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -494,10 +442,94 @@ jobs:
echo "::error::Digest should not be empty"
exit 1
fi

digest:
runs-on: ubuntu-latest
env:
DOCKER_IMAGE: localhost:5000/name/app
strategy:
fail-fast: false
matrix:
driver:
- docker
- docker-container
load:
- true
- false
push:
- true
- false
exclude:
- driver: docker
load: true
push: true
- driver: docker-container
load: true
push: true
- driver: docker
load: false
push: false
- driver: docker-container
load: false
push: false
services:
registry:
image: registry:2
ports:
- 5000:5000
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Dump context
if: always()
uses: crazy-max/ghaction-dump-context@v1
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
with:
version: v0.8.0
driver: ${{ matrix.driver }}
driver-opts: |
network=host
-
name: Build
id: docker_build
uses: ./
with:
context: ./test
load: ${{ matrix.load }}
push: ${{ matrix.push }}
tags: ${{ env.DOCKER_IMAGE }}:latest
platforms: ${{ matrix.platforms }}
-
name: Docker images
run: |
docker image ls --no-trunc
-
name: Check digest
if: ${{ matrix.push }}
run: |
if [ -z "${{ steps.docker_build.outputs.digest }}" ]; then
echo "::error::Digest should not be empty"
exit 1
fi
-
name: Check manifest
if: ${{ matrix.push }}
run: |
set -x
docker buildx imagetools inspect ${{ env.DOCKER_IMAGE }}@${{ steps.docker_build.outputs.digest }} --format '{{json .}}'
-
name: Check image ID
run: |
if [ -z "${{ steps.docker_build.outputs.imageid }}" ]; then
echo "::error::Image ID should not be empty"
exit 1
fi
-
name: Inspect image
if: ${{ matrix.load }}
run: |
set -x
docker image inspect ${{ steps.docker_build.outputs.imageid }}

registry-cache:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -584,10 +616,6 @@ jobs:
echo "::error::Digests should be identical"
exit 1
fi
-
name: Dump context
if: always()
uses: crazy-max/ghaction-dump-context@v1

local-cache-first:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -650,10 +678,6 @@ jobs:
echo "::error::Digest should not be empty"
exit 1
fi
-
name: Dump context
if: always()
uses: crazy-max/ghaction-dump-context@v1

local-cache-hit:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -723,10 +747,6 @@ jobs:
-
name: Cache hit
run: echo ${{ steps.cache.outputs.cache-hit }}
-
name: Dump context
if: always()
uses: crazy-max/ghaction-dump-context@v1

github-cache:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -773,7 +793,3 @@ jobs:
name: Inspect
run: |
docker buildx imagetools inspect localhost:5000/name/app:1.0.0
-
name: Dump context
if: always()
uses: crazy-max/ghaction-dump-context@v1
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -241,7 +241,8 @@ Following outputs are available

| Name | Type | Description |
|-------------------|---------|---------------------------------------|
| `digest` | String | Image content-addressable identifier also called a digest |
| `imageid` | String | Image ID |
| `digest` | String | Image digest |
| `metadata` | JSON | Build result metadata |

## Troubleshooting
Expand Down
17 changes: 13 additions & 4 deletions __tests__/buildx.test.ts
Expand Up @@ -7,7 +7,7 @@ import * as buildx from '../src/buildx';
import * as context from '../src/context';

const tmpNameSync = path.join('/tmp/.docker-build-push-jest', '.tmpname-jest').split(path.sep).join(path.posix.sep);
const digest = 'sha256:bfb45ab72e46908183546477a08f8867fc40cebadd00af54b071b097aed127a9';
const imageID = 'sha256:bfb45ab72e46908183546477a08f8867fc40cebadd00af54b071b097aed127a9';
const metadata = `{
"containerimage.config.digest": "sha256:059b68a595b22564a1cbc167af369349fdc2ecc1f7bc092c2235cbf601a795fd",
"containerimage.digest": "sha256:b09b9482c72371486bb2c1d2c2a2633ed1d0b8389e12c8d52b9e052725c0c83c"
Expand All @@ -28,9 +28,9 @@ jest.spyOn(context, 'tmpNameSync').mockImplementation((): string => {
describe('getImageID', () => {
it('matches', async () => {
const imageIDFile = await buildx.getImageIDFile();
await fs.writeFileSync(imageIDFile, digest);
const imageID = await buildx.getImageID();
expect(imageID).toEqual(digest);
await fs.writeFileSync(imageIDFile, imageID);
const expected = await buildx.getImageID();
expect(expected).toEqual(imageID);
});
});

Expand All @@ -43,6 +43,15 @@ describe('getMetadata', () => {
});
});

describe('getDigest', () => {
it('matches', async () => {
const metadataFile = await buildx.getMetadataFile();
await fs.writeFileSync(metadataFile, metadata);
const expected = await buildx.getDigest(metadata);
expect(expected).toEqual('sha256:b09b9482c72371486bb2c1d2c2a2633ed1d0b8389e12c8d52b9e052725c0c83c');
});
});

describe('isLocalOrTarExporter', () => {
// prettier-ignore
test.each([
Expand Down
4 changes: 3 additions & 1 deletion action.yml
Expand Up @@ -89,8 +89,10 @@ inputs:
required: false

outputs:
imageid:
description: 'Image ID'
digest:
description: 'Image content-addressable identifier also called a digest'
description: 'Image digest'
metadata:
description: 'Build result metadata'

Expand Down
30 changes: 25 additions & 5 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.