Merge pull request #209 from crazy-max/docker-context

fix current context as builder name for docker driver
This commit is contained in:
CrazyMax 2023-03-03 10:51:02 +01:00 committed by GitHub
commit 03a7a3d9fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 34 additions and 11 deletions

View File

@ -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

View File

@ -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) => {

4
dist/index.js generated vendored

File diff suppressed because one or more lines are too long

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@ -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"
},

View File

@ -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>> {

View File

@ -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"