From 15c6a86f2df20151ee0a003a10f81c84d1c14759 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Wed, 12 Aug 2020 15:10:05 +0200 Subject: [PATCH] Add 'use' input Signed-off-by: CrazyMax --- .github/workflows/setup-buildx-ci.yml | 22 ++++++++++++++++++++++ setup-buildx/README.md | 1 + setup-buildx/action.yml | 4 ++++ setup-buildx/dist/index.js | 5 ++++- setup-buildx/src/main.ts | 7 +++++-- 5 files changed, 36 insertions(+), 3 deletions(-) diff --git a/.github/workflows/setup-buildx-ci.yml b/.github/workflows/setup-buildx-ci.yml index b22cdba..45b776e 100644 --- a/.github/workflows/setup-buildx-ci.yml +++ b/.github/workflows/setup-buildx-ci.yml @@ -62,6 +62,28 @@ jobs: run: | docker build --help + use: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + use: + - true + - false + steps: + - + name: Checkout + uses: actions/checkout@v2.3.1 + - + name: Set up Docker Buildx + id: buildx + uses: ./setup-buildx/ + with: + use: ${{ matrix.use }} + - + name: List builder instances + run: docker buildx ls + driver: runs-on: ubuntu-latest strategy: diff --git a/setup-buildx/README.md b/setup-buildx/README.md index a668fb6..fe19622 100644 --- a/setup-buildx/README.md +++ b/setup-buildx/README.md @@ -94,6 +94,7 @@ Following inputs can be used as `step.with` keys | `driver` | String | `docker-container` | Sets the [builder driver](https://github.com/docker/buildx#--driver-driver) to be used. | | `driver-opt` | String | | Passes additional [driver-specific options](https://github.com/docker/buildx#--driver-opt-options). e.g. `image=moby/buildkit:master` | | `install` | Bool | `false` | Sets up `docker build` command as an alias to `docker buildx` | +| `use` | Bool | `true` | Switch to this builder instance | ### outputs diff --git a/setup-buildx/action.yml b/setup-buildx/action.yml index 1f9e633..10f2409 100644 --- a/setup-buildx/action.yml +++ b/setup-buildx/action.yml @@ -22,6 +22,10 @@ inputs: description: 'Sets up docker build command as an alias to docker buildx' default: 'false' required: false + use: + description: 'Switch to this builder instance' + default: 'true' + required: false outputs: platforms: diff --git a/setup-buildx/dist/index.js b/setup-buildx/dist/index.js index b5d108a..64c4791 100644 --- a/setup-buildx/dist/index.js +++ b/setup-buildx/dist/index.js @@ -2495,6 +2495,7 @@ function run() { const driver = core.getInput('driver') || 'docker-container'; const driverOpt = core.getInput('driver-opt'); const install = /true/i.test(core.getInput('install')); + const use = /true/i.test(core.getInput('use')); const dockerConfigHome = process.env.DOCKER_CONFIG || path.join(os.homedir(), '.docker'); yield installer.buildx(buildxVer, dockerConfigHome); core.info('📣 Buildx info'); @@ -2503,7 +2504,6 @@ function run() { let createArgs = [ 'buildx', 'create', - '--use', '--name', `builder-${process.env.GITHUB_SHA}`, '--driver', @@ -2512,6 +2512,9 @@ function run() { if (driverOpt) { createArgs.push('--driver-opt', driverOpt); } + if (use) { + createArgs.push('--use'); + } yield exec.exec('docker', createArgs); core.info('🏃 Booting builder...'); yield exec.exec('docker', ['buildx', 'inspect', '--bootstrap']); diff --git a/setup-buildx/src/main.ts b/setup-buildx/src/main.ts index 9293823..a29da5c 100644 --- a/setup-buildx/src/main.ts +++ b/setup-buildx/src/main.ts @@ -17,6 +17,8 @@ async function run(): Promise { const driver: string = core.getInput('driver') || 'docker-container'; const driverOpt: string = core.getInput('driver-opt'); const install: boolean = /true/i.test(core.getInput('install')); + const use: boolean = /true/i.test(core.getInput('use')); + const dockerConfigHome: string = process.env.DOCKER_CONFIG || path.join(os.homedir(), '.docker'); await installer.buildx(buildxVer, dockerConfigHome); @@ -27,16 +29,17 @@ async function run(): Promise { let createArgs: Array = [ 'buildx', 'create', - '--use', '--name', `builder-${process.env.GITHUB_SHA}`, '--driver', driver ]; - if (driverOpt) { createArgs.push('--driver-opt', driverOpt); } + if (use) { + createArgs.push('--use'); + } await exec.exec('docker', createArgs);