GoogleContainerTools / jib

🏗 Build container images for your Java applications.
Apache License 2.0
13.61k stars 1.43k forks source link

Add missing simple documentation for how to use JIB on Google Cloud Build in README #3545

Closed vorburger closed 1 year ago

vorburger commented 2 years ago

Background: I'm looking into https://github.com/vorburger/www.fineract.dev/issues/11 and need to convert a Google Cloud Build YAML configuration which used to "just work" for an open source project which used to have a Dockerfile and was switched to JIB by a contributor.

In an ideal world, it would be neat if I could just Ctrl-F for "Google Cloud Build" on the JIB README and it would tell me what I need to do.

Would you accept to review and merge a Pull Request with some addendum to the doc for this?

vorburger commented 2 years ago

It seems like nowadaways this is as simple as shown e.g. in https://github.com/GoogleCloudPlatform/air-draw-demo/blob/master/cloudbuild.yaml? That seems wortwhile (even only very succintly) mentioning on the README.

vorburger commented 2 years ago

The non-availability of gcr.io/cloud-builders/javac:17 (nor :11, only :8) can be a "show stopper" for using JIB from Google Cloud Build for some projects.

vorburger commented 2 years ago

The non-availability of gcr.io/cloud-builders/javac:17 (nor :11, only :8) can be a "show stopper" for using JIB from Google Cloud Build for some projects.

This is wrong, as per this discussion, one CAN use other Java container images.

But a ./gradlew in gcr.io/distroless/java17-debian11:debug fails with:

Step #1: standard_init_linux.go:228: exec user process caused: no such file or directory

but using (e.g.) docker.io/library/eclipse-temurin:17 for https://hub.docker.com/_/eclipse-temurin/ from https://adoptium.net works, as do presumably a number of other JDK container images, such as azul/zulu-openjdk-alpine:17 (not tested).

Would a PR with something about this added to the README be welcome?

@jamesward FYI

jamesward commented 2 years ago

Oh, right. I forgot that the distroless images are based on busybox so you have to do something like:

  - id: 'test'
    name: 'gcr.io/distroless/java:8-debug'
    entrypoint: '/busybox/sh'
    args:
      - -c
      - |
        ln -s /busybox/sh /bin/sh
        ./gradlew --console=plain --no-daemon --gradle-user-home=/home/.gradle test

Or maybe:

- id: 'build-image'
    name: 'gcr.io/distroless/java:8-debug'
    entrypoint: '/busybox/sh'
    args:
      - -c
      - |
        ln -s /busybox/env /usr/bin/env
        /workspace/gradlew --console=plain --no-daemon --gradle-user-home=/home/.gradle bootBuildImage --imageName=gcr.io/$PROJECT_ID/$REPO_NAME:$COMMIT_SHA

A non-Jib example that might be helpful: https://github.com/jamesward/spring-kotlin-postgres/blob/c50c5cdff58970c2fb6249a020e2eb8136478ef3/cloudbuild.yaml

meltsufin commented 2 years ago

@vorburger Please let us know or contribute the documentation update once you test out the suggested options. Thanks!