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

Proposal RFC: Jib Core as a library for Java #987

Merged
merged 6 commits into from
Sep 28, 2018
Merged
Changes from 5 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
76 changes: 76 additions & 0 deletions proposals/jib_core_library.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Proposal: Jib Core as a library for Java

The tracking issue is at [#337](https://github.com/GoogleContainerTools/jib/issues/337).

# Goal

Design for Jib Core as a Java library for building container images.

# Proposed API

`Jib` - the main entrypoint for using Jib Core
- `JibContainerBuilder from(String baseImageReference)`
- `JibContainerBuilder from(ImageReference baseImageReference)`
- `JibContainerBuilder from(RegistryImage baseImage)`

`JibContainerBuilder` - configures the container to build
- `JibContainerBuilder layer(List<Path> files, Path pathInContainer)`
- `JibContainerBuilder layer(LayerConfiguration)`
Copy link
Contributor

Choose a reason for hiding this comment

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

These two were changed to addLayer, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, I'll change this over.

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

- `JibContainerBuilder setEntrypoint(List<String>/String...)`
- `JibContainerBuilder setProgramArguments(List<String>/String...)`
- `JibContainerBuilder setEnvironment(Map<String, String> environmentMap)`
- `JibContainerBuilder addEnvironmentVariable(String name, String value)`
- `JibContainerBuilder setExposedPorts(List<Port>/Port...)`
- `JibContainerBuilder addExposedPort(Port port)`
- `JibContainerBuilder setLabels(Map<String, String> labelMap)`
- `JibContainerBuilder addLabel(String key, String value)`
Copy link
Member

Choose a reason for hiding this comment

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

Weren't we talking about having a more fluent-looking environment(), labels()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, that was in #953 - I'll update these to reflect the proposal there.

Copy link
Contributor Author

@coollog coollog Sep 17, 2018

Choose a reason for hiding this comment

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

Actually, after changing this over, I feel like the way we have it now is clearer, since there's a combination of set... and add... methods and removing the prefixes may be confusing since most of the set... methods mean "replace with" rather than "append".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Scratch that - I'll rework this with the setters changed into the ...Only names.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, but for setters like setLayers, layersOnly or the like doesn't sound right.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And just layers is unclear as to whether it appends or replaces.

Copy link
Member

Choose a reason for hiding this comment

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

But I don't think we ever replace layers, do we. At least, not for the API. Right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

- `JibContainer containerize(Containerizer)`

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)`
- `static Containerizer to(DockerDaemonImage)`
- `static Containerizer to(TarImage)`
- `Containerizer setExecutorService(ExecutorService)`
- `Containerizer setCacheConfiguration(CacheConfiguration)`
- `Containerizer setEventHandlers(EventHandlers)`

## For Java containers

`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()`

# Simple example

```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"));
```