From 865f2a86ecb5c43b848880359279f6f484fda080 Mon Sep 17 00:00:00 2001 From: Ricardo Rosales <728243+missingcharacter@users.noreply.github.com> Date: Mon, 18 Sep 2023 11:18:38 -0500 Subject: [PATCH] [GitHub Actions] Added support for building and pushing container images to ghcr.io --- .github/workflows/build-docker-image.yml | 59 ++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 .github/workflows/build-docker-image.yml diff --git a/.github/workflows/build-docker-image.yml b/.github/workflows/build-docker-image.yml new file mode 100644 index 0000000..bf7651a --- /dev/null +++ b/.github/workflows/build-docker-image.yml @@ -0,0 +1,59 @@ +name: Docker image + +on: + workflow_dispatch: + pull_request: + push: + branches: + - main + +jobs: + generate-tag: + runs-on: windows-2022 + outputs: + image_tag: ${{ steps.gen-image-tag.outputs.image_tag }} + steps: + - uses: actions/checkout@v3 + - name: Generate image tag + shell: bash + id: gen-image-tag + run: | + if [ "${{ github.event_name }}" == "pull_request" ]; then + ref=PR-${{ github.event.number }} + # NOTE: we tag images with the head commit so they can be easily tagged/deployed, + # but on pull requests the image is actually built with the merge commit + head_commit=${{ github.event.pull_request.head.sha }} + else + ref=${{ github.ref_name }} + head_commit=${{ github.sha }} + fi + # for PRs: PR-11850.37.e7426df + # for push (develop/main/master): master.37.e7426df + echo "image_tag=${ref}.${{ github.run_number }}.$(echo ${head_commit} | cut -c1-7)" >> $GITHUB_OUTPUT + build-without-jdk: + needs: generate-tag + permissions: write-all + runs-on: windows-2022 + steps: + - uses: actions/checkout@v3 + - uses: mr-smithers-excellent/docker-build-push@v6 + with: + image: adf-shir + tags: ${{ needs.generate-tag.outputs.image_tag }} + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + build-with-jdk: + needs: generate-tag + permissions: write-all + runs-on: windows-2022 + steps: + - uses: actions/checkout@v3 + - uses: mr-smithers-excellent/docker-build-push@v6 + with: + image: adf-shir + tags: ${{ needs.generate-tag.outputs.image_tag }}-jdk11 + buildArgs: "INSTALL_JDK=true" + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }}