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

Fill in a small amount of details on the jib-as-a-library proposal #1093

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
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
58 changes: 43 additions & 15 deletions proposals/jib_core_library.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,19 @@ Design for Jib Core as a Java library for building container images.

# Proposed API

## General Containers

`Jib` - the main entrypoint for using Jib Core

- `JibContainerBuilder from(String baseImageReference)`
- `JibContainerBuilder from(ImageReference baseImageReference)`
- `JibContainerBuilder from(RegistryImage baseImage)`
- `static Containerizer to(RegistryImage)`
- `static Containerizer to(DockerDaemonImage)`
- `static Containerizer to(TarImage)`

`JibContainerBuilder` - configures the container to build

- `JibContainerBuilder addLayer(List<Path> files, Path pathInContainer)`
- `JibContainerBuilder addLayer(LayerConfiguration)`
- `JibContainerBuilder setLayers(List<LayerConfiguration>/LayerConfiguration...)`
Expand All @@ -31,46 +38,67 @@ Design for Jib Core as a Java library for building container images.
Three `TargetImage` types (`RegistryImage`, `DockerDaemonImage`, and `TarImage`) define the 3 different targets Jib can build to.

`RegistryImage` - builds to a container registry

- `static RegistryImage named(ImageReference/String)`
- `RegistryImage addCredential(String username, String password)`
- `RegistryImage addCredentialRetriever(CredentialRetriever)`

`DockerDaemonImage` - builds to a Docker daemon

- `static DockerDaemonImage named(ImageReference/String)`
- `DockerDaemonImage setDockerExecutable(Path)`

`TarImage` - builds to a tarball archive

- `Builder`
- `TarImage saveTo(Path outputFile)`
- `static Builder named(ImageReference/String)`

`Containerizer` - configures how and where to containerize to
- `static Containerizer to(RegistryImage)`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the reasoning for having the static initializers on Containerizer is to increase discoverability since JibContainerBuilder#containerize takes a Containerizer - so it's like of like Streams.of and then Stream#collect(Collector) with Collectors.to....

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The examples put these methods on Jib (Jib.to), not Containerizer. Will update the examples instead.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah oops that was a mistake then. Thanks!

- `static Containerizer to(DockerDaemonImage)`
- `static Containerizer to(TarImage)`
- `Containerizer setExecutorService(ExecutorService)`
- `Containerizer setCacheConfiguration(CacheConfiguration)`
- `Containerizer setEventHandlers(EventHandlers)`

## For Java containers
## Simple example

```java
Jib.from("busybox")
// TODO: this doesn't seem right, especially if multiple files are in the .addLayer call (are they cat'ed, or is /helloworld.sh a directory?)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pathInContainer is actually a directory path to place the files under. Maybe it makes more sense to call it directoryInContainer?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

directoryInContainer is good. Updating the example...

.addLayer(Arrays.asList(Paths.get("helloworld.sh")), "/helloworld.sh")
.setEntrypoint("/helloworld.sh")
.containerize(
Jib.to(RegistryImage.named("coollog/jibtestimage")
.setCredential("coollog", "notmyrealpassword")));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: mis-aligned indentation

```

# For Java containers

`JavaContainerBuilder` - builds a `JibContainerBuilder` for Java apps.

`JavaContainerBuilder` - builds a `JibContainerBuilder` for Java apps
- `static JavaContainerBuilder builder()`
- `JavaContainerBuilder addDependencies(List<Path> dependencyFiles)`
- `JavaContainerBuilder addResources(List<Path> resourceFiles)`
- `JavaContainerBuilder addClasses(List<Path> classFiles)`
- `JavaContainerBuilder addToClasspath(List<Path> otherFiles)`
- `JavaContainerBuilder setJvmFlags(List<String>/String... jvmFlags)`
- `JavaContainerBuilder setMainClass(String mainClass)`
- `JavaContainerBuilder toContainerBuilder()`
- `JibContainerBuilder toContainerBuilder()`

# Simple example
Returns a `JibContainerBuilder` that, when built, will produce a minimal Java image that executes the java application specified by the builder methods previously called on this `JavaContainerBuilder`.

```java
Jib.from("busybox")
.addLayer(Arrays.asList(Paths.get("helloworld.sh")), "/helloworld.sh")
.setEntrypoint("/helloworld.sh")
.containerize(
Jib.to(RegistryImage.named("coollog/jibtestimage")
.setCredential("coollog", "notmyrealpassword"));
```
Example:

```java
RegistryImage destination = RegistryImage.named("gcr.io/myuser/my-java-container:latest");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When using gcr.io, I would say gcr.io/my-cloud-project/....

nit: misaligned indentation


JibContainerBuilder javaImage = JavaContainerBuilder.builder()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JavaContainerBuidler javaImage = ..., since JibContainerBuilder doesn't have addDependencies() and such. And rename javaImage to javaContainerBuilder or containerBuilder, since the builder is not an Image.

@GoogleContainerTools/java-tools I don't remember, will we have JavaContainerBuilder and methods like addDependencies, etc?

.addDependencies(Lists.newArrayList(Paths.get("/my/filesystem/lib/my-dependency.jar")))
.addClasses(Lists.newArrayList(Paths.get("/my/filesystem/target/com/google/FooMain.class")))
.setMainClass("com.google.FooMain")
.toContainerBuilder()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's already a container builder, so this doesn't sound right.

// Add other customization to the image, maybe some labels
.addExposedPort(Port.tcp(8080));

// Throws an exception if the image couldn't be build.
JibContainer result = javaImage.containerize(Jib.to(destination));
```