Skip to content

Commit

Permalink
Add digest output
Browse files Browse the repository at this point in the history
Fix platforms and allow inputs

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
  • Loading branch information
CrazyMax committed Aug 17, 2020
1 parent 44d05b9 commit 38c1f18
Show file tree
Hide file tree
Showing 8 changed files with 228 additions and 52 deletions.
49 changes: 48 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,54 @@ on:
- v2-working-branch # remove when merged to master

jobs:
main:
single:
runs-on: ubuntu-latest
steps:
-
name: Run local registry
run: |
docker run -d -p 5000:5000 registry:2
-
name: Checkout
uses: actions/checkout@v2.3.1
-
name: Set up QEMU
uses: ./setup-qemu/ # change to docker/setup-qemu-action@master
with:
platforms: all
-
name: Set up Docker Buildx
id: buildx
uses: ./setup-buildx/ # change to docker/setup-buildx-action@master
with:
driver-opt: network=host
buildkitd-flags: --allow-insecure-entitlement security.insecure
-
name: Build and push
id: docker_build
uses: ./
with:
context: ./test
file: ./test/Dockerfile
builder: ${{ steps.buildx.outputs.name }}
allow: network.host,security.insecure
push: true
tags: |
localhost:5000/name/app:latest
localhost:5000/name/app:1.0.0
-
name: Inspect
run: |
docker buildx imagetools inspect localhost:5000/name/app:1.0.0
-
name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
-
name: Dump context
if: always()
uses: crazy-max/ghaction-dump-context@v1

multi:
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand Down
52 changes: 50 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,56 @@ on:
tags:

jobs:
buildx:
main:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Set up QEMU
uses: docker/setup-qemu-action@v1
with:
platforms: all
-
name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
-
name: Login to DockerHub
uses: crazy-max/ghaction-docker-login@v1 # switch to docker/login-action@v1 when available
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
-
name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
builder: ${{ steps.buildx.outputs.name }}
push: true
tags: |
user/app:latest
user/app:1.0.0
-
name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
```
### Multi-platform image
```yaml
name: ci

on:
pull_request:
branches: master
push:
branches: master
tags:

jobs:
multi:
runs-on: ubuntu-latest
steps:
-
Expand All @@ -58,7 +107,6 @@ jobs:
uses: docker/build-push-action@v2
with:
builder: ${{ steps.buildx.outputs.name }}
platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/386,linux/ppc64le,linux/s390x
push: true
tags: |
user/app:latest
Expand Down
15 changes: 15 additions & 0 deletions __tests__/buildx.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import fs from 'fs';
import * as buildx from '../src/buildx';

const digest = 'sha256:bfb45ab72e46908183546477a08f8867fc40cebadd00af54b071b097aed127a9';

describe('getImageID', () => {
it('matches', async () => {
const imageIDFile = await buildx.getImageIDFile();
console.log(`imageIDFile: ${imageIDFile}`);
await fs.writeFileSync(imageIDFile, digest);
const imageID = await buildx.getImageID();
console.log(`imageID: ${imageID}`);
expect(imageID).toEqual(digest);
});
});
16 changes: 8 additions & 8 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ inputs:
required: false
default: './Dockerfile'
build-args:
description: "Newline-delimited list of build-time variables"
description: "List of build-time variables"
required: false
labels:
description: "Newline-delimited list of metadata for an image"
description: "List of metadata for an image"
required: false
tags:
description: "Newline-delimited list of tags"
description: "List of tags"
required: false
pull:
description: "Always attempt to pull a newer version of the image"
Expand All @@ -35,14 +35,14 @@ inputs:
description: "Sets the target stage to build"
required: false
allow:
description: "Allow extra privileged entitlement (eg. network.host,security.insecure)"
description: "List of extra privileged entitlement (eg. network.host,security.insecure)"
required: false
no-cache:
description: "Do not use cache when building the image"
required: false
default: 'false'
platforms:
description: "Comma-delimited list of target platforms for build"
description: "List of target platforms for build"
required: false
load:
description: "Load is a shorthand for --output=type=docker"
Expand All @@ -53,13 +53,13 @@ inputs:
required: false
default: 'false'
outputs:
description: "Newline-delimited list of output destinations (format: type=local,dest=path)"
description: "List of output destinations (format: type=local,dest=path)"
required: false
cache-from:
description: "Newline-delimited list of external cache sources for buildx (eg. user/app:cache, type=local,src=path/to/dir)"
description: "List of external cache sources for buildx (eg. user/app:cache, type=local,src=path/to/dir)"
required: false
cache-to:
description: "Newline-delimited list of cache export destinations for buildx (eg. user/app:cache, type=local,dest=path/to/dir)"
description: "List of cache export destinations for buildx (eg. user/app:cache, type=local,dest=path/to/dir)"
required: false

outputs:
Expand Down
80 changes: 58 additions & 22 deletions dist/index.js

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

15 changes: 15 additions & 0 deletions src/buildx.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
import fs from 'fs';
import path from 'path';
import * as context from './context';
import * as exec from './exec';

export async function getImageIDFile(): Promise<string> {
return path.join(context.tmpDir, 'iidfile');
}

export async function getImageID(): Promise<string | undefined> {
const iidFile = await getImageIDFile();
if (!fs.existsSync(iidFile)) {
return undefined;
}
return fs.readFileSync(iidFile, {encoding: 'utf-8'});
}

export async function isAvailable(): Promise<Boolean> {
return await exec.exec(`docker`, ['buildx'], true).then(res => {
if (res.stderr != '' && !res.success) {
Expand Down
Loading

0 comments on commit 38c1f18

Please sign in to comment.