From c75e11dc6a7e98ea052410fccc687954c30beb3e Mon Sep 17 00:00:00 2001 From: Ivan Hernandez Date: Mon, 17 May 2021 16:10:42 +0200 Subject: [PATCH] sshAgent as input parameter --- action.yml | 4 ++++ src/index.ts | 4 ++-- src/model/__mocks__/input.ts | 1 + src/model/action.ts | 4 ---- src/model/build-parameters.ts | 1 + src/model/docker.ts | 8 ++++---- src/model/input.ts | 4 ++++ 7 files changed, 16 insertions(+), 10 deletions(-) diff --git a/action.yml b/action.yml index 839b1b50..a0917501 100644 --- a/action.yml +++ b/action.yml @@ -106,6 +106,10 @@ inputs: Parameters must start with a hyphen (-) and may be followed by a value (without hyphen). Parameters without a value will be considered booleans (with a value of true). + sshAgent: + required: false + default: '' + description: 'SSH Agent path to forward to the container' chownFilesTo: required: false default: '' diff --git a/src/index.ts b/src/index.ts index dbb5c021..2d5687af 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,7 +6,7 @@ async function run() { Action.checkCompatibility(); Cache.verify(); - const { dockerfile, workspace, actionFolder, sshAgent } = Action; + const { dockerfile, workspace, actionFolder } = Action; const buildParameters = await BuildParameters.create(); const baseImage = new ImageTag(buildParameters); @@ -27,7 +27,7 @@ async function run() { default: core.info('Building locally'); builtImage = await Docker.build({ path: actionFolder, dockerfile, baseImage }); - await Docker.run(builtImage, { workspace, sshAgent, ...buildParameters }); + await Docker.run(builtImage, { workspace, ...buildParameters }); break; } diff --git a/src/model/__mocks__/input.ts b/src/model/__mocks__/input.ts index 87f6c91a..33f1091a 100644 --- a/src/model/__mocks__/input.ts +++ b/src/model/__mocks__/input.ts @@ -10,6 +10,7 @@ export const mockGetFromUser = jest.fn().mockResolvedValue({ buildMethod: undefined, buildVersion: '1.3.37', customParameters: '', + sshAgent: '', chownFilesTo: '', }); diff --git a/src/model/action.ts b/src/model/action.ts index 6eb07132..b7703e8b 100644 --- a/src/model/action.ts +++ b/src/model/action.ts @@ -37,10 +37,6 @@ class Action { return process.env.GITHUB_WORKSPACE; } - static get sshAgent() { - return process.env.SSH_AUTH_SOCK; - } - static checkCompatibility() { const currentPlatform = process.platform; if (!Action.supportedPlatforms.includes(currentPlatform)) { diff --git a/src/model/build-parameters.ts b/src/model/build-parameters.ts index e4e119e9..dde48e43 100644 --- a/src/model/build-parameters.ts +++ b/src/model/build-parameters.ts @@ -60,6 +60,7 @@ class BuildParameters { androidKeyaliasName: Input.androidKeyaliasName, androidKeyaliasPass: Input.androidKeyaliasPass, customParameters: Input.customParameters, + sshAgent: Input.sshAgent, chownFilesTo: Input.chownFilesTo, remoteBuildCluster: Input.remoteBuildCluster, awsStackName: Input.awsStackName, diff --git a/src/model/docker.ts b/src/model/docker.ts index 9301f545..d4767f70 100644 --- a/src/model/docker.ts +++ b/src/model/docker.ts @@ -36,8 +36,8 @@ class Docker { androidKeyaliasName, androidKeyaliasPass, customParameters, - chownFilesTo, sshAgent, + chownFilesTo, } = parameters; const command = `docker run \ @@ -80,13 +80,13 @@ class Docker { --env RUNNER_TOOL_CACHE \ --env RUNNER_TEMP \ --env RUNNER_WORKSPACE \ - --env SSH_AUTH_SOCK=/ssh-agent \ + ${sshAgent ? '--env SSH_AUTH_SOCK=/ssh-agent' : ''} \ --volume "/var/run/docker.sock":"/var/run/docker.sock" \ --volume "${runnerTempPath}/_github_home":"/root" \ --volume "${runnerTempPath}/_github_workflow":"/github/workflow" \ --volume "${workspace}":"/github/workspace" \ - --volume "${sshAgent}":"/ssh-agent" \ - --volume /home/runner/.ssh/known_hosts:/root/.ssh/known_hosts:ro \ + ${sshAgent ? "--volume " + sshAgent + ":/ssh-agent" : ''} \ + ${sshAgent ? '--volume /home/runner/.ssh/known_hosts:/root/.ssh/known_hosts:ro' : ''} \ ${image}`; await exec(command, undefined, { silent }); diff --git a/src/model/input.ts b/src/model/input.ts index 42f15489..5c5b8667 100644 --- a/src/model/input.ts +++ b/src/model/input.ts @@ -85,6 +85,10 @@ class Input { return core.getInput('customParameters') || ''; } + static get sshAgent() { + return core.getInput('sshAgent') || ''; + } + static get chownFilesTo() { return core.getInput('chownFilesTo') || ''; }