Skip to content

Commit

Permalink
Merge pull request #69 from crazy-max/inspect
Browse files Browse the repository at this point in the history
Enhance builder inspection
  • Loading branch information
crazy-max authored Apr 23, 2021
2 parents abdb186 + 7275023 commit 0f03438
Show file tree
Hide file tree
Showing 10 changed files with 215 additions and 53 deletions.
42 changes: 28 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ jobs:
with:
version: ${{ matrix.buildx-version }}
-
name: Builder instance name
run: echo ${{ steps.buildx.outputs.name }}
-
name: Available platforms
run: echo ${{ steps.buildx.outputs.platforms }}
name: Inspect builder
run: |
echo "Name: ${{ steps.buildx.outputs.name }}"
echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}"
echo "Status: ${{ steps.buildx.outputs.status }}"
echo "Flags: ${{ steps.buildx.outputs.flags }}"
echo "Platforms: ${{ steps.buildx.outputs.platforms }}"
-
name: Dump context
uses: crazy-max/ghaction-dump-context@v1
Expand All @@ -55,15 +57,25 @@ jobs:
id: buildx1
uses: ./
-
name: Builder 1 instance name
run: echo ${{ steps.buildx1.outputs.name }}
name: Inspect builder 1
run: |
echo "Name: ${{ steps.buildx1.outputs.name }}"
echo "Endpoint: ${{ steps.buildx1.outputs.endpoint }}"
echo "Status: ${{ steps.buildx1.outputs.status }}"
echo "Flags: ${{ steps.buildx1.outputs.flags }}"
echo "Platforms: ${{ steps.buildx1.outputs.platforms }}"
-
name: Set up Docker Buildx 2
id: buildx2
uses: ./
-
name: Builder 2 instance name
run: echo ${{ steps.buildx2.outputs.name }}
name: Inspect builder 2
run: |
echo "Name: ${{ steps.buildx2.outputs.name }}"
echo "Endpoint: ${{ steps.buildx2.outputs.endpoint }}"
echo "Status: ${{ steps.buildx2.outputs.status }}"
echo "Flags: ${{ steps.buildx2.outputs.flags }}"
echo "Platforms: ${{ steps.buildx2.outputs.platforms }}"
install:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -204,8 +216,10 @@ jobs:
with:
version: ${{ matrix.buildx-version }}
-
name: Available platforms
run: echo ${{ steps.buildx.outputs.platforms }}
-
name: Builder instance name
run: echo ${{ steps.buildx.outputs.name }}
name: Inspect builder
run: |
echo "Name: ${{ steps.buildx.outputs.name }}"
echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}"
echo "Status: ${{ steps.buildx.outputs.status }}"
echo "Flags: ${{ steps.buildx.outputs.flags }}"
echo "Platforms: ${{ steps.buildx.outputs.platforms }}"
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ jobs:
uses: docker/bake-action@v1
with:
targets: validate
-
name: Set up Docker Buildx
uses: ./
-
name: Test
uses: docker/bake-action@v1
Expand Down
22 changes: 14 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ jobs:
id: buildx
uses: docker/setup-buildx-action@v1
-
name: Builder instance name
run: echo ${{ steps.buildx.outputs.name }}
-
name: Available platforms
run: echo ${{ steps.buildx.outputs.platforms }}
name: Inspect builder
run: |
echo "Name: ${{ steps.buildx.outputs.name }}"
echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}"
echo "Status: ${{ steps.buildx.outputs.status }}"
echo "Flags: ${{ steps.buildx.outputs.flags }}"
echo "Platforms: ${{ steps.buildx.outputs.platforms }}"
```
### With QEMU
Expand Down Expand Up @@ -129,7 +131,7 @@ Following inputs can be used as `step.with` keys
| `install` | Bool | Sets up `docker build` command as an alias to `docker buildx` (default `false`) |
| `use` | Bool | Switch to this builder instance (default `true`) |
| `endpoint` | String | [Optional address for docker socket](https://github.com/docker/buildx/blob/master/docs/reference/buildx_create.md#description) or context from `docker context ls` |
| `config` | String | [Optional config file path](https://github.com/docker/buildx/blob/master/docs/reference/buildx_create.md#config) |
| `config` | String | [BuildKit config file](https://github.com/docker/buildx/blob/master/docs/reference/buildx_create.md#config) |

> `CSV` type must be a newline-delimited string
> ```yaml
Expand All @@ -147,8 +149,12 @@ Following outputs are available

