Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removes SourceFilesConfiguration in favor of list of LayerConfiguration in BuildConfiguration. #516

Merged
merged 27 commits into from
Jul 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b468528
Removes SourceFilesConfiguration in favor of list of LayerConfigurati…
coollog Jul 6, 2018
69e6b57
Applies to jib-gradle-plugin.
coollog Jul 6, 2018
84f5ef6
Fixes format.
coollog Jul 10, 2018
fd6daaf
Merge branch 'master' into no-sourcefilesconfiguration
coollog Jul 19, 2018
780332a
Merge branch 'master' into no-sourcefilesconfiguration
coollog Jul 19, 2018
e3d835d
Fixes auth issue.
coollog Jul 19, 2018
fd46ee2
Merge branch 'master' into no-sourcefilesconfiguration
coollog Jul 19, 2018
4736f4d
Merge branch 'master' into no-sourcefilesconfiguration
coollog Jul 20, 2018
00176fe
Refactors entrypoint building.
coollog Jul 20, 2018
36791ac
Fixes tests.
coollog Jul 20, 2018
fcde23c
Fixes jib-gradle-plugin.
coollog Jul 20, 2018
06e5b46
Changes for jib-maven-plugin.
coollog Jul 20, 2018
0bc2536
Merge branch 'master' into no-sourcefilesconfiguration
coollog Jul 20, 2018
7162e85
Simplifies DockerContextGenerator and labels layers to avoid indexing.
coollog Jul 21, 2018
7c28ffe
Merge branch 'master' into no-sourcefilesconfiguration
coollog Jul 21, 2018
e871c14
Fixes words.
coollog Jul 21, 2018
77339ff
Prints all layer entries.
coollog Jul 21, 2018
614dbc7
Fixes format.
coollog Jul 22, 2018
5a8247a
Changes fields to nullable.
coollog Jul 24, 2018
bc46b0b
Renames JavaEntrypointConstructor.
coollog Jul 24, 2018
72abd98
Merge branch 'master' into no-sourcefilesconfiguration
coollog Jul 24, 2018
0ee1e86
Some more comments.
coollog Jul 24, 2018
3596206
Fixes format.
coollog Jul 24, 2018
d7da59d
Fixes CHANGLOG.
coollog Jul 24, 2018
69764a0
A typo.
coollog Jul 24, 2018
19db093
Fixes format.
coollog Jul 25, 2018
bbe18c4
Merge branch 'master' into no-sourcefilesconfiguration
coollog Jul 25, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,23 @@
import com.google.cloud.tools.jib.cache.CacheDirectoryNotOwnedException;
import com.google.cloud.tools.jib.cache.CacheMetadataCorruptedException;
import com.google.cloud.tools.jib.cache.Caches;
import com.google.cloud.tools.jib.configuration.LayerConfiguration;
import com.google.cloud.tools.jib.frontend.ExposedPortsParser;
import com.google.cloud.tools.jib.frontend.JavaEntrypointConstructor;
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 com.google.common.collect.ImmutableList;
import com.google.common.io.Resources;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collections;
import java.util.concurrent.ExecutionException;
import java.util.stream.Stream;
import org.hamcrest.CoreMatchers;
import org.junit.Assert;
import org.junit.Before;
Expand All @@ -42,25 +49,36 @@
/** Integration tests for {@link BuildSteps}. */
public class BuildStepsIntegrationTest {

/** Lists the files in the {@code resourcePath} resources directory. */
private static ImmutableList<Path> getResourceFilesList(String resourcePath)
throws URISyntaxException, IOException {
try (Stream<Path> fileStream =
Files.list(Paths.get(Resources.getResource(resourcePath).toURI()))) {
return fileStream.collect(ImmutableList.toImmutableList());
}
}

@ClassRule public static LocalRegistry localRegistry = new LocalRegistry(5000);

private static final TestBuildLogger logger = new TestBuildLogger();

@Rule public TemporaryFolder temporaryCacheDirectory = new TemporaryFolder();

@Rule public TemporaryFolder temporaryTarOutput = new TemporaryFolder();
@Rule public final TemporaryFolder temporaryFolder = new TemporaryFolder();

private SourceFilesConfiguration sourceFilesConfiguration;
private ImmutableList<LayerConfiguration> fakeLayerConfigurations;

@Before
public void setUp() throws IOException, URISyntaxException {
sourceFilesConfiguration =
TestSourceFilesConfiguration.builder()
.withClasses()
.withDependencies()
.withSnapshotDependencies()
.withResources()
.build();
fakeLayerConfigurations =
ImmutableList.of(
LayerConfiguration.builder()
.addEntry(getResourceFilesList("application/dependencies"), "/app/libs/")
.build(),
LayerConfiguration.builder()
.addEntry(getResourceFilesList("application/resources"), "/app/resources/")
.build(),
LayerConfiguration.builder()
.addEntry(getResourceFilesList("application/classes"), "/app/classes/")
.build());
}

@Test
Expand All @@ -72,11 +90,14 @@ public void testSteps_forBuildToDockerRegistry()
BuildConfiguration.builder(logger)
.setBaseImage(ImageReference.of("gcr.io", "distroless/java", "latest"))
.setTargetImage(ImageReference.of("localhost:5000", "testimage", "testtag"))
.setMainClass("HelloWorld")
.setJavaArguments(Collections.singletonList("An argument."))
.setExposedPorts(
ExposedPortsParser.parse(Arrays.asList("1000", "2000-2002/tcp", "3000/udp")))
.setAllowInsecureRegistries(true)
.setLayerConfigurations(fakeLayerConfigurations)
.setEntrypoint(
JavaEntrypointConstructor.makeDefaultEntrypoint(
Collections.emptyList(), "HelloWorld"))
.build());

