diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f6afb0648b..c2caef8984 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -24,7 +24,9 @@ Jib comes as 3 components: - `jib-maven-plugin`: a Maven plugin that uses `jib-core` and `jib-plugins-common` - `jib-gradle-plugin`: a Gradle plugin that uses `jib-core` and `jib-plugins-common` -To build, use the provided `build.sh` which builds and tests each of the components into your local `~/.m2/repository`. Note that this script does not run integration tests. +To build, use the provided `build.sh` which builds and tests each of the +components into your local `~/.m2/repository`. Note that this script does +not run integration tests. ## Code Reviews @@ -45,7 +47,17 @@ To build, use the provided `build.sh` which builds and tests each of the compone 5. Associate the change with an existing issue or file a [new issue](../../issues). 6. Create a pull request! -**Note** that in order to run integration tests, you will need to set the environment variable `JIB_INTEGRATION_TESTING_PROJECT` to the GCP project you would like to use for testing. You will also need Docker installed with the daemon running. Otherwise, feel free to skip integration tests. +**Note** that in order to run integration tests, you will need to set one of the +following environment variables: + + - `JIB_INTEGRATION_TESTING_PROJECT`: the GCP project to use for testing; + the registry tested will be `gcr.io/`. + - `JIB_INTEGRATION_TESTING_LOCATION`: a specific registry for testing. + To run the integration tests locally, you can run + `docker run -d -p 9990:5000 registry:2` and use `localhost:9990`. + +You will also need Docker installed with the daemon running. Note that the +integration tests will create local registries on ports 5000 and 6000. # Development Tips diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/IntegrationTestingConfiguration.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/IntegrationTestingConfiguration.java index f39ef24abc..7c3e0ef844 100644 --- a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/IntegrationTestingConfiguration.java +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/IntegrationTestingConfiguration.java @@ -22,13 +22,19 @@ /** Configuration for integration tests. */ public class IntegrationTestingConfiguration { - public static String getGCPProject() { + public static String getTestRepositoryLocation() { String projectId = System.getenv("JIB_INTEGRATION_TESTING_PROJECT"); - if (Strings.isNullOrEmpty(projectId)) { + if (!Strings.isNullOrEmpty(projectId)) { + return "gcr.io/" + projectId; + } + String location = System.getenv("JIB_INTEGRATION_TESTING_LOCATION"); + if (Strings.isNullOrEmpty(location)) { Assert.fail( - "Must set environment variable JIB_INTEGRATION_TESTING_PROJECT to the GCP project to use for integration testing."); + "Must set environment variable JIB_INTEGRATION_TESTING_PROJECT to the " + + "GCP project to use for integration testing or " + + "JIB_INTEGRATION_TESTING_LOCATION to a suitable registry/repository location."); } - return projectId; + return location; } private IntegrationTestingConfiguration() {} diff --git a/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/EmptyProjectIntegrationTest.java b/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/EmptyProjectIntegrationTest.java index f382198c46..db839e9e0e 100644 --- a/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/EmptyProjectIntegrationTest.java +++ b/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/EmptyProjectIntegrationTest.java @@ -62,8 +62,7 @@ private static void assertDockerInspect(String imageReference) @Test public void testBuild_empty() throws IOException, InterruptedException, DigestException { String targetImage = - "gcr.io/" - + IntegrationTestingConfiguration.getGCPProject() + IntegrationTestingConfiguration.getTestRepositoryLocation() + "/emptyimage:gradle" + System.nanoTime(); Assert.assertEquals("", JibRunHelper.buildAndRun(emptyTestProject, targetImage)); @@ -75,8 +74,7 @@ public void testBuild_empty() throws IOException, InterruptedException, DigestEx public void testBuild_multipleTags() throws IOException, InterruptedException, InvalidImageReferenceException, DigestException { String targetImage = - "gcr.io/" - + IntegrationTestingConfiguration.getGCPProject() + IntegrationTestingConfiguration.getTestRepositoryLocation() + "/multitag-image:gradle" + System.nanoTime(); JibRunHelper.buildAndRunAdditionalTag( diff --git a/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/JibRunHelper.java b/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/JibRunHelper.java index 975483883a..17e909a05f 100644 --- a/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/JibRunHelper.java +++ b/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/JibRunHelper.java @@ -55,6 +55,7 @@ static String buildAndRun( "-Djib.useOnlyProjectCache=true", "-Djib.console=plain", "-D_TARGET_IMAGE=" + imageReference, + "-Djib.allowInsecureRegistries=" + imageReference.startsWith("localhost"), "-b=" + gradleBuildFile); assertBuildSuccess(buildResult, "jib", "Built and pushed image as "); assertImageDigestAndId(testProject.getProjectRoot()); @@ -73,6 +74,7 @@ static void buildAndRunAdditionalTag( "-Djib.useOnlyProjectCache=true", "-Djib.console=plain", "-D_TARGET_IMAGE=" + imageReference, + "-Djib.allowInsecureRegistries=" + imageReference.startsWith("localhost"), "-D_ADDITIONAL_TAG=" + additionalTag); assertBuildSuccess(buildResult, "jib", "Built and pushed image as "); assertImageDigestAndId(testProject.getProjectRoot()); @@ -99,6 +101,7 @@ static BuildResult buildToDockerDaemon( "-Djib.useOnlyProjectCache=true", "-Djib.console=plain", "-D_TARGET_IMAGE=" + imageReference, + "-Djib.allowInsecureRegistries=" + imageReference.startsWith("localhost"), "-b=" + gradleBuildFile); assertBuildSuccess(buildResult, "jibDockerBuild", "Built image to Docker daemon as "); assertImageDigestAndId(testProject.getProjectRoot()); diff --git a/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/SingleProjectIntegrationTest.java b/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/SingleProjectIntegrationTest.java index 4598457ae0..29da90afb2 100644 --- a/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/SingleProjectIntegrationTest.java +++ b/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/SingleProjectIntegrationTest.java @@ -179,8 +179,7 @@ public void setup() throws IOException, InterruptedException { @Test public void testBuild_simple() throws IOException, InterruptedException, DigestException { String targetImage = - "gcr.io/" - + IntegrationTestingConfiguration.getGCPProject() + IntegrationTestingConfiguration.getTestRepositoryLocation() + "/simpleimage:gradle" + System.nanoTime(); @@ -218,8 +217,7 @@ public void testBuild_simple() throws IOException, InterruptedException, DigestE @Test public void testBuild_failOffline() { String targetImage = - "gcr.io/" - + IntegrationTestingConfiguration.getGCPProject() + IntegrationTestingConfiguration.getTestRepositoryLocation() + "/simpleimageoffline:gradle" + System.nanoTime(); diff --git a/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/WarProjectIntegrationTest.java b/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/WarProjectIntegrationTest.java index 5a093ee96c..1b161061ce 100644 --- a/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/WarProjectIntegrationTest.java +++ b/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/WarProjectIntegrationTest.java @@ -74,7 +74,7 @@ public void testBuild_tomcatServlet25() private void verifyBuildAndRun(TestProject project, String label, String gradleBuildFile) throws IOException, InterruptedException, DigestException { - String nameBase = "gcr.io/" + IntegrationTestingConfiguration.getGCPProject() + '/'; + String nameBase = IntegrationTestingConfiguration.getTestRepositoryLocation() + '/'; String targetImage = nameBase + label + System.nanoTime(); String output = JibRunHelper.buildAndRun(project, targetImage, gradleBuildFile, "--detach", "-p8080:8080"); diff --git a/jib-maven-plugin/src/test/java/com/google/cloud/tools/jib/maven/BuildImageMojoIntegrationTest.java b/jib-maven-plugin/src/test/java/com/google/cloud/tools/jib/maven/BuildImageMojoIntegrationTest.java index 645c6cb9af..603d2dfe02 100644 --- a/jib-maven-plugin/src/test/java/com/google/cloud/tools/jib/maven/BuildImageMojoIntegrationTest.java +++ b/jib-maven-plugin/src/test/java/com/google/cloud/tools/jib/maven/BuildImageMojoIntegrationTest.java @@ -74,8 +74,8 @@ public class BuildImageMojoIntegrationTest { @ClassRule public static final TestProject servlet25Project = new TestProject(testPlugin, "war_servlet25"); - private static String getGcrImageReference(String label) { - String nameBase = "gcr.io/" + IntegrationTestingConfiguration.getGCPProject() + '/'; + private static String getTestImageReference(String label) { + String nameBase = IntegrationTestingConfiguration.getTestRepositoryLocation() + '/'; return nameBase + label + System.nanoTime(); } @@ -104,6 +104,9 @@ private static Verifier build( Verifier verifier = new Verifier(projectRoot.toString()); verifier.setSystemProperty("jib.useOnlyProjectCache", "true"); verifier.setSystemProperty("_TARGET_IMAGE", imageReference); + if (imageReference.startsWith("localhost")) { + verifier.setSystemProperty("jib.allowInsecureRegistries", "true"); + } verifier.setAutoclean(false); verifier.addCliOption("-X"); verifier.addCliOption("--file=" + pomXml); @@ -163,6 +166,9 @@ private static String buildAndRunAdditionalTag( verifier.setSystemProperty("jib.useOnlyProjectCache", "true"); verifier.setSystemProperty("_TARGET_IMAGE", imageReference); verifier.setSystemProperty("_ADDITIONAL_TAG", additionalTag); + if (imageReference.startsWith("localhost")) { + verifier.setSystemProperty("jib.allowInsecureRegistries", "true"); + } verifier.setAutoclean(false); verifier.addCliOption("-X"); verifier.executeGoals(Arrays.asList("clean", "compile", "jib:build")); @@ -324,7 +330,7 @@ public void tearDown() throws IOException, InterruptedException { @Test public void testExecute_simple() throws VerificationException, IOException, InterruptedException, DigestException { - String targetImage = getGcrImageReference("simpleimage:maven"); + String targetImage = getTestImageReference("simpleimage:maven"); // Test empty output error try { @@ -372,7 +378,7 @@ public void testExecute_simple() @Test public void testExecute_failOffline() throws IOException { - String targetImage = getGcrImageReference("simpleimageoffline:maven"); + String targetImage = getTestImageReference("simpleimageoffline:maven"); // Test empty output error try { @@ -395,7 +401,7 @@ public void testExecute_simpleOnJava11() throws DigestException, VerificationException, IOException, InterruptedException { Assume.assumeTrue(isJava11RuntimeOrHigher()); - String targetImage = getGcrImageReference("simpleimage:maven"); + String targetImage = getTestImageReference("simpleimage:maven"); Assert.assertEquals( "Hello, world. An argument.\n", buildAndRun(simpleTestProject.getProjectRoot(), targetImage, "pom-java11.xml", false)); @@ -424,7 +430,7 @@ public void testExecute_simpleWithIncomptiableJava11() @Test public void testExecute_empty() throws InterruptedException, IOException, VerificationException, DigestException { - String targetImage = getGcrImageReference("emptyimage:maven"); + String targetImage = getTestImageReference("emptyimage:maven"); Assert.assertEquals( "", buildAndRun(emptyTestProject.getProjectRoot(), targetImage, "pom.xml", false)); assertCreationTimeEpoch(targetImage); @@ -435,7 +441,7 @@ public void testExecute_empty() public void testExecute_multipleTags() throws IOException, InterruptedException, InvalidImageReferenceException, VerificationException, DigestException { - String targetImage = getGcrImageReference("multitag-image:maven"); + String targetImage = getTestImageReference("multitag-image:maven"); Assert.assertEquals( "", buildAndRunAdditionalTag( @@ -445,7 +451,7 @@ public void testExecute_multipleTags() @Test public void testExecute_multipleExtraDirectories() throws DigestException, VerificationException, IOException, InterruptedException { - String targetImage = getGcrImageReference("simpleimage:maven"); + String targetImage = getTestImageReference("simpleimage:maven"); Assert.assertEquals( "Hello, world. An argument.\nrw-r--r--\nrw-r--r--\nfoo\ncat\nbaz\n", buildAndRun(simpleTestProject.getProjectRoot(), targetImage, "pom-extra-dirs.xml", false)); @@ -469,7 +475,7 @@ public void testExecute_bothDeprecatedAndNewExtraDirectoryConfigUsed() throws IO @Test public void testExecute_deprecatedExtraDirectoryConfigUsed() throws IOException, VerificationException { - String targetImage = getGcrImageReference("simpleimage:maven"); + String targetImage = getTestImageReference("simpleimage:maven"); build(simpleTestProject.getProjectRoot(), targetImage, "pom-deprecated-extra-dir.xml", false) .verifyTextInLog( " is deprecated; use with "); @@ -594,11 +600,14 @@ public void testExecute_tomcatServlet25() private void buildAndRunWar(String label, String pomXml) throws VerificationException, IOException, InterruptedException { - String targetImage = getGcrImageReference(label); + String targetImage = getTestImageReference(label); Verifier verifier = new Verifier(servlet25Project.getProjectRoot().toString()); verifier.setSystemProperty("jib.useOnlyProjectCache", "true"); verifier.setSystemProperty("_TARGET_IMAGE", targetImage); + if (targetImage.startsWith("localhost")) { + verifier.setSystemProperty("jib.allowInsecureRegistries", "true"); + } verifier.setAutoclean(false); verifier.addCliOption("-X"); verifier.addCliOption("--file=" + pomXml);