Skip to content

Commit

Permalink
add imageid output and use metadata to set digest output
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
  • Loading branch information
crazy-max committed Mar 9, 2022
1 parent fe02965 commit 6b68332
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 87 deletions.
150 changes: 79 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,86 @@ 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:
include:
- driver: docker
load: false
push: true
- driver: docker
load: true
push: false
- driver: docker-container
load: false
push: true
- driver: docker-container
load: true
push: false
services:
registry:
image: registry:2
ports:
- 5000:5000
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
with:
version: https://github.com/docker/buildx.git#master
driver: ${{ matrix.driver }}
driver-opts: |
network=host
image=moby/buildkit:master
-
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: Dump context
if: always()
uses: crazy-max/ghaction-dump-context@v1
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 +608,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 +670,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 +739,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 +785,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.

0 comments on commit 6b68332

Please sign in to comment.