Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow building buildx from source #99

Merged
merged 1 commit into from Jul 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/ci.yml
Expand Up @@ -313,3 +313,37 @@ jobs:
echo "Status: ${{ steps.buildx.outputs.status }}"
echo "Flags: ${{ steps.buildx.outputs.flags }}"
echo "Platforms: ${{ steps.buildx.outputs.platforms }}"

build-ref:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
ref:
- master
- refs/tags/v0.5.1
- refs/pull/648/head
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Set up Docker Buildx
uses: ./
with:
version: https://github.com/docker/buildx.git#${{ matrix.ref }}
-
name: Check version
run: |
docker buildx version
-
name: Create Dockerfile
run: |
cat > ./Dockerfile <<EOL
FROM alpine
EOL
-
name: Build
uses: docker/build-push-action@master
with:
context: .
2 changes: 1 addition & 1 deletion .prettierrc.json
@@ -1,5 +1,5 @@
{
"printWidth": 120,
"printWidth": 240,
"tabWidth": 2,
"useTabs": false,
"semi": true,
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -125,7 +125,7 @@ Following inputs can be used as `step.with` keys

| Name | Type | Description |
|--------------------|---------|-----------------------------------|
| `version` | String | [Buildx](https://github.com/docker/buildx) version. (eg. `v0.3.0`, `latest`) |
| `version` | String | [buildx](https://github.com/docker/buildx) version. (eg. `v0.3.0`, `latest`, `https://github.com/docker/buildx.git#master`) |
| `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`) |
| `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`) |
| `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)) |
Expand Down
39 changes: 34 additions & 5 deletions __tests__/buildx.test.ts
@@ -1,10 +1,19 @@
import fs = require('fs');
import * as buildx from '../src/buildx';
import * as path from 'path';
import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
import * as buildx from '../src/buildx';
import * as context from '../src/context';
import * as semver from 'semver';
import * as exec from '@actions/exec';

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)) {
fs.mkdirSync(tmpDir, {recursive: true});
}
return tmpDir;
});

describe('isAvailable', () => {
const execSpy: jest.SpyInstance = jest.spyOn(exec, 'getExecOutput');
buildx.isAvailable();
Expand Down Expand Up @@ -41,9 +50,20 @@ describe('parseVersion', () => {
test.each([
['github.com/docker/buildx 0.4.1+azure bda4882a65349ca359216b135896bddc1d92461c', '0.4.1'],
['github.com/docker/buildx v0.4.1 bda4882a65349ca359216b135896bddc1d92461c', '0.4.1'],
['github.com/docker/buildx v0.4.2 fb7b670b764764dc4716df3eba07ffdae4cc47b2', '0.4.2']
['github.com/docker/buildx v0.4.2 fb7b670b764764dc4716df3eba07ffdae4cc47b2', '0.4.2'],
['github.com/docker/buildx f117971 f11797113e5a9b86bd976329c5dbb8a8bfdfadfa', 'f117971']
])('given %p', async (stdout, expected) => {
expect(await buildx.parseVersion(stdout)).toEqual(expected);
expect(buildx.parseVersion(stdout)).toEqual(expected);
});
});

describe('satisfies', () => {
test.each([
['0.4.1', '>=0.3.2', true],
['bda4882a65349ca359216b135896bddc1d92461c', '>0.1.0', false],
['f117971', '>0.6.0', true]
])('given %p', async (version, range, expected) => {
expect(buildx.satisfies(version, range)).toBe(expected);
});
});

Expand Down Expand Up @@ -72,6 +92,15 @@ describe('inspect', () => {
);
});

describe('build', () => {
it.skip('valid', async () => {
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'setup-buildx-'));
const buildxBin = await buildx.build('https://github.com/docker/buildx.git#refs/pull/648/head', tmpDir);
console.log(buildxBin);
expect(fs.existsSync(buildxBin)).toBe(true);
}, 100000);
});

describe('install', () => {
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'setup-buildx-'));
it('acquires v0.4.1 version of buildx', async () => {
Expand Down
10 changes: 10 additions & 0 deletions __tests__/context.test.ts
@@ -1,6 +1,16 @@
import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
import * as context from '../src/context';

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)) {
fs.mkdirSync(tmpDir, {recursive: true});
}
return tmpDir;
});

describe('getInputList', () => {
it('handles single line correctly', async () => {
await setInput('foo', 'bar');
Expand Down
9 changes: 9 additions & 0 deletions __tests__/git.test.ts
@@ -0,0 +1,9 @@
import * as git from '../src/git';

describe('git', () => {
it('returns git remote ref', async () => {
const ref: string = await git.getRemoteSha('https://github.com/docker/buildx.git', 'refs/pull/648/head');
console.log(`ref: ${ref}`);
expect(ref).toEqual('f11797113e5a9b86bd976329c5dbb8a8bfdfadfa');
});
});
11 changes: 11 additions & 0 deletions __tests__/util.test.ts
@@ -0,0 +1,11 @@
import * as util from '../src/util';

describe('isValidUrl', () => {
test.each([
['https://github.com/docker/buildx.git', true],
['https://github.com/docker/buildx.git#refs/pull/648/head', true],
['v0.4.1', false]
])('given %p', async (url, expected) => {
expect(util.isValidUrl(url)).toEqual(expected);
});
});
3 changes: 3 additions & 0 deletions codecov.yml
@@ -0,0 +1,3 @@
comment: false
github_checks:
annotations: false