use new implementation from toolkit

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2023-04-17 01:32:21 +02:00
parent 7e3a79c50d
commit a54198e85a
No known key found for this signature in database
GPG Key ID: 3248E46B6BB8C7F7
3 changed files with 15 additions and 14 deletions

@ -609,7 +609,7 @@ nproc=3`],
jest.spyOn(Buildx.prototype, 'version').mockImplementation(async (): Promise<string> => { jest.spyOn(Buildx.prototype, 'version').mockImplementation(async (): Promise<string> => {
return buildxVersion; return buildxVersion;
}); });
const inp = await context.getInputs(toolkit); const inp = await context.getInputs();
const res = await context.getArgs(inp, toolkit); const res = await context.getArgs(inp, toolkit);
expect(res).toEqual(expected); expect(res).toEqual(expected);
} }

@ -39,7 +39,7 @@ export interface Inputs {
githubToken: string; githubToken: string;
} }
export async function getInputs(toolkit: Toolkit): Promise<Inputs> { export async function getInputs(): Promise<Inputs> {
return { return {
addHosts: Util.getInputList('add-hosts'), addHosts: Util.getInputList('add-hosts'),
allow: Util.getInputList('allow'), allow: Util.getInputList('allow'),
@ -59,7 +59,7 @@ export async function getInputs(toolkit: Toolkit): Promise<Inputs> {
noCacheFilters: Util.getInputList('no-cache-filters'), noCacheFilters: Util.getInputList('no-cache-filters'),
outputs: Util.getInputList('outputs', {ignoreComma: true}), outputs: Util.getInputList('outputs', {ignoreComma: true}),
platforms: Util.getInputList('platforms'), platforms: Util.getInputList('platforms'),
provenance: toolkit.buildx.inputs.getProvenanceInput('provenance'), provenance: BuildxInputs.getProvenanceInput('provenance'),
pull: core.getBooleanInput('pull'), pull: core.getBooleanInput('pull'),
push: core.getBooleanInput('push'), push: core.getBooleanInput('push'),
sbom: core.getInput('sbom'), sbom: core.getInput('sbom'),
@ -120,7 +120,7 @@ async function getBuildArgs(inputs: Inputs, context: string, toolkit: Toolkit):
args.push('--file', inputs.file); args.push('--file', inputs.file);
} }
if (!BuildxInputs.hasLocalExporter(inputs.outputs) && !BuildxInputs.hasTarExporter(inputs.outputs) && (inputs.platforms.length == 0 || (await toolkit.buildx.versionSatisfies('>=0.4.2')))) { if (!BuildxInputs.hasLocalExporter(inputs.outputs) && !BuildxInputs.hasTarExporter(inputs.outputs) && (inputs.platforms.length == 0 || (await toolkit.buildx.versionSatisfies('>=0.4.2')))) {
args.push('--iidfile', toolkit.buildx.inputs.getBuildImageIDFilePath()); args.push('--iidfile', BuildxInputs.getBuildImageIDFilePath());
} }
await Util.asyncForEach(inputs.labels, async label => { await Util.asyncForEach(inputs.labels, async label => {
args.push('--label', label); args.push('--label', label);
@ -144,10 +144,10 @@ async function getBuildArgs(inputs: Inputs, context: string, toolkit: Toolkit):
if (GitHub.context.payload.repository?.private ?? false) { if (GitHub.context.payload.repository?.private ?? false) {
// if this is a private repository, we set the default provenance // if this is a private repository, we set the default provenance
// attributes being set in buildx: https://github.com/docker/buildx/blob/fb27e3f919dcbf614d7126b10c2bc2d0b1927eb6/build/build.go#L603 // attributes being set in buildx: https://github.com/docker/buildx/blob/fb27e3f919dcbf614d7126b10c2bc2d0b1927eb6/build/build.go#L603
args.push('--provenance', toolkit.buildx.inputs.resolveProvenanceAttrs(`mode=min,inline-only=true`)); args.push('--provenance', BuildxInputs.resolveProvenanceAttrs(`mode=min,inline-only=true`));
} else { } else {
// for a public repository, we set max provenance mode. // for a public repository, we set max provenance mode.
args.push('--provenance', toolkit.buildx.inputs.resolveProvenanceAttrs(`mode=max`)); args.push('--provenance', BuildxInputs.resolveProvenanceAttrs(`mode=max`));
} }
} }
if (inputs.sbom) { if (inputs.sbom) {
@ -156,20 +156,20 @@ async function getBuildArgs(inputs: Inputs, context: string, toolkit: Toolkit):
} }
await Util.asyncForEach(inputs.secrets, async secret => { await Util.asyncForEach(inputs.secrets, async secret => {
try { try {
args.push('--secret', toolkit.buildx.inputs.resolveBuildSecretString(secret)); args.push('--secret', BuildxInputs.resolveBuildSecretString(secret));
} catch (err) { } catch (err) {
core.warning(err.message); core.warning(err.message);
} }
}); });
await Util.asyncForEach(inputs.secretFiles, async secretFile => { await Util.asyncForEach(inputs.secretFiles, async secretFile => {
try { try {
args.push('--secret', toolkit.buildx.inputs.resolveBuildSecretFile(secretFile)); args.push('--secret', BuildxInputs.resolveBuildSecretFile(secretFile));
} catch (err) { } catch (err) {
core.warning(err.message); core.warning(err.message);
} }
}); });
if (inputs.githubToken && !BuildxInputs.hasGitAuthTokenSecret(inputs.secrets) && context.startsWith(Context.gitContext())) { if (inputs.githubToken && !BuildxInputs.hasGitAuthTokenSecret(inputs.secrets) && context.startsWith(Context.gitContext())) {
args.push('--secret', toolkit.buildx.inputs.resolveBuildSecretString(`GIT_AUTH_TOKEN=${inputs.githubToken}`)); args.push('--secret', BuildxInputs.resolveBuildSecretString(`GIT_AUTH_TOKEN=${inputs.githubToken}`));
} }
if (inputs.shmSize) { if (inputs.shmSize) {
args.push('--shm-size', inputs.shmSize); args.push('--shm-size', inputs.shmSize);
@ -198,7 +198,7 @@ async function getCommonArgs(inputs: Inputs, toolkit: Toolkit): Promise<Array<st
args.push('--load'); args.push('--load');
} }
if (await toolkit.buildx.versionSatisfies('>=0.6.0')) { if (await toolkit.buildx.versionSatisfies('>=0.6.0')) {
args.push('--metadata-file', toolkit.buildx.inputs.getBuildMetadataFilePath()); args.push('--metadata-file', BuildxInputs.getBuildMetadataFilePath());
} }
if (inputs.network) { if (inputs.network) {
args.push('--network', inputs.network); args.push('--network', inputs.network);

@ -6,6 +6,7 @@ import {Context} from '@docker/actions-toolkit/lib/context';
import {Docker} from '@docker/actions-toolkit/lib/docker/docker'; import {Docker} from '@docker/actions-toolkit/lib/docker/docker';
import {Exec} from '@docker/actions-toolkit/lib/exec'; import {Exec} from '@docker/actions-toolkit/lib/exec';
import {GitHub} from '@docker/actions-toolkit/lib/github'; import {GitHub} from '@docker/actions-toolkit/lib/github';
import {Inputs as BuildxInputs} from '@docker/actions-toolkit/lib/buildx/inputs';
import {Toolkit} from '@docker/actions-toolkit/lib/toolkit'; import {Toolkit} from '@docker/actions-toolkit/lib/toolkit';
import * as context from './context'; import * as context from './context';
@ -13,8 +14,8 @@ import * as context from './context';
actionsToolkit.run( actionsToolkit.run(
// main // main
async () => { async () => {
const inputs: context.Inputs = await context.getInputs();
const toolkit = new Toolkit(); const toolkit = new Toolkit();
const inputs: context.Inputs = await context.getInputs(toolkit);
await core.group(`GitHub Actions runtime token ACs`, async () => { await core.group(`GitHub Actions runtime token ACs`, async () => {
try { try {
@ -54,9 +55,9 @@ actionsToolkit.run(
} }
}); });
const imageID = await toolkit.buildx.inputs.resolveBuildImageID(); const imageID = BuildxInputs.resolveBuildImageID();
const metadata = await toolkit.buildx.inputs.resolveBuildMetadata(); const metadata = BuildxInputs.resolveBuildMetadata();
const digest = await toolkit.buildx.inputs.resolveDigest(); const digest = BuildxInputs.resolveDigest();
if (imageID) { if (imageID) {
await core.group(`ImageID`, async () => { await core.group(`ImageID`, async () => {