1
0
Fork 0
mirror of https://github.com/docker/build-push-action.git synced 2025-05-11 16:09:30 +02:00

Merge branch 'master' of github.com:docker/build-push-action into argument-collection

This commit is contained in:
Phred 2021-11-17 09:21:47 -06:00
commit 529b1b6a4b
No known key found for this signature in database
GPG key ID: 8103F27168DAA2A0
13 changed files with 237 additions and 110 deletions

View file

@ -28,10 +28,8 @@ jest.spyOn(context, 'tmpNameSync').mockImplementation((): string => {
describe('getImageID', () => {
it('matches', async () => {
const imageIDFile = await buildx.getImageIDFile();
console.log(`imageIDFile: ${imageIDFile}`);
await fs.writeFileSync(imageIDFile, digest);
const imageID = await buildx.getImageID();
console.log(`imageID: ${imageID}`);
expect(imageID).toEqual(digest);
});
});
@ -39,10 +37,8 @@ describe('getImageID', () => {
describe('getMetadata', () => {
it('matches', async () => {
const metadataFile = await buildx.getMetadataFile();
console.log(`metadataFile: ${metadataFile}`);
await fs.writeFileSync(metadataFile, metadata);
const expected = await buildx.getMetadata();
console.log(`metadata: ${expected}`);
expect(expected).toEqual(metadata);
});
});
@ -132,7 +128,6 @@ describe('getVersion', () => {
'valid',
async () => {
const version = await buildx.getVersion();
console.log(`version: ${version}`);
expect(semver.valid(version)).not.toBeNull();
},
100000
@ -179,10 +174,8 @@ describe('getSecret', () => {
secret = await buildx.getSecretString(kvp);
}
expect(true).toBe(!invalid);
console.log(`secret: ${secret}`);
expect(secret).toEqual(`id=${exKey},src=${tmpNameSync}`);
const secretValue = await fs.readFileSync(tmpNameSync, 'utf-8');
console.log(`secretValue: ${secretValue}`);
expect(secretValue).toEqual(exValue);
} catch (err) {
expect(true).toBe(invalid);

View file

@ -140,13 +140,14 @@ describe('getArgs', () => {
// prettier-ignore
test.each([
[
0,
'0.4.1',
new Map<string, string>([
['context', '.'],
['load', 'false'],
['no-cache', 'false'],
['push', 'false'],
['pull', 'false']
['pull', 'false'],
]),
[
'buildx',
@ -156,13 +157,14 @@ describe('getArgs', () => {
]
],
[
1,
'0.4.2',
new Map<string, string>([
['build-args', 'MY_ARG=val1,val2,val3\nARG=val'],
['load', 'false'],
['no-cache', 'false'],
['push', 'false'],
['pull', 'false']
['pull', 'false'],
]),
[
'buildx',
@ -174,13 +176,14 @@ describe('getArgs', () => {
]
],
[
2,
'0.4.2',
new Map<string, string>([
['tags', 'name/app:7.4, name/app:latest'],
['load', 'false'],
['no-cache', 'false'],
['push', 'false'],
['pull', 'false']
['pull', 'false'],
]),
[
'buildx',
@ -192,6 +195,7 @@ describe('getArgs', () => {
]
],
[
3,
'0.4.2',
new Map<string, string>([
['context', '.'],
@ -200,7 +204,7 @@ describe('getArgs', () => {
['load', 'false'],
['no-cache', 'false'],
['push', 'false'],
['pull', 'false']
['pull', 'false'],
]),
[
'buildx',
@ -212,6 +216,7 @@ describe('getArgs', () => {
]
],
[
4,
'0.4.1',
new Map<string, string>([
['context', '.'],
@ -219,7 +224,7 @@ describe('getArgs', () => {
['load', 'false'],
['no-cache', 'false'],
['push', 'false'],
['pull', 'false']
['pull', 'false'],
]),
[
'buildx',
@ -229,13 +234,14 @@ describe('getArgs', () => {
]
],
[
5,
'0.4.1',
new Map<string, string>([
['context', '.'],
['load', 'false'],
['no-cache', 'false'],
['push', 'false'],
['pull', 'false']
['pull', 'false'],
]),
[
'buildx',
@ -245,6 +251,7 @@ describe('getArgs', () => {
]
],
[
6,
'0.4.2',
new Map<string, string>([
['context', '.'],
@ -252,7 +259,7 @@ describe('getArgs', () => {
['load', 'false'],
['no-cache', 'false'],
['push', 'false'],
['pull', 'false']
['pull', 'false'],
]),
[
'buildx',
@ -263,6 +270,7 @@ describe('getArgs', () => {
]
],
[
7,
'0.4.2',
new Map<string, string>([
['github-token', 'abcdefghijklmno0123456789'],
@ -270,7 +278,7 @@ describe('getArgs', () => {
['load', 'false'],
['no-cache', 'false'],
['push', 'false'],
['pull', 'false']
['pull', 'false'],
]),
[
'buildx',
@ -281,6 +289,7 @@ describe('getArgs', () => {
]
],
[
8,
'0.4.2',
new Map<string, string>([
['context', 'https://github.com/docker/build-push-action.git#refs/heads/master'],
@ -292,21 +301,22 @@ describe('getArgs', () => {
['load', 'false'],
['no-cache', 'false'],
['push', 'true'],
['pull', 'false']
['pull', 'false'],
]),
[
'buildx',
'build',
'--platform', 'linux/amd64,linux/arm64',
'--iidfile', '/tmp/.docker-build-push-jest/iidfile',
'--secret', 'id=GIT_AUTH_TOKEN,src=/tmp/.docker-build-push-jest/.tmpname-jest',
'--file', './test/Dockerfile',
'--iidfile', '/tmp/.docker-build-push-jest/iidfile',
'--platform', 'linux/amd64,linux/arm64',
'--secret', 'id=GIT_AUTH_TOKEN,src=/tmp/.docker-build-push-jest/.tmpname-jest',
'--builder', 'builder-git-context-2',
'--push',
'https://github.com/docker/build-push-action.git#refs/heads/master'
]
],
[
9,
'0.4.2',
new Map<string, string>([
['context', 'https://github.com/docker/build-push-action.git#refs/heads/master'],
@ -326,24 +336,25 @@ ccc"`],
['load', 'false'],
['no-cache', 'false'],
['push', 'true'],
['pull', 'false']
['pull', 'false'],
]),
[
'buildx',
'build',
'--platform', 'linux/amd64,linux/arm64',
'--file', './test/Dockerfile',
'--iidfile', '/tmp/.docker-build-push-jest/iidfile',
'--platform', 'linux/amd64,linux/arm64',
'--secret', 'id=GIT_AUTH_TOKEN,src=/tmp/.docker-build-push-jest/.tmpname-jest',
'--secret', 'id=MYSECRET,src=/tmp/.docker-build-push-jest/.tmpname-jest',
'--secret', 'id=FOO,src=/tmp/.docker-build-push-jest/.tmpname-jest',
'--secret', 'id=EMPTYLINE,src=/tmp/.docker-build-push-jest/.tmpname-jest',
'--file', './test/Dockerfile',
'--builder', 'builder-git-context-2',
'--push',
'https://github.com/docker/build-push-action.git#refs/heads/master'
]
],
[
10,
'0.4.2',
new Map<string, string>([
['context', 'https://github.com/docker/build-push-action.git#refs/heads/master'],
@ -363,24 +374,25 @@ ccc`],
['load', 'false'],
['no-cache', 'false'],
['push', 'true'],
['pull', 'false']
['pull', 'false'],
]),
[
'buildx',
'build',
'--platform', 'linux/amd64,linux/arm64',
'--file', './test/Dockerfile',
'--iidfile', '/tmp/.docker-build-push-jest/iidfile',
'--platform', 'linux/amd64,linux/arm64',
'--secret', 'id=GIT_AUTH_TOKEN,src=/tmp/.docker-build-push-jest/.tmpname-jest',
'--secret', 'id=MYSECRET,src=/tmp/.docker-build-push-jest/.tmpname-jest',
'--secret', 'id=FOO,src=/tmp/.docker-build-push-jest/.tmpname-jest',
'--secret', 'id=EMPTYLINE,src=/tmp/.docker-build-push-jest/.tmpname-jest',
'--file', './test/Dockerfile',
'--builder', 'builder-git-context-2',
'--push',
'https://github.com/docker/build-push-action.git#refs/heads/master'
]
],
[
11,
'0.5.1',
new Map<string, string>([
['context', 'https://github.com/docker/build-push-action.git#refs/heads/master'],
@ -392,14 +404,14 @@ ccc`],
['load', 'false'],
['no-cache', 'false'],
['push', 'true'],
['pull', 'false']
['pull', 'false'],
]),
[
'buildx',
'build',
'--file', './test/Dockerfile',
'--iidfile', '/tmp/.docker-build-push-jest/iidfile',
'--secret', 'id=MY_SECRET,src=/tmp/.docker-build-push-jest/.tmpname-jest',
'--file', './test/Dockerfile',
'--builder', 'builder-git-context-2',
'--network', 'host',
'--push',
@ -407,6 +419,7 @@ ccc`],
]
],
[
12,
'0.4.2',
new Map<string, string>([
['context', '.'],
@ -415,7 +428,7 @@ ccc`],
['load', 'false'],
['no-cache', 'false'],
['push', 'false'],
['pull', 'false']
['pull', 'false'],
]),
[
'buildx',
@ -427,6 +440,7 @@ ccc`],
]
],
[
13,
'0.6.0',
new Map<string, string>([
['context', '.'],
@ -436,30 +450,56 @@ ccc`],
['load', 'false'],
['no-cache', 'false'],
['push', 'true'],
['pull', 'false']
['pull', 'false'],
]),
[
'buildx',
'build',
'--file', './test/Dockerfile',
'--iidfile', '/tmp/.docker-build-push-jest/iidfile',
'--metadata-file', '/tmp/.docker-build-push-jest/metadata-file',
'--file', './test/Dockerfile',
'--network', 'host',
'--push',
'.'
]
],
[
14,
'0.7.0',
new Map<string, string>([
['context', '.'],
['file', './test/Dockerfile'],
['cgroup-parent', 'foo'],
['shm-size', '2g'],
['ulimit', `nofile=1024:1024
nproc=3`],
['load', 'false'],
['no-cache', 'false'],
['push', 'false'],
['pull', 'false'],
]),
[
'buildx',
'build',
'--ulimit', 'nofile=1024:1024',
'--ulimit', 'nproc=3',
'--cgroup-parent', 'foo',
'--file', './test/Dockerfile',
'--iidfile', '/tmp/.docker-build-push-jest/iidfile',
'--shm-size', '2g',
'--metadata-file', '/tmp/.docker-build-push-jest/metadata-file',
'.'
]
],
])(
'given %p with %p as inputs, returns %p',
async (buildxVersion: string, inputs: Map<string, any>, expected: Array<string>) => {
'[%d] given %p with %p as inputs, returns %p',
async (num: number, 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);
}
);
@ -469,63 +509,54 @@ describe('getInputList', () => {
it('single line correctly', async () => {
await setInput('foo', 'bar');
const res = await context.getInputList('foo');
console.log(res);
expect(res).toEqual(['bar']);
});
it('multiline correctly', async () => {
setInput('foo', 'bar\nbaz');
const res = await context.getInputList('foo');
console.log(res);
expect(res).toEqual(['bar', 'baz']);
});
it('empty lines correctly', async () => {
setInput('foo', 'bar\n\nbaz');
const res = await context.getInputList('foo');
console.log(res);
expect(res).toEqual(['bar', 'baz']);
});
it('comma correctly', async () => {
setInput('foo', 'bar,baz');
const res = await context.getInputList('foo');
console.log(res);
expect(res).toEqual(['bar', 'baz']);
});
it('empty result correctly', async () => {
setInput('foo', 'bar,baz,');
const res = await context.getInputList('foo');
console.log(res);
expect(res).toEqual(['bar', 'baz']);
});
it('different new lines correctly', async () => {
setInput('foo', 'bar\r\nbaz');
const res = await context.getInputList('foo');
console.log(res);
expect(res).toEqual(['bar', 'baz']);
});
it('different new lines and comma correctly', async () => {
setInput('foo', 'bar\r\nbaz,bat');
const res = await context.getInputList('foo');
console.log(res);
expect(res).toEqual(['bar', 'baz', 'bat']);
});
it('multiline and ignoring comma correctly', async () => {
setInput('cache-from', 'user/app:cache\ntype=local,src=path/to/dir');
const res = await context.getInputList('cache-from', true);
console.log(res);
expect(res).toEqual(['user/app:cache', 'type=local,src=path/to/dir']);
});
it('different new lines and ignoring comma correctly', async () => {
setInput('cache-from', 'user/app:cache\r\ntype=local,src=path/to/dir');
const res = await context.getInputList('cache-from', true);
console.log(res);
expect(res).toEqual(['user/app:cache', 'type=local,src=path/to/dir']);
});
@ -539,7 +570,6 @@ ccccccccc"
FOO=bar`
);
const res = await context.getInputList('secrets', true);
console.log(res);
expect(res).toEqual([
'GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789',
`MYSECRET=aaaaaaaa
@ -563,7 +593,6 @@ bbbb
ccc"`
);
const res = await context.getInputList('secrets', true);
console.log(res);
expect(res).toEqual([
'GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789',
`MYSECRET=aaaaaaaa
@ -587,7 +616,6 @@ ccccccccc
FOO=bar`
);
const res = await context.getInputList('secrets', true);
console.log(res);
expect(res).toEqual(['GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789', 'MYSECRET=aaaaaaaa', 'bbbbbbb', 'ccccccccc', 'FOO=bar']);
});
@ -598,7 +626,6 @@ FOO=bar`
FOO=bar`
);
const res = await context.getInputList('secrets', true);
console.log(res);
expect(res).toEqual([`GPG_KEY=${pgp}`, 'FOO=bar']);
});
@ -612,7 +639,6 @@ ccccccccc"
FOO=bar`
);
const res = await context.getInputList('secrets', true);
console.log(res);
expect(res).toEqual([
'GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789',
`MYSECRET=aaaaaaaa