From fa61d38ad89e452238659465fb016c7a8d4bb478 Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Fri, 11 Sep 2020 11:23:49 +1200 Subject: [PATCH] Add --ssh arg support Signed-off-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> --- README.md | 1 + action.yml | 3 +++ dist/index.js | 6 +++++- src/context.ts | 11 +++++++++-- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3e92f9a..4541be1 100644 --- a/README.md +++ b/README.md @@ -673,6 +673,7 @@ Following inputs can be used as `step.with` keys | `cache-from` | List | List of [external cache sources](https://github.com/docker/buildx#--cache-fromnametypetypekeyvalue) (eg. `type=local,src=path/to/dir`) | | `cache-to` | List | List of [cache export destinations](https://github.com/docker/buildx#--cache-tonametypetypekeyvalue) (eg. `type=local,dest=path/to/dir`) | | `secrets` | List | List of secrets to expose to the build (eg. `key=value`, `GIT_AUTH_TOKEN=mytoken`) | +| `ssh` | List | List of SSH agent socket or keys to expose to the build (eg: `default|[=|[,]]`) | ### outputs diff --git a/action.yml b/action.yml index f13442c..9e61087 100644 --- a/action.yml +++ b/action.yml @@ -67,6 +67,9 @@ inputs: description: "GitHub Token used to authenticate against a repository for Git context" default: ${{ github.token }} required: false + ssh: + description: "List of SSH agent socket or keys to expose to the build (eg: default)" + required: false outputs: digest: diff --git a/dist/index.js b/dist/index.js index 06d16f9..2ca1678 100644 --- a/dist/index.js +++ b/dist/index.js @@ -12082,7 +12082,8 @@ function getInputs(defaultContext) { cacheFrom: yield getInputList('cache-from', true), cacheTo: yield getInputList('cache-to', true), secrets: yield getInputList('secrets', true), - githubToken: core.getInput('github-token') + githubToken: core.getInput('github-token'), + ssh: yield getInputList('ssh') }; }); } @@ -12137,6 +12138,9 @@ function getBuildArgs(inputs, defaultContext, buildxVersion) { if (inputs.githubToken && !buildx.hasGitAuthToken(inputs.secrets) && inputs.context == defaultContext) { args.push('--secret', yield buildx.getSecret(`GIT_AUTH_TOKEN=${inputs.githubToken}`)); } + yield exports.asyncForEach(inputs.ssh, (ssh) => __awaiter(this, void 0, void 0, function* () { + args.push('--ssh', ssh); + })); if (inputs.file) { args.push('--file', inputs.file); } diff --git a/src/context.ts b/src/context.ts index 94dcdae..fc7a81d 100644 --- a/src/context.ts +++ b/src/context.ts @@ -3,10 +3,12 @@ import * as os from 'os'; import * as path from 'path'; import * as semver from 'semver'; import * as tmp from 'tmp'; -import * as buildx from './buildx'; + import * as core from '@actions/core'; import * as github from '@actions/github'; +import * as buildx from './buildx'; + let _defaultContext, _tmpDir: string; export interface Inputs { @@ -28,6 +30,7 @@ export interface Inputs { cacheTo: string[]; secrets: string[]; githubToken: string; + ssh: string[]; } export function defaultContext(): string { @@ -69,7 +72,8 @@ export async function getInputs(defaultContext: string): Promise { cacheFrom: await getInputList('cache-from', true), cacheTo: await getInputList('cache-to', true), secrets: await getInputList('secrets', true), - githubToken: core.getInput('github-token') + githubToken: core.getInput('github-token'), + ssh: await getInputList('ssh') }; } @@ -122,6 +126,9 @@ async function getBuildArgs(inputs: Inputs, defaultContext: string, buildxVersio if (inputs.githubToken && !buildx.hasGitAuthToken(inputs.secrets) && inputs.context == defaultContext) { args.push('--secret', await buildx.getSecret(`GIT_AUTH_TOKEN=${inputs.githubToken}`)); } + await asyncForEach(inputs.ssh, async ssh => { + args.push('--ssh', ssh); + }); if (inputs.file) { args.push('--file', inputs.file); }