| Name | Type | Description |
|---------------|---------|---------------------------------------|
| `name` | String | Builder instance name |
| `platforms` | String | Available platforms (comma separated) |
| `name` | String | Builder name |
| `driver` | String | Builder driver |
| `endpoint` | String | Builder node endpoint |
| `status` | String | Builder node status |
| `flags` | String | Builder node flags (if applicable) |
| `platforms` | String | Builder node platforms available (comma separated) |

### environment variables

Expand Down
12 changes: 7 additions & 5 deletions __tests__/buildx.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,19 @@ describe('parseVersion', () => {
});
});

describe('platforms', () => {
describe('inspect', () => {
async function isDaemonRunning() {
return await docker.isDaemonRunning();
}
(isDaemonRunning() ? it : it.skip)(
'valid',
async () => {
const platforms = buildx.platforms();
console.log(`platforms: ${platforms}`);
expect(platforms).not.toBeUndefined();
expect(platforms).not.toEqual('');
const builder = await buildx.inspect('');
console.log('builder', builder);
expect(builder).not.toBeUndefined();
expect(builder.name).not.toEqual('');
expect(builder.driver).not.toEqual('');
expect(builder.node_platforms).not.toEqual('');
},
100000
);
Expand Down
30 changes: 30 additions & 0 deletions __tests__/context.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as os from 'os';
import * as context from '../src/context';

describe('getInputList', () => {
Expand Down Expand Up @@ -78,6 +79,27 @@ describe('asyncForEach', () => {
});
});

describe('setOutput', () => {
beforeEach(() => {
process.stdout.write = jest.fn();
});

it('setOutput produces the correct command', () => {
context.setOutput('some output', 'some value');
assertWriteCalls([`::set-output name=some output::some value${os.EOL}`]);
});

it('setOutput handles bools', () => {
context.setOutput('some output', false);
assertWriteCalls([`::set-output name=some output::false${os.EOL}`]);
});

it('setOutput handles numbers', () => {
context.setOutput('some output', 1.01);
assertWriteCalls([`::set-output name=some output::1.01${os.EOL}`]);
});
});

// See: https://github.com/actions/toolkit/blob/master/packages/core/src/core.ts#L67
function getInputName(name: string): string {
return `INPUT_${name.replace(/ /g, '_').toUpperCase()}`;
Expand All @@ -86,3 +108,11 @@ function getInputName(name: string): string {
function setInput(name: string, value: string): void {
process.env[getInputName(name)] = value;
}

// Assert that process.stdout.write calls called only with the given arguments.
function assertWriteCalls(calls: string[]): void {
expect(process.stdout.write).toHaveBeenCalledTimes(calls.length);
for (let i = 0; i < calls.length; i++) {
expect(process.stdout.write).toHaveBeenNthCalledWith(i + 1, calls[i]);
}
}
14 changes: 11 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,22 @@ inputs:
description: 'Optional address for docker socket or context from `docker context ls`'
required: false
config:
description: 'Optional config file path'
description: 'BuildKit config file'
required: false

outputs:
name:
description: 'Builder instance name'
description: 'Builder name'
driver:
description: 'Builder driver'
endpoint:
description: 'Builder node endpoint'
status:
description: 'Builder node status'
flags:
description: 'Builder node flags (if applicable)'
platforms:
description: 'Available platforms (comma separated)'
description: 'Builder node platforms available (comma separated)'

runs:
using: 'node12'
Expand Down
71 changes: 58 additions & 13 deletions dist/index.js

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

Loading

0 comments on commit 0f03438

Please sign in to comment.