{"id":383,"date":"2018-07-16T21:34:46","date_gmt":"2018-07-16T19:34:46","guid":{"rendered":"https:\/\/craftcoders.app\/?p=383"},"modified":"2024-08-14T13:38:10","modified_gmt":"2024-08-14T11:38:10","slug":"jib-introduction","status":"publish","type":"post","link":"https:\/\/craftcoders.app\/jib-introduction\/","title":{"rendered":"A quick Introduction to Jib"},"content":{"rendered":"

Hey guys, last week I stumbled upon an announcement<\/a> on the Google Cloud Platform. They presented a new open-source tool which aims to ease the containerization of your Java project. Without even reading the whole announcement, I declared it the topic of my next blog post. Well, here it is \ud83d\ude42<\/p>\n

What is Jib?<\/h2>\n

Jib is a containerizer for Java applications you can seamlessly integrate into your favourite build management tool (given it is either Maven or Gradle). The essence of the functionality is pretty simple: It abstracts most of the steps of packaging your application into a Docker image and pushing it to a registry. As a result you don’t have to write Dockerfiles and besides that you don\u2019t even have to have Docker installed on your computer, which is pretty cool.<\/p>\n

\"several<\/a>

Build flow without Jib<\/p><\/div>\n

\"Jib<\/a>

build flow with jib<\/p><\/div>\n

Why should you use Jib?<\/h2>\n

Google promises three major points that improve your development process if you use Jib:<\/p>\n

    \n
  1. Simple<\/li>\n
  2. Fast<\/li>\n
  3. Reproducible<\/li>\n<\/ol>\n

    I thought this to be very interesting, as I have been struggling with writing Dockerfiles ever since I started using Docker. I decided to take it easy at first and start out with trying out Jib on a simple Hello World application, since I was a bit cautious because it is still in the beta phase (Version 0.9.6 as of now). My precautions turned out to be partly justified, due to the (to me) confusing credential management.<\/p>\n

    All examples shown in this post are done with the Maven plugin, the steps and configuration parameters are similar for gradle though.<\/p>\n

    Hello World<\/h2>\n

    Alright, let\u2019s containerize a simple Hello World application! I\u2019m gonna spare you the Hello World code and jump right into the pom.xml.<\/p>\n

    <build>\r\n    <plugins>\r\n      ...\r\n        <plugin>\r\n            <groupId>com.google.cloud.tools<\/groupId>\r\n            <artifactId>jib-maven-plugin<\/artifactId>\r\n            <version>0.9.6<\/version>\r\n            <configuration>\r\n                <to>\r\n                    <image>registry.hub.docker.com\/craftcodecrew\/jibdemo<\/image>\r\n                    <credHelper>wincred<\/credHelper>\r\n                <\/to>\r\n                <container>\r\n                    <mainClass>jib.demo.HelloWorld<\/mainClass>\r\n                <\/container>\r\n            <\/configuration>\r\n        <\/plugin>\r\n        ...\r\n    <\/plugins>\r\n<\/build>\r\n<\/code><\/pre>\n

    As you can see Jib is a simple maven plugin with, in this case, the configuration optionsxml<to><\/code> and xml<container><\/code>. xml<to><\/code> specifies the registry you want your image automatically pushed to and your preferred credential helper. xml<container><\/code> lets you configure your image to your likings, just like you would in a normal Dockerfile. You can set the main class, some jvm flags, arguments and the ports you want your container to expose. For a more detailed documentation of the configuration options visit the extended usage<\/a> part of the jib documentation.<\/p>\n

    Credential management<\/h3>\n

    I composed this configuration rather quick and as I was already using the wincred credential helper on my Windows 10 laptop and was logged into my DockerHub account, I was certain that it was going to work out of the box. Sadly, it didn\u2019t ?. It didn’t work because I wasn\u2019t aware that my credential helper had stored my credentials for the official DockerHub API Url \u201chttps:\/\/index.docker.io\/v1\/\u201d. You have to store the credentials for the exact URL you specified in the xml<image><\/code> tag of your pom.xml, so in my case “registry.hub.docker.com”. Hence, it doesn\u2019t work when you specify a protocol either, as I tried out with the registry URL \u201chttps:\/\/registry.hub.docker.com\u201d.<\/p>\n

    This confused me for longer than it should have, because at first I didn\u2019t even know how to store new credentials in the credential helper. Furthermore, there are no examples in the documentation of the plugin nor on the documentation of the credential-helper itself. Eventually, I was able to store the credentials for the example above in the docker-credentials-wincred using the Windows PowerShell with following command:<\/p>\n

    type .\\credentials.txt | .\\docker-credential-wincred.exe store\r\n<\/code><\/pre>\n

    The content of credentials.txt<\/em> is<\/p>\n

    { \r\n    \"ServerURL\": \"registry.hub.docker.com\",\r\n    \"Username\": \"craftcodecrew\", \r\n    \"Secret\": {my-super-secret-password} \r\n}\r\n<\/code><\/pre>\n

    The type<\/em> command is similar to cat<\/em> on Linux systems, so the command pipes the contents of the credentials.txt<\/code> file into the standard input. The docker-credential-wincred<\/em> application reads from and stores a new credential into the application.
    \nI could have just put the credentials in the settings.xml<\/code> in my .m2<\/code> folder, but I just had to get it done with the credential helper. I realize that this is probably quite a rookie mistake, but Jib is supposed to be especially designed for Java Developers who are not very experienced with containerization.
    \nTherefore, I would have appreciated a little more documentation for the credential management either on the plugin or the credential management website. Hopefully my struggle with the credentials helps you getting your configuration done faster than me.<\/p>\n

    After I figured this out, the build process worked smoothly and I was able to push my containerized Hello World<\/em> application effortlessly to DockerHub with the following command<\/p>\n

    mvn compile jib:build\r\n<\/code><\/pre>\n

    If this command is too long for you to type you can also bind the Jib containerization to a Maven lifecycle of your liking, for example package<\/code>. You just have to add a <execution><\/code> tag to the plugin definition of Jib<\/p>\n

    <plugin>\r\n  <groupId>com.google.com.tools<\/groupId>\r\n  <artifactId>jib-maven-plugin<\/artifactId>\r\n  ...\r\n  <executions>\r\n    <execution>\r\n      <phase>package<\/phase>\r\n      <goals>\r\n        <goal>build<\/goal>\r\n      <\/goals>\r\n    <\/execution>\r\n  <\/executions>\r\n<\/plugin>\r\n<\/code><\/pre>\n

    Now you can build a jar, make a container image out of it and finally push it to a docker registry by simply typing mvn package<\/code>. If that isn’t convenient I don’t know what is. You can try out my awesome Hello world<\/em> container by typing the command<\/p>\n

    docker pull craftcodecrew\/jibdemo\r\ndocker run craftcodecrew\/jibdemo\r\n<\/code><\/pre>\n

    The example code is available in our GitHub organization<\/a>.<\/p>\n

    Conclusion<\/h2>\n

    Coming back to the three promises Google made, I can confirm all three of them as confidently as someone who containerized a Hello World application with it. The only real struggle was the fumbling around with the credentials and the credential helper, but that was only partly the “fault” of the Jib plugin. I will try to set up Jib for more complex applications in the near future, propably on some Spring Boot applications, so stay tuned for an update on this post.<\/p>\n

    Cheers,
    \nLeon<\/p>\n","protected":false},"excerpt":{"rendered":"

    Hey guys, last week I stumbled upon an announcement on the Google Cloud Platform. They presented a new open-source tool which aims to ease the containerization of your Java project. Without even reading the whole announcement, I declared it the topic of my next blog post. Well, here it is \ud83d\ude42 What is Jib? Jib is a containerizer for Java … Read More<\/a><\/p>\n","protected":false},"author":7,"featured_media":2360,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[108,109],"tags":[],"acf":[],"yoast_head":"\nA quick Introduction to Jib from Leon Gottschick - CraftCoders.app<\/title>\n<meta name=\"description\" content=\"In this post I describe my first experiences using the containerization tool Jib from Google to dockerize a Maven project.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/craftcoders.app\/jib-introduction\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"A quick Introduction to Jib from Leon Gottschick - CraftCoders.app\" \/>\n<meta property=\"og:description\" content=\"In this post I describe my first experiences using the containerization tool Jib from Google to dockerize a Maven project.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/craftcoders.app\/jib-introduction\/\" \/>\n<meta property=\"og:site_name\" content=\"CraftCoders.app\" \/>\n<meta property=\"article:published_time\" content=\"2018-07-16T19:34:46+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-08-14T11:38:10+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/craftcoders.app\/wp-content\/uploads\/2018\/07\/Bildschirmfoto-2019-02-03-um-17.41.33-768x638-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"768\" \/>\n\t<meta property=\"og:image:height\" content=\"638\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Leon Gottschick\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Leon Gottschick\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/craftcoders.app\/jib-introduction\/\",\"url\":\"https:\/\/craftcoders.app\/jib-introduction\/\",\"name\":\"A quick Introduction to Jib from Leon Gottschick - CraftCoders.app\",\"isPartOf\":{\"@id\":\"https:\/\/craftcoders.app\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/craftcoders.app\/jib-introduction\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/craftcoders.app\/jib-introduction\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/craftcoders.app\/wp-content\/uploads\/2018\/07\/Bildschirmfoto-2019-02-03-um-17.41.33-768x638-1.png\",\"datePublished\":\"2018-07-16T19:34:46+00:00\",\"dateModified\":\"2024-08-14T11:38:10+00:00\",\"author\":{\"@id\":\"https:\/\/craftcoders.app\/#\/schema\/person\/5ece49c0f004fa0def05eabd3e877f46\"},\"description\":\"In this post I describe my first experiences using the containerization tool Jib from Google to dockerize a Maven project.\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/craftcoders.app\/jib-introduction\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/craftcoders.app\/jib-introduction\/#primaryimage\",\"url\":\"https:\/\/craftcoders.app\/wp-content\/uploads\/2018\/07\/Bildschirmfoto-2019-02-03-um-17.41.33-768x638-1.png\",\"contentUrl\":\"https:\/\/craftcoders.app\/wp-content\/uploads\/2018\/07\/Bildschirmfoto-2019-02-03-um-17.41.33-768x638-1.png\",\"width\":768,\"height\":638},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/craftcoders.app\/#website\",\"url\":\"https:\/\/craftcoders.app\/\",\"name\":\"CraftCoders.app\",\"description\":\"Jira and Confluence apps\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/craftcoders.app\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/craftcoders.app\/#\/schema\/person\/5ece49c0f004fa0def05eabd3e877f46\",\"name\":\"Leon Gottschick\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/craftcoders.app\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/a3d3933320fa0864064ffa224e524439?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/a3d3933320fa0864064ffa224e524439?s=96&d=mm&r=g\",\"caption\":\"Leon Gottschick\"},\"url\":\"https:\/\/craftcoders.app\/author\/leon\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"A quick Introduction to Jib from Leon Gottschick - CraftCoders.app","description":"In this post I describe my first experiences using the containerization tool Jib from Google to dockerize a Maven project.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/craftcoders.app\/jib-introduction\/","og_locale":"en_US","og_type":"article","og_title":"A quick Introduction to Jib from Leon Gottschick - CraftCoders.app","og_description":"In this post I describe my first experiences using the containerization tool Jib from Google to dockerize a Maven project.","og_url":"https:\/\/craftcoders.app\/jib-introduction\/","og_site_name":"CraftCoders.app","article_published_time":"2018-07-16T19:34:46+00:00","article_modified_time":"2024-08-14T11:38:10+00:00","og_image":[{"width":768,"height":638,"url":"https:\/\/craftcoders.app\/wp-content\/uploads\/2018\/07\/Bildschirmfoto-2019-02-03-um-17.41.33-768x638-1.png","type":"image\/png"}],"author":"Leon Gottschick","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Leon Gottschick","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/craftcoders.app\/jib-introduction\/","url":"https:\/\/craftcoders.app\/jib-introduction\/","name":"A quick Introduction to Jib from Leon Gottschick - CraftCoders.app","isPartOf":{"@id":"https:\/\/craftcoders.app\/#website"},"primaryImageOfPage":{"@id":"https:\/\/craftcoders.app\/jib-introduction\/#primaryimage"},"image":{"@id":"https:\/\/craftcoders.app\/jib-introduction\/#primaryimage"},"thumbnailUrl":"https:\/\/craftcoders.app\/wp-content\/uploads\/2018\/07\/Bildschirmfoto-2019-02-03-um-17.41.33-768x638-1.png","datePublished":"2018-07-16T19:34:46+00:00","dateModified":"2024-08-14T11:38:10+00:00","author":{"@id":"https:\/\/craftcoders.app\/#\/schema\/person\/5ece49c0f004fa0def05eabd3e877f46"},"description":"In this post I describe my first experiences using the containerization tool Jib from Google to dockerize a Maven project.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/craftcoders.app\/jib-introduction\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/craftcoders.app\/jib-introduction\/#primaryimage","url":"https:\/\/craftcoders.app\/wp-content\/uploads\/2018\/07\/Bildschirmfoto-2019-02-03-um-17.41.33-768x638-1.png","contentUrl":"https:\/\/craftcoders.app\/wp-content\/uploads\/2018\/07\/Bildschirmfoto-2019-02-03-um-17.41.33-768x638-1.png","width":768,"height":638},{"@type":"WebSite","@id":"https:\/\/craftcoders.app\/#website","url":"https:\/\/craftcoders.app\/","name":"CraftCoders.app","description":"Jira and Confluence apps","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/craftcoders.app\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/craftcoders.app\/#\/schema\/person\/5ece49c0f004fa0def05eabd3e877f46","name":"Leon Gottschick","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/craftcoders.app\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/a3d3933320fa0864064ffa224e524439?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a3d3933320fa0864064ffa224e524439?s=96&d=mm&r=g","caption":"Leon Gottschick"},"url":"https:\/\/craftcoders.app\/author\/leon\/"}]}},"_links":{"self":[{"href":"https:\/\/craftcoders.app\/wp-json\/wp\/v2\/posts\/383"}],"collection":[{"href":"https:\/\/craftcoders.app\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/craftcoders.app\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/craftcoders.app\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/craftcoders.app\/wp-json\/wp\/v2\/comments?post=383"}],"version-history":[{"count":1,"href":"https:\/\/craftcoders.app\/wp-json\/wp\/v2\/posts\/383\/revisions"}],"predecessor-version":[{"id":2361,"href":"https:\/\/craftcoders.app\/wp-json\/wp\/v2\/posts\/383\/revisions\/2361"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/craftcoders.app\/wp-json\/wp\/v2\/media\/2360"}],"wp:attachment":[{"href":"https:\/\/craftcoders.app\/wp-json\/wp\/v2\/media?parent=383"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/craftcoders.app\/wp-json\/wp\/v2\/categories?post=383"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/craftcoders.app\/wp-json\/wp\/v2\/tags?post=383"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}