Skip to content

Commit bc333e2

Browse files
authored
feat(core): DockerBuildOptions support network param (#34725)
### Issue # (if applicable) Closes #34514 ### Reason for this change `DockerRunOptions` has `network` param but `DockerBuildOptions` doesn't ### Description of changes `DockerBuildOptions` support `network` param ### Describe any new or updated permissions being added ### Description of how you validated changes Unit + Integ #### Test DockerImage.fromBuild with python-alpha/test/integ.function.custom-build ```console $ ps aux | grep "docker build" superch+ 44036 0.1 0.1 1994552 26112 pts/0 Sl+ 08:20 0:00 docker build -t cdk-5322298f1d5d198bb67c2885f92ffc76a9e60f4ec4b584a8df116ebc75ebc843 --network default /workspaces/aws-cdk/packages/@aws-cdk/aws-lambda-python-alpha/test/lambda-handler-custom-build ``` #### Test PythonLayerVersion with python-alpha/test/integ.function.project ```console $ ps aux | grep "docker build" superch+ 76129 100 0.1 1920308 24064 pts/0 Sl+ 09:09 0:00 docker build -t cdk-858025f5c9bccadc11d046a66c283180089509773bb117d94236a7e2c03a0295 --platform linux/amd64 --network default --build-arg IMAGE=public.ecr.aws/sam/build-python3.13 /workspaces/aws-cdk/packages/@aws-cdk/aws-lambda-python-alpha/lib ``` ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 7ca6671 commit bc333e2

File tree

32 files changed

+62158
-2157
lines changed

32 files changed

+62158
-2157
lines changed

packages/@aws-cdk/aws-lambda-go-alpha/lib/bundling.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ export class Bundling implements cdk.BundlingOptions {
148148
IMAGE: Runtime.GO_1_X.bundlingImage.image, // always use the GO_1_X build image
149149
},
150150
platform: props.architecture.dockerPlatform,
151+
network: props.network,
151152
})
152153
: cdk.DockerImage.fromRegistry('dummy'); // Do not build if we don't need to
153154

packages/@aws-cdk/aws-lambda-go-alpha/test/bundling.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ test('bundling', () => {
3939
environment: {
4040
KEY: 'value',
4141
},
42+
network: 'host',
4243
});
4344

4445
expect(Code.fromAsset).toHaveBeenCalledWith(path.dirname(moduleDir), {
@@ -65,6 +66,7 @@ test('bundling', () => {
6566
IMAGE: expect.stringMatching(/build-go/),
6667
}),
6768
platform: 'linux/amd64',
69+
network: 'host',
6870
}));
6971
});
7072

packages/@aws-cdk/aws-lambda-python-alpha/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,12 @@ new python.PythonFunction(this, 'function', {
210210
entry,
211211
runtime: Runtime.PYTHON_3_8,
212212
bundling: {
213-
network: 'host',
214-
securityOpt: 'no-new-privileges',
215-
user: 'user:group',
216-
volumesFrom: ['777f7dc92da7'],
217-
volumes: [{ hostPath: '/host-path', containerPath: '/container-path' }],
218-
},
213+
network: 'host',
214+
securityOpt: 'no-new-privileges',
215+
user: 'user:group',
216+
volumesFrom: ['777f7dc92da7'],
217+
volumes: [{ hostPath: '/host-path', containerPath: '/container-path' }],
218+
},
219219
});
220220
```
221221

packages/@aws-cdk/aws-lambda-python-alpha/lib/bundling.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ export class Bundling implements CdkBundlingOptions {
105105
IMAGE: runtime.bundlingImage.image,
106106
},
107107
platform: architecture.dockerPlatform,
108+
network: props.network,
108109
});
109110
this.command = props.command ?? ['bash', '-c', chain(bundlingCommands)];
110111
this.entrypoint = props.entrypoint;

packages/@aws-cdk/aws-lambda-python-alpha/test/bundling.test.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ test('Bundling a function without dependencies', () => {
3131
entry: entry,
3232
runtime: Runtime.PYTHON_3_7,
3333
architecture: Architecture.X86_64,
34+
network: 'host',
3435
});
3536

3637
// Correctly bundles
@@ -48,6 +49,7 @@ test('Bundling a function without dependencies', () => {
4849
IMAGE: expect.stringMatching(/build-python/),
4950
}),
5051
platform: 'linux/amd64',
52+
network: 'host',
5153
}));
5254

5355
const files = fs.readdirSync(assetCode.path);
@@ -426,7 +428,6 @@ test('Bundling with volumes from other container', () => {
426428
entry: entry,
427429
runtime: Runtime.PYTHON_3_7,
428430
volumesFrom: ['777f7dc92da7'],
429-
430431
});
431432

432433
expect(Code.fromAsset).toHaveBeenCalledWith(entry, expect.objectContaining({
@@ -442,7 +443,6 @@ test('Bundling with custom volume paths', () => {
442443
entry: entry,
443444
runtime: Runtime.PYTHON_3_7,
444445
volumes: [{ hostPath: '/host-path', containerPath: '/container-path' }],
445-
446446
});
447447

448448
expect(Code.fromAsset).toHaveBeenCalledWith(entry, expect.objectContaining({
@@ -474,7 +474,6 @@ test('Bundling with custom user', () => {
474474
entry: entry,
475475
runtime: Runtime.PYTHON_3_7,
476476
user: 'user:group',
477-
478477
});
479478

480479
expect(Code.fromAsset).toHaveBeenCalledWith(entry, expect.objectContaining({
@@ -490,7 +489,6 @@ test('Bundling with custom securityOpt', () => {
490489
entry: entry,
491490
runtime: Runtime.PYTHON_3_7,
492491
securityOpt: 'no-new-privileges',
493-
494492
});
495493

496494
expect(Code.fromAsset).toHaveBeenCalledWith(entry, expect.objectContaining({
@@ -506,7 +504,6 @@ test('Bundling with custom network', () => {
506504
entry: entry,
507505
runtime: Runtime.PYTHON_3_7,
508506
network: 'host',
509-
510507
});
511508

512509
expect(Code.fromAsset).toHaveBeenCalledWith(entry, expect.objectContaining({
@@ -522,7 +519,6 @@ test('Bundling with docker copy variant', () => {
522519
entry: entry,
523520
runtime: Runtime.PYTHON_3_7,
524521
bundlingFileAccess: BundlingFileAccess.VOLUME_COPY,
525-
526522
});
527523

528524
expect(Code.fromAsset).toHaveBeenCalledWith(entry, expect.objectContaining({

0 commit comments

Comments
 (0)