|
| 1 | +# |
| 2 | +name: Create and publish a the Glance compatible image |
| 3 | + |
| 4 | +# Configures this workflow to run every time a change is pushed to the branch called `release`. |
| 5 | +on: |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + imageTag: |
| 9 | + description: 'Set tag for the image' |
| 10 | + required: true |
| 11 | + default: 'master-ubuntu_jammy' |
| 12 | + type: choice |
| 13 | + options: |
| 14 | + - master-ubuntu_jammy |
| 15 | + - 2023.1-ubuntu_jammy |
| 16 | + - 2023.2-ubuntu_jammy |
| 17 | + - 2024.1-ubuntu_jammy |
| 18 | + pluginTag: |
| 19 | + description: 'Set release used for the build environment' |
| 20 | + required: true |
| 21 | + default: 'master' |
| 22 | + type: choice |
| 23 | + options: |
| 24 | + - "master" |
| 25 | + - "2023.1" |
| 26 | + - "2023.2" |
| 27 | + - "2024.1" |
| 28 | + |
| 29 | +# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds. |
| 30 | +env: |
| 31 | + REGISTRY: ghcr.io |
| 32 | + IMAGE_NAME: ${{ github.repository }} |
| 33 | + |
| 34 | +# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu. |
| 35 | +jobs: |
| 36 | + build-and-push-image: |
| 37 | + outputs: |
| 38 | + MY_DATE: ${{ steps.mydate.outputs.MY_DATE }} |
| 39 | + MY_CONTAINER: ${{ steps.mycontainer.outputs.MY_CONTAINER }} |
| 40 | + runs-on: ubuntu-latest |
| 41 | + # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. |
| 42 | + permissions: |
| 43 | + contents: read |
| 44 | + packages: write |
| 45 | + steps: |
| 46 | + - name: Checkout repository |
| 47 | + uses: actions/checkout@v4 |
| 48 | + # Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here. |
| 49 | + - name: Log in to the Container registry |
| 50 | + uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 |
| 51 | + with: |
| 52 | + registry: ${{ env.REGISTRY }} |
| 53 | + username: ${{ github.actor }} |
| 54 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 55 | + # This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels. |
| 56 | + - name: Extract metadata (tags, labels) for Docker |
| 57 | + id: meta |
| 58 | + uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 |
| 59 | + with: |
| 60 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 61 | + # This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages. |
| 62 | + # It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository. |
| 63 | + # It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step. |
| 64 | + - name: Dynamically set MY_DATE environment variable |
| 65 | + run: echo "MY_DATE=$(date +%s)" >> $GITHUB_ENV |
| 66 | + - name: Build and push Docker image |
| 67 | + uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 |
| 68 | + with: |
| 69 | + context: . |
| 70 | + file: Containerfiles/Glance-Containerfile |
| 71 | + push: true |
| 72 | + tags: | |
| 73 | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/glance:${{ github.event.inputs.imageTag }} |
| 74 | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/glance:${{ github.event.inputs.imageTag }}-${{ env.MY_DATE }} |
| 75 | + labels: ${{ steps.meta.outputs.labels }} |
| 76 | + build-args: | |
| 77 | + VERSION=${{ github.event.inputs.imageTag }} |
| 78 | + PLUGIN_VERSION=${{ github.event.inputs.pluginTag }} |
| 79 | + - name: Dynamically set MY_CONTAINER output option |
| 80 | + id: mycontainer |
| 81 | + run: echo "MY_CONTAINER=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/glance:${{ github.event.inputs.imageTag }}-${{ env.MY_DATE }}" >> $GITHUB_OUTPUT |
| 82 | + - name: Dynamically set MY_DATE output option |
| 83 | + id: mydate |
| 84 | + run: echo "MY_DATE=${{ env.MY_DATE }}" >> $GITHUB_OUTPUT |
| 85 | + |
| 86 | + change-original-images: |
| 87 | + runs-on: ubuntu-latest |
| 88 | + needs: [build-and-push-image] |
| 89 | + permissions: |
| 90 | + contents: write |
| 91 | + pull-requests: write |
| 92 | + steps: |
| 93 | + - name: Checkout repository |
| 94 | + uses: actions/checkout@v4 |
| 95 | + - name: Dynamically update the original images file |
| 96 | + run: jq '. + ["${{ needs.build-and-push-image.outputs.MY_CONTAINER }}"] | sort' .original-images.json | tee .original-images.json.new |
| 97 | + - name: Rewrite original images file |
| 98 | + run: mv .original-images.json.new .original-images.json |
| 99 | + - name: Create Pull Request |
| 100 | + id: cpr |
| 101 | + uses: peter-evans/create-pull-request@v7 |
| 102 | + with: |
| 103 | + commit-message: Update original images with new container |
| 104 | + committer: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> |
| 105 | + author: ${{ github.actor }} <${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com> |
| 106 | + signoff: false |
| 107 | + branch: ${{ needs.build-and-push-image.outputs.MY_DATE }} |
| 108 | + sign-commits: true |
| 109 | + delete-branch: true |
| 110 | + title: 'chore: Update original images' |
| 111 | + body: | |
| 112 | + Update container image |
| 113 | + - Updated original image file with container ${{needs.build-and-push-image.outputs.MY_CONTAINER}} |
| 114 | + change request Auto-generated |
| 115 | + labels: | |
| 116 | + container images |
| 117 | + automated pr |
| 118 | + draft: false |
0 commit comments