Skip to content

Commit e115266

Browse files
authored
Merge pull request #569 from crazy-max/imageid-digest
add imageid output and use metadata to set digest output
2 parents 309fb91 + 50fa005 commit e115266

File tree

7 files changed

+153
-87
lines changed

7 files changed

+153
-87
lines changed

.github/workflows/ci.yml

+87-71
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ jobs:
2626
uses: ./action
2727
with:
2828
file: ./test/Dockerfile
29-
-
30-
name: Dump context
31-
if: always()
32-
uses: crazy-max/ghaction-dump-context@v1
3329

3430
git-context:
3531
runs-on: ubuntu-latest
@@ -77,10 +73,6 @@ jobs:
7773
echo "::error::Digest should not be empty"
7874
exit 1
7975
fi
80-
-
81-
name: Dump context
82-
if: always()
83-
uses: crazy-max/ghaction-dump-context@v1
8476
8577
git-context-secret:
8678
runs-on: ubuntu-latest
@@ -137,10 +129,6 @@ jobs:
137129
echo "::error::Digest should not be empty"
138130
exit 1
139131
fi
140-
-
141-
name: Dump context
142-
if: always()
143-
uses: crazy-max/ghaction-dump-context@v1
144132
145133
path-context:
146134
runs-on: ubuntu-latest
@@ -192,10 +180,6 @@ jobs:
192180
echo "::error::Digest should not be empty"
193181
exit 1
194182
fi
195-
-
196-
name: Dump context
197-
if: always()
198-
uses: crazy-max/ghaction-dump-context@v1
199183
200184
error:
201185
runs-on: ubuntu-latest
@@ -223,10 +207,6 @@ jobs:
223207
echo "::error::Should have failed"
224208
exit 1
225209
fi
226-
-
227-
name: Dump context
228-
if: always()
229-
uses: crazy-max/ghaction-dump-context@v1
230210
231211
error-buildx:
232212
runs-on: ubuntu-latest
@@ -259,10 +239,6 @@ jobs:
259239
echo "::error::Should have failed"
260240
exit 1
261241
fi
262-
-
263-
name: Dump context
264-
if: always()
265-
uses: crazy-max/ghaction-dump-context@v1
266242
267243
docker-driver:
268244
runs-on: ubuntu-latest
@@ -284,10 +260,6 @@ jobs:
284260
file: ./test/Dockerfile
285261
push: true
286262
tags: localhost:5000/name/app:latest
287-
-
288-
name: Dump context
289-
if: always()
290-
uses: crazy-max/ghaction-dump-context@v1
291263

292264
export-docker:
293265
runs-on: ubuntu-latest
@@ -307,10 +279,6 @@ jobs:
307279
name: Inspect
308280
run: |
309281
docker image inspect myimage:latest
310-
-
311-
name: Dump context
312-
if: always()
313-
uses: crazy-max/ghaction-dump-context@v1
314282
315283
network:
316284
runs-on: ubuntu-latest
@@ -331,10 +299,6 @@ jobs:
331299
context: ./test
332300
tags: name/app:latest
333301
network: host
334-
-
335-
name: Dump context
336-
if: always()
337-
uses: crazy-max/ghaction-dump-context@v1
338302

339303
shm-size:
340304
runs-on: ubuntu-latest
@@ -357,10 +321,6 @@ jobs:
357321
file: ./test/shmsize.Dockerfile
358322
tags: name/app:latest
359323
shm-size: 2g
360-
-
361-
name: Dump context
362-
if: always()
363-
uses: crazy-max/ghaction-dump-context@v1
364324

