Skip to content

Commit

Permalink
add ssh option (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
paretje committed Apr 3, 2023
1 parent af6e4cb commit b61506f
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ inputs:
platform:
description: "Docker build platform passed via --platform"
required: false
ssh:
description: "Docker build ssh options passed via --ssh"
required: false
username:
description: "Docker registry username"
required: false
Expand Down
9 changes: 8 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9458,7 +9458,8 @@ const buildOpts = {
overrideDriver: false,
enableBuildKit: false,
platform: undefined,
skipPush: false
skipPush: false,
ssh: undefined
};

const setBuildOpts = (addLatest, addTimestamp) => {
Expand All @@ -9472,6 +9473,7 @@ const setBuildOpts = (addLatest, addTimestamp) => {
buildOpts.enableBuildKit = core.getInput('enableBuildKit') === 'true';
buildOpts.platform = core.getInput('platform');
buildOpts.skipPush = core.getInput('pushImage') === 'false';
buildOpts.ssh = parseArray(core.getInput('ssh'));
};

const run = () => {
Expand Down Expand Up @@ -9598,6 +9600,11 @@ const createBuildCommand = (imageName, dockerfile, buildOpts) => {
buildCommandPrefix = `${buildCommandPrefix} --push`;
}

if (buildOpts.ssh) {
const sshSuffix = buildOpts.ssh.map(ssh => `--ssh ${ssh}`).join(' ');
buildCommandPrefix = `${buildCommandPrefix} ${sshSuffix}`;
}

if (buildOpts.enableBuildKit) {
buildCommandPrefix = `DOCKER_BUILDKIT=1 ${buildCommandPrefix}`;
}
Expand Down
4 changes: 3 additions & 1 deletion src/docker-build-push.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const buildOpts = {
overrideDriver: false,
enableBuildKit: false,
platform: undefined,
skipPush: false
skipPush: false,
ssh: undefined
};

const setBuildOpts = (addLatest, addTimestamp) => {
Expand All @@ -27,6 +28,7 @@ const setBuildOpts = (addLatest, addTimestamp) => {
buildOpts.enableBuildKit = core.getInput('enableBuildKit') === 'true';
buildOpts.platform = core.getInput('platform');
buildOpts.skipPush = core.getInput('pushImage') === 'false';
buildOpts.ssh = parseArray(core.getInput('ssh'));
};

const run = () => {
Expand Down
5 changes: 5 additions & 0 deletions src/docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ const createBuildCommand = (imageName, dockerfile, buildOpts) => {
buildCommandPrefix = `${buildCommandPrefix} --push`;
}

if (buildOpts.ssh) {
const sshSuffix = buildOpts.ssh.map(ssh => `--ssh ${ssh}`).join(' ');
buildCommandPrefix = `${buildCommandPrefix} ${sshSuffix}`;
}

if (buildOpts.enableBuildKit) {
buildCommandPrefix = `DOCKER_BUILDKIT=1 ${buildCommandPrefix}`;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/docker-build-push.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const mockRepoName = 'some-repo';

const runAssertions = (imageFullName, inputs, tagOverrides) => {
// Inputs
expect(core.getInput).toHaveBeenCalledTimes(18);
expect(core.getInput).toHaveBeenCalledTimes(19);

// Outputs
const tags = tagOverrides || parseArray(inputs.tags);
Expand Down

0 comments on commit b61506f

Please sign in to comment.