From 05ca2e6f5ee052a514ce8898bbf3e0c67618a398 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Sat, 25 Feb 2023 16:16:08 +0100 Subject: [PATCH] fix current context as builder name for docker driver Signed-off-by: CrazyMax --- .github/workflows/ci.yml | 17 +++++++++++++++++ __tests__/context.test.ts | 5 +++++ package.json | 2 +- src/context.ts | 7 ++++--- yarn.lock | 8 ++++---- 5 files changed, 31 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 234f657..3a5b3ae 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/__tests__/context.test.ts b/__tests__/context.test.ts index ca2c437..b63d070 100644 --- a/__tests__/context.test.ts +++ b/__tests__/context.test.ts @@ -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 => { + return Promise.resolve('default'); +}); + describe('getCreateArgs', () => { beforeEach(() => { process.env = Object.keys(process.env).reduce((object, key) => { diff --git a/package.json b/package.json index 6f86676..de56278 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/src/context.ts b/src/context.ts index f527fe5..583d8ba 100644 --- a/src/context.ts +++ b/src/context.ts @@ -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 { 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 { }; } -export function getBuilderName(driver: string): string { - return driver == 'docker' ? 'default' : `builder-${uuid.v4()}`; +export async function getBuilderName(driver: string): Promise { + return driver == 'docker' ? await Docker.context() : `builder-${uuid.v4()}`; } export async function getCreateArgs(inputs: Inputs, toolkit: Toolkit): Promise> { diff --git a/yarn.lock b/yarn.lock index 84f933e..db558b3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"