use of com.google.cloud.tools.jib.Command in project jib by google.
the class BuildImageMojoIT method buildAndRun.
/**
* Builds and runs jib:build on a project at {@code projectRoot} pushing to {@code
* imageReference}.
*/
private static String buildAndRun(Path projectRoot, String imageReference) throws VerificationException, IOException, InterruptedException {
Verifier verifier = new Verifier(projectRoot.toString());
verifier.setAutoclean(false);
verifier.executeGoal("package");
// Builds twice, and checks if the second build took less time.
long lastTime = System.nanoTime();
verifier.executeGoal("jib:build");
long timeOne = System.nanoTime() - lastTime;
lastTime = System.nanoTime();
verifier.executeGoal("jib:build");
long timeTwo = System.nanoTime() - lastTime;
verifier.verifyErrorFreeLog();
Assert.assertTrue("First build time (" + timeOne + ") is not greater than second build time (" + timeTwo + ")", timeOne > timeTwo);
new Command("docker", "pull", imageReference).run();
return new Command("docker", "run", imageReference).run();
}
use of com.google.cloud.tools.jib.Command in project jib by google.
the class LocalRegistry method after.
/**
* Stops the local registry.
*/
@Override
protected void after() {
try {
// Stops the registry.
new Command("docker", "stop", containerName).run();
// Removes the container.
new Command("docker", "rm", "-v", containerName).run();
} catch (InterruptedException | IOException ex) {
throw new RuntimeException("Could not stop local registry fully: " + containerName, ex);
}
}
use of com.google.cloud.tools.jib.Command in project jib by google.
the class DockerCredentialHelperIntegrationTest method testRetrieveGCR.
/**
* Tests retrieval via {@code docker-credential-gcr} CLI.
*/
@Test
public void testRetrieveGCR() throws IOException, NonexistentServerUrlDockerCredentialHelperException, NonexistentDockerCredentialHelperException, URISyntaxException, InterruptedException {
new Command("docker-credential-gcr", "store").run(Files.readAllBytes(Paths.get(Resources.getResource("credentials.json").toURI())));
DockerCredentialHelper dockerCredentialHelper = new DockerCredentialHelperFactory("myregistry").withCredentialHelperSuffix("gcr");
Authorization authorization = dockerCredentialHelper.retrieve();
// Checks that token received was base64 encoding of "myusername:mysecret".
Assert.assertEquals("bXl1c2VybmFtZTpteXNlY3JldA==", authorization.getToken());
}
use of com.google.cloud.tools.jib.Command in project jib by google.
the class BuildImageStepsIntegrationTest method testSteps.
@Test
public void testSteps() throws Exception {
SourceFilesConfiguration sourceFilesConfiguration = new TestSourceFilesConfiguration();
BuildConfiguration buildConfiguration = BuildConfiguration.builder(logger).setBaseImage(ImageReference.of("gcr.io", "distroless/java", "latest")).setTargetImage(ImageReference.of("localhost:5000", "testimage", "testtag")).setMainClass("HelloWorld").build();
Path cacheDirectory = temporaryCacheDirectory.newFolder().toPath();
BuildImageSteps buildImageSteps = new BuildImageSteps(buildConfiguration, sourceFilesConfiguration, Caches.newInitializer(cacheDirectory).setBaseCacheDirectory(cacheDirectory));
long lastTime = System.nanoTime();
buildImageSteps.run();
logger.info("Initial build time: " + ((System.nanoTime() - lastTime) / 1_000_000));
lastTime = System.nanoTime();
buildImageSteps.run();
logger.info("Secondary build time: " + ((System.nanoTime() - lastTime) / 1_000_000));
String imageReference = "localhost:5000/testimage:testtag";
new Command("docker", "pull", imageReference).run();
Assert.assertEquals("Hello world\n", new Command("docker", "run", imageReference).run());
}
use of com.google.cloud.tools.jib.Command in project jib by google.
the class JibPluginIntegrationTest method buildAndRun.
private static String buildAndRun(TestProject testProject, String imageReference) throws IOException, InterruptedException {
BuildResult buildResult = testProject.build();
BuildTask jibTask = buildResult.task(":jib");
Assert.assertNotNull(jibTask);
Assert.assertEquals(TaskOutcome.SUCCESS, jibTask.getOutcome());
Assert.assertThat(buildResult.getOutput(), CoreMatchers.containsString("Built and pushed image as " + imageReference));
new Command("docker", "pull", imageReference).run();
return new Command("docker", "run", imageReference).run();
}
Aggregations