Compare commits

...

14 Commits

Author SHA1 Message Date
CrazyMax
b0518231d0 Merge pull request #72 from crazy-max/bump-csv-parse
Some checks failed
publish / publish (push) Has been cancelled
build(deps): bump csv-parse from 5.3.5 to 5.3.6
2023-03-13 09:55:51 +00:00
CrazyMax
c0da63f810 build(deps): bump csv-parse from 5.3.5 to 5.3.6
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2023-03-13 10:51:00 +01:00
CrazyMax
041d9693ab Merge pull request #71 from crazy-max/bake
bake class to parse definitions and handle exporters type
2023-03-13 09:49:01 +00:00
CrazyMax
39158d8047 bake class to parse definitions and handle exporters type
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2023-03-13 10:44:48 +01:00
CrazyMax
a6c94b5167 Merge pull request #70 from crazy-max/static-inputs
buildx: make inputs methods static
2023-03-13 09:42:37 +00:00
CrazyMax
a5943234fd Merge pull request #69 from crazy-max/bump-releases-json
Bump releases-json action to 6dc3187
2023-03-13 08:54:48 +00:00
CrazyMax
03977693c1 buildx: make inputs methods static
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2023-03-12 23:40:54 +01:00
CrazyMax
d6d770f303 Bump releases-json action to 6dc3187
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2023-03-12 13:13:02 +01:00
CrazyMax
8df8cee02f Merge pull request #68 from crazy-max/fix-driver-opts-parsing
Some checks failed
publish / publish (push) Has been cancelled
builder: fix regex to parse driver-opts
2023-03-11 16:47:42 +00:00
CrazyMax
94febd1da7 builder: fix regex to parse driver-opts
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2023-03-11 16:48:56 +01:00
CrazyMax
b7cdc617ce Merge pull request #65 from docker/dependabot/npm_and_yarn/csv-parse-5.3.6
build(deps): bump csv-parse from 5.3.5 to 5.3.6
2023-03-08 18:16:10 +00:00
CrazyMax
75c0c7fac0 Merge pull request #66 from docker/dependabot/npm_and_yarn/actions/http-client-2.1.0
build(deps): bump @actions/http-client from 2.0.1 to 2.1.0
2023-03-08 18:15:51 +00:00
dependabot[bot]
7b50104faa build(deps): bump @actions/http-client from 2.0.1 to 2.1.0
Bumps [@actions/http-client](https://github.com/actions/toolkit/tree/HEAD/packages/http-client) from 2.0.1 to 2.1.0.
- [Release notes](https://github.com/actions/toolkit/releases)
- [Changelog](https://github.com/actions/toolkit/blob/main/packages/http-client/RELEASES.md)
- [Commits](https://github.com/actions/toolkit/commits/HEAD/packages/http-client)

---
updated-dependencies:
- dependency-name: "@actions/http-client"
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-06 23:20:20 +00:00
dependabot[bot]
d7735e9ddf build(deps): bump csv-parse from 5.3.5 to 5.3.6
Bumps [csv-parse](https://github.com/adaltas/node-csv/tree/HEAD/packages/csv-parse) from 5.3.5 to 5.3.6.
- [Release notes](https://github.com/adaltas/node-csv/releases)
- [Changelog](https://github.com/adaltas/node-csv/blob/master/packages/csv-parse/CHANGELOG.md)
- [Commits](https://github.com/adaltas/node-csv/commits/csv-parse@5.3.6/packages/csv-parse)

---
updated-dependencies:
- dependency-name: csv-parse
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-06 23:18:48 +00:00
14 changed files with 795 additions and 62 deletions

View File

@@ -17,7 +17,7 @@ on:
jobs:
generate:
uses: crazy-max/.github/.github/workflows/releases-json.yml@2a596c917a8ad3e6203ae99b777148525a2e00d5
uses: crazy-max/.github/.github/workflows/releases-json.yml@6dc31870ca6c4f8489bf5a408ab38fae60f47eec
with:
repository: docker/buildx
artifact_name: buildx-releases-json

View File

@@ -17,7 +17,7 @@ on:
jobs:
generate:
uses: crazy-max/.github/.github/workflows/releases-json.yml@2a596c917a8ad3e6203ae99b777148525a2e00d5
uses: crazy-max/.github/.github/workflows/releases-json.yml@6dc31870ca6c4f8489bf5a408ab38fae60f47eec
with:
repository: moby/moby
artifact_name: docker-releases-json

View File

@@ -0,0 +1,459 @@
/**
* Copyright 2023 actions-toolkit authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {beforeEach, describe, expect, jest, test} from '@jest/globals';
import * as path from 'path';
import {Bake} from '../../src/buildx/bake';
import {BakeDefinition} from '../../src/types/bake';
const fixturesDir = path.join(__dirname, '..', 'fixtures');
beforeEach(() => {
jest.clearAllMocks();
});
describe('parseDefinitions', () => {
// prettier-ignore
test.each([
[
[path.join(fixturesDir, 'bake.hcl')],
['validate'],
{
"group": {
"default": {
"targets": [
"validate"
]
},
"validate": {
"targets": [
"lint",
"validate-vendor",
"validate-docs"
]
}
},
"target": {
"lint": {
"context": ".",
"dockerfile": "./hack/dockerfiles/lint.Dockerfile",
"args": {
"BUILDKIT_CONTEXT_KEEP_GIT_DIR": "1",
"GO_VERSION": "1.20"
},
"output": [
"type=cacheonly"
]
},
"validate-docs": {
"context": ".",
"dockerfile": "./hack/dockerfiles/docs.Dockerfile",
"args": {
"BUILDKIT_CONTEXT_KEEP_GIT_DIR": "1",
"BUILDX_EXPERIMENTAL": "1",
"FORMATS": "md",
"GO_VERSION": "1.20"
},
"target": "validate",
"output": [
"type=cacheonly"
]
},
"validate-vendor": {
"context": ".",
"dockerfile": "./hack/dockerfiles/vendor.Dockerfile",
"args": {
"BUILDKIT_CONTEXT_KEEP_GIT_DIR": "1",
"GO_VERSION": "1.20"
},
"target": "validate",
"output": [
"type=cacheonly"
]
}
}
}
]
])('given %p', async (files, targets, expected: BakeDefinition) => {
const bake = new Bake();
expect(await bake.parseDefinitions(files, targets)).toEqual(expected);
});
});
describe('hasLocalExporter', () => {
// prettier-ignore
test.each([
[
{
"target": {
"build": {
"output": [
"type=docker"
]
},
}
},
false
],
[
{
"target": {
"local": {
"output": [
"type=local,dest=./release-out"
]
},
}
},
true
],
[
{
"target": {
"tar": {
"output": [
"type=tar,dest=/tmp/image.tar"
]
},
}
},
false
],
[
{
"target": {
"tar": {
"output": [
'"type=tar","dest=/tmp/image.tar"',
]
},
}
},
false
],
[
{
"target": {
"local": {
"output": [
'" type= local" , dest=./release-out',
]
},
}
},
true
],
[
{
"target": {
"local": {
"output": [
".",
]
},
}
},
true
]
])('given %o returns %p', async (def: BakeDefinition, expected: boolean) => {
expect(Bake.hasLocalExporter(def)).toEqual(expected);
});
});
describe('hasTarExporter', () => {
// prettier-ignore
test.each([
[
{
"target": {
"reg": {
"output": [
"type=registry,ref=user/app"
]
},
}
},
false
],
[
{
"target": {
"build": {
"output": [
"type=docker"
]
},
}
},
false
],
[
{
"target": {
"local": {
"output": [
"type=local,dest=./release-out"
]
},
}
},
false
],
[
{
"target": {
"tar": {
"output": [
"type=tar,dest=/tmp/image.tar"
]
},
}
},
true
],
[
{
"target": {
"multi": {
"output": [
"type=docker",
"type=tar,dest=/tmp/image.tar"
]
},
}
},
true
],
[
{
"target": {
"tar": {
"output": [
'"type=tar","dest=/tmp/image.tar"',
]
},
}
},
true
],
[
{
"target": {
"local": {
"output": [
'" type= local" , dest=./release-out',
]
},
}
},
false
],
[
{
"target": {
"local": {
"output": [
".",
]
},
}
},
false
],
])('given %o returns %p', async (def: BakeDefinition, expected: boolean) => {
expect(Bake.hasTarExporter(def)).toEqual(expected);
});
});
describe('hasDockerExporter', () => {
// prettier-ignore
test.each([
[
{
"target": {
"reg": {
"output": [
"type=registry,ref=user/app"
]
},
}
},
false,
undefined
],
[
{
"target": {
"build": {
"output": [
"type=docker"
]
},
}
},
true,
undefined
],
[
{
"target": {
"multi": {
"output": [
"type=docker",
"type=tar,dest=/tmp/image.tar"
]
},
}
},
true,
undefined
],
[
{
"target": {
"local": {
"output": [
'" type= local" , dest=./release-out'
]
},
}
},
false,
undefined
],
[
{
"target": {
"local": {
"output": [
"type=local,dest=./release-out"
]
},
}
},
false,
undefined
],
[
{
"target": {
"tar": {
"output": [
"type=tar,dest=/tmp/image.tar"
]
},
}
},
false,
undefined
],
[
{
"target": {
"multi": {
"output": [
"type=docker",
"type=tar,dest=/tmp/image.tar"
]
},
}
},
true,
undefined
],
[
{
"target": {
"tar": {
"output": [
'"type=tar","dest=/tmp/image.tar"'
]
},
}
},
false,
undefined
],
[
{
"target": {
"tar": {
"output": [
'"type=tar","dest=/tmp/image.tar"'
]
},
}
},
false,
undefined
],
[
{
"target": {
"local": {
"output": [
'" type= local" , dest=./release-out'
]
},
}
},
false,
undefined
],
[
{
"target": {
"build": {
"output": [
"type=docker"
]
},
}
},
true,
false
],
[
{
"target": {
"build": {
"output": [
"type=docker"
]
},
}
},
true,
true
],
[
{
"target": {
"build": {
"output": [
"."
]
},
}
},
true,
true
],
])('given %o and load:%p returns %p', async (def: BakeDefinition, expected: boolean, load: boolean) => {
expect(Bake.hasDockerExporter(def, load)).toEqual(expected);
});
});

View File

@@ -38,7 +38,7 @@ jest.spyOn(Builder.prototype, 'inspect').mockImplementation(async (): Promise<Bu
{
buildkit: 'v0.11.0',
'buildkitd-flags': '--debug --allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host',
'driver-opts': ['BUILDKIT_STEP_LOG_MAX_SIZE=10485760', 'BUILDKIT_STEP_LOG_MAX_SPEED=10485760', 'JAEGER_TRACE=localhost:6831', 'image=moby/buildkit:latest', 'network=host'],
'driver-opts': ['BUILDKIT_STEP_LOG_MAX_SIZE=10485760', 'BUILDKIT_STEP_LOG_MAX_SPEED=10485760', 'JAEGER_TRACE=localhost:6831', 'image=moby/buildkit:latest', 'network=host', 'qemu.install=true'],
endpoint: 'unix:///var/run/docker.sock',
name: 'builder20',
platforms: 'linux/amd64,linux/amd64/v2,linux/amd64/v3,linux/arm64,linux/riscv64,linux/ppc64le,linux/s390x,linux/386,linux/mips64le,linux/mips64,linux/arm/v7,linux/arm/v6',
@@ -196,11 +196,12 @@ describe('parseInspect', () => {
"buildkit": "v0.11.0",
"buildkitd-flags": "--debug --allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host",
"driver-opts": [
"BUILDKIT_STEP_LOG_MAX_SIZE=10485760",
"BUILDKIT_STEP_LOG_MAX_SPEED=10485760",
"JAEGER_TRACE=localhost:6831",
"env.BUILDKIT_STEP_LOG_MAX_SIZE=10485760",
"env.BUILDKIT_STEP_LOG_MAX_SPEED=10485760",
"env.JAEGER_TRACE=localhost:6831",
"image=moby/buildkit:latest",
"network=host"
"network=host",
"qemu.install=true"
],
"endpoint": "unix:///var/run/docker.sock",
"name": "builder20",

View File

@@ -20,7 +20,6 @@ import * as path from 'path';
import * as rimraf from 'rimraf';
import {Context} from '../../src/context';
import {Buildx} from '../../src/buildx/buildx';
import {Inputs} from '../../src/buildx/inputs';
const fixturesDir = path.join(__dirname, '..', 'fixtures');
@@ -53,31 +52,28 @@ afterEach(() => {
describe('resolveBuildImageID', () => {
it('matches', async () => {
const buildx = new Buildx();
const imageID = 'sha256:bfb45ab72e46908183546477a08f8867fc40cebadd00af54b071b097aed127a9';
const imageIDFile = buildx.inputs.getBuildImageIDFilePath();
const imageIDFile = Inputs.getBuildImageIDFilePath();
await fs.writeFileSync(imageIDFile, imageID);
const expected = buildx.inputs.resolveBuildImageID();
const expected = Inputs.resolveBuildImageID();
expect(expected).toEqual(imageID);
});
});
describe('resolveBuildMetadata', () => {
it('matches', async () => {
const buildx = new Buildx();
const metadataFile = buildx.inputs.getBuildMetadataFilePath();
const metadataFile = Inputs.getBuildMetadataFilePath();
await fs.writeFileSync(metadataFile, metadata);
const expected = buildx.inputs.resolveBuildMetadata();
const expected = Inputs.resolveBuildMetadata();
expect(expected).toEqual(metadata);
});
});
describe('resolveDigest', () => {
it('matches', async () => {
const buildx = new Buildx();
const metadataFile = buildx.inputs.getBuildMetadataFilePath();
const metadataFile = Inputs.getBuildMetadataFilePath();
await fs.writeFileSync(metadataFile, metadata);
const expected = buildx.inputs.resolveDigest();
const expected = Inputs.resolveDigest();
expect(expected).toEqual('sha256:b09b9482c72371486bb2c1d2c2a2633ed1d0b8389e12c8d52b9e052725c0c83c');
});
});
@@ -124,8 +120,7 @@ describe('getProvenanceInput', () => {
],
])('given input %p', async (input: string, expected: string) => {
await setInput('provenance', input);
const buildx = new Buildx();
expect(buildx.inputs.getProvenanceInput('provenance')).toEqual(expected);
expect(Inputs.getProvenanceInput('provenance')).toEqual(expected);
});
});
@@ -153,8 +148,7 @@ describe('resolveProvenanceAttrs', () => {
'builder-id=https://github.com/docker/actions-toolkit/actions/runs/123'
],
])('given %p', async (input: string, expected: string) => {
const buildx = new Buildx();
expect(buildx.inputs.resolveProvenanceAttrs(input)).toEqual(expected);
expect(Inputs.resolveProvenanceAttrs(input)).toEqual(expected);
});
});
@@ -170,12 +164,11 @@ describe('resolveBuildSecret', () => {
[`notfound=secret`, true, '', '', new Error('secret file secret not found')]
])('given %p key and %p secret', async (kvp: string, file: boolean, exKey: string, exValue: string, error: Error) => {
try {
const buildx = new Buildx();
let secret: string;
if (file) {
secret = buildx.inputs.resolveBuildSecretFile(kvp);
secret = Inputs.resolveBuildSecretFile(kvp);
} else {
secret = buildx.inputs.resolveBuildSecretString(kvp);
secret = Inputs.resolveBuildSecretString(kvp);
}
expect(secret).toEqual(`id=${exKey},src=${tmpName}`);
expect(fs.readFileSync(tmpName, 'utf-8')).toEqual(exValue);

172
__tests__/fixtures/bake.hcl Normal file
View File

@@ -0,0 +1,172 @@
// Copyright 2023 actions-toolkit authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
variable "GO_VERSION" {
default = "1.20"
}
variable "DOCS_FORMATS" {
default = "md"
}
variable "DESTDIR" {
default = "./bin"
}
# Special target: https://github.com/docker/metadata-action#bake-definition
target "meta-helper" {
tags = ["docker/buildx-bin:local"]
}
target "_common" {
args = {
GO_VERSION = GO_VERSION
BUILDKIT_CONTEXT_KEEP_GIT_DIR = 1
}
}
group "default" {
targets = ["binaries"]
}
group "validate" {
targets = ["lint", "validate-vendor", "validate-docs"]
}
target "lint" {
inherits = ["_common"]
dockerfile = "./hack/dockerfiles/lint.Dockerfile"
output = ["type=cacheonly"]
}
target "validate-vendor" {
inherits = ["_common"]
dockerfile = "./hack/dockerfiles/vendor.Dockerfile"
target = "validate"
output = ["type=cacheonly"]
}
target "validate-docs" {
inherits = ["_common"]
args = {
FORMATS = DOCS_FORMATS
BUILDX_EXPERIMENTAL = 1 // enables experimental cmds/flags for docs generation
}
dockerfile = "./hack/dockerfiles/docs.Dockerfile"
target = "validate"
output = ["type=cacheonly"]
}
target "validate-authors" {
inherits = ["_common"]
dockerfile = "./hack/dockerfiles/authors.Dockerfile"
target = "validate"
output = ["type=cacheonly"]
}
target "validate-generated-files" {
inherits = ["_common"]
dockerfile = "./hack/dockerfiles/generated-files.Dockerfile"
target = "validate"
output = ["type=cacheonly"]
}
target "update-vendor" {
inherits = ["_common"]
dockerfile = "./hack/dockerfiles/vendor.Dockerfile"
target = "update"
output = ["."]
}
target "update-docs" {
inherits = ["_common"]
args = {
FORMATS = DOCS_FORMATS
BUILDX_EXPERIMENTAL = 1 // enables experimental cmds/flags for docs generation
}
dockerfile = "./hack/dockerfiles/docs.Dockerfile"
target = "update"
output = ["./docs/reference"]
}
target "update-authors" {
inherits = ["_common"]
dockerfile = "./hack/dockerfiles/authors.Dockerfile"
target = "update"
output = ["."]
}
target "update-generated-files" {
inherits = ["_common"]
dockerfile = "./hack/dockerfiles/generated-files.Dockerfile"
target = "update"
output = ["."]
}
target "mod-outdated" {
inherits = ["_common"]
dockerfile = "./hack/dockerfiles/vendor.Dockerfile"
target = "outdated"
no-cache-filter = ["outdated"]
output = ["type=cacheonly"]
}
target "test" {
inherits = ["_common"]
target = "test-coverage"
output = ["${DESTDIR}/coverage"]
}
target "binaries" {
inherits = ["_common"]
target = "binaries"
output = ["${DESTDIR}/build"]
platforms = ["local"]
}
target "binaries-cross" {
inherits = ["binaries"]
platforms = [
"darwin/amd64",
"darwin/arm64",
"linux/amd64",
"linux/arm/v6",
"linux/arm/v7",
"linux/arm64",
"linux/ppc64le",
"linux/riscv64",
"linux/s390x",
"windows/amd64",
"windows/arm64"
]
}
target "release" {
inherits = ["binaries-cross"]
target = "release"
output = ["${DESTDIR}/release"]
}
target "image" {
inherits = ["meta-helper", "binaries"]
output = ["type=image"]
}
target "image-cross" {
inherits = ["meta-helper", "binaries-cross"]
output = ["type=image"]
}
target "image-local" {
inherits = ["image"]
output = ["type=docker"]
}

View File

@@ -5,7 +5,7 @@ Last Activity: 2023-01-16 09:45:23 +0000 UTC
Nodes:
Name: builder20
Endpoint: unix:///var/run/docker.sock
Driver Options: env.BUILDKIT_STEP_LOG_MAX_SIZE="10485760" env.BUILDKIT_STEP_LOG_MAX_SPEED="10485760" env.JAEGER_TRACE="localhost:6831" image="moby/buildkit:latest" network="host"
Driver Options: env.BUILDKIT_STEP_LOG_MAX_SIZE="10485760" env.BUILDKIT_STEP_LOG_MAX_SPEED="10485760" env.JAEGER_TRACE="localhost:6831" image="moby/buildkit:latest" network="host" qemu.install="true"
Status: running
Flags: --debug --allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host
Buildkit: v0.11.0

View File

@@ -51,7 +51,7 @@
"@actions/io": "^1.1.2",
"@actions/tool-cache": "^2.0.1",
"async-retry": "^1.3.3",
"csv-parse": "^5.3.5",
"csv-parse": "^5.3.6",
"handlebars": "^4.7.7",
"jwt-decode": "^3.1.2",
"semver": "^7.3.8",

74
src/buildx/bake.ts Normal file
View File

@@ -0,0 +1,74 @@
/**
* Copyright 2023 actions-toolkit authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {Buildx} from './buildx';
import {Exec} from '../exec';
import {Inputs} from './inputs';
import {BakeDefinition} from '../types/bake';
export interface BakeOpts {
buildx?: Buildx;
}
export class Bake {
private readonly buildx: Buildx;
constructor(opts?: BakeOpts) {
this.buildx = opts?.buildx || new Buildx();
}
public async parseDefinitions(files: Array<string>, targets: Array<string>): Promise<BakeDefinition> {
const args = ['bake'];
if (files) {
for (const file of files) {
args.push('--file', file);
}
}
const printCmd = await this.buildx.getCommand([...args, '--print', ...targets]);
return await Exec.getExecOutput(printCmd.command, printCmd.args, {
ignoreReturnCode: true,
silent: true
}).then(res => {
if (res.stderr.length > 0 && res.exitCode != 0) {
throw new Error(res.stderr);
}
return <BakeDefinition>JSON.parse(res.stdout.trim());
});
}
public static hasLocalExporter(def: BakeDefinition): boolean {
return Inputs.hasExporterType('local', Bake.exporters(def));
}
public static hasTarExporter(def: BakeDefinition): boolean {
return Inputs.hasExporterType('tar', Bake.exporters(def));
}
public static hasDockerExporter(def: BakeDefinition, load?: boolean): boolean {
return load || Inputs.hasExporterType('docker', Bake.exporters(def));
}
private static exporters(def: BakeDefinition): Array<string> {
const exporters = new Array<string>();
for (const key in def.target) {
const target = def.target[key];
exporters.push(...target.output);
}
return exporters;
}
}

View File

@@ -105,7 +105,7 @@ export class Builder {
break;
}
case 'driver options': {
node['driver-opts'] = (value.match(/(\w+)="([^"]*)"/g) || []).map(v => v.replace(/^(.*)="(.*)"$/g, '$1=$2'));
node['driver-opts'] = (value.match(/([a-zA-Z0-9_.]+)="([^"]*)"/g) || []).map(v => v.replace(/^(.*)="(.*)"$/g, '$1=$2'));
break;
}
case 'status': {

View File

@@ -21,7 +21,6 @@ import * as semver from 'semver';
import {Docker} from '../docker/docker';
import {Exec} from '../exec';
import {Inputs} from './inputs';
import {Cert} from '../types/buildx';
@@ -34,15 +33,12 @@ export class Buildx {
private _versionOnce: boolean;
private readonly _standalone: boolean | undefined;
public readonly inputs: Inputs;
public static readonly containerNamePrefix = 'buildx_buildkit_';
constructor(opts?: BuildxOpts) {
this._standalone = opts?.standalone;
this._version = '';
this._versionOnce = false;
this.inputs = new Inputs();
}
static get configDir(): string {

View File

@@ -22,24 +22,24 @@ import {parse} from 'csv-parse/sync';
import {Context} from '../context';
export class Inputs {
public getBuildImageIDFilePath(): string {
public static getBuildImageIDFilePath(): string {
return path.join(Context.tmpDir(), 'iidfile');
}
public getBuildMetadataFilePath(): string {
public static getBuildMetadataFilePath(): string {
return path.join(Context.tmpDir(), 'metadata-file');
}
public resolveBuildImageID(): string | undefined {
const iidFile = this.getBuildImageIDFilePath();
public static resolveBuildImageID(): string | undefined {
const iidFile = Inputs.getBuildImageIDFilePath();
if (!fs.existsSync(iidFile)) {
return undefined;
}
return fs.readFileSync(iidFile, {encoding: 'utf-8'}).trim();
}
public resolveBuildMetadata(): string | undefined {
const metadataFile = this.getBuildMetadataFilePath();
public static resolveBuildMetadata(): string | undefined {
const metadataFile = Inputs.getBuildMetadataFilePath();
if (!fs.existsSync(metadataFile)) {
return undefined;
}
@@ -50,8 +50,8 @@ export class Inputs {
return content;
}
public resolveDigest(): string | undefined {
const metadata = this.resolveBuildMetadata();
public static resolveDigest(): string | undefined {
const metadata = Inputs.resolveBuildMetadata();
if (metadata === undefined) {
return undefined;
}
@@ -62,15 +62,15 @@ export class Inputs {
return undefined;
}
public resolveBuildSecretString(kvp: string): string {
return this.resolveBuildSecret(kvp, false);
public static resolveBuildSecretString(kvp: string): string {
return Inputs.resolveBuildSecret(kvp, false);
}
public resolveBuildSecretFile(kvp: string): string {
return this.resolveBuildSecret(kvp, true);
public static resolveBuildSecretFile(kvp: string): string {
return Inputs.resolveBuildSecret(kvp, true);
}
public resolveBuildSecret(kvp: string, file: boolean): string {
public static resolveBuildSecret(kvp: string, file: boolean): string {
const delimiterIndex = kvp.indexOf('=');
const key = kvp.substring(0, delimiterIndex);
let value = kvp.substring(delimiterIndex + 1);
@@ -88,7 +88,7 @@ export class Inputs {
return `id=${key},src=${secretFile}`;
}
public getProvenanceInput(name: string): string {
public static getProvenanceInput(name: string): string {
const input = core.getInput(name);
if (!input) {
// if input is not set returns empty string
@@ -98,11 +98,11 @@ export class Inputs {
return core.getBooleanInput(name) ? `builder-id=${Context.provenanceBuilderID()}` : 'false';
} catch (err) {
// not a valid boolean, so we assume it's a string
return this.resolveProvenanceAttrs(input);
return Inputs.resolveProvenanceAttrs(input);
}
}
public resolveProvenanceAttrs(input: string): string {
public static resolveProvenanceAttrs(input: string): string {
if (!input) {
return `builder-id=${Context.provenanceBuilderID()}`;
}

45
src/types/bake.ts Normal file
View File

@@ -0,0 +1,45 @@
/**
* Copyright 2023 actions-toolkit authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export interface BakeDefinition {
group: Record<string, Group>;
target: Record<string, Target>;
}
export interface Group {
targets: Array<string>;
}
export interface Target {
args: Record<string, string>;
attest: Array<string>;
'cache-from': Array<string>;
'cache-to': Array<string>;
context: string;
contexts: Record<string, string>;
dockerfile: string;
'dockerfile-inline': string;
labels: Record<string, string>;
'no-cache': boolean;
'no-cache-filter': Array<string>;
output: Array<string>;
platforms: Array<string>;
pull: boolean;
secret: Array<string>;
ssh: Array<string>;
tags: Array<string>;
target: string;
}

View File

@@ -37,11 +37,11 @@ __metadata:
linkType: hard
"@actions/http-client@npm:^2.0.1":
version: 2.0.1
resolution: "@actions/http-client@npm:2.0.1"
version: 2.1.0
resolution: "@actions/http-client@npm:2.1.0"
dependencies:
tunnel: ^0.0.6
checksum: 799ec3df91e28a9da91ce6592e94f8b8923ccf6cc21a2f72c7429be5af5273f1625335411adc2a1bb222d56c852d5767214dfa6fa32a6da7e81dba8290e08f17
checksum: 25a72a952cc95fb4b3ab086da73a5754dd0957c206637cace69be2e16f018cc1b3d3c40d3bcf89ffd8a5929d5e8445594b498b50db306a50ad7536023f8e3800
languageName: node
linkType: hard
@@ -776,7 +776,7 @@ __metadata:
"@typescript-eslint/parser": ^5.49.0
async-retry: ^1.3.3
cpy-cli: ^4.2.0
csv-parse: ^5.3.5
csv-parse: ^5.3.6
dotenv: ^16.0.3
eslint: ^8.33.0
eslint-config-prettier: ^8.6.0
@@ -2573,17 +2573,10 @@ __metadata:
languageName: node
linkType: hard
"csv-parse@npm:*":
version: 5.3.3
resolution: "csv-parse@npm:5.3.3"
checksum: 9f16e2003ef47c901aab31d202e1c9edb70c00faa7777e17a50087314c9da6561233bc60542c15d71f7973c7a0e947c35515ea2689929881c9430a8af374089e
languageName: node
linkType: hard
"csv-parse@npm:^5.3.5":
version: 5.3.5
resolution: "csv-parse@npm:5.3.5"
checksum: 077e010db2ebbc9db708b719f2f650577c5ec8d176cd4363235d6644c36c642811d05ef1b6907390dd7466bde20a8dbb0f34994bc0e101521eb09e6691a02206
"csv-parse@npm:*, csv-parse@npm:^5.3.6":
version: 5.3.6
resolution: "csv-parse@npm:5.3.6"
checksum: a6dcb61a0676121e84a29cdee4978a0516d1412fbe8895057d17e1a95a2013e6283b253135465ad562222d095988a74587d92b2fa04192bef15090acce2a0433
languageName: node
linkType: hard