Skip to content

Commit f40e889

Browse files
committed
Allow building buildx from source
Signed-off-by: CrazyMax <[email protected]>
1 parent a1c666d commit f40e889

14 files changed

Lines changed: 342 additions & 44 deletions

File tree

.github/workflows/ci.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,3 +313,37 @@ jobs:
313313
echo "Status: ${{ steps.buildx.outputs.status }}"
314314
echo "Flags: ${{ steps.buildx.outputs.flags }}"
315315
echo "Platforms: ${{ steps.buildx.outputs.platforms }}"
316+
317+
build-ref:
318+
runs-on: ubuntu-latest
319+
strategy:
320+
fail-fast: false
321+
matrix:
322+
ref:
323+
- master
324+
- refs/tags/v0.5.1
325+
- refs/pull/648/head
326+
steps:
327+
-
328+
name: Checkout
329+
uses: actions/checkout@v2
330+
-
331+
name: Set up Docker Buildx
332+
uses: ./
333+
with:
334+
version: https://github.com/docker/buildx.git#${{ matrix.ref }}
335+
-
336+
name: Check version
337+
run: |
338+
docker buildx version
339+
-
340+
name: Create Dockerfile
341+
run: |
342+
cat > ./Dockerfile <<EOL
343+
FROM alpine
344+
EOL
345+
-
346+
name: Build
347+
uses: docker/build-push-action@master
348+
with:
349+
context: .

.prettierrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"printWidth": 120,
2+
"printWidth": 240,
33
"tabWidth": 2,
44
"useTabs": false,
55
"semi": true,

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ Following inputs can be used as `step.with` keys
125125

126126
| Name | Type | Description |
127127
|--------------------|---------|-----------------------------------|
128-
| `version` | String | [Buildx](https://github.com/docker/buildx) version. (eg. `v0.3.0`, `latest`) |
128+
| `version` | String | [buildx](https://github.com/docker/buildx) version. (eg. `v0.3.0`, `latest`, `https://github.com/docker/buildx.git#master`) |
129129
| `driver` | String | Sets the [builder driver](https://github.com/docker/buildx/blob/master/docs/reference/buildx_create.md#driver) to be used (default `docker-container`) |
130130
| `driver-opts` | CSV | List of additional [driver-specific options](https://github.com/docker/buildx/blob/master/docs/reference/buildx_create.md#driver-opt) (eg. `image=moby/buildkit:master`) |
131131
| `buildkitd-flags` | String | [Flags for buildkitd](https://github.com/moby/buildkit/blob/master/docs/buildkitd.toml.md) daemon (since [buildx v0.3.0](https://github.com/docker/buildx/releases/tag/v0.3.0)) |

__tests__/buildx.test.ts

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
1-
import fs = require('fs');
2-
import * as buildx from '../src/buildx';
3-
import * as path from 'path';
1+
import * as fs from 'fs';
42
import * as os from 'os';
3+
import * as path from 'path';
4+
import * as buildx from '../src/buildx';
5+
import * as context from '../src/context';
56
import * as semver from 'semver';
67
import * as exec from '@actions/exec';
78

9+
jest.spyOn(context, 'tmpDir').mockImplementation((): string => {
10+
const tmpDir = path.join('/tmp/.docker-setup-buildx-jest').split(path.sep).join(path.posix.sep);
11+
if (!fs.existsSync(tmpDir)) {
12+
fs.mkdirSync(tmpDir, {recursive: true});
13+
}
14+
return tmpDir;
15+
});
16+
817
describe('isAvailable', () => {
918
const execSpy: jest.SpyInstance = jest.spyOn(exec, 'getExecOutput');
1019
buildx.isAvailable();
@@ -41,9 +50,20 @@ describe('parseVersion', () => {
4150
test.each([
4251
['github.com/docker/buildx 0.4.1+azure bda4882a65349ca359216b135896bddc1d92461c', '0.4.1'],
4352
['github.com/docker/buildx v0.4.1 bda4882a65349ca359216b135896bddc1d92461c', '0.4.1'],
44-
['github.com/docker/buildx v0.4.2 fb7b670b764764dc4716df3eba07ffdae4cc47b2', '0.4.2']
53+
['github.com/docker/buildx v0.4.2 fb7b670b764764dc4716df3eba07ffdae4cc47b2', '0.4.2'],
54+
['github.com/docker/buildx f117971 f11797113e5a9b86bd976329c5dbb8a8bfdfadfa', 'f117971']
4555
])('given %p', async (stdout, expected) => {
46-
expect(await buildx.parseVersion(stdout)).toEqual(expected);
56+
expect(buildx.parseVersion(stdout)).toEqual(expected);
57+
});
58+
});
59+
60+
describe('satisfies', () => {
61+
test.each([
62+
['0.4.1', '>=0.3.2', true],
63+
['bda4882a65349ca359216b135896bddc1d92461c', '>0.1.0', false],
64+
['f117971', '>0.6.0', true]
65+
])('given %p', async (version, range, expected) => {
66+
expect(buildx.satisfies(version, range)).toBe(expected);
4767
});
4868
});
4969

@@ -72,6 +92,15 @@ describe('inspect', () => {
7292
);
7393
});
7494

95+
describe('build', () => {
96+
it.skip('valid', async () => {
97+
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'setup-buildx-'));
98+
const buildxBin = await buildx.build('https://github.com/docker/buildx.git#refs/pull/648/head', tmpDir);
99+
console.log(buildxBin);
100+
expect(fs.existsSync(buildxBin)).toBe(true);
101+
}, 100000);
102+
});
103+
75104
describe('install', () => {
76105
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'setup-buildx-'));
77106
it('acquires v0.4.1 version of buildx', async () => {

__tests__/context.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
1+
import * as fs from 'fs';
12
import * as os from 'os';
3+
import * as path from 'path';
24
import * as context from '../src/context';
35

6+
jest.spyOn(context, 'tmpDir').mockImplementation((): string => {
7+
const tmpDir = path.join('/tmp/.docker-setup-buildx-jest').split(path.sep).join(path.posix.sep);
8+
if (!fs.existsSync(tmpDir)) {
9+
fs.mkdirSync(tmpDir, {recursive: true});
10+
}
11+
return tmpDir;
12+
});
13+
414
describe('getInputList', () => {
515
it('handles single line correctly', async () => {
616
await setInput('foo', 'bar');

__tests__/git.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import * as git from '../src/git';
2+
3+
describe('git', () => {
4+
it('returns git remote ref', async () => {
5+
const ref: string = await git.getRemoteSha('https://github.com/docker/buildx.git', 'refs/pull/648/head');
6+
console.log(`ref: ${ref}`);
7+
expect(ref).toEqual('f11797113e5a9b86bd976329c5dbb8a8bfdfadfa');
8+
});
9+
});

__tests__/util.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import * as util from '../src/util';
2+
3+
describe('isValidUrl', () => {
4+
test.each([
5+
['https://github.com/docker/buildx.git', true],
6+
['https://github.com/docker/buildx.git#refs/pull/648/head', true],
7+
['v0.4.1', false]
8+
])('given %p', async (url, expected) => {
9+
expect(util.isValidUrl(url)).toEqual(expected);
10+
});
11+
});

codecov.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
comment: false
2+
github_checks:
3+
annotations: false

0 commit comments

Comments
 (0)