bake: support composable attributes

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2024-11-27 15:29:51 +01:00
parent 2e6acb85f0
commit 068b0dcb39
8 changed files with 376 additions and 143 deletions

View File

@@ -22,7 +22,9 @@
"linux/amd64"
],
"output": [
"type=docker"
{
"type": "docker"
}
]
}
}

View File

@@ -22,7 +22,9 @@
"GO_VERSION": "1.20"
},
"output": [
"type=cacheonly"
{
"type": "cacheonly"
}
]
},
"validate-docs": {
@@ -36,7 +38,9 @@
},
"target": "validate",
"output": [
"type=cacheonly"
{
"type": "cacheonly"
}
]
},
"validate-vendor": {
@@ -48,7 +52,9 @@
},
"target": "validate",
"output": [
"type=cacheonly"
{
"type": "cacheonly"
}
]
}
}

View File

@@ -0,0 +1,38 @@
{
"target": {
"default": {
"context": ".",
"dockerfile": "Dockerfile",
"cache-from": [
{
"scope": "build",
"type": "gha"
},
{
"ref": "user/repo:cache",
"type": "registry"
}
],
"cache-to": [
{
"mode": "max",
"scope": "build",
"type": "gha"
},
{
"type": "inline"
}
],
"output": [
{
"dest": "./release-out",
"type": "local"
},
{
"ref": "user/app",
"type": "registry"
}
]
}
}
}

View File

@@ -0,0 +1,28 @@
// Copyright 2024 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.
target "default" {
cache-from = [
"type=gha,scope=build",
"user/repo:cache",
]
cache-to = [
"type=gha,scope=build,mode=max",
"type=inline"
]
output = [
"./release-out",
"type=registry,ref=user/app"
]
}

View File

@@ -29,7 +29,10 @@
"windows/arm64"
],
"output": [
"./bin/build"
{
"dest": "./bin/build",
"type": "local"
}
]
}
}

View File

@@ -94,7 +94,14 @@ describe('getDefinition', () => {
['*.output=type=docker', '*.platform=linux/amd64'],
undefined,
path.join(fixturesDir, 'bake-01-overrides.json')
]
],
[
[path.join(fixturesDir, 'bake-03.hcl')],
[],
[],
undefined,
path.join(fixturesDir, 'bake-03-default.json')
],
])('given %p', async (files: string[], targets: string[], overrides: string[], execOptions: ExecOptions | undefined, out: string) => {
const bake = new Bake();
const expectedDef = <BakeDefinition>JSON.parse(fs.readFileSync(out, {encoding: 'utf-8'}).trim())
@@ -103,7 +110,7 @@ describe('getDefinition', () => {
targets: targets,
overrides: overrides
}, execOptions)).toEqual(expectedDef);
});
}, 30 * 60 * 1000);
});
describe('hasLocalExporter', () => {
@@ -114,7 +121,9 @@ describe('hasLocalExporter', () => {
"target": {
"build": {
"output": [
"type=docker"
{
"type": "docker"
}
]
},
}
@@ -136,7 +145,10 @@ describe('hasLocalExporter', () => {
"target": {
"local": {
"output": [
"type=local,dest=./release-out"
{
"type": "local",
"dest": "./release-out"
}
]
},
}
@@ -148,19 +160,10 @@ describe('hasLocalExporter', () => {
"target": {
"tar": {
"output": [
"type=tar,dest=/tmp/image.tar"
]
},
}
} as unknown as BakeDefinition,
false
],
[
{
"target": {
"tar": {
"output": [
'"type=tar","dest=/tmp/image.tar"',
{
"type": "tar",
"dest": "/tmp/image.tar"
}
]
},
}
@@ -172,19 +175,10 @@ describe('hasLocalExporter', () => {
"target": {
"local": {
"output": [
'" type= local" , dest=./release-out',
]
},
}
} as unknown as BakeDefinition,
true
],
[
{
"target": {
"local": {
"output": [
".",
{
"type": "local",
"dest": "."
}
]
},
}
@@ -204,7 +198,10 @@ describe('hasTarExporter', () => {
"target": {
"reg": {
"output": [
"type=registry,ref=user/app"
{
"type": "registry",
"ref": "user/app"
}
]
},
}
@@ -216,7 +213,9 @@ describe('hasTarExporter', () => {
"target": {
"build": {
"output": [
"type=docker"
{
"type": "docker"
}
]
},
}
@@ -228,7 +227,10 @@ describe('hasTarExporter', () => {
"target": {
"local": {
"output": [
"type=local,dest=./release-out"
{
"type": "local",
"dest": "./release-out"
}
]
},
}
@@ -240,7 +242,10 @@ describe('hasTarExporter', () => {
"target": {
"tar": {
"output": [
"type=tar,dest=/tmp/image.tar"
{
"type": "tar",
"dest": "/tmp/image.tar"
}
]
},
}
@@ -252,20 +257,13 @@ describe('hasTarExporter', () => {
"target": {
"multi": {
"output": [
"type=docker",
"type=tar,dest=/tmp/image.tar"
]
},
}
} as unknown as BakeDefinition,
true
],
[
{
"target": {
"tar": {
"output": [
'"type=tar","dest=/tmp/image.tar"',
{
"type": "docker"
},
{
"type": "tar",
"dest": "/tmp/image.tar"
}
]
},
}
@@ -277,19 +275,10 @@ describe('hasTarExporter', () => {
"target": {
"local": {
"output": [
'" type= local" , dest=./release-out',
]
},
}
} as unknown as BakeDefinition,
false
],
[
{
"target": {
"local": {
"output": [
".",
{
"type": "local",
"dest": "."
}
]
},
}
@@ -309,7 +298,10 @@ describe('hasDockerExporter', () => {
"target": {
"reg": {
"output": [
"type=registry,ref=user/app"
{
"type": "registry",
"ref": "user/app"
}
]
},
}
@@ -322,7 +314,9 @@ describe('hasDockerExporter', () => {
"target": {
"build": {
"output": [
"type=docker"
{
"type": "docker"
}
]
},
}
@@ -335,8 +329,13 @@ describe('hasDockerExporter', () => {
"target": {
"multi": {
"output": [
"type=docker",
"type=tar,dest=/tmp/image.tar"
{
"type": "docker"
},
{
"type": "tar",
"dest": "/tmp/image.tar"
}
]
},
}
@@ -349,20 +348,10 @@ describe('hasDockerExporter', () => {
"target": {
"local": {
"output": [
'" type= local" , dest=./release-out'
]
},
}
} as unknown as BakeDefinition,
false,
undefined
],
[
{
"target": {
"local": {
"output": [
"type=local,dest=./release-out"
{
"type": "local",
"dest": "./release-out"
}
]
},
}
@@ -375,7 +364,10 @@ describe('hasDockerExporter', () => {
"target": {
"tar": {
"output": [
"type=tar,dest=/tmp/image.tar"
{
"type": "tar",
"dest": "/tmp/image.tar"
}
]
},
}
@@ -388,8 +380,13 @@ describe('hasDockerExporter', () => {
"target": {
"multi": {
"output": [
"type=docker",
"type=tar,dest=/tmp/image.tar"
{
"type": "docker"
},
{
"type": "tar",
"dest": "/tmp/image.tar"
}
]
},
}
@@ -397,51 +394,14 @@ describe('hasDockerExporter', () => {
true,
undefined
],
[
{
"target": {
"tar": {
"output": [
'"type=tar","dest=/tmp/image.tar"'
]
},
}
} as unknown as BakeDefinition,
false,
undefined
],
[
{
"target": {
"tar": {
"output": [
'"type=tar","dest=/tmp/image.tar"'
]
},
}
} as unknown as BakeDefinition,
false,
undefined
],
[
{
"target": {
"local": {
"output": [
'" type= local" , dest=./release-out'
]
},
}
} as unknown as BakeDefinition,
false,
undefined
],
[
{
"target": {
"build": {
"output": [
"type=docker"
{
"type": "docker"
}
]
},
}
@@ -454,7 +414,9 @@ describe('hasDockerExporter', () => {
"target": {
"build": {
"output": [
"type=docker"
{
"type": "docker"
}
]
},
}
@@ -467,7 +429,10 @@ describe('hasDockerExporter', () => {
"target": {
"build": {
"output": [
"."
{
"type": "local",
"dest": "."
}
]
},
}