Skip to content

Commit

Permalink
fix(cdk-assets): propagate buildSsh flag to docker build (#26846)
Browse files Browse the repository at this point in the history
A few weeks ago I added the --ssh flag to the constructs for building a cdk with that arg; However, I missed actually passing that arg to the docker.build in the cdk-assets container-images. This adds that arg where it should be.

Closes 12062.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
JackWBoynton authored Aug 23, 2023
1 parent d5050ce commit 87869c8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/aws-cdk-lib/aws-lambda/test/code.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,13 +334,15 @@ describe('code', () => {
const dockerfilePath = 'Dockerfile';
const dockerBuildTarget = 'stage';
const dockerBuildArgs = { arg1: 'val1', arg2: 'val2' };
const dockerBuildSsh = 'default';

// when
new lambda.Function(stack, 'Fn', {
code: lambda.Code.fromAssetImage(path.join(__dirname, 'docker-lambda-handler'), {
file: dockerfilePath,
target: dockerBuildTarget,
buildArgs: dockerBuildArgs,
buildSsh: dockerBuildSsh,
}),
handler: lambda.Handler.FROM_IMAGE,
runtime: lambda.Runtime.FROM_IMAGE,
Expand All @@ -349,9 +351,10 @@ describe('code', () => {
// then
Template.fromStack(stack).hasResource('AWS::Lambda::Function', {
Metadata: {
[cxapi.ASSET_RESOURCE_METADATA_PATH_KEY]: 'asset.a8922a1fd787021d071844bc2b1fe3622372bbdfda823528c00983a806ba0e26',
[cxapi.ASSET_RESOURCE_METADATA_PATH_KEY]: 'asset.4d4e274f69ea222694c68ac0cea32b855247d6bdad3074a5987e3a7a907c4745',
[cxapi.ASSET_RESOURCE_METADATA_DOCKERFILE_PATH_KEY]: dockerfilePath,
[cxapi.ASSET_RESOURCE_METADATA_DOCKER_BUILD_ARGS_KEY]: dockerBuildArgs,
[cxapi.ASSET_RESOURCE_METADATA_DOCKER_BUILD_SSH_KEY]: dockerBuildSsh,
[cxapi.ASSET_RESOURCE_METADATA_DOCKER_BUILD_TARGET_KEY]: dockerBuildTarget,
[cxapi.ASSET_RESOURCE_METADATA_PROPERTY_KEY]: 'Code.ImageUri',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export class AssetManifestBuilder {
directory: asset.directoryName,
dockerBuildArgs: asset.dockerBuildArgs,
dockerBuildSecrets: asset.dockerBuildSecrets,
dockerBuildSsh: asset.dockerBuildSsh,
dockerBuildTarget: asset.dockerBuildTarget,
dockerFile: asset.dockerFile,
networkMode: asset.networkMode,
Expand Down
2 changes: 2 additions & 0 deletions packages/aws-cdk-lib/core/lib/stack-synthesizers/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ export class LegacyStackSynthesizer extends StackSynthesizer implements IReusabl
path: asset.directoryName,
sourceHash: asset.sourceHash,
buildArgs: asset.dockerBuildArgs,
buildSecrets: asset.dockerBuildSecrets,
buildSsh: asset.dockerBuildSsh,
target: asset.dockerBuildTarget,
file: asset.dockerFile,
networkMode: asset.networkMode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ class ContainerImageBuilder {
tag: localTagName,
buildArgs: source.dockerBuildArgs,
buildSecrets: source.dockerBuildSecrets,
buildSsh: source.dockerBuildSsh,
target: source.dockerBuildTarget,
file: source.dockerFile,
networkMode: source.networkMode,
Expand Down

0 comments on commit 87869c8

Please sign in to comment.