From bf2c46813e60be383927ddac1a1520edac3709e9 Mon Sep 17 00:00:00 2001 From: Steve Houel Date: Wed, 31 Jan 2024 11:26:43 +0100 Subject: [PATCH 1/4] fix: Fix Dockerfile reference issue --- src/bundling.ts | 2 +- test/bundling.test.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bundling.ts b/src/bundling.ts index 69cff7a..f4971ff 100644 --- a/src/bundling.ts +++ b/src/bundling.ts @@ -111,7 +111,7 @@ export class Bundling implements CdkBundlingOptions { !checkInstalledTarget(toTarget(this.props.architecture)); this.image = shouldBuildImage ? props.dockerImage ?? - DockerImage.fromBuild(path.join(__dirname, '../src'), { + DockerImage.fromBuild(__dirname, { buildArgs: { ...(props.buildArgs ?? {}), // If runtime isn't passed use regional default, lowest common denominator is node18 diff --git a/test/bundling.test.ts b/test/bundling.test.ts index 8284c14..33040ba 100644 --- a/test/bundling.test.ts +++ b/test/bundling.test.ts @@ -80,7 +80,7 @@ describe('Bundling in Docker', () => { ); expect(DockerImage.fromBuild).toHaveBeenCalledWith( - expect.stringMatching(/aws-lambda-rust\/src$/), + expect.stringMatching(/aws-lambda-rust\/lib$/), expect.objectContaining({ buildArgs: expect.objectContaining({ IMAGE: expect.stringMatching(/build-provided.al2023$/), @@ -274,7 +274,7 @@ describe('Bundling in Docker', () => { }); expect(DockerImage.fromBuild).toHaveBeenCalledWith( - expect.stringMatching(/src$/), + expect.stringMatching(/lib$/), expect.objectContaining({ buildArgs: expect.objectContaining({ HELLO: 'WORLD', From ad4be053810acf8aff398d2b62e9f6826e86071a Mon Sep 17 00:00:00 2001 From: Steve Houel Date: Wed, 31 Jan 2024 12:10:03 +0100 Subject: [PATCH 2/4] Moving Dockerfile to be packged by CI --- src/Dockerfile => Dockerfile | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/Dockerfile => Dockerfile (100%) diff --git a/src/Dockerfile b/Dockerfile similarity index 100% rename from src/Dockerfile rename to Dockerfile From aad25732b92d5c124dcba205f7530799352b09d5 Mon Sep 17 00:00:00 2001 From: Steve Houel Date: Wed, 31 Jan 2024 15:15:30 +0100 Subject: [PATCH 3/4] Fixing docker tests --- test/docker.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/docker.test.ts b/test/docker.test.ts index 8298cf0..d5990fe 100644 --- a/test/docker.test.ts +++ b/test/docker.test.ts @@ -6,7 +6,7 @@ const docker = process.env.CDK_DOCKER ?? 'docker'; beforeAll(() => { const process = spawnSync( docker, - ['build', '-t', 'cargo-builder', path.join(__dirname, '../src')], + ['build', '-t', 'cargo-builder', path.join(__dirname, '../')], { stdio: 'inherit' }, ); expect(process.error).toBeUndefined(); From 32837fa2bffcd88f4168b70580ae6acb37726151 Mon Sep 17 00:00:00 2001 From: Steve Houel Date: Wed, 31 Jan 2024 16:21:17 +0100 Subject: [PATCH 4/4] Fix bundling tests and force Docker bundling for Integration tests to guarantee same behavior between local / CI tests --- src/bundling.ts | 2 +- test/bundling.test.ts | 4 ++-- test/integ.function-bins.ts | 3 +++ test/integ.function-workspace.ts | 3 +++ test/integ.function.ts | 3 +++ 5 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/bundling.ts b/src/bundling.ts index f4971ff..bd57019 100644 --- a/src/bundling.ts +++ b/src/bundling.ts @@ -111,7 +111,7 @@ export class Bundling implements CdkBundlingOptions { !checkInstalledTarget(toTarget(this.props.architecture)); this.image = shouldBuildImage ? props.dockerImage ?? - DockerImage.fromBuild(__dirname, { + DockerImage.fromBuild(path.join(__dirname, '../'), { buildArgs: { ...(props.buildArgs ?? {}), // If runtime isn't passed use regional default, lowest common denominator is node18 diff --git a/test/bundling.test.ts b/test/bundling.test.ts index 33040ba..cedea0a 100644 --- a/test/bundling.test.ts +++ b/test/bundling.test.ts @@ -80,7 +80,7 @@ describe('Bundling in Docker', () => { ); expect(DockerImage.fromBuild).toHaveBeenCalledWith( - expect.stringMatching(/aws-lambda-rust\/lib$/), + expect.stringMatching(/aws-lambda-rust\/$/), expect.objectContaining({ buildArgs: expect.objectContaining({ IMAGE: expect.stringMatching(/build-provided.al2023$/), @@ -274,7 +274,7 @@ describe('Bundling in Docker', () => { }); expect(DockerImage.fromBuild).toHaveBeenCalledWith( - expect.stringMatching(/lib$/), + expect.stringMatching(/aws-lambda-rust\/$/), expect.objectContaining({ buildArgs: expect.objectContaining({ HELLO: 'WORLD', diff --git a/test/integ.function-bins.ts b/test/integ.function-bins.ts index 0529e3e..46154cc 100644 --- a/test/integ.function-bins.ts +++ b/test/integ.function-bins.ts @@ -15,6 +15,9 @@ class TestStack extends Stack { const fn = new RustFunction(this, 'binary1', { entry: 'rust-bins/Cargo.toml', binaryName: 'my_lambda1', + bundling: { + forceDockerBundling: true, + }, }); this.functionName = fn.functionName; diff --git a/test/integ.function-workspace.ts b/test/integ.function-workspace.ts index 91ec193..0175afb 100644 --- a/test/integ.function-workspace.ts +++ b/test/integ.function-workspace.ts @@ -15,6 +15,9 @@ class TestStack extends Stack { const fn = new RustFunction(this, 'binary1', { entry: 'rust-workspaces/Cargo.toml', binaryName: 'my_lambda2', + bundling: { + forceDockerBundling: true, + }, }); this.functionName = fn.functionName; diff --git a/test/integ.function.ts b/test/integ.function.ts index 8989b0b..6268ebe 100644 --- a/test/integ.function.ts +++ b/test/integ.function.ts @@ -14,6 +14,9 @@ class TestStack extends Stack { const fn = new RustFunction(this, 'binary1', { entry: 'rust-standalone/Cargo.toml', + bundling: { + forceDockerBundling: true, + }, }); this.functionName = fn.functionName;