Skip to content

Commit 94ab11c

Browse files
authored
Merge pull request #106 from crazy-max/config-inline
Add `config-inline` input
2 parents ee7ac31 + 34e94a5 commit 94ab11c

13 files changed

+6795
-2060
lines changed

.github/dependabot.yml

+4-8
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,15 @@ updates:
44
directory: "/"
55
schedule:
66
interval: "daily"
7-
time: "06:00"
8-
timezone: "Europe/Paris"
97
labels:
10-
- ":game_die: dependencies"
11-
- ":robot: bot"
8+
- "dependencies"
9+
- "bot"
1210
- package-ecosystem: "npm"
1311
directory: "/"
1412
schedule:
1513
interval: "daily"
16-
time: "06:00"
17-
timezone: "Europe/Paris"
1814
allow:
1915
- dependency-type: "production"
2016
labels:
21-
- ":game_die: dependencies"
22-
- ":robot: bot"
17+
- "dependencies"
18+
- "bot"

.github/workflows/ci.yml

+27
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,33 @@ jobs:
278278
with:
279279
context: .
280280

281+
config-inline:
282+
runs-on: ubuntu-latest
283+
steps:
284+
-
285+
name: Checkout
286+
uses: actions/checkout@v2
287+
-
288+
name: Create Dockerfile
289+
run: |
290+
cat > ./Dockerfile <<EOL
291+
FROM alpine
292+
EOL
293+
-
294+
name: Set up Docker Buildx
295+
uses: ./
296+
with:
297+
buildkitd-flags: --debug
298+
config-inline: |
299+
debug = true
300+
[registry."docker.io"]
301+
mirrors = ["mirror.gcr.io"]
302+
-
303+
name: Build
304+
uses: docker/build-push-action@v2
305+
with:
306+
context: .
307+
281308
with-qemu:
282309
runs-on: ubuntu-latest
283310
strategy:

README.md