365325
ulimit:
366326
runs-on: ubuntu-latest
@@ -385,10 +345,6 @@ jobs:
385345
ulimit: |
386346
nofile=1024:1024
387347
nproc=3
388-
-
389-
name: Dump context
390-
if: always()
391-
uses: crazy-max/ghaction-dump-context@v1
392348
393349
cgroup-parent:
394350
runs-on: ubuntu-latest
@@ -411,10 +367,6 @@ jobs:
411367
file: ./test/cgroup.Dockerfile
412368
tags: name/app:latest
413369
cgroup-parent: foo
414-
-
415-
name: Dump context
416-
if: always()
417-
uses: crazy-max/ghaction-dump-context@v1
418370

419371
add-hosts:
420372
runs-on: ubuntu-latest
@@ -435,10 +387,6 @@ jobs:
435387
add-hosts: |
436388
docker:10.180.0.1
437389
foo:10.0.0.1
438-
-
439-
name: Dump context
440-
if: always()
441-
uses: crazy-max/ghaction-dump-context@v1
442390
443391
multi:
444392
runs-on: ubuntu-latest
@@ -494,10 +442,94 @@ jobs:
494442
echo "::error::Digest should not be empty"
495443
exit 1
496444
fi
445+
446+
digest:
447+
runs-on: ubuntu-latest
448+
env:
449+
DOCKER_IMAGE: localhost:5000/name/app
450+
strategy:
451+
fail-fast: false
452+
matrix:
453+
driver:
454+
- docker
455+
- docker-container
456+
load:
457+
- true
458+
- false
459+
push:
460+
- true
461+
- false
462+
exclude:
463+
- driver: docker
464+
load: true
465+
push: true
466+
- driver: docker-container
467+
load: true
468+
push: true
469+
- driver: docker
470+
load: false
471+
push: false
472+
- driver: docker-container
473+
load: false
474+
push: false
475+
services:
476+
registry:
477+
image: registry:2
478+
ports:
479+
- 5000:5000
480+
steps:
481+
-
482+
name: Checkout
483+
uses: actions/checkout@v2
484+
-
485+
name: Set up Docker Buildx
486+
uses: docker/setup-buildx-action@v1
487+
with:
488+
version: v0.8.0
489+
driver: ${{ matrix.driver }}
490+
driver-opts: |
491+
network=host
492+
-
493+
name: Build
494+
id: docker_build
495+
uses: ./
496+
with:
497+
context: ./test
498+
load: ${{ matrix.load }}
499+
push: ${{ matrix.push }}
500+
tags: ${{ env.DOCKER_IMAGE }}:latest
501+
platforms: ${{ matrix.platforms }}
502+
-
503+
name: Docker images
504+
run: |
505+
docker image ls --no-trunc
506+
-
507+
name: Check digest
508+
if: ${{ matrix.push }}
509+
run: |
510+
if [ -z "${{ steps.docker_build.outputs.digest }}" ]; then
511+
echo "::error::Digest should not be empty"
512+
exit 1
513+
fi
514+
-
515+
name: Check manifest
516+
if: ${{ matrix.push }}
517+
run: |
518+
set -x
519+
docker buildx imagetools inspect ${{ env.DOCKER_IMAGE }}@${{ steps.docker_build.outputs.digest }} --format '{{json .}}'
520+
-
521+
name: Check image ID
522+
run: |
523+
if [ -z "${{ steps.docker_build.outputs.imageid }}" ]; then
524+
echo "::error::Image ID should not be empty"
525+
exit 1
526+
fi
497527
-
498-
name: Dump context
499-
if: always()
500-
uses: crazy-max/ghaction-dump-context@v1
528+
name: Inspect image
529+
if: ${{ matrix.load }}
530+
run: |
531+
set -x
532+
docker image inspect ${{ steps.docker_build.outputs.imageid }}
501533
502534
registry-cache:
503535
runs-on: ubuntu-latest
@@ -584,10 +616,6 @@ jobs:
584616
echo "::error::Digests should be identical"
585617
exit 1
586618
fi
587-
-
588-
name: Dump context
589-
if: always()
590-
uses: crazy-max/ghaction-dump-context@v1
591619
592620
local-cache-first:
593621
runs-on: ubuntu-latest
@@ -650,10 +678,6 @@ jobs:
650678
echo "::error::Digest should not be empty"
651679
exit 1
652680
fi
653-
-
654-
name: Dump context
655-
if: always()
656-
uses: crazy-max/ghaction-dump-context@v1
657681
658682
local-cache-hit:
659683
runs-on: ubuntu-latest
@@ -723,10 +747,6 @@ jobs:
723747
-
724748
name: Cache hit
725749
run: echo ${{ steps.cache.outputs.cache-hit }}
726-
-
727-
name: Dump context
728-
if: always()
729-
uses: crazy-max/ghaction-dump-context@v1
730750

