mirror of
https://github.com/docker/build-push-action.git
synced 2025-06-15 15:47:12 +02:00
Compare commits
25 Commits
Author | SHA1 | Date | |
---|---|---|---|
1bc1040cae | |||
fcaaa5e487 | |||
0987321e12 | |||
94827201d1 | |||
128f05c85a | |||
a15ef4dd9f | |||
c7dab97e55 | |||
a1d2218d38 | |||
0b56a3c3b3 | |||
ae29b67b96 | |||
b44cfd9087 | |||
a437a4518f | |||
a7071c9d9a | |||
9199c83f6e | |||
93a9859764 | |||
9cbc67d577 | |||
07bca60c0f | |||
cc01c17e75 | |||
90850ba046 | |||
915370c72f | |||
f87b75314d | |||
ecbc0634e4 | |||
06b9aae8bc | |||
779802e2ee | |||
dd8c19ed49 |
2
.github/ISSUE_TEMPLATE/bug_report.md
vendored
2
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@ -5,7 +5,7 @@ about: Create a report to help us improve
|
|||||||
|
|
||||||
### Troubleshooting
|
### Troubleshooting
|
||||||
|
|
||||||
Before sumbitting a bug report please read the [Troubleshooting doc](https://github.com/docker/build-push-action/blob/master/TROUBLESHOOTING.md).
|
Before submitting a bug report please read the [Troubleshooting doc](https://github.com/docker/build-push-action/blob/master/TROUBLESHOOTING.md).
|
||||||
|
|
||||||
### Behaviour
|
### Behaviour
|
||||||
|
|
||||||
|
8
.github/dependabot.yml
vendored
8
.github/dependabot.yml
vendored
@ -5,8 +5,8 @@ updates:
|
|||||||
schedule:
|
schedule:
|
||||||
interval: "daily"
|
interval: "daily"
|
||||||
labels:
|
labels:
|
||||||
- ":game_die: dependencies"
|
- "dependencies"
|
||||||
- ":robot: bot"
|
- "bot"
|
||||||
- package-ecosystem: "npm"
|
- package-ecosystem: "npm"
|
||||||
directory: "/"
|
directory: "/"
|
||||||
schedule:
|
schedule:
|
||||||
@ -14,5 +14,5 @@ updates:
|
|||||||
allow:
|
allow:
|
||||||
- dependency-type: "production"
|
- dependency-type: "production"
|
||||||
labels:
|
labels:
|
||||||
- ":game_die: dependencies"
|
- "dependencies"
|
||||||
- ":robot: bot"
|
- "bot"
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"printWidth": 120,
|
"printWidth": 240,
|
||||||
"tabWidth": 2,
|
"tabWidth": 2,
|
||||||
"useTabs": false,
|
"useTabs": false,
|
||||||
"semi": true,
|
"semi": true,
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as semver from 'semver';
|
import * as semver from 'semver';
|
||||||
|
import * as exec from '@actions/exec';
|
||||||
|
|
||||||
import * as buildx from '../src/buildx';
|
import * as buildx from '../src/buildx';
|
||||||
import * as context from '../src/context';
|
import * as context from '../src/context';
|
||||||
import * as docker from '../src/docker';
|
|
||||||
|
|
||||||
const tmpNameSync = path.join('/tmp/.docker-build-push-jest', '.tmpname-jest').split(path.sep).join(path.posix.sep);
|
const tmpNameSync = path.join('/tmp/.docker-build-push-jest', '.tmpname-jest').split(path.sep).join(path.posix.sep);
|
||||||
const digest = 'sha256:bfb45ab72e46908183546477a08f8867fc40cebadd00af54b071b097aed127a9';
|
const digest = 'sha256:bfb45ab72e46908183546477a08f8867fc40cebadd00af54b071b097aed127a9';
|
||||||
@ -92,9 +92,26 @@ describe('isLocalOrTarExporter', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('isAvailable', () => {
|
||||||
|
const execSpy: jest.SpyInstance = jest.spyOn(exec, 'getExecOutput');
|
||||||
|
buildx.isAvailable();
|
||||||
|
|
||||||
|
expect(execSpy).toHaveBeenCalledWith(`docker`, ['buildx'], {
|
||||||
|
silent: true,
|
||||||
|
ignoreReturnCode: true
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('getVersion', () => {
|
describe('getVersion', () => {
|
||||||
async function isDaemonRunning() {
|
async function isDaemonRunning() {
|
||||||
return await docker.isDaemonRunning();
|
return await exec
|
||||||
|
.getExecOutput(`docker`, ['version', '--format', '{{.Server.Os}}'], {
|
||||||
|
ignoreReturnCode: true,
|
||||||
|
silent: true
|
||||||
|
})
|
||||||
|
.then(res => {
|
||||||
|
return !res.stdout.includes(' ') && res.exitCode == 0;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
(isDaemonRunning() ? it : it.skip)(
|
(isDaemonRunning() ? it : it.skip)(
|
||||||
'valid',
|
'valid',
|
||||||
@ -111,9 +128,20 @@ describe('parseVersion', () => {
|
|||||||
test.each([
|
test.each([
|
||||||
['github.com/docker/buildx 0.4.1+azure bda4882a65349ca359216b135896bddc1d92461c', '0.4.1'],
|
['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.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) => {
|
])('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);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -125,13 +153,7 @@ describe('getSecret', () => {
|
|||||||
['aaaaaaaa', false, '', '', true],
|
['aaaaaaaa', false, '', '', true],
|
||||||
['aaaaaaaa=', false, '', '', true],
|
['aaaaaaaa=', false, '', '', true],
|
||||||
['=bbbbbbb', false, '', '', true],
|
['=bbbbbbb', false, '', '', true],
|
||||||
[
|
[`foo=${path.join(__dirname, 'fixtures', 'secret.txt').split(path.sep).join(path.posix.sep)}`, true, 'foo', 'bar', false],
|
||||||
`foo=${path.join(__dirname, 'fixtures', 'secret.txt').split(path.sep).join(path.posix.sep)}`,
|
|
||||||
true,
|
|
||||||
'foo',
|
|
||||||
'bar',
|
|
||||||
false
|
|
||||||
],
|
|
||||||
[`notfound=secret`, true, '', '', true]
|
[`notfound=secret`, true, '', '', true]
|
||||||
])('given %p key and %p secret', async (kvp, file, exKey, exValue, invalid) => {
|
])('given %p key and %p secret', async (kvp, file, exKey, exValue, invalid) => {
|
||||||
try {
|
try {
|
||||||
|
@ -143,6 +143,10 @@ describe('getArgs', () => {
|
|||||||
'0.4.1',
|
'0.4.1',
|
||||||
new Map<string, string>([
|
new Map<string, string>([
|
||||||
['context', '.'],
|
['context', '.'],
|
||||||
|
['load', 'false'],
|
||||||
|
['no-cache', 'false'],
|
||||||
|
['push', 'false'],
|
||||||
|
['pull', 'false']
|
||||||
]),
|
]),
|
||||||
[
|
[
|
||||||
'buildx',
|
'buildx',
|
||||||
@ -155,6 +159,10 @@ describe('getArgs', () => {
|
|||||||
'0.4.2',
|
'0.4.2',
|
||||||
new Map<string, string>([
|
new Map<string, string>([
|
||||||
['build-args', 'MY_ARG=val1,val2,val3\nARG=val'],
|
['build-args', 'MY_ARG=val1,val2,val3\nARG=val'],
|
||||||
|
['load', 'false'],
|
||||||
|
['no-cache', 'false'],
|
||||||
|
['push', 'false'],
|
||||||
|
['pull', 'false']
|
||||||
]),
|
]),
|
||||||
[
|
[
|
||||||
'buildx',
|
'buildx',
|
||||||
@ -169,6 +177,10 @@ describe('getArgs', () => {
|
|||||||
'0.4.2',
|
'0.4.2',
|
||||||
new Map<string, string>([
|
new Map<string, string>([
|
||||||
['tags', 'name/app:7.4, name/app:latest'],
|
['tags', 'name/app:7.4, name/app:latest'],
|
||||||
|
['load', 'false'],
|
||||||
|
['no-cache', 'false'],
|
||||||
|
['push', 'false'],
|
||||||
|
['pull', 'false']
|
||||||
]),
|
]),
|
||||||
[
|
[
|
||||||
'buildx',
|
'buildx',
|
||||||
@ -184,7 +196,11 @@ describe('getArgs', () => {
|
|||||||
new Map<string, string>([
|
new Map<string, string>([
|
||||||
['context', '.'],
|
['context', '.'],
|
||||||
['labels', 'org.opencontainers.image.title=buildkit\norg.opencontainers.image.description=concurrent, cache-efficient, and Dockerfile-agnostic builder toolkit'],
|
['labels', 'org.opencontainers.image.title=buildkit\norg.opencontainers.image.description=concurrent, cache-efficient, and Dockerfile-agnostic builder toolkit'],
|
||||||
['outputs', 'type=local,dest=./release-out']
|
['outputs', 'type=local,dest=./release-out'],
|
||||||
|
['load', 'false'],
|
||||||
|
['no-cache', 'false'],
|
||||||
|
['push', 'false'],
|
||||||
|
['pull', 'false']
|
||||||
]),
|
]),
|
||||||
[
|
[
|
||||||
'buildx',
|
'buildx',
|
||||||
@ -199,7 +215,11 @@ describe('getArgs', () => {
|
|||||||
'0.4.1',
|
'0.4.1',
|
||||||
new Map<string, string>([
|
new Map<string, string>([
|
||||||
['context', '.'],
|
['context', '.'],
|
||||||
['platforms', 'linux/amd64,linux/arm64']
|
['platforms', 'linux/amd64,linux/arm64'],
|
||||||
|
['load', 'false'],
|
||||||
|
['no-cache', 'false'],
|
||||||
|
['push', 'false'],
|
||||||
|
['pull', 'false']
|
||||||
]),
|
]),
|
||||||
[
|
[
|
||||||
'buildx',
|
'buildx',
|
||||||
@ -211,7 +231,11 @@ describe('getArgs', () => {
|
|||||||
[
|
[
|
||||||
'0.4.1',
|
'0.4.1',
|
||||||
new Map<string, string>([
|
new Map<string, string>([
|
||||||
['context', '.']
|
['context', '.'],
|
||||||
|
['load', 'false'],
|
||||||
|
['no-cache', 'false'],
|
||||||
|
['push', 'false'],
|
||||||
|
['pull', 'false']
|
||||||
]),
|
]),
|
||||||
[
|
[
|
||||||
'buildx',
|
'buildx',
|
||||||
@ -225,6 +249,10 @@ describe('getArgs', () => {
|
|||||||
new Map<string, string>([
|
new Map<string, string>([
|
||||||
['context', '.'],
|
['context', '.'],
|
||||||
['secrets', 'GIT_AUTH_TOKEN=abcdefghijklmno=0123456789'],
|
['secrets', 'GIT_AUTH_TOKEN=abcdefghijklmno=0123456789'],
|
||||||
|
['load', 'false'],
|
||||||
|
['no-cache', 'false'],
|
||||||
|
['push', 'false'],
|
||||||
|
['pull', 'false']
|
||||||
]),
|
]),
|
||||||
[
|
[
|
||||||
'buildx',
|
'buildx',
|
||||||
@ -238,7 +266,11 @@ describe('getArgs', () => {
|
|||||||
'0.4.2',
|
'0.4.2',
|
||||||
new Map<string, string>([
|
new Map<string, string>([
|
||||||
['github-token', 'abcdefghijklmno0123456789'],
|
['github-token', 'abcdefghijklmno0123456789'],
|
||||||
['outputs', '.']
|
['outputs', '.'],
|
||||||
|
['load', 'false'],
|
||||||
|
['no-cache', 'false'],
|
||||||
|
['push', 'false'],
|
||||||
|
['pull', 'false']
|
||||||
]),
|
]),
|
||||||
[
|
[
|
||||||
'buildx',
|
'buildx',
|
||||||
@ -257,7 +289,10 @@ describe('getArgs', () => {
|
|||||||
['secrets', 'GIT_AUTH_TOKEN=abcdefghijklmno=0123456789'],
|
['secrets', 'GIT_AUTH_TOKEN=abcdefghijklmno=0123456789'],
|
||||||
['file', './test/Dockerfile'],
|
['file', './test/Dockerfile'],
|
||||||
['builder', 'builder-git-context-2'],
|
['builder', 'builder-git-context-2'],
|
||||||
['push', 'true']
|
['load', 'false'],
|
||||||
|
['no-cache', 'false'],
|
||||||
|
['push', 'true'],
|
||||||
|
['pull', 'false']
|
||||||
]),
|
]),
|
||||||
[
|
[
|
||||||
'buildx',
|
'buildx',
|
||||||
@ -288,7 +323,10 @@ bbbb
|
|||||||
ccc"`],
|
ccc"`],
|
||||||
['file', './test/Dockerfile'],
|
['file', './test/Dockerfile'],
|
||||||
['builder', 'builder-git-context-2'],
|
['builder', 'builder-git-context-2'],
|
||||||
['push', 'true']
|
['load', 'false'],
|
||||||
|
['no-cache', 'false'],
|
||||||
|
['push', 'true'],
|
||||||
|
['pull', 'false']
|
||||||
]),
|
]),
|
||||||
[
|
[
|
||||||
'buildx',
|
'buildx',
|
||||||
@ -322,7 +360,10 @@ bbbb
|
|||||||
ccc`],
|
ccc`],
|
||||||
['file', './test/Dockerfile'],
|
['file', './test/Dockerfile'],
|
||||||
['builder', 'builder-git-context-2'],
|
['builder', 'builder-git-context-2'],
|
||||||
['push', 'true']
|
['load', 'false'],
|
||||||
|
['no-cache', 'false'],
|
||||||
|
['push', 'true'],
|
||||||
|
['pull', 'false']
|
||||||
]),
|
]),
|
||||||
[
|
[
|
||||||
'buildx',
|
'buildx',
|
||||||
@ -348,7 +389,10 @@ ccc`],
|
|||||||
['file', './test/Dockerfile'],
|
['file', './test/Dockerfile'],
|
||||||
['builder', 'builder-git-context-2'],
|
['builder', 'builder-git-context-2'],
|
||||||
['network', 'host'],
|
['network', 'host'],
|
||||||
['push', 'true']
|
['load', 'false'],
|
||||||
|
['no-cache', 'false'],
|
||||||
|
['push', 'true'],
|
||||||
|
['pull', 'false']
|
||||||
]),
|
]),
|
||||||
[
|
[
|
||||||
'buildx',
|
'buildx',
|
||||||
@ -367,7 +411,11 @@ ccc`],
|
|||||||
new Map<string, string>([
|
new Map<string, string>([
|
||||||
['context', '.'],
|
['context', '.'],
|
||||||
['labels', 'org.opencontainers.image.title=filter_results_top_n\norg.opencontainers.image.description=Reference implementation of operation "filter results (top-n)"'],
|
['labels', 'org.opencontainers.image.title=filter_results_top_n\norg.opencontainers.image.description=Reference implementation of operation "filter results (top-n)"'],
|
||||||
['outputs', 'type=local,dest=./release-out']
|
['outputs', 'type=local,dest=./release-out'],
|
||||||
|
['load', 'false'],
|
||||||
|
['no-cache', 'false'],
|
||||||
|
['push', 'false'],
|
||||||
|
['pull', 'false']
|
||||||
]),
|
]),
|
||||||
[
|
[
|
||||||
'buildx',
|
'buildx',
|
||||||
@ -517,13 +565,7 @@ FOO=bar`
|
|||||||
);
|
);
|
||||||
const res = await context.getInputList('secrets', true);
|
const res = await context.getInputList('secrets', true);
|
||||||
console.log(res);
|
console.log(res);
|
||||||
expect(res).toEqual([
|
expect(res).toEqual(['GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789', 'MYSECRET=aaaaaaaa', 'bbbbbbb', 'ccccccccc', 'FOO=bar']);
|
||||||
'GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789',
|
|
||||||
'MYSECRET=aaaaaaaa',
|
|
||||||
'bbbbbbb',
|
|
||||||
'ccccccccc',
|
|
||||||
'FOO=bar'
|
|
||||||
]);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('large multiline values', async () => {
|
it('large multiline values', async () => {
|
||||||
@ -592,7 +634,7 @@ describe('setOutput', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// See: https://github.com/actions/toolkit/blob/master/packages/core/src/core.ts#L67
|
// See: https://github.com/actions/toolkit/blob/a1b068ec31a042ff1e10a522d8fdf0b8869d53ca/packages/core/src/core.ts#L89
|
||||||
function getInputName(name: string): string {
|
function getInputName(name: string): string {
|
||||||
return `INPUT_${name.replace(/ /g, '_').toUpperCase()}`;
|
return `INPUT_${name.replace(/ /g, '_').toUpperCase()}`;
|
||||||
}
|
}
|
||||||
|
3
codecov.yml
Normal file
3
codecov.yml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
comment: false
|
||||||
|
github_checks:
|
||||||
|
annotations: false
|
24180
dist/index.js
generated
vendored
24180
dist/index.js
generated
vendored
File diff suppressed because one or more lines are too long
26
package.json
26
package.json
@ -28,26 +28,26 @@
|
|||||||
],
|
],
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.3.0",
|
"@actions/core": "^1.4.0",
|
||||||
"@actions/exec": "^1.0.4",
|
"@actions/exec": "^1.1.0",
|
||||||
"@actions/github": "^5.0.0",
|
"@actions/github": "^5.0.0",
|
||||||
"csv-parse": "^4.15.4",
|
"csv-parse": "^4.16.0",
|
||||||
"semver": "^7.3.5",
|
"semver": "^7.3.5",
|
||||||
"tmp": "^0.2.1"
|
"tmp": "^0.2.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/csv-parse": "^1.2.2",
|
"@types/csv-parse": "^1.2.2",
|
||||||
"@types/jest": "^26.0.3",
|
"@types/jest": "^26.0.23",
|
||||||
"@types/node": "^14.0.14",
|
"@types/node": "^14.17.4",
|
||||||
"@types/tmp": "^0.2.0",
|
"@types/tmp": "^0.2.0",
|
||||||
"@vercel/ncc": "^0.23.0",
|
"@vercel/ncc": "^0.28.6",
|
||||||
"dotenv": "^8.2.0",
|
"dotenv": "^8.6.0",
|
||||||
"jest": "^26.1.0",
|
"jest": "^26.6.3",
|
||||||
"jest-circus": "^26.1.0",
|
"jest-circus": "^26.6.3",
|
||||||
"jest-runtime": "^26.1.0",
|
"jest-runtime": "^26.6.3",
|
||||||
"prettier": "^2.0.5",
|
"prettier": "^2.3.1",
|
||||||
"ts-jest": "^26.1.1",
|
"ts-jest": "^26.5.6",
|
||||||
"typescript": "^3.9.5",
|
"typescript": "^4.3.4",
|
||||||
"typescript-formatter": "^7.2.2"
|
"typescript-formatter": "^7.2.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,9 @@ import csvparse from 'csv-parse/lib/sync';
|
|||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import * as semver from 'semver';
|
import * as semver from 'semver';
|
||||||
|
import * as exec from '@actions/exec';
|
||||||
|
|
||||||
import * as context from './context';
|
import * as context from './context';
|
||||||
import * as exec from './exec';
|
|
||||||
|
|
||||||
export async function getImageIDFile(): Promise<string> {
|
export async function getImageIDFile(): Promise<string> {
|
||||||
return path.join(context.tmpDir(), 'iidfile').split(path.sep).join(path.posix.sep);
|
return path.join(context.tmpDir(), 'iidfile').split(path.sep).join(path.posix.sep);
|
||||||
@ -80,27 +80,41 @@ export function hasGitAuthToken(secrets: string[]): Boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function isAvailable(): Promise<Boolean> {
|
export async function isAvailable(): Promise<Boolean> {
|
||||||
return await exec.exec(`docker`, ['buildx'], true).then(res => {
|
return await exec
|
||||||
if (res.stderr != '' && !res.success) {
|
.getExecOutput('docker', ['buildx'], {
|
||||||
return false;
|
ignoreReturnCode: true,
|
||||||
}
|
silent: true
|
||||||
return res.success;
|
})
|
||||||
});
|
.then(res => {
|
||||||
|
if (res.stderr.length > 0 && res.exitCode != 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return res.exitCode == 0;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getVersion(): Promise<string> {
|
export async function getVersion(): Promise<string> {
|
||||||
return await exec.exec(`docker`, ['buildx', 'version'], true).then(res => {
|
return await exec
|
||||||
if (res.stderr != '' && !res.success) {
|
.getExecOutput('docker', ['buildx', 'version'], {
|
||||||
throw new Error(res.stderr);
|
ignoreReturnCode: true,
|
||||||
}
|
silent: true
|
||||||
return parseVersion(res.stdout);
|
})
|
||||||
});
|
.then(res => {
|
||||||
|
if (res.stderr.length > 0 && res.exitCode != 0) {
|
||||||
|
throw new Error(res.stderr.trim());
|
||||||
|
}
|
||||||
|
return parseVersion(res.stdout.trim());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function parseVersion(stdout: string): Promise<string> {
|
export function parseVersion(stdout: string): string {
|
||||||
const matches = /\sv?([0-9.]+)/.exec(stdout);
|
const matches = /\sv?([0-9a-f]{7}|[0-9.]+)/.exec(stdout);
|
||||||
if (!matches) {
|
if (!matches) {
|
||||||
throw new Error(`Cannot parse buildx version`);
|
throw new Error(`Cannot parse buildx version`);
|
||||||
}
|
}
|
||||||
return semver.clean(matches[1]);
|
return matches[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function satisfies(version: string, range: string): boolean {
|
||||||
|
return semver.satisfies(version, range) || /^[0-9a-f]{7}$/.exec(version) !== null;
|
||||||
}
|
}
|
||||||
|
@ -46,9 +46,7 @@ export function defaultContext(): string {
|
|||||||
if (github.context.sha && !ref.startsWith(`refs/pull/`)) {
|
if (github.context.sha && !ref.startsWith(`refs/pull/`)) {
|
||||||
ref = github.context.sha;
|
ref = github.context.sha;
|
||||||
}
|
}
|
||||||
_defaultContext = `${process.env.GITHUB_SERVER_URL || 'https://github.com'}/${github.context.repo.owner}/${
|
_defaultContext = `${process.env.GITHUB_SERVER_URL || 'https://github.com'}/${github.context.repo.owner}/${github.context.repo.repo}.git#${ref}`;
|
||||||
github.context.repo.repo
|
|
||||||
}.git#${ref}`;
|
|
||||||
}
|
}
|
||||||
return _defaultContext;
|
return _defaultContext;
|
||||||
}
|
}
|
||||||
@ -74,13 +72,13 @@ export async function getInputs(defaultContext: string): Promise<Inputs> {
|
|||||||
context: core.getInput('context') || defaultContext,
|
context: core.getInput('context') || defaultContext,
|
||||||
file: core.getInput('file'),
|
file: core.getInput('file'),
|
||||||
labels: await getInputList('labels', true),
|
labels: await getInputList('labels', true),
|
||||||
load: /true/i.test(core.getInput('load')),
|
load: core.getBooleanInput('load'),
|
||||||
network: core.getInput('network'),
|
network: core.getInput('network'),
|
||||||
noCache: /true/i.test(core.getInput('no-cache')),
|
noCache: core.getBooleanInput('no-cache'),
|
||||||
outputs: await getInputList('outputs', true),
|
outputs: await getInputList('outputs', true),
|
||||||
platforms: await getInputList('platforms'),
|
platforms: await getInputList('platforms'),
|
||||||
pull: /true/i.test(core.getInput('pull')),
|
pull: core.getBooleanInput('pull'),
|
||||||
push: /true/i.test(core.getInput('push')),
|
push: core.getBooleanInput('push'),
|
||||||
secrets: await getInputList('secrets', true),
|
secrets: await getInputList('secrets', true),
|
||||||
secretFiles: await getInputList('secret-files', true),
|
secretFiles: await getInputList('secret-files', true),
|
||||||
ssh: await getInputList('ssh'),
|
ssh: await getInputList('ssh'),
|
||||||
@ -121,10 +119,7 @@ async function getBuildArgs(inputs: Inputs, defaultContext: string, buildxVersio
|
|||||||
await asyncForEach(inputs.outputs, async output => {
|
await asyncForEach(inputs.outputs, async output => {
|
||||||
args.push('--output', output);
|
args.push('--output', output);
|
||||||
});
|
});
|
||||||
if (
|
if (!buildx.isLocalOrTarExporter(inputs.outputs) && (inputs.platforms.length == 0 || buildx.satisfies(buildxVersion, '>=0.4.2'))) {
|
||||||
!buildx.isLocalOrTarExporter(inputs.outputs) &&
|
|
||||||
(inputs.platforms.length == 0 || semver.satisfies(buildxVersion, '>=0.4.2'))
|
|
||||||
) {
|
|
||||||
args.push('--iidfile', await buildx.getImageIDFile());
|
args.push('--iidfile', await buildx.getImageIDFile());
|
||||||
}
|
}
|
||||||
await asyncForEach(inputs.cacheFrom, async cacheFrom => {
|
await asyncForEach(inputs.cacheFrom, async cacheFrom => {
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
import * as exec from './exec';
|
|
||||||
|
|
||||||
export async function isDaemonRunning(): Promise<boolean> {
|
|
||||||
return await exec.exec(`docker`, ['version', '--format', '{{.Server.Os}}'], true).then(res => {
|
|
||||||
return !res.stdout.includes(' ') && res.success;
|
|
||||||
});
|
|
||||||
}
|
|
34
src/exec.ts
34
src/exec.ts
@ -1,34 +0,0 @@
|
|||||||
import * as aexec from '@actions/exec';
|
|
||||||
import {ExecOptions} from '@actions/exec';
|
|
||||||
|
|
||||||
export interface ExecResult {
|
|
||||||
success: boolean;
|
|
||||||
stdout: string;
|
|
||||||
stderr: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const exec = async (command: string, args: string[] = [], silent?: boolean): Promise<ExecResult> => {
|
|
||||||
let stdout: string = '';
|
|
||||||
let stderr: string = '';
|
|
||||||
|
|
||||||
const options: ExecOptions = {
|
|
||||||
silent: silent,
|
|
||||||
ignoreReturnCode: true
|
|
||||||
};
|
|
||||||
options.listeners = {
|
|
||||||
stdout: (data: Buffer) => {
|
|
||||||
stdout += data.toString();
|
|
||||||
},
|
|
||||||
stderr: (data: Buffer) => {
|
|
||||||
stderr += data.toString();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const returnCode: number = await aexec.exec(command, args, options);
|
|
||||||
|
|
||||||
return {
|
|
||||||
success: returnCode === 0,
|
|
||||||
stdout: stdout.trim(),
|
|
||||||
stderr: stderr.trim()
|
|
||||||
};
|
|
||||||
};
|
|
16
src/main.ts
16
src/main.ts
@ -1,9 +1,9 @@
|
|||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as buildx from './buildx';
|
import * as buildx from './buildx';
|
||||||
import * as context from './context';
|
import * as context from './context';
|
||||||
import * as exec from './exec';
|
|
||||||
import * as stateHelper from './state-helper';
|
import * as stateHelper from './state-helper';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
|
import * as exec from '@actions/exec';
|
||||||
|
|
||||||
async function run(): Promise<void> {
|
async function run(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
@ -23,11 +23,15 @@ async function run(): Promise<void> {
|
|||||||
let inputs: context.Inputs = await context.getInputs(defContext);
|
let inputs: context.Inputs = await context.getInputs(defContext);
|
||||||
|
|
||||||
const args: string[] = await context.getArgs(inputs, defContext, buildxVersion);
|
const args: string[] = await context.getArgs(inputs, defContext, buildxVersion);
|
||||||
await exec.exec('docker', args).then(res => {
|
await exec
|
||||||
if (res.stderr != '' && !res.success) {
|
.getExecOutput('docker', args, {
|
||||||
throw new Error(`buildx call failed with: ${res.stderr.match(/(.*)\s*$/)![0]}`);
|
ignoreReturnCode: true
|
||||||
}
|
})
|
||||||
});
|
.then(res => {
|
||||||
|
if (res.stderr.length > 0 && res.exitCode != 0) {
|
||||||
|
throw new Error(`buildx failed with: ${res.stderr.match(/(.*)\s*$/)![0].trim()}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const imageID = await buildx.getImageID();
|
const imageID = await buildx.getImageID();
|
||||||
if (imageID) {
|
if (imageID) {
|
||||||
|
Reference in New Issue
Block a user