Skip to content

Commit b2d0a9b

Browse files
authored
Merge pull request #49 from franc-liuzzi/feature/docker-build-provenance-flag-support
feat: add support for provenance option in docker build
2 parents f4d411e + 219ffcc commit b2d0a9b

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

Diff for: docs/guides/functions.md

+2
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ Additionally, you can define arguments that will be passed to the `docker build`
300300
- `buildArgs`: With the `buildArgs` property, you can define arguments that will be passed to `docker build` command with `--build-arg` flag. They might be later referenced via `ARG` within your `Dockerfile`. (See [Documentation](https://docs.docker.com/engine/reference/builder/#arg))
301301
- `cacheFrom`: The `cacheFrom` property can be used to specify which images to use as a source for layer caching in the `docker build` command with `--cache-from` flag. (See [Documentation](https://docs.docker.com/engine/reference/builder/#usage))
302302
- `platform`: The `platform` property can be used to specify the architecture target in the `docker build` command with the `--platform` flag. If not specified, Docker will build for your computer's architecture by default. AWS Lambda typically uses `x86` architecture unless otherwise specified in the Lambda's runtime settings. In order to avoid runtime errors when building on an ARM-based machine (e.g. Apple M1 Mac), `linux/amd64` must be used here. The options for this flag are `linux/amd64` (`x86`-based Lambdas), `linux/arm64` (`arm`-based Lambdas), or `windows/amd64`. (See [Documentation](https://docs.docker.com/engine/reference/builder/#from))
303+
- `provenance` Use the `provenance` property to disable multi-architecture manifest generated from BuildKit or `docker buildx`, allows the architecture specified in `platform` to be recognized by AWS Lambda during deployment.
303304

304305
When `uri` is defined for an image, `buildArgs`, `cacheFrom`, and `platform` cannot be defined.
305306

@@ -320,6 +321,7 @@ provider:
320321
cacheFrom:
321322
- my-image:latest
322323
platform: linux/amd64
324+
provenance: false
323325
anotherimage:
324326
uri: 000000000000.dkr.ecr.sa-east-1.amazonaws.com/test-lambda-docker@sha256:6bb600b4d6e1d7cf521097177dd0c4e9ea373edb91984a505333be8ac9455d38
325327
```

Diff for: lib/plugins/aws/provider.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,7 @@ class AwsProvider {
11351135
buildArgs: { type: 'object', additionalProperties: { type: 'string' } },
11361136
cacheFrom: { type: 'array', items: { type: 'string' } },
11371137
platform: { type: 'string' },
1138+
provenance: { type: 'string' },
11381139
},
11391140
additionalProperties: false,
11401141
},
@@ -2215,6 +2216,7 @@ Object.defineProperties(
22152216
buildArgs,
22162217
cacheFrom,
22172218
platform,
2219+
provenance,
22182220
scanOnPush,
22192221
}) {
22202222
const imageProgress = progress.get(`containerImage:${imageName}`);
@@ -2261,8 +2263,10 @@ Object.defineProperties(
22612263
imagePath,
22622264
];
22632265

2264-
// This is an optional argument, so we only append to the arguments if "platform" is specified.
2266+
// These are optional arguments, so we only append to the arguments
2267+
// if "platform" or "provenance" is specified.
22652268
if (platform !== '') buildDockerArgs.push(`--platform=${platform}`);
2269+
if (provenance !== '') buildDockerArgs.push(`--provenance=${provenance}`);
22662270

22672271
let imageSha;
22682272
try {
@@ -2397,6 +2401,7 @@ Object.defineProperties(
23972401
const defaultCacheFrom = [];
23982402
const defaultScanOnPush = false;
23992403
const defaultPlatform = '';
2404+
const defaultProvenance = '';
24002405

24012406
if (imageUri) {
24022407
return await this.resolveImageUriAndShaFromUri(imageUri);
@@ -2451,6 +2456,12 @@ Object.defineProperties(
24512456
'ECR_IMAGE_BOTH_URI_AND_PLATFORM_DEFINED_ERROR'
24522457
);
24532458
}
2459+
if (imageDefinedInProvider.uri && imageDefinedInProvider.provenance) {
2460+
throw new ServerlessError(
2461+
`The "provenance" property cannot be used with "uri" property "${imageName}"`,
2462+
'ECR_IMAGE_BOTH_URI_AND_PROVENANCE_DEFINED_ERROR'
2463+
);
2464+
}
24542465
if (imageDefinedInProvider.path) {
24552466
return await this.resolveImageUriAndShaFromPath({
24562467
imageName,
@@ -2459,6 +2470,7 @@ Object.defineProperties(
24592470
buildArgs: imageDefinedInProvider.buildArgs || defaultBuildArgs,
24602471
cacheFrom: imageDefinedInProvider.cacheFrom || defaultCacheFrom,
24612472
platform: imageDefinedInProvider.platform || defaultPlatform,
2473+
provenance: imageDefinedInProvider.provenance || defaultProvenance,
24622474
scanOnPush: imageScanDefinedInProvider,
24632475
});
24642476
}
@@ -2474,6 +2486,7 @@ Object.defineProperties(
24742486
buildArgs: imageDefinedInProvider.buildArgs || defaultBuildArgs,
24752487
cacheFrom: imageDefinedInProvider.cacheFrom || defaultCacheFrom,
24762488
platform: imageDefinedInProvider.platform || defaultPlatform,
2489+
provenance: imageDefinedInProvider.provenance || defaultProvenance,
24772490
scanOnPush: imageScanDefinedInProvider,
24782491
});
24792492
},

0 commit comments

Comments
 (0)