diff --git a/.github/workflows/java-gradle-docker.yaml b/.github/workflows/java-gradle-docker.yaml index db7ab6f1d..287b9ee22 100644 --- a/.github/workflows/java-gradle-docker.yaml +++ b/.github/workflows/java-gradle-docker.yaml @@ -13,6 +13,11 @@ on: required: false type: string default: "docker.io" + platforms: + description: "Architectures for the created image (comma separated)" + required: false + default: "linux/amd64,linux/arm64" + type: string java-distribution: description: "Java distribution to be installed. (Default is microsoft)" required: false @@ -105,13 +110,21 @@ jobs: sonar-token: ${{ secrets.sonar-token }} build-jib: - name: Build tarball image + name: Build Docker image runs-on: ubuntu-22.04 needs: build-and-test steps: - - name: Build tarball image - uses: bakdata/ci-templates/actions/java-gradle-build-jib@1.49.0 + - name: Login into docker + uses: docker/login-action@v3 + with: + registry: ${{ inputs.docker-registry }} + username: ${{ secrets.docker-username }} + password: ${{ secrets.docker-password }} + + - name: Jib build + id: build-image + uses: bakdata/ci-templates/actions/java-gradle-build-jib@1.55.0 with: java-distribution: ${{ inputs.java-distribution }} java-version: ${{ inputs.java-version }} @@ -120,6 +133,8 @@ jobs: gradle-cache-read-only: true gradle-refresh-dependencies: ${{ inputs.gradle-refresh-dependencies }} working-directory: ${{ inputs.working-directory }} + repository: ${{ inputs.docker-registry }}/${{ inputs.docker-publisher }} + platforms: ${{ inputs.platforms }} publish: name: Publish @@ -143,29 +158,11 @@ jobs: gradle-refresh-dependencies: ${{ inputs.gradle-refresh-dependencies }} working-directory: ${{ inputs.working-directory }} - publish-jib-image: - name: Publish tarball image - runs-on: ubuntu-22.04 - needs: build-jib - - steps: - - name: Login into docker - uses: docker/login-action@v3 - with: - registry: ${{ inputs.docker-registry }} - username: ${{ secrets.docker-username }} - password: ${{ secrets.docker-password }} - - name: Publish tarball image - uses: bakdata/ci-templates/actions/docker-publish@1.49.0 - with: - docker-registry: ${{ inputs.docker-registry }} - image-namespace: ${{ inputs.docker-publisher }} - release: name: Create Github release if: startsWith(github.ref, 'refs/tags/') runs-on: ubuntu-22.04 - needs: [publish, publish-jib-image] + needs: [publish, build-jib] steps: - name: Release on Github diff --git a/actions/java-gradle-build-jib/action.yaml b/actions/java-gradle-build-jib/action.yaml index 11863a10c..3b2f2d5d7 100644 --- a/actions/java-gradle-build-jib/action.yaml +++ b/actions/java-gradle-build-jib/action.yaml @@ -4,7 +4,7 @@ description: "Build Multi-Platform image using Gradle" outputs: image-tag: description: "The tag of the docker image." - value: ${{ steps.meta.outputs.tags }} + value: ${{ steps.tag.outputs.name }} inputs: platforms: @@ -12,13 +12,9 @@ inputs: required: false default: "linux/amd64,linux/arm64" type: string - image-name: - description: "Name of Docker image." + repository: + description: "The repository to push the image to" required: false - default: "${{ github.event.repository.name }}" - full-image-name: - description: "Full name of image (registry/image). The image should be provided without a tag." - required: true allow-insecure-registries: description: "Whether to allow insecure registries or not. (Default is false)" required: false @@ -61,9 +57,6 @@ inputs: description: "Whether the Git checkout action should resolve LFS files or not. (Default is false)" required: false default: "false" - subproject: - description: "The Gradle subproject for which the image should be built (If not specified, an image for the root project will be built)" - required: false runs: using: "composite" steps: @@ -85,22 +78,28 @@ runs: id: meta uses: docker/metadata-action@v5 with: - images: ${{ inputs.image-name }} + images: ${{ github.event.repository.name }} tags: | event=tag,type=semver,pattern={{version}} event=push,type=raw,value=pipeline-${{ github.run_id }}-git-{{sha}},enable=${{ github.ref_type != 'tag' }} flavor: | latest=false + - name: Create tag output + id: tag + run: echo "name=$(echo ${{ steps.meta.outputs.tags }} | sed 's/.*:\(.*\)/\1/')" >> "$GITHUB_OUTPUT" + shell: bash + working-directory: ${{ inputs.working-directory }} + - name: Build Docker image run: | - ./gradlew ${{ inputs.subproject && format('{0}:', inputs.subproject) || '' }}jib \ + ./gradlew jib \ --info --stacktrace \ - --image=${{ inputs.image-name }} \ -Djib.from.platforms=${{ inputs.platforms }} \ ${{ inputs.jib-from-image && format('-Djib.from.image={0}', inputs.jib-from-image) || '' }} \ ${{ inputs.class && format('-Djib.container.mainClass={0}', inputs.class) || '' }} \ - -Djib.to.image=${{ inputs.full-image-name }}$(echo ${{ steps.meta.outputs.tags }} | sed 's/.*\(:.*\)/\1/') \ + ${{ inputs.repository && format('-DjibImage.repository={0}', inputs.repository) || '' }} \ + -DjibImage.tag=${{ steps.tag.outputs.name }} \ $([[ "${{ github.ref_type }}" == "tag" ]] && echo "-Djib.to.tags=latest") \ ${{ inputs.gradle-refresh-dependencies == 'true' && '--refresh-dependencies' || '' }} \ ${{ inputs.allow-insecure-registries == 'true' && '-Djib.allowInsecureRegistries=true' || '' }} diff --git a/docs/actions/java-gradle-build-jib/README.md b/docs/actions/java-gradle-build-jib/README.md index 9d97446e6..6b92155cc 100644 --- a/docs/actions/java-gradle-build-jib/README.md +++ b/docs/actions/java-gradle-build-jib/README.md @@ -9,17 +9,15 @@ | allow-insecure-registries | string | false | `"false"` | Whether to allow insecure registries or not. (Default is false) | | class | string | false | | The entrypoint class to be used for the image | | download-lfs-files | string | false | `"false"` | Whether the Git checkout action should resolve LFS files or not. (Default is false) | -| full-image-name | string | true | | Full name of image (registry/image). The image should be provided without a tag. | | gradle-cache | string | false | `"true"` | Whether Gradle caching is enabled or not. (Default is true) | | gradle-cache-read-only | string | false | `"${{ github.event.repository != null && github.ref_name != github.event.repository.default_branch }}"` | Whether Gradle caching should be read-only. By default this value is 'false' for workflows on the GitHub default branch and 'true' for workflows on other branches. | | gradle-refresh-dependencies | string | false | `"false"` | Whether Gradle should refresh dependencies. (Default is false) | | gradle-version | string | false | `"wrapper"` | Gradle version to be installed. (Default is wrapper) | -| image-name | string | false | `"${{ github.event.repository.name }}"` | Name of Docker image. | | java-distribution | string | false | `"microsoft"` | Java distribution to be installed. (Default is microsoft) | | java-version | string | false | `"11"` | Java version to be installed. (Default is 11) | | jib-from-image | string | false | | The Jib base image to use | | platforms | string | false | `"linux/amd64,linux/arm64"` | Architectures for the created image (comma separated) | -| subproject | string | false | | The Gradle subproject for which the image should be built (If not specified, an image for the root project will be built) | +| repository | string | false | | The repository to push the image to | | working-directory | string | false | `"."` | Working directory of your Gradle artifacts. (Default is .) | diff --git a/docs/workflows/java-gradle-docker/README.md b/docs/workflows/java-gradle-docker/README.md index 18f9d30a0..54afb943a 100644 --- a/docs/workflows/java-gradle-docker/README.md +++ b/docs/workflows/java-gradle-docker/README.md @@ -58,17 +58,18 @@ jobs: -| INPUT | TYPE | REQUIRED | DEFAULT | DESCRIPTION | -| --------------------------- | ------- | -------- | ------------- | ------------------------------------------------------------------------------------------------- | -| docker-publisher | string | true | | Publisher to prefix Docker image. | -| docker-registry | string | false | `"docker.io"` | Host where the image should be pushed to. | -| gradle-cache | boolean | false | `true` | Whether Gradle caching is enabled or not. (Default is true) | -| gradle-cache-read-only | boolean | false | `false` | Whether Gradle caching should be read-only. Only used for build and test jobs. (Default is false) | -| gradle-refresh-dependencies | boolean | false | `false` | Whether Gradle should refresh dependencies. (Default is false) | -| gradle-version | string | false | `"wrapper"` | Gradle version to be installed. (Default is wrapper) | -| java-distribution | string | false | `"microsoft"` | Java distribution to be installed. (Default is microsoft) | -| java-version | string | false | `"11"` | Java version to be installed. (Default is 11) | -| working-directory | string | false | `"."` | Working directory of your Gradle artifacts. (Default is .) | +| INPUT | TYPE | REQUIRED | DEFAULT | DESCRIPTION | +| --------------------------- | ------- | -------- | --------------------------- | ------------------------------------------------------------------------------------------------- | +| docker-publisher | string | true | | Publisher to prefix Docker image. | +| docker-registry | string | false | `"docker.io"` | Host where the image should be pushed to. | +| gradle-cache | boolean | false | `true` | Whether Gradle caching is enabled or not. (Default is true) | +| gradle-cache-read-only | boolean | false | `false` | Whether Gradle caching should be read-only. Only used for build and test jobs. (Default is false) | +| gradle-refresh-dependencies | boolean | false | `false` | Whether Gradle should refresh dependencies. (Default is false) | +| gradle-version | string | false | `"wrapper"` | Gradle version to be installed. (Default is wrapper) | +| java-distribution | string | false | `"microsoft"` | Java distribution to be installed. (Default is microsoft) | +| java-version | string | false | `"11"` | Java version to be installed. (Default is 11) | +| platforms | string | false | `"linux/amd64,linux/arm64"` | Architectures for the created image (comma separated) | +| working-directory | string | false | `"."` | Working directory of your Gradle artifacts. (Default is .) |