From eb2035517aa76e4d1dfced6d9f2d2363c85a7c09 Mon Sep 17 00:00:00 2001 From: Praveen Date: Fri, 4 Oct 2024 15:49:09 +0530 Subject: [PATCH 1/3] Pushing the image both in DockerHub and GitHub -GHCR.io in the develop branch --- .github/workflows/build-and-publish.yml | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build-and-publish.yml b/.github/workflows/build-and-publish.yml index 4237f6f..47b60aa 100644 --- a/.github/workflows/build-and-publish.yml +++ b/.github/workflows/build-and-publish.yml @@ -2,10 +2,12 @@ name: Build and Publish on: push: + branches: + - develop jobs: build-and-publish: - name: Build and Publish + name: Build and Publish Docker Image runs-on: ubuntu-latest steps: - name: Checkout code @@ -17,18 +19,25 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Log in to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Extract metadata (tags, labels) for Docker id: meta uses: docker/metadata-action@v5 with: - images: ${{ vars.DOCKER_ORG }}/${{ github.event.repository.name }} + images: | + ${{ vars.DOCKER_ORG }}/${{ github.event.repository.name }} + ghcr.io/${{ github.repository }} tags: | - type=ref,event=branch - type=ref,event=tag - # set latest tag for master branch - type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }} + type=ref,event=branch # Tag with branch name + type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'develop') }} - - name: Build and push Docker image + - name: Build and push Docker image to Docker Hub and GHCR uses: docker/build-push-action@v5 with: context: . From 3e40a0d8ced8ec1515ec4472066d335c7e7a3966 Mon Sep 17 00:00:00 2001 From: Praveen Date: Fri, 4 Oct 2024 15:51:20 +0530 Subject: [PATCH 2/3] Pushing the image both in DockerHub and GitHub -GHCR.io in the main branch --- .github/workflows/build-and-publish.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-and-publish.yml b/.github/workflows/build-and-publish.yml index 47b60aa..f6147fe 100644 --- a/.github/workflows/build-and-publish.yml +++ b/.github/workflows/build-and-publish.yml @@ -3,7 +3,7 @@ name: Build and Publish on: push: branches: - - develop + - main jobs: build-and-publish: @@ -35,7 +35,7 @@ jobs: ghcr.io/${{ github.repository }} tags: | type=ref,event=branch # Tag with branch name - type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'develop') }} + type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }} - name: Build and push Docker image to Docker Hub and GHCR uses: docker/build-push-action@v5 From 2da814e70d31d0fe355457cd5e01fb6f00749678 Mon Sep 17 00:00:00 2001 From: Praveen Date: Tue, 8 Oct 2024 12:03:49 +0530 Subject: [PATCH 3/3] updated the tags updated the tags and the versions --- .github/workflows/build-and-publish.yml | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build-and-publish.yml b/.github/workflows/build-and-publish.yml index f6147fe..31841cc 100644 --- a/.github/workflows/build-and-publish.yml +++ b/.github/workflows/build-and-publish.yml @@ -2,12 +2,12 @@ name: Build and Publish on: push: - branches: - - main + branches: [ 'main' ] # Trigger on push to 'main' + tags: [ '[0-9]+.[0-9]+.[0-9]+' ] # Trigger on version tags like '0.1.0' jobs: build-and-publish: - name: Build and Publish Docker Image + name: Build and Publish Docker image runs-on: ubuntu-latest steps: - name: Checkout code @@ -35,9 +35,15 @@ jobs: ghcr.io/${{ github.repository }} tags: | type=ref,event=branch # Tag with branch name - type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }} + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + # labels: | + # org.opencontainers.image.source=${{ github.repository }} + # org.opencontainers.image.revision=${{ github.sha }} + # org.opencontainers.image.created=${{ github.event.head_commit.timestamp }} - - name: Build and push Docker image to Docker Hub and GHCR + - name: Build and push Docker image to DockerHub and GHCR uses: docker/build-push-action@v5 with: context: .