+68-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ ___
2121
* [Quick start](#quick-start)
2222
* [With QEMU](#with-qemu)
2323
* [Install by default](#install-by-default)
24+
* [BuildKit daemon configuration](#buildkit-daemon-configuration)
25+
* [Registry mirror](#registry-mirror)
26+
* [Max parallelism](#max-parallelism)
2427
* [Customizing](#customizing)
2528
* [inputs](#inputs)
2629
* [outputs](#outputs)
@@ -91,8 +94,6 @@ jobs:
9194
9295
### Install by default
9396
94-
Implemented with https://github.com/docker/buildx#setting-buildx-as-default-builder-in-docker-1903
95-
9697
```yaml
9798
name: ci
9899

@@ -117,6 +118,68 @@ jobs:
117118
docker build . # will run buildx
118119
```
119120
121+
### BuildKit daemon configuration
122+
123+
You can provide a [BuildKit configuration](https://github.com/moby/buildkit/blob/master/docs/buildkitd.toml.md)
124+
to your builder if you're using the [`docker-container` driver](https://github.com/docker/buildx/blob/master/docs/reference/buildx_create.md#driver)
125+
(default) with the `config` or `config-inline` inputs:
126+
127+
#### Registry mirror
128+
129+
You can configure a registry mirror using an inline block directly in your
130+
workflow with the `config-inline` input:
131+
132+
```yaml
133+
name: ci
134+
135+
on:
136+
push:
137+
138+
jobs:
139+
buildx:
140+
runs-on: ubuntu-latest
141+
steps:
142+
-
143+
name: Set up Docker Buildx
144+
uses: docker/setup-buildx-action@v1
145+
with:
146+
config-inline: |
147+
[registry."docker.io"]
148+
mirrors = ["mirror.gcr.io"]
149+
```
150+
151+
#### Max parallelism
152+
153+
You can limit the parallelism of the BuildKit solver which is particularly
154+
useful for low-powered machines.
155+
156+
You can use the `config-inline` input like the
157+
previous example, or you can use a dedicated BuildKit config file from your
158+
repo if you want with the `config` input:
159+
160+
```toml
161+
# .github/buildkitd.toml
162+
[worker.oci]
163+
max-parallelism = 4
164+
```
165+
166+
```yaml
167+
name: ci
168+
169+
on:
170+
push:
171+
172+
jobs:
173+
buildx:
174+
runs-on: ubuntu-latest
175+
steps:
176+
-
177+
name: Set up Docker Buildx
178+
uses: docker/setup-buildx-action@v1
179+
with:
180+
config: .github/buildkitd.toml
181+
```
182+
120183
## Customizing
121184

122185
### inputs
@@ -133,6 +196,9 @@ Following inputs can be used as `step.with` keys
133196
| `use` | Bool | Switch to this builder instance (default `true`) |
134197
| `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` |
135198
| `config` | String | [BuildKit config file](https://github.com/docker/buildx/blob/master/docs/reference/buildx_create.md#config) |
199+
| `config-inline` | String | Same as `config` but inline |
200+
201+
> `config` and `config-inline` are mutually exclusive.
136202

137203
> `CSV` type must be a newline-delimited string
138204
> ```yaml

__tests__/buildx.test.ts

+40
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import * as context from '../src/context';
66
import * as semver from 'semver';
77
import * as exec from '@actions/exec';
88

9+
const tmpNameSync = path.join('/tmp/.docker-setup-buildx-jest', '.tmpname-jest').split(path.sep).join(path.posix.sep);
10+
911
jest.spyOn(context, 'tmpDir').mockImplementation((): string => {
1012
const tmpDir = path.join('/tmp/.docker-setup-buildx-jest').split(path.sep).join(path.posix.sep);
1113
if (!fs.existsSync(tmpDir)) {
@@ -14,6 +16,10 @@ jest.spyOn(context, 'tmpDir').mockImplementation((): string => {
1416
return tmpDir;
1517
});
1618

19+
jest.spyOn(context, 'tmpNameSync').mockImplementation((): string => {
20+
return tmpNameSync;
21+
});
22+
1723
describe('isAvailable', () => {
1824
const execSpy: jest.SpyInstance = jest.spyOn(exec, 'getExecOutput');
1925
buildx.isAvailable();
@@ -119,3 +125,37 @@ describe('install', () => {
119125
expect(fs.existsSync(buildxBin)).toBe(true);
120126
}, 100000);
121127
});
128+
129+
describe('getConfig', () => {
130+
test.each([
131+
['debug = true', false, 'debug = true', false],
132+
[`notfound.toml`, true, '', true],
133+
[
134+
`${path.join(__dirname, 'fixtures', 'buildkitd.toml').split(path.sep).join(path.posix.sep)}`,
135+
true,
136+
`debug = true
137+
[registry."docker.io"]
138+
mirrors = ["mirror.gcr.io"]
139+
`,
140+
false
141+
]
142+
])('given %p config', async (val, file, exValue, invalid) => {
143+
try {
144+
let config: string;
145+
if (file) {
146+
config = await buildx.getConfigFile(val);
147+
} else {
148+
config = await buildx.getConfigInline(val);
149+
}
150+
expect(true).toBe(!invalid);
151+
console.log(`config: ${config}`);
152+
expect(config).toEqual(`${tmpNameSync}`);
153+
const configValue = await fs.readFileSync(tmpNameSync, 'utf-8');
154+
console.log(`configValue: ${configValue}`);
155+
expect(configValue).toEqual(exValue);
156+
} catch (err) {
157+
console.log(err);
158+
expect(true).toBe(invalid);
159+
}
160+
});
161+
});

__tests__/context.test.ts

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ jest.spyOn(context, 'tmpDir').mockImplementation((): string => {
1111
return tmpDir;
1212
});
1313

14+
jest.spyOn(context, 'tmpNameSync').mockImplementation((): string => {
15+
return path.join('/tmp/.docker-setup-buildx-jest', '.tmpname-jest').split(path.sep).join(path.posix.sep);
16+
});
17+
1418
describe('getInputList', () => {
1519
it('handles single line correctly', async () => {
1620
await setInput('foo', 'bar');

__tests__/fixtures/buildkitd.toml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
debug = true
2+
[registry."docker.io"]
3+
mirrors = ["mirror.gcr.io"]

action.yml

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ inputs:
3535
config:
3636
description: 'BuildKit config file'
3737
required: false
38+
config-inline:
39+
description: 'Inline BuildKit config'
40+
required: false
3841

3942
outputs:
4043
name:

0 commit comments

Comments
 (0)