long lastTime = System.nanoTime();
Expand Down Expand Up @@ -110,9 +131,12 @@ public void testSteps_forBuildToDockerRegistry_dockerHubBaseImage()
BuildConfiguration.builder(logger)
.setBaseImage(ImageReference.parse("openjdk:8-jre-alpine"))
.setTargetImage(ImageReference.of("localhost:5000", "testimage", "testtag"))
.setMainClass("HelloWorld")
.setJavaArguments(Collections.singletonList("An argument."))
.setAllowInsecureRegistries(true)
.setLayerConfigurations(fakeLayerConfigurations)
.setEntrypoint(
JavaEntrypointConstructor.makeDefaultEntrypoint(
Collections.emptyList(), "HelloWorld"))
.build())
.run();

Expand All @@ -130,16 +154,18 @@ public void testSteps_forBuildToDockerDaemon()
BuildConfiguration.builder(logger)
.setBaseImage(ImageReference.of("gcr.io", "distroless/java", "latest"))
.setTargetImage(ImageReference.of(null, "testdocker", null))
.setMainClass("HelloWorld")
.setJavaArguments(Collections.singletonList("An argument."))
.setExposedPorts(
ExposedPortsParser.parse(Arrays.asList("1000", "2000-2002/tcp", "3000/udp")))
.setLayerConfigurations(fakeLayerConfigurations)
.setEntrypoint(
JavaEntrypointConstructor.makeDefaultEntrypoint(
Collections.emptyList(), "HelloWorld"))
.build();

Path cacheDirectory = temporaryCacheDirectory.newFolder().toPath();
Path cacheDirectory = temporaryFolder.newFolder().toPath();
BuildSteps.forBuildToDockerDaemon(
buildConfiguration,
sourceFilesConfiguration,
new Caches.Initializer(cacheDirectory, false, cacheDirectory, false))
.run();

Expand All @@ -164,16 +190,18 @@ public void testSteps_forBuildToTarball()
BuildConfiguration.builder(logger)
.setBaseImage(ImageReference.of("gcr.io", "distroless/java", "latest"))
.setTargetImage(ImageReference.of(null, "testtar", null))
.setMainClass("HelloWorld")
.setJavaArguments(Collections.singletonList("An argument."))
.setLayerConfigurations(fakeLayerConfigurations)
.setEntrypoint(
JavaEntrypointConstructor.makeDefaultEntrypoint(
Collections.emptyList(), "HelloWorld"))
.build();

Path outputPath = temporaryTarOutput.newFolder().toPath().resolve("test.tar");
Path cacheDirectory = temporaryCacheDirectory.newFolder().toPath();
Path outputPath = temporaryFolder.newFolder().toPath().resolve("test.tar");
Path cacheDirectory = temporaryFolder.newFolder().toPath();
BuildSteps.forBuildToTar(
outputPath,
buildConfiguration,
sourceFilesConfiguration,
new Caches.Initializer(cacheDirectory, false, cacheDirectory, false))
.run();

Expand All @@ -183,10 +211,8 @@ public void testSteps_forBuildToTarball()
}

private BuildSteps getBuildSteps(BuildConfiguration buildConfiguration) throws IOException {
Path cacheDirectory = temporaryCacheDirectory.newFolder().toPath();
Path cacheDirectory = temporaryFolder.newFolder().toPath();
return BuildSteps.forBuildToDockerRegistry(
buildConfiguration,
sourceFilesConfiguration,
new Caches.Initializer(cacheDirectory, false, cacheDirectory, false));
buildConfiguration, new Caches.Initializer(cacheDirectory, false, cacheDirectory, false));
}
}
Loading