From 6610737b17ed991ea604b61253cd0b767ef0af06 Mon Sep 17 00:00:00 2001 From: zJ <19760191+zJuuu@users.noreply.github.com> Date: Fri, 14 Jun 2024 16:42:19 +0200 Subject: [PATCH 1/2] build docker image on new release --- .github/workflows/publish-ghcr.yml | 43 ++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 .github/workflows/publish-ghcr.yml diff --git a/.github/workflows/publish-ghcr.yml b/.github/workflows/publish-ghcr.yml new file mode 100644 index 0000000..d3d4ada --- /dev/null +++ b/.github/workflows/publish-ghcr.yml @@ -0,0 +1,43 @@ +# +name: Create and publish a Docker image + +on: + workflow_dispatch: + + release: + types: [published] + +# Defines three 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. +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + VERSION: ${{ github.sha }} + +# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu. +jobs: + build-and-push-image-normal: + runs-on: ubuntu-latest + # Sets the permissions granted to the `GH_PAT` for the actions in this job. + permissions: + contents: read + packages: write + # + steps: + - name: Checkout repository + uses: actions/checkout@v4 + # 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. + - name: Log in to the Container registry + uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GH_PAT }} + - name: lowercase github.repository + run: | + echo "IMAGE_NAME=`echo ${{github.repository}} | tr '[:upper:]' '[:lower:]'`" >>${GITHUB_ENV} + - name: Build and push Docker image + uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 + with: + context: . + push: true + tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }} \ No newline at end of file From ea1c4bed569f0227651aeec356c02f1ad3531492 Mon Sep 17 00:00:00 2001 From: zJ <19760191+zJuuu@users.noreply.github.com> Date: Mon, 17 Jun 2024 14:28:18 +0200 Subject: [PATCH 2/2] update versions and use release tag as version --- .github/workflows/publish-ghcr.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/publish-ghcr.yml b/.github/workflows/publish-ghcr.yml index d3d4ada..dbada29 100644 --- a/.github/workflows/publish-ghcr.yml +++ b/.github/workflows/publish-ghcr.yml @@ -7,11 +7,10 @@ on: release: types: [published] -# Defines three 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. +# Defines environment variables for the workflow. These are used for the Container registry domain, and a version for the Docker image that this workflow builds. env: REGISTRY: ghcr.io - IMAGE_NAME: ${{ github.repository }} - VERSION: ${{ github.sha }} + VERSION: ${{ github.ref_name }} # There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu. jobs: @@ -21,13 +20,12 @@ jobs: permissions: contents: read packages: write - # steps: - name: Checkout repository uses: actions/checkout@v4 # 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. - name: Log in to the Container registry - uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 + uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} @@ -36,8 +34,9 @@ jobs: run: | echo "IMAGE_NAME=`echo ${{github.repository}} | tr '[:upper:]' '[:lower:]'`" >>${GITHUB_ENV} - name: Build and push Docker image - uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 + uses: docker/build-push-action@v6 with: context: . + file: ./Dockerfile push: true tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }} \ No newline at end of file