Skip to content

Commit

Permalink
Add config-inline input
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 Sep 3, 2021
1 parent ee7ac31 commit 34e94a5
Show file tree
Hide file tree
Showing 13 changed files with 6,795 additions and 2,060 deletions.
12 changes: 4 additions & 8 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,15 @@ updates:
directory: "/"
schedule:
interval: "daily"
time: "06:00"
timezone: "Europe/Paris"
labels:
- ":game_die: dependencies"
- ":robot: bot"
- "dependencies"
- "bot"
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "daily"
time: "06:00"
timezone: "Europe/Paris"
allow:
- dependency-type: "production"
labels:
- ":game_die: dependencies"
- ":robot: bot"
- "dependencies"
- "bot"
27 changes: 27 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,33 @@ jobs:
with:
context: .

config-inline:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Create Dockerfile
run: |
cat > ./Dockerfile <<EOL
FROM alpine
EOL
-
name: Set up Docker Buildx
uses: ./
with:
buildkitd-flags: --debug
config-inline: |
debug = true
[registry."docker.io"]
mirrors = ["mirror.gcr.io"]
-
name: Build
uses: docker/build-push-action@v2
with:
context: .

with-qemu:
runs-on: ubuntu-latest
strategy:
Expand Down
70 changes: 68 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ ___
* [Quick start](#quick-start)
* [With QEMU](#with-qemu)
* [Install by default](#install-by-default)
* [BuildKit daemon configuration](#buildkit-daemon-configuration)
* [Registry mirror](#registry-mirror)
* [Max parallelism](#max-parallelism)
* [Customizing](#customizing)
* [inputs](#inputs)
* [outputs](#outputs)
Expand Down Expand Up @@ -91,8 +94,6 @@ jobs:
### Install by default
Implemented with https://github.com/docker/buildx#setting-buildx-as-default-builder-in-docker-1903
```yaml
name: ci

Expand All @@ -117,6 +118,68 @@ jobs:
docker build . # will run buildx
```
### BuildKit daemon configuration
You can provide a [BuildKit configuration](https://github.com/moby/buildkit/blob/master/docs/buildkitd.toml.md)
to your builder if you're using the [`docker-container` driver](https://github.com/docker/buildx/blob/master/docs/reference/buildx_create.md#driver)
(default) with the `config` or `config-inline` inputs:

#### Registry mirror

You can configure a registry mirror using an inline block directly in your
workflow with the `config-inline` input:

```yaml
name: ci
on:
push:
jobs:
buildx:
runs-on: ubuntu-latest
steps:
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
with:
config-inline: |
[registry."docker.io"]
mirrors = ["mirror.gcr.io"]
```

#### Max parallelism

You can limit the parallelism of the BuildKit solver which is particularly
useful for low-powered machines.

You can use the `config-inline` input like the
previous example, or you can use a dedicated BuildKit config file from your
repo if you want with the `config` input:

```toml
# .github/buildkitd.toml
[worker.oci]
max-parallelism = 4
```

```yaml
name: ci
on:
push:
jobs:
buildx:
runs-on: ubuntu-latest
steps:
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
with:
config: .github/buildkitd.toml
```

## Customizing

### inputs
Expand All @@ -133,6 +196,9 @@ Following inputs can be used as `step.with` keys
| `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 | [BuildKit config file](https://github.com/docker/buildx/blob/master/docs/reference/buildx_create.md#config) |
| `config-inline` | String | Same as `config` but inline |

> `config` and `config-inline` are mutually exclusive.

> `CSV` type must be a newline-delimited string
> ```yaml
Expand Down
40 changes: 40 additions & 0 deletions __tests__/buildx.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import * as context from '../src/context';
import * as semver from 'semver';
import * as exec from '@actions/exec';

const tmpNameSync = path.join('/tmp/.docker-setup-buildx-jest', '.tmpname-jest').split(path.sep).join(path.posix.sep);

jest.spyOn(context, 'tmpDir').mockImplementation((): string => {
const tmpDir = path.join('/tmp/.docker-setup-buildx-jest').split(path.sep).join(path.posix.sep);
if (!fs.existsSync(tmpDir)) {
Expand All @@ -14,6 +16,10 @@ jest.spyOn(context, 'tmpDir').mockImplementation((): string => {
return tmpDir;
});

jest.spyOn(context, 'tmpNameSync').mockImplementation((): string => {
return tmpNameSync;
});

describe('isAvailable', () => {
const execSpy: jest.SpyInstance = jest.spyOn(exec, 'getExecOutput');
buildx.isAvailable();
Expand Down Expand Up @@ -119,3 +125,37 @@ describe('install', () => {
expect(fs.existsSync(buildxBin)).toBe(true);
}, 100000);
});

describe('getConfig', () => {
test.each([
['debug = true', false, 'debug = true', false],
[`notfound.toml`, true, '', true],
[
`${path.join(__dirname, 'fixtures', 'buildkitd.toml').split(path.sep).join(path.posix.sep)}`,
true,
`debug = true
[registry."docker.io"]
mirrors = ["mirror.gcr.io"]
`,
false
]
])('given %p config', async (val, file, exValue, invalid) => {
try {
let config: string;
if (file) {
config = await buildx.getConfigFile(val);
} else {
config = await buildx.getConfigInline(val);
}
expect(true).toBe(!invalid);
console.log(`config: ${config}`);
expect(config).toEqual(`${tmpNameSync}`);
const configValue = await fs.readFileSync(tmpNameSync, 'utf-8');
console.log(`configValue: ${configValue}`);
expect(configValue).toEqual(exValue);
} catch (err) {
console.log(err);
expect(true).toBe(invalid);
}
});
});
4 changes: 4 additions & 0 deletions __tests__/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ jest.spyOn(context, 'tmpDir').mockImplementation((): string => {
return tmpDir;
});

jest.spyOn(context, 'tmpNameSync').mockImplementation((): string => {
return path.join('/tmp/.docker-setup-buildx-jest', '.tmpname-jest').split(path.sep).join(path.posix.sep);
});

describe('getInputList', () => {
it('handles single line correctly', async () => {
await setInput('foo', 'bar');
Expand Down
3 changes: 3 additions & 0 deletions __tests__/fixtures/buildkitd.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
debug = true
[registry."docker.io"]
mirrors = ["mirror.gcr.io"]
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ inputs:
config:
description: 'BuildKit config file'
required: false
config-inline:
description: 'Inline BuildKit config'
required: false

outputs:
name:
Expand Down
Loading

0 comments on commit 34e94a5

Please sign in to comment.