Skip to content

Commit b38a5ad

Browse files
authored
Merge pull request #6032 from gchq/6031-docker-images
Issue 6031 - Disable provenance in Docker images for lambdas
2 parents 4d0a99b + 7020690 commit b38a5ad

File tree

5 files changed

+22
-18
lines changed

5 files changed

+22
-18
lines changed

java/clients/src/main/java/sleeper/clients/deploy/container/UploadDockerImages.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,13 @@ private void buildAndPushImage(String tag, StackDockerImage image) throws IOExce
100100
if (image.isMultiplatform()) {
101101
commandRunner.runOrThrow("docker", "buildx", "build", "--platform", "linux/amd64,linux/arm64", "-t", tag, "--push", dockerfileDirectory.toString());
102102
} else {
103-
commandRunner.runOrThrow("docker", "build", "-t", tag, dockerfileDirectory.toString());
103+
if (image.getLambdaJar().isPresent()) {
104+
// At time of writing AWS Lambda does not support images with provenance enabled.
105+
// See https://docs.aws.amazon.com/lambda/latest/dg/java-image.html
106+
commandRunner.runOrThrow("docker", "build", "--provenance=false", "-t", tag, dockerfileDirectory.toString());
107+
} else {
108+
commandRunner.runOrThrow("docker", "build", "-t", tag, dockerfileDirectory.toString());
109+
}
104110
commandRunner.runOrThrow("docker", "push", tag);
105111
}
106112
}

java/clients/src/test/java/sleeper/clients/deploy/container/DockerImagesTestBase.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,8 @@ protected CommandPipeline buildImageCommand(String tag, String dockerDirectory)
104104
return pipeline(command("docker", "build", "-t", tag, dockerDirectory));
105105
}
106106

