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 2 commits
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
73 changes: 56 additions & 17 deletions proposals/jib_core_library.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,32 @@ 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 JibContainerBuilder from(String baseImageReference)`
- `static JibContainerBuilder from(ImageReference baseImageReference)`
- `static JibContainerBuilder from(RegistryImage baseImage)`

`JibContainerBuilder` - configures the container to build
- `JibContainerBuilder addLayer(List<Path> files, Path pathInContainer)`

- `JibContainerBuilder addLayer(List<Path> files, String directoryInContainer)`

Adds a new layer that will consists of the files referred to by `files`, each of which is copied into the `directoryInContainer`. Regardless of the directory nesting of files in `files`, they will be copied into the same level inside the container. Each `Path` object in `files` must represent a file, not a directory.
nick-someone marked this conversation as resolved.
Show resolved Hide resolved

```java
container.addLayer(
Copy link
Member

Choose a reason for hiding this comment

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

containerBuilder.addLayer( looks less confusing.

Arrays.asList(
Paths.get("/a/b/c.txt"),
Paths.get("/a/b.txt"),
Paths.get("/a/c.txt")),
"/root");
// container will have /root/b.txt, and /root/c.txt (from /a/c.txt)
```

- `JibContainerBuilder addLayer(LayerConfiguration)`
- `JibContainerBuilder setLayers(List<LayerConfiguration>/LayerConfiguration...)`

- `JibContainerBuilder setEntrypoint(List<String>/String...)`
- `JibContainerBuilder setProgramArguments(List<String>/String...)`
- `JibContainerBuilder setEnvironment(Map<String, String> environmentMap)`
Expand All @@ -31,15 +47,18 @@ 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)`
Expand All @@ -52,25 +71,45 @@ Three `TargetImage` types (`RegistryImage`, `DockerDaemonImage`, and `TarImage`)
- `Containerizer setCacheConfiguration(CacheConfiguration)`
- `Containerizer setEventHandlers(EventHandlers)`

## For Java containers
## Simple example

```java
Jib.from("busybox")
.addLayer(Arrays.asList(Paths.get("helloworld.sh")), "/")
.setEntrypoint("/helloworld.sh")
.containerize(
Containerizer.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")))
nick-someone marked this conversation as resolved.
Show resolved Hide resolved
.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(Containerizer.to(destination));
Copy link
Member

Choose a reason for hiding this comment

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

javaImage -> containerBuilder, as I said above.

```