briandealwis / cram

Command-line utility for creating container images from file-system content without Docker

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cram

Note: Cram has been moved into Jib as the Jib CLI utility

Cram is a little Java-based command-line utility for building Docker containers from file system content. It serves as a demonstration of Jib Core, a Java library for building containers without Docker.

(Cram was initially called Bilge, because a Jib is also a sail and... hence the rename.)

Building

mvn package

This creates a fatjar in target/cram-0.0.1-SNAPSHOT-jar-with-dependencies.jar.

Examples

nginx

The following example creates an nginx-based container to serve static content that is found in path/to/website. The result is loaded to the local Docker daemon as my-static-website:

$ java -jar cram/target/cram-0.0.1-SNAPSHOT-jar-with-dependencies.jar \
  --docker \
  nginx \
  my-static-website \
  --port 80 \
  --entrypoint "nginx,-g,daemon off;" \
  path/to/website:/usr/share/nginx/html
$ docker run -it --rm -p 8080:80 my-static-website

Java app

The following example uses cram to containerize itself. The image is pushed to a registry at localhost:5000:

$ java -jar cram/target/cram-0.0.1-SNAPSHOT-jar-with-dependencies.jar \
  --registry \
  gcr.io/distroless/java \
  localhost:5000/cram:latest \
  --insecure \
  --entrypoint "java,-jar,/app/cram.jar" \
  cram/target/cram-0.0.1-SNAPSHOT-jar-with-dependencies.jar:/app/cram.jar
$ docker run --rm localhost:5000/cram:latest

We need to use --insecure assuming the local registry does not support SSL.

Note that we'd be better off using jib-maven-plugin to create the container since it would create better layer strategy that negates the need to use a fatjar.

Compiling with Graal's native-image

$ sh build-native.sh
  • switched to using SLF4j with Apache Commons Logging facade to avoid the need to configure reflection for LogFactory
  • must explicitly enable http and https support
  • must somehow set java.library.path at compile time, or copy in $GRAALVM/jre/lib/libsunec.* into the current directory, to make the SunEC JCA extensions available.
  • the graal-jib-reflect.json must be updated as Jib Core adds new fields to Jackson JSON templates.

About

Command-line utility for creating container images from file-system content without Docker

License:Apache License 2.0


Languages

Language:Java 96.5%Language:Shell 3.5%