731751
github-cache:
732752
runs-on: ubuntu-latest
@@ -773,7 +793,3 @@ jobs:
773793
name: Inspect
774794
run: |
775795
docker buildx imagetools inspect localhost:5000/name/app:1.0.0
776-
-
777-
name: Dump context
778-
if: always()
779-
uses: crazy-max/ghaction-dump-context@v1

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ Following outputs are available
241241

242242
| Name | Type | Description |
243243
|-------------------|---------|---------------------------------------|
244-
| `digest` | String | Image content-addressable identifier also called a digest |
244+
| `imageid` | String | Image ID |
245+
| `digest` | String | Image digest |
245246
| `metadata` | JSON | Build result metadata |
246247

247248
## Troubleshooting

__tests__/buildx.test.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as buildx from '../src/buildx';
77
import * as context from '../src/context';
88

99
const tmpNameSync = path.join('/tmp/.docker-build-push-jest', '.tmpname-jest').split(path.sep).join(path.posix.sep);
10-
const digest = 'sha256:bfb45ab72e46908183546477a08f8867fc40cebadd00af54b071b097aed127a9';
10+
const imageID = 'sha256:bfb45ab72e46908183546477a08f8867fc40cebadd00af54b071b097aed127a9';
1111
const metadata = `{
1212
"containerimage.config.digest": "sha256:059b68a595b22564a1cbc167af369349fdc2ecc1f7bc092c2235cbf601a795fd",
1313
"containerimage.digest": "sha256:b09b9482c72371486bb2c1d2c2a2633ed1d0b8389e12c8d52b9e052725c0c83c"
@@ -28,9 +28,9 @@ jest.spyOn(context, 'tmpNameSync').mockImplementation((): string => {
2828
describe('getImageID', () => {
2929
it('matches', async () => {
3030
const imageIDFile = await buildx.getImageIDFile();
31-
await fs.writeFileSync(imageIDFile, digest);
32-
const imageID = await buildx.getImageID();
33-
expect(imageID).toEqual(digest);
31+
await fs.writeFileSync(imageIDFile, imageID);
32+
const expected = await buildx.getImageID();
33+
expect(expected).toEqual(imageID);
3434
});
3535
});
3636

@@ -43,6 +43,15 @@ describe('getMetadata', () => {
4343
});
4444
});
4545

46+
describe('getDigest', () => {
47+
it('matches', async () => {
48+
const metadataFile = await buildx.getMetadataFile();
49+
await fs.writeFileSync(metadataFile, metadata);
50+
const expected = await buildx.getDigest(metadata);
51+
expect(expected).toEqual('sha256:b09b9482c72371486bb2c1d2c2a2633ed1d0b8389e12c8d52b9e052725c0c83c');
52+
});
53+
});
54+
4655
describe('isLocalOrTarExporter', () => {
4756
// prettier-ignore
4857
test.each([

action.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,10 @@ inputs:
8989
required: false
9090

9191
outputs:
92+
imageid:
93+
description: 'Image ID'
9294
digest:
93-
description: 'Image content-addressable identifier also called a digest'
95+
description: 'Image digest'
9496
metadata:
9597
description: 'Build result metadata'
9698

dist/index.js

+25-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)