Avoid image pulls in integration tests

This commit sets the pull policy to `IF_NOT_PRESENT` where possible
in integration tests for the Maven and Gradle plugins to reduce
the number of times the default Paketo builder and run images are
pulled from Docker Hub.

Fixes gh-24113
This commit is contained in:
Scott Frederick
2020-11-10 16:19:05 -06:00
parent 21d97524d8
commit 59e0f7317e
2 changed files with 48 additions and 47 deletions

View File

@@ -56,11 +56,10 @@ class BootBuildImageIntegrationTests {
void buildsImageWithDefaultBuilder() throws IOException {
writeMainClass();
writeLongNameResource();
BuildResult result = this.gradleBuild.build("bootBuildImage");
BuildResult result = this.gradleBuild.build("bootBuildImage", "--pullPolicy=IF_NOT_PRESENT");
String projectName = this.gradleBuild.getProjectDir().getName();
assertThat(result.task(":bootBuildImage").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
assertThat(result.getOutput()).contains("docker.io/library/" + projectName);
assertThat(result.getOutput()).contains("paketobuildpacks/builder");
ImageReference imageReference = ImageReference.of(ImageName.of(projectName));
try (GenericContainer<?> container = new GenericContainer<>(imageReference.toString())) {
container.waitingFor(Wait.forLogMessage("Launched\\n", 1)).start();
@@ -74,10 +73,9 @@ class BootBuildImageIntegrationTests {
void buildsImageWithCustomName() throws IOException {
writeMainClass();
writeLongNameResource();
BuildResult result = this.gradleBuild.build("bootBuildImage");
BuildResult result = this.gradleBuild.build("bootBuildImage", "--pullPolicy=IF_NOT_PRESENT");
assertThat(result.task(":bootBuildImage").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
assertThat(result.getOutput()).contains("example/test-image-name");
assertThat(result.getOutput()).contains("paketobuildpacks/builder");
ImageReference imageReference = ImageReference.of(ImageName.of("example/test-image-name"));
try (GenericContainer<?> container = new GenericContainer<>(imageReference.toString())) {
container.waitingFor(Wait.forLogMessage("Launched\\n", 1)).start();
@@ -91,11 +89,9 @@ class BootBuildImageIntegrationTests {
void buildsImageWithCustomBuilderAndRunImage() throws IOException {
writeMainClass();
writeLongNameResource();
BuildResult result = this.gradleBuild.build("bootBuildImage");
BuildResult result = this.gradleBuild.build("bootBuildImage", "--pullPolicy=IF_NOT_PRESENT");
assertThat(result.task(":bootBuildImage").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
assertThat(result.getOutput()).contains("example/test-image-custom");
assertThat(result.getOutput()).contains("paketobuildpacks/builder:full");
assertThat(result.getOutput()).contains("paketobuildpacks/run:full");
ImageReference imageReference = ImageReference.of(ImageName.of("example/test-image-custom"));
try (GenericContainer<?> container = new GenericContainer<>(imageReference.toString())) {
container.waitingFor(Wait.forLogMessage("Launched\\n", 1)).start();
@@ -109,12 +105,11 @@ class BootBuildImageIntegrationTests {
void buildsImageWithCommandLineOptions() throws IOException {
writeMainClass();
writeLongNameResource();
BuildResult result = this.gradleBuild.build("bootBuildImage", "--imageName=example/test-image-cmd",
"--builder=paketobuildpacks/builder:full", "--runImage=paketobuildpacks/run:full-cnb");
BuildResult result = this.gradleBuild.build("bootBuildImage", "--pullPolicy=IF_NOT_PRESENT",
"--imageName=example/test-image-cmd", "--builder=paketobuildpacks/builder:full",
"--runImage=paketobuildpacks/run:full-cnb");
assertThat(result.task(":bootBuildImage").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
assertThat(result.getOutput()).contains("example/test-image-cmd");
assertThat(result.getOutput()).contains("paketobuildpacks/builder:full");
assertThat(result.getOutput()).contains("paketobuildpacks/run:full");
ImageReference imageReference = ImageReference.of(ImageName.of("example/test-image-cmd"));
try (GenericContainer<?> container = new GenericContainer<>(imageReference.toString())) {
container.waitingFor(Wait.forLogMessage("Launched\\n", 1)).start();
@@ -162,7 +157,7 @@ class BootBuildImageIntegrationTests {
void failsWithBuilderError() {
writeMainClass();
writeLongNameResource();
BuildResult result = this.gradleBuild.buildAndFail("bootBuildImage");
BuildResult result = this.gradleBuild.buildAndFail("bootBuildImage", "--pullPolicy=IF_NOT_PRESENT");
assertThat(result.task(":bootBuildImage").getOutcome()).isEqualTo(TaskOutcome.FAILED);
assertThat(result.getOutput()).containsPattern("Builder lifecycle '.*' failed with status code");
}