Skip to content

Commit

Permalink
Merge pull request #185 from crazy-max/fix-iidfile
Browse files Browse the repository at this point in the history
Do not set --iidfile flag if local or tar exporters are used
  • Loading branch information
CrazyMax authored and GitHub committed Oct 20, 2020
2 parents 5ab22b2 + 6751eb6 commit 84306df
Show file tree
Hide file tree
Showing 11 changed files with 1,875 additions and 315 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,27 @@ on:
- master

jobs:
minimal:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2.3.3
with:
path: action
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
-
name: Build
uses: ./action
with:
file: ./test/Dockerfile
-
name: Dump context
if: always()
uses: crazy-max/ghaction-dump-context@v1

git-context:
runs-on: ubuntu-latest
services:
Expand Down Expand Up @@ -240,6 +261,7 @@ jobs:
id: buildx
uses: docker/setup-buildx-action@v1
with:
# TODO: Remove image=moby/buildkit:buildx-stable-1 when moby/buildkit#1727 fixed
driver-opts: |
network=host
image=moby/buildkit:buildx-stable-1
Expand Down Expand Up @@ -327,6 +349,7 @@ jobs:
id: buildx
uses: docker/setup-buildx-action@v1
with:
# TODO: Remove image=moby/buildkit:buildx-stable-1 when moby/buildkit#1727 fixed
driver-opts: |
network=host
image=moby/buildkit:buildx-stable-1
Expand Down Expand Up @@ -391,6 +414,7 @@ jobs:
id: buildx
uses: docker/setup-buildx-action@v1
with:
# TODO: Remove image=moby/buildkit:buildx-stable-1 when moby/buildkit#1727 fixed
driver-opts: |
network=host
image=moby/buildkit:buildx-stable-1
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ build-secrets, remote cache, etc. and different builder deployment/namespacing o

### Git context

The default behavior of this action is to use the [Git context invoked by your workflow](https://github.com/docker/build-push-action/blob/master/src/context.ts#L10-L12).
The default behavior of this action is to use the [Git context invoked by your workflow](https://github.com/docker/build-push-action/blob/master/src/context.ts#L31-L35).

```yaml
name: ci
Expand Down
76 changes: 75 additions & 1 deletion __tests__/buildx.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
import fs from 'fs';
import * as fs from 'fs';
import * as path from 'path';
import * as semver from 'semver';
import * as buildx from '../src/buildx';
import * as exec from '@actions/exec';
import * as context from '../src/context';

const digest = 'sha256:bfb45ab72e46908183546477a08f8867fc40cebadd00af54b071b097aed127a9';

jest.spyOn(context, 'tmpDir').mockImplementation((): string => {
const tmpDir = path.join('/tmp/.docker-build-push-jest').split(path.sep).join(path.posix.sep);
if (!fs.existsSync(tmpDir)) {
fs.mkdirSync(tmpDir, {recursive: true});
}
return tmpDir;
});

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

describe('getImageID', () => {
it('matches', async () => {
const imageIDFile = await buildx.getImageIDFile();
Expand All @@ -16,6 +30,66 @@ describe('getImageID', () => {
});
});

describe('isLocalOrTarExporter', () => {
// prettier-ignore
test.each([
[
[
'type=registry,ref=user/app',
],
false
],
[
[
'type=docker',
],
false
],
[
[
'type=local,dest=./release-out'
],
true
],
[
[
'type=tar,dest=/tmp/image.tar'
],
true
],
[
[
'type=docker',
'type=tar,dest=/tmp/image.tar'
],
true
],
[
[
'"type=tar","dest=/tmp/image.tar"'
],
true
],
[
[
'" type= local" , dest=./release-out'
],
true
],
[
[
'.'
],
true
],
])(
'given %p returns %p',
async (outputs: Array<string>, expected: boolean) => {
expect(buildx.isLocalOrTarExporter(outputs)).toEqual(expected);
}
);
});

describe('getVersion', () => {
it('valid', async () => {
await exec.exec('docker', ['buildx', 'version']);
Expand Down
116 changes: 116 additions & 0 deletions __tests__/context.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,120 @@
import * as fs from 'fs';
import * as path from 'path';
import * as context from '../src/context';
import * as buildx from '../src/buildx';

jest.spyOn(context, 'defaultContext').mockImplementation((): string => {
return 'https://github.com/docker/build-push-action.git#test-jest';
});

jest.spyOn(context, 'tmpDir').mockImplementation((): string => {
const tmpDir = path.join('/tmp/.docker-build-push-jest').split(path.sep).join(path.posix.sep);
if (!fs.existsSync(tmpDir)) {
fs.mkdirSync(tmpDir, {recursive: true});
}
return tmpDir;
});

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

describe('getArgs', () => {
beforeEach(() => {
process.env = Object.keys(process.env).reduce((object, key) => {
if (!key.startsWith('INPUT_')) {
object[key] = process.env[key];
}
return object;
}, {});
});

// prettier-ignore
test.each([
[
'0.4.2',
new Map<string, string>([
// noop
]),
[
'buildx',
'build',
'--iidfile', '/tmp/.docker-build-push-jest/iidfile',
'--file', 'Dockerfile',
'https://github.com/docker/build-push-action.git#test-jest'
]
],
[
'0.4.2',
new Map<string, string>([
['context', '.'],
['outputs', 'type=local,dest=./release-out']
]),
[
'buildx',
'build',
'--output', 'type=local,dest=./release-out',
'--file', 'Dockerfile',
'.'
]
],
[
'0.4.1',
new Map<string, string>([
['context', '.']
]),
[
'buildx',
'build',
'--file', 'Dockerfile',
'.'
]
],
[
'0.4.2',
new Map<string, string>([
['context', '.'],
['secrets', 'GIT_AUTH_TOKEN=abcdefghijklmno0123456789'],
]),
[
'buildx',
'build',
'--iidfile', '/tmp/.docker-build-push-jest/iidfile',
'--secret', 'id=GIT_AUTH_TOKEN,src=/tmp/.docker-build-push-jest/.tmpname-jest',
'--file', 'Dockerfile',
'.'
]
],
[
'0.4.2',
new Map<string, string>([
['github-token', 'abcdefghijklmno0123456789'],
['outputs', '.']
]),
[
'buildx',
'build',
'--output', '.',
'--secret', 'id=GIT_AUTH_TOKEN,src=/tmp/.docker-build-push-jest/.tmpname-jest',
'--file', 'Dockerfile',
'https://github.com/docker/build-push-action.git#test-jest'
]
]
])(
'given %p with %p as inputs, returns %p',
async (buildxVersion: string, inputs: Map<string, any>, expected: Array<string>) => {
await inputs.forEach((value: string, name: string) => {
setInput(name, value);
});
const defContext = context.defaultContext();
const inp = await context.getInputs(defContext);
console.log(inp);
const res = await context.getArgs(inp, defContext, buildxVersion);
console.log(res);
expect(res).toEqual(expected);
}
);
});

describe('getInputList', () => {
it('handles single line correctly', async () => {
Expand Down
Loading

0 comments on commit 84306df

Please sign in to comment.