-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds JibContainerBuilder#containerize. (#1076)
- Loading branch information
Showing
15 changed files
with
403 additions
and
45 deletions.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* Copyright 2018 Google LLC. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package com.google.cloud.tools.jib.api; | ||
|
||
import com.google.cloud.tools.jib.Command; | ||
import com.google.cloud.tools.jib.configuration.CacheDirectoryCreationException; | ||
import com.google.cloud.tools.jib.configuration.credentials.Credential; | ||
import com.google.cloud.tools.jib.image.ImageReference; | ||
import com.google.cloud.tools.jib.image.InvalidImageReferenceException; | ||
import com.google.cloud.tools.jib.registry.LocalRegistry; | ||
import java.io.IOException; | ||
import java.util.Optional; | ||
import java.util.concurrent.ExecutionException; | ||
import org.junit.After; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
|
||
/** Integration tests for {@link Jib}. */ | ||
public class JibIntegrationTest { | ||
|
||
@ClassRule | ||
public static final LocalRegistry localRegistry = new LocalRegistry(5000, "username", "password"); | ||
|
||
/** | ||
* Pulls a built image and attempts to run it. | ||
* | ||
* @param imageReference the image reference of the built image | ||
* @return the container output | ||
* @throws IOException if an I/O exception occurs | ||
* @throws InterruptedException if the process was interrupted | ||
*/ | ||
private static String pullAndRunBuiltImage(String imageReference) | ||
throws IOException, InterruptedException { | ||
localRegistry.pull(imageReference); | ||
return new Command("docker", "run", "--rm", imageReference).run(); | ||
} | ||
|
||
@Before | ||
public void setUp() { | ||
System.setProperty("sendCredentialsOverHttp", "true"); | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
System.clearProperty("sendCredentialsOverHttp"); | ||
} | ||
|
||
@Test | ||
public void testBasic_helloWorld() | ||
throws InvalidImageReferenceException, InterruptedException, ExecutionException, | ||
CacheDirectoryCreationException, IOException { | ||
ImageReference targetImageReference = | ||
ImageReference.of("localhost:5000", "jib-core", "basic-helloworld"); | ||
JibContainer jibContainer = | ||
Jib.from("busybox") | ||
.setEntrypoint("echo", "Hello World") | ||
.containerize( | ||
Containerizer.to( | ||
RegistryImage.named(targetImageReference) | ||
.addCredentialRetriever( | ||
() -> Optional.of(Credential.basic("username", "password")))) | ||
.setAllowInsecureRegistries(true)); | ||
|
||
Assert.assertEquals("Hello World\n", pullAndRunBuiltImage(targetImageReference.toString())); | ||
Assert.assertEquals( | ||
"Hello World\n", | ||
pullAndRunBuiltImage( | ||
targetImageReference.withTag(jibContainer.getDigest().toString()).toString())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
jib-core/src/main/java/com/google/cloud/tools/jib/api/JibContainer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2018 Google LLC. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package com.google.cloud.tools.jib.api; | ||
|
||
import com.google.cloud.tools.jib.image.DescriptorDigest; | ||
|
||
/** The container built by Jib. */ | ||
public class JibContainer { | ||
|
||
private final DescriptorDigest imageDigest; | ||
|
||
JibContainer(DescriptorDigest imageDigest) { | ||
this.imageDigest = imageDigest; | ||
} | ||
|
||
/** | ||
* Gets the digest of the container image built by Jib. | ||
* | ||
* @return the image digest | ||
*/ | ||
public DescriptorDigest getDigest() { | ||
return imageDigest; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.