Skip to content

Commit

Permalink
Merge pull request #209 from crazy-max/docker-context
Browse files Browse the repository at this point in the history
fix current context as builder name for docker driver
  • Loading branch information
crazy-max authored Mar 3, 2023
2 parents 774ea5c + 30389db commit 03a7a3d
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 11 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions __tests__/context.test.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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) => {
Expand Down
4 changes: 2 additions & 2 deletions dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
7 changes: 4 additions & 3 deletions src/context.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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',
Expand All @@ -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>> {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 03a7a3d

Please sign in to comment.