Gradle Jib build

CustomDockerImage build with Gradle and Jib plugin

DockerImage component uses Kaniko to build the Docker images from a Dockerfile. For cases with other image building solutions you can use CustomDockerImage and run whatever commands you need.

Here is an example with CustomDockerImage component building an image from a Java app with Gradle and Jib plugin.

Gradle with Jib plugin

You can check the Gradle and Jib configuration in the repository https://github.com/bunnyshell/templates/tree/main/components/springboot-rest-api-gradle. All you need to do in the CustomDockerImage component is to pass the image name and push credentials to the Gradle command. See Custom Docker Image for $BNS_IMAGE_* environment variables.

kind: Environment
name: 'SpringBoot Gradle'
type: primary
components:
    -
        kind: CustomDockerImage
        name: api-image
        gitRepo: 'https://github.com/bunnyshell/templates.git'
        gitBranch: main
        gitApplicationPath: components/springboot-rest-api-gradle
        runnerImage: 'openjdk:17-jdk-alpine'
        build:
            - 'cd ./components/springboot-rest-api-gradle'
            - './gradlew :jib --image="$BNS_IMAGE_FULL_NAME" -Djib.to.auth.username="$BNS_IMAGE_REGISTRY_USERNAME" -Djib.to.auth.password="$BNS_IMAGE_REGISTRY_PASSWORD"'
    -
        kind: Application
        name: api
        gitRepo: 'https://github.com/bunnyshell/templates.git'
        gitBranch: main
        gitApplicationPath: components/springboot-rest-api-gradle
        dockerCompose:
            image: '{{ components.api-image.image }}'
            environment:
                DATABASE_DBNAME: bunny_books
                DATABASE_HOST: db
                DATABASE_PASSWORD: need-to-replace
                DATABASE_PORT: '3306'
                DATABASE_USER: books
                FRONTEND_URL: 'https://{{ components.frontend.ingress.hosts[0].hostname }}'
            ports:
                - '9000:9000'
        hosts:
            -
                hostname: 'api-{{ env.base_domain }}'
                path: /
                servicePort: 9000
        dependsOn:
            - api-image

Then you use the built image in another component, like an Application in the example, using the interpolation expression.