Search in sources :

Example 1 with Command

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();
}
Also used : Command(com.google.cloud.tools.jib.Command) Verifier(org.apache.maven.it.Verifier)

Example 2 with Command

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);
    }
}
Also used : Command(com.google.cloud.tools.jib.Command) IOException(java.io.IOException)

Example 3 with Command

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());
}
Also used : Authorization(com.google.cloud.tools.jib.http.Authorization) Command(com.google.cloud.tools.jib.Command) Test(org.junit.Test)

Example 4 with Command

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());
}
Also used : Path(java.nio.file.Path) Command(com.google.cloud.tools.jib.Command) Test(org.junit.Test)

Example 5 with Command

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();
}
Also used : BuildResult(org.gradle.testkit.runner.BuildResult) BuildTask(org.gradle.testkit.runner.BuildTask) Command(com.google.cloud.tools.jib.Command)

Aggregations

Command (com.google.cloud.tools.jib.Command)6 Test (org.junit.Test)2 Authorization (com.google.cloud.tools.jib.http.Authorization)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 Verifier (org.apache.maven.it.Verifier)1 BuildResult (org.gradle.testkit.runner.BuildResult)1 BuildTask (org.gradle.testkit.runner.BuildTask)1