Compare commits
8 Commits
v0.1.0-bet
...
v0.1.0-rc.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b0518231d0 | ||
|
|
c0da63f810 | ||
|
|
041d9693ab | ||
|
|
39158d8047 | ||
|
|
a6c94b5167 | ||
|
|
a5943234fd | ||
|
|
03977693c1 | ||
|
|
d6d770f303 |
2
.github/workflows/buildx-releases-json.yml
vendored
2
.github/workflows/buildx-releases-json.yml
vendored
@@ -17,7 +17,7 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
generate:
|
generate:
|
||||||
uses: crazy-max/.github/.github/workflows/releases-json.yml@2a596c917a8ad3e6203ae99b777148525a2e00d5
|
uses: crazy-max/.github/.github/workflows/releases-json.yml@6dc31870ca6c4f8489bf5a408ab38fae60f47eec
|
||||||
with:
|
with:
|
||||||
repository: docker/buildx
|
repository: docker/buildx
|
||||||
artifact_name: buildx-releases-json
|
artifact_name: buildx-releases-json
|
||||||
|
|||||||
2
.github/workflows/docker-releases-json.yml
vendored
2
.github/workflows/docker-releases-json.yml
vendored
@@ -17,7 +17,7 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
generate:
|
generate:
|
||||||
uses: crazy-max/.github/.github/workflows/releases-json.yml@2a596c917a8ad3e6203ae99b777148525a2e00d5
|
uses: crazy-max/.github/.github/workflows/releases-json.yml@6dc31870ca6c4f8489bf5a408ab38fae60f47eec
|
||||||
with:
|
with:
|
||||||
repository: moby/moby
|
repository: moby/moby
|
||||||
artifact_name: docker-releases-json
|
artifact_name: docker-releases-json
|
||||||
|
|||||||
459
__tests__/buildx/bake.test.ts
Normal file
459
__tests__/buildx/bake.test.ts
Normal 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);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -20,7 +20,6 @@ import * as path from 'path';
|
|||||||
import * as rimraf from 'rimraf';
|
import * as rimraf from 'rimraf';
|
||||||
|
|
||||||
import {Context} from '../../src/context';
|
import {Context} from '../../src/context';
|
||||||
import {Buildx} from '../../src/buildx/buildx';
|
|
||||||
import {Inputs} from '../../src/buildx/inputs';
|
import {Inputs} from '../../src/buildx/inputs';
|
||||||
|
|
||||||
const fixturesDir = path.join(__dirname, '..', 'fixtures');
|
const fixturesDir = path.join(__dirname, '..', 'fixtures');
|
||||||
@@ -53,31 +52,28 @@ afterEach(() => {
|
|||||||
|
|
||||||
describe('resolveBuildImageID', () => {
|
describe('resolveBuildImageID', () => {
|
||||||
it('matches', async () => {
|
it('matches', async () => {
|
||||||
const buildx = new Buildx();
|
|
||||||
const imageID = 'sha256:bfb45ab72e46908183546477a08f8867fc40cebadd00af54b071b097aed127a9';
|
const imageID = 'sha256:bfb45ab72e46908183546477a08f8867fc40cebadd00af54b071b097aed127a9';
|
||||||
const imageIDFile = buildx.inputs.getBuildImageIDFilePath();
|
const imageIDFile = Inputs.getBuildImageIDFilePath();
|
||||||
await fs.writeFileSync(imageIDFile, imageID);
|
await fs.writeFileSync(imageIDFile, imageID);
|
||||||
const expected = buildx.inputs.resolveBuildImageID();
|
const expected = Inputs.resolveBuildImageID();
|
||||||
expect(expected).toEqual(imageID);
|
expect(expected).toEqual(imageID);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('resolveBuildMetadata', () => {
|
describe('resolveBuildMetadata', () => {
|
||||||
it('matches', async () => {
|
it('matches', async () => {
|
||||||
const buildx = new Buildx();
|
const metadataFile = Inputs.getBuildMetadataFilePath();
|
||||||
const metadataFile = buildx.inputs.getBuildMetadataFilePath();
|
|
||||||
await fs.writeFileSync(metadataFile, metadata);
|
await fs.writeFileSync(metadataFile, metadata);
|
||||||
const expected = buildx.inputs.resolveBuildMetadata();
|
const expected = Inputs.resolveBuildMetadata();
|
||||||
expect(expected).toEqual(metadata);
|
expect(expected).toEqual(metadata);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('resolveDigest', () => {
|
describe('resolveDigest', () => {
|
||||||
it('matches', async () => {
|
it('matches', async () => {
|
||||||
const buildx = new Buildx();
|
const metadataFile = Inputs.getBuildMetadataFilePath();
|
||||||
const metadataFile = buildx.inputs.getBuildMetadataFilePath();
|
|
||||||
await fs.writeFileSync(metadataFile, metadata);
|
await fs.writeFileSync(metadataFile, metadata);
|
||||||
const expected = buildx.inputs.resolveDigest();
|
const expected = Inputs.resolveDigest();
|
||||||
expect(expected).toEqual('sha256:b09b9482c72371486bb2c1d2c2a2633ed1d0b8389e12c8d52b9e052725c0c83c');
|
expect(expected).toEqual('sha256:b09b9482c72371486bb2c1d2c2a2633ed1d0b8389e12c8d52b9e052725c0c83c');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -124,8 +120,7 @@ describe('getProvenanceInput', () => {
|
|||||||
],
|
],
|
||||||
])('given input %p', async (input: string, expected: string) => {
|
])('given input %p', async (input: string, expected: string) => {
|
||||||
await setInput('provenance', input);
|
await setInput('provenance', input);
|
||||||
const buildx = new Buildx();
|
expect(Inputs.getProvenanceInput('provenance')).toEqual(expected);
|
||||||
expect(buildx.inputs.getProvenanceInput('provenance')).toEqual(expected);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -153,8 +148,7 @@ describe('resolveProvenanceAttrs', () => {
|
|||||||
'builder-id=https://github.com/docker/actions-toolkit/actions/runs/123'
|
'builder-id=https://github.com/docker/actions-toolkit/actions/runs/123'
|
||||||
],
|
],
|
||||||
])('given %p', async (input: string, expected: string) => {
|
])('given %p', async (input: string, expected: string) => {
|
||||||
const buildx = new Buildx();
|
expect(Inputs.resolveProvenanceAttrs(input)).toEqual(expected);
|
||||||
expect(buildx.inputs.resolveProvenanceAttrs(input)).toEqual(expected);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -170,12 +164,11 @@ describe('resolveBuildSecret', () => {
|
|||||||
[`notfound=secret`, true, '', '', new Error('secret file secret not found')]
|
[`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) => {
|
])('given %p key and %p secret', async (kvp: string, file: boolean, exKey: string, exValue: string, error: Error) => {
|
||||||
try {
|
try {
|
||||||
const buildx = new Buildx();
|
|
||||||
let secret: string;
|
let secret: string;
|
||||||
if (file) {
|
if (file) {
|
||||||
secret = buildx.inputs.resolveBuildSecretFile(kvp);
|
secret = Inputs.resolveBuildSecretFile(kvp);
|
||||||
} else {
|
} else {
|
||||||
secret = buildx.inputs.resolveBuildSecretString(kvp);
|
secret = Inputs.resolveBuildSecretString(kvp);
|
||||||
}
|
}
|
||||||
expect(secret).toEqual(`id=${exKey},src=${tmpName}`);
|
expect(secret).toEqual(`id=${exKey},src=${tmpName}`);
|
||||||
expect(fs.readFileSync(tmpName, 'utf-8')).toEqual(exValue);
|
expect(fs.readFileSync(tmpName, 'utf-8')).toEqual(exValue);
|
||||||
|
|||||||
172
__tests__/fixtures/bake.hcl
Normal file
172
__tests__/fixtures/bake.hcl
Normal 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"]
|
||||||
|
}
|
||||||
@@ -51,7 +51,7 @@
|
|||||||
"@actions/io": "^1.1.2",
|
"@actions/io": "^1.1.2",
|
||||||
"@actions/tool-cache": "^2.0.1",
|
"@actions/tool-cache": "^2.0.1",
|
||||||
"async-retry": "^1.3.3",
|
"async-retry": "^1.3.3",
|
||||||
"csv-parse": "^5.3.5",
|
"csv-parse": "^5.3.6",
|
||||||
"handlebars": "^4.7.7",
|
"handlebars": "^4.7.7",
|
||||||
"jwt-decode": "^3.1.2",
|
"jwt-decode": "^3.1.2",
|
||||||
"semver": "^7.3.8",
|
"semver": "^7.3.8",
|
||||||
|
|||||||
74
src/buildx/bake.ts
Normal file
74
src/buildx/bake.ts
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,7 +21,6 @@ import * as semver from 'semver';
|
|||||||
|
|
||||||
import {Docker} from '../docker/docker';
|
import {Docker} from '../docker/docker';
|
||||||
import {Exec} from '../exec';
|
import {Exec} from '../exec';
|
||||||
import {Inputs} from './inputs';
|
|
||||||
|
|
||||||
import {Cert} from '../types/buildx';
|
import {Cert} from '../types/buildx';
|
||||||
|
|
||||||
@@ -34,15 +33,12 @@ export class Buildx {
|
|||||||
private _versionOnce: boolean;
|
private _versionOnce: boolean;
|
||||||
private readonly _standalone: boolean | undefined;
|
private readonly _standalone: boolean | undefined;
|
||||||
|
|
||||||
public readonly inputs: Inputs;
|
|
||||||
|
|
||||||
public static readonly containerNamePrefix = 'buildx_buildkit_';
|
public static readonly containerNamePrefix = 'buildx_buildkit_';
|
||||||
|
|
||||||
constructor(opts?: BuildxOpts) {
|
constructor(opts?: BuildxOpts) {
|
||||||
this._standalone = opts?.standalone;
|
this._standalone = opts?.standalone;
|
||||||
this._version = '';
|
this._version = '';
|
||||||
this._versionOnce = false;
|
this._versionOnce = false;
|
||||||
this.inputs = new Inputs();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static get configDir(): string {
|
static get configDir(): string {
|
||||||
|
|||||||
@@ -22,24 +22,24 @@ import {parse} from 'csv-parse/sync';
|
|||||||
import {Context} from '../context';
|
import {Context} from '../context';
|
||||||
|
|
||||||
export class Inputs {
|
export class Inputs {
|
||||||
public getBuildImageIDFilePath(): string {
|
public static getBuildImageIDFilePath(): string {
|
||||||
return path.join(Context.tmpDir(), 'iidfile');
|
return path.join(Context.tmpDir(), 'iidfile');
|
||||||
}
|
}
|
||||||
|
|
||||||
public getBuildMetadataFilePath(): string {
|
public static getBuildMetadataFilePath(): string {
|
||||||
return path.join(Context.tmpDir(), 'metadata-file');
|
return path.join(Context.tmpDir(), 'metadata-file');
|
||||||
}
|
}
|
||||||
|
|
||||||
public resolveBuildImageID(): string | undefined {
|
public static resolveBuildImageID(): string | undefined {
|
||||||
const iidFile = this.getBuildImageIDFilePath();
|
const iidFile = Inputs.getBuildImageIDFilePath();
|
||||||
if (!fs.existsSync(iidFile)) {
|
if (!fs.existsSync(iidFile)) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
return fs.readFileSync(iidFile, {encoding: 'utf-8'}).trim();
|
return fs.readFileSync(iidFile, {encoding: 'utf-8'}).trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
public resolveBuildMetadata(): string | undefined {
|
public static resolveBuildMetadata(): string | undefined {
|
||||||
const metadataFile = this.getBuildMetadataFilePath();
|
const metadataFile = Inputs.getBuildMetadataFilePath();
|
||||||
if (!fs.existsSync(metadataFile)) {
|
if (!fs.existsSync(metadataFile)) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
@@ -50,8 +50,8 @@ export class Inputs {
|
|||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
public resolveDigest(): string | undefined {
|
public static resolveDigest(): string | undefined {
|
||||||
const metadata = this.resolveBuildMetadata();
|
const metadata = Inputs.resolveBuildMetadata();
|
||||||
if (metadata === undefined) {
|
if (metadata === undefined) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
@@ -62,15 +62,15 @@ export class Inputs {
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
public resolveBuildSecretString(kvp: string): string {
|
public static resolveBuildSecretString(kvp: string): string {
|
||||||
return this.resolveBuildSecret(kvp, false);
|
return Inputs.resolveBuildSecret(kvp, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public resolveBuildSecretFile(kvp: string): string {
|
public static resolveBuildSecretFile(kvp: string): string {
|
||||||
return this.resolveBuildSecret(kvp, true);
|
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 delimiterIndex = kvp.indexOf('=');
|
||||||
const key = kvp.substring(0, delimiterIndex);
|
const key = kvp.substring(0, delimiterIndex);
|
||||||
let value = kvp.substring(delimiterIndex + 1);
|
let value = kvp.substring(delimiterIndex + 1);
|
||||||
@@ -88,7 +88,7 @@ export class Inputs {
|
|||||||
return `id=${key},src=${secretFile}`;
|
return `id=${key},src=${secretFile}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getProvenanceInput(name: string): string {
|
public static getProvenanceInput(name: string): string {
|
||||||
const input = core.getInput(name);
|
const input = core.getInput(name);
|
||||||
if (!input) {
|
if (!input) {
|
||||||
// if input is not set returns empty string
|
// if input is not set returns empty string
|
||||||
@@ -98,11 +98,11 @@ export class Inputs {
|
|||||||
return core.getBooleanInput(name) ? `builder-id=${Context.provenanceBuilderID()}` : 'false';
|
return core.getBooleanInput(name) ? `builder-id=${Context.provenanceBuilderID()}` : 'false';
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// not a valid boolean, so we assume it's a string
|
// 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) {
|
if (!input) {
|
||||||
return `builder-id=${Context.provenanceBuilderID()}`;
|
return `builder-id=${Context.provenanceBuilderID()}`;
|
||||||
}
|
}
|
||||||
|
|||||||
45
src/types/bake.ts
Normal file
45
src/types/bake.ts
Normal 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;
|
||||||
|
}
|
||||||
@@ -776,7 +776,7 @@ __metadata:
|
|||||||
"@typescript-eslint/parser": ^5.49.0
|
"@typescript-eslint/parser": ^5.49.0
|
||||||
async-retry: ^1.3.3
|
async-retry: ^1.3.3
|
||||||
cpy-cli: ^4.2.0
|
cpy-cli: ^4.2.0
|
||||||
csv-parse: ^5.3.5
|
csv-parse: ^5.3.6
|
||||||
dotenv: ^16.0.3
|
dotenv: ^16.0.3
|
||||||
eslint: ^8.33.0
|
eslint: ^8.33.0
|
||||||
eslint-config-prettier: ^8.6.0
|
eslint-config-prettier: ^8.6.0
|
||||||
@@ -2573,7 +2573,7 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"csv-parse@npm:*, csv-parse@npm:^5.3.5":
|
"csv-parse@npm:*, csv-parse@npm:^5.3.6":
|
||||||
version: 5.3.6
|
version: 5.3.6
|
||||||
resolution: "csv-parse@npm:5.3.6"
|
resolution: "csv-parse@npm:5.3.6"
|
||||||
checksum: a6dcb61a0676121e84a29cdee4978a0516d1412fbe8895057d17e1a95a2013e6283b253135465ad562222d095988a74587d92b2fa04192bef15090acce2a0433
|
checksum: a6dcb61a0676121e84a29cdee4978a0516d1412fbe8895057d17e1a95a2013e6283b253135465ad562222d095988a74587d92b2fa04192bef15090acce2a0433
|
||||||
|
|||||||
Reference in New Issue
Block a user