107-
protected CommandPipeline buildImageCommandWithArgs(String... args) {
108-
List<String> fullArgs = new ArrayList<>(List.of("docker", "build"));
109-
fullArgs.addAll(List.of(args));
110-
return pipeline(command(fullArgs.toArray(String[]::new)));
107+
protected CommandPipeline buildLambdaImageCommand(String tag, String dockerDirectory) {
108+
return pipeline(command("docker", "build", "--provenance=false", "-t", tag, dockerDirectory));
111109
}
112110

113111
protected CommandPipeline pullImageCommand(String tag) {

java/clients/src/test/java/sleeper/clients/deploy/container/UploadDockerImagesToEcrFileIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ void shouldUploadTwoLambdaImagesOverwritingJarEachTime() throws Exception {
6868
String expectedTag2 = "123.dkr.ecr.test-region.amazonaws.com/test-instance/ingest-task-creator-lambda:1.0.0";
6969
assertThat(commandsThatRan).containsExactly(
7070
dockerLoginToEcrCommand(),
71-
buildImageCommandWithArgs("-t", expectedTag1, lambdaImageDir.toString()),
71+
buildLambdaImageCommand(expectedTag1, lambdaImageDir.toString()),
7272
pushImageCommand(expectedTag1),
73-
buildImageCommandWithArgs("-t", expectedTag2, lambdaImageDir.toString()),
73+
buildLambdaImageCommand(expectedTag2, lambdaImageDir.toString()),
7474
pushImageCommand(expectedTag2));
7575

7676
assertThat(fileToContentUnder(dir)).isEqualTo(Map.of(

java/clients/src/test/java/sleeper/clients/deploy/container/UploadDockerImagesToEcrTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ void shouldPushCoreImage() throws Exception {
120120
String expectedTag = "123.dkr.ecr.test-region.amazonaws.com/test-instance/statestore-lambda:1.0.0";
121121
assertThat(commandsThatRan).containsExactly(
122122
dockerLoginToEcrCommand(),
123-
buildImageCommandWithArgs("-t", expectedTag, "./docker/lambda"),
123+
buildLambdaImageCommand(expectedTag, "./docker/lambda"),
124124
pushImageCommand(expectedTag));
125125
assertThat(files).isEqualTo(Map.of(
126126
Path.of("./jars/statestore.jar"), "statestore-jar-content",
@@ -143,9 +143,9 @@ void shouldPushImageForCoreAndOptionalLambdaInNewInstance() throws Exception {
143143
String expectedTag2 = "123.dkr.ecr.test-region.amazonaws.com/test-instance/ingest-task-creator-lambda:1.0.0";
144144
assertThat(commandsThatRan).containsExactly(
145145
dockerLoginToEcrCommand(),
146-
buildImageCommandWithArgs("-t", expectedTag1, "./docker/lambda"),
146+
buildLambdaImageCommand(expectedTag1, "./docker/lambda"),
147147
pushImageCommand(expectedTag1),
148-
buildImageCommandWithArgs("-t", expectedTag2, "./docker/lambda"),
148+
buildLambdaImageCommand(expectedTag2, "./docker/lambda"),
149149
pushImageCommand(expectedTag2));
150150
assertThat(files).isEqualTo(Map.of(
151151
Path.of("./jars/statestore.jar"), "statestore-jar-content",
@@ -169,7 +169,7 @@ void shouldPushImageForOptionalLambdaWhenAdded() throws Exception {
169169
String expectedTag = "123.dkr.ecr.test-region.amazonaws.com/test-instance/ingest-task-creator-lambda:1.0.0";
170170
assertThat(commandsThatRan).containsExactly(
171171
dockerLoginToEcrCommand(),
172-
buildImageCommandWithArgs("-t", expectedTag, "./docker/lambda"),
172+
buildLambdaImageCommand(expectedTag, "./docker/lambda"),
173173
pushImageCommand(expectedTag));
174174
assertThat(files).isEqualTo(Map.of(
175175
Path.of("./jars/ingest.jar"), "ingest-jar-content",
@@ -192,7 +192,7 @@ void shouldPushImageForOptionalLambdaWhenOneOfItsStacksIsAdded() throws Exceptio
192192
String expectedTag = "123.dkr.ecr.test-region.amazonaws.com/test-instance/bulk-import-starter-lambda:1.0.0";
193193
assertThat(commandsThatRan).containsExactly(
194194
dockerLoginToEcrCommand(),
195-
buildImageCommandWithArgs("-t", expectedTag, "./docker/lambda"),
195+
buildLambdaImageCommand(expectedTag, "./docker/lambda"),
196196
pushImageCommand(expectedTag));
197197
assertThat(files).isEqualTo(Map.of(
198198
Path.of("./jars/bulk-import-starter.jar"), "bulk-import-starter-jar-content",
@@ -215,7 +215,7 @@ void shouldPushImageForOptionalLambdaWhenSeveralOfItsStacksAreAdded() throws Exc
215215
String expectedTag = "123.dkr.ecr.test-region.amazonaws.com/test-instance/bulk-import-starter-lambda:1.0.0";
216216
assertThat(commandsThatRan).containsExactly(
217217
dockerLoginToEcrCommand(),
218-
buildImageCommandWithArgs("-t", expectedTag, "./docker/lambda"),
218+
buildLambdaImageCommand(expectedTag, "./docker/lambda"),
219219
pushImageCommand(expectedTag));
220220
assertThat(files).isEqualTo(Map.of(
221221
Path.of("./jars/bulk-import-starter.jar"), "bulk-import-starter-jar-content",
@@ -249,7 +249,7 @@ void shouldDeployLambdaByDockerWhenConfiguredToAlwaysDeployByDocker() throws Exc
249249
String expectedTag = "123.dkr.ecr.test-region.amazonaws.com/test-instance/athena-lambda:1.0.0";
250250
assertThat(commandsThatRan).containsExactly(
251251
dockerLoginToEcrCommand(),
252-
buildImageCommandWithArgs("-t", expectedTag, "./docker/lambda"),
252+
buildLambdaImageCommand(expectedTag, "./docker/lambda"),
253253
pushImageCommand(expectedTag));
254254
assertThat(files).isEqualTo(Map.of(
255255
Path.of("./jars/athena.jar"), "athena-jar-content",

java/clients/src/test/java/sleeper/clients/deploy/container/UploadDockerImagesToRepositoryTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,13 @@ void shouldBuildAndPushLambdaImages() throws Exception {
104104
String expectedBulkImportTag = "www.somedocker.com/prefix/bulk-import-starter-lambda:1.0.0";
105105
String expectedAthenaTag = "www.somedocker.com/prefix/athena-lambda:1.0.0";
106106
assertThat(commandsThatRan).containsExactly(
107-
buildImageCommandWithArgs("-t", expectedStatestoreTag, "./docker/lambda"),
107+
buildLambdaImageCommand(expectedStatestoreTag, "./docker/lambda"),
108108
pushImageCommand(expectedStatestoreTag),
109-
buildImageCommandWithArgs("-t", expectedIngestTaskTag, "./docker/lambda"),
109+
buildLambdaImageCommand(expectedIngestTaskTag, "./docker/lambda"),
110110
pushImageCommand(expectedIngestTaskTag),
111-
buildImageCommandWithArgs("-t", expectedBulkImportTag, "./docker/lambda"),
111+
buildLambdaImageCommand(expectedBulkImportTag, "./docker/lambda"),
112112
pushImageCommand(expectedBulkImportTag),
113-
buildImageCommandWithArgs("-t", expectedAthenaTag, "./docker/lambda"),
113+
buildLambdaImageCommand(expectedAthenaTag, "./docker/lambda"),
114114
pushImageCommand(expectedAthenaTag));
115115

116116
assertThat(files).isEqualTo(Map.of(

0 commit comments

Comments
 (0)