fix current context as builder name for docker driver

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2023-02-25 16:16:08 +01:00
parent 774ea5c2f1
commit 05ca2e6f5e
No known key found for this signature in database
GPG Key ID: 3248E46B6BB8C7F7
5 changed files with 31 additions and 8 deletions

@ -464,3 +464,20 @@ jobs:
uses: ./
with:
platforms: linux/amd64
docker-context:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v3
-
name: Create Docker context
run: |
docker context create foo
docker context use foo
-
name: Set up Docker Buildx
uses: ./
with:
driver: docker

@ -1,5 +1,6 @@
import {beforeEach, describe, expect, jest, test} from '@jest/globals';
import * as uuid from 'uuid';
import {Docker} from '@docker/actions-toolkit/lib/docker';
import {Toolkit} from '@docker/actions-toolkit/lib/toolkit';
import {Node} from '@docker/actions-toolkit/lib/types/builder';
@ -8,6 +9,10 @@ import * as context from '../src/context';
jest.mock('uuid');
jest.spyOn(uuid, 'v4').mockReturnValue('9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d');
jest.spyOn(Docker, 'context').mockImplementation((): Promise<string> => {
return Promise.resolve('default');
});
describe('getCreateArgs', () => {
beforeEach(() => {
process.env = Object.keys(process.env).reduce((object, key) => {

@ -29,7 +29,7 @@
"dependencies": {
"@actions/core": "^1.10.0",
"@actions/exec": "^1.1.1",
"@docker/actions-toolkit": "^0.1.0-beta.15",
"@docker/actions-toolkit": "^0.1.0-beta.16",
"js-yaml": "^4.1.0",
"uuid": "^9.0.0"
},

@ -1,5 +1,6 @@
import * as uuid from 'uuid';
import * as core from '@actions/core';
import {Docker} from '@docker/actions-toolkit/lib/docker';
import {Util} from '@docker/actions-toolkit/lib/util';
import {Toolkit} from '@docker/actions-toolkit/lib/toolkit';
import {Node} from '@docker/actions-toolkit/lib/types/builder';
@ -24,7 +25,7 @@ export interface Inputs {
export async function getInputs(): Promise<Inputs> {
return {
version: core.getInput('version'),
name: getBuilderName(core.getInput('driver') || 'docker-container'),
name: await getBuilderName(core.getInput('driver') || 'docker-container'),
driver: core.getInput('driver') || 'docker-container',
driverOpts: Util.getInputList('driver-opts', {ignoreComma: true, quote: false}),
buildkitdFlags: core.getInput('buildkitd-flags') || '--allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host',
@ -38,8 +39,8 @@ export async function getInputs(): Promise<Inputs> {
};
}
export function getBuilderName(driver: string): string {
return driver == 'docker' ? 'default' : `builder-${uuid.v4()}`;
export async function getBuilderName(driver: string): Promise<string> {
return driver == 'docker' ? await Docker.context() : `builder-${uuid.v4()}`;
}
export async function getCreateArgs(inputs: Inputs, toolkit: Toolkit): Promise<Array<string>> {

@ -563,10 +563,10 @@
dependencies:
"@cspotcode/source-map-consumer" "0.8.0"
"@docker/actions-toolkit@^0.1.0-beta.15":
version "0.1.0-beta.15"
resolved "https://registry.yarnpkg.com/@docker/actions-toolkit/-/actions-toolkit-0.1.0-beta.15.tgz#46d9f4b1582f19ce3cb68cf272fbee335e693212"
integrity sha512-YdOHXz+r1fkoYYA5tR+Ji6jiqw5wU7gYsL8ISW+mQicm6f4Ckw4PNNADEZR+X8paEc+96Xl5Osr2tKmM3mOZOA==
"@docker/actions-toolkit@^0.1.0-beta.16":
version "0.1.0-beta.16"
resolved "https://registry.yarnpkg.com/@docker/actions-toolkit/-/actions-toolkit-0.1.0-beta.16.tgz#a34915e2957872296c8d5334809e707e6628ed4e"
integrity sha512-uWdhvQdpinyC633C+3RjFXZdE5bVJoJ4ADWE3568ldEBARWxRfw04VGUa4+cQ8/UqPS5goXoTjU6c7ws0jn5RQ==
dependencies:
"@actions/core" "^1.10.0"
"@actions/exec" "^1.1.1"