From 5b3b2c328fd8cb78d73576e8486470a5b2cd1671 Mon Sep 17 00:00:00 2001 From: Asaph Irabaruta Date: Thu, 3 Oct 2024 10:02:55 +0200 Subject: [PATCH 1/3] push images to ghcr rather than dockerhub --- .github/workflows/publish-to-dockerhub.yml | 15 ++++++++------- docker-compose.yml | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.github/workflows/publish-to-dockerhub.yml b/.github/workflows/publish-to-dockerhub.yml index de27c9785..ba2d4aa68 100644 --- a/.github/workflows/publish-to-dockerhub.yml +++ b/.github/workflows/publish-to-dockerhub.yml @@ -1,5 +1,4 @@ -name: Publish image to Dockerhub - +name: Publish image to GitHub Container Registry on: push: branches: @@ -29,15 +28,17 @@ jobs: - name: Get tags run: git fetch --tags origin - - name: Login to DockerHub + - name: Login to GitHub Container Registry uses: docker/login-action@v3 with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_TOKEN }} + registry: ghcr.io + username: ${{ secrets.GH_USERNAME }} + password: ${{ secrets.GH_PAT}} + - name: Push image env: - DOCKERHUB_ACCOUNT: ${{ secrets.DOCKERHUB_ACCOUNT }} - DOCKERHUB_REPO: ${{ secrets.DOCKERHUB_REPO }} + GITHUB_ACCOUNT: ${{ secrets.GITHUB_ACCOUNT }} + GH_CONTAINER_REGISTRY_REPO: ${{ secrets.GH_CONTAINER_REGISTRY_REPO }} run: | # Check if the current commit has a tag and use it; otherwise, use the short SHA of the HEAD commit export COUNTRY_CONFIG_VERSION=$(git describe --tags --exact-match 2>/dev/null || git rev-parse --short=7 HEAD) diff --git a/docker-compose.yml b/docker-compose.yml index f7025fcab..2891fdc34 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,5 +8,5 @@ # Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. services: countryconfig: - image: ${DOCKERHUB_ACCOUNT}/${DOCKERHUB_REPO}:${COUNTRY_CONFIG_VERSION} + image: ghcr.io/${GITHUB_ACCOUNT}/${GH_CONTAINER_REGISTRY_REPO}:${COUNTRY_CONFIG_VERSION} build: . From 804177d66a61ad8a4f747c1d84ece5905bec15a4 Mon Sep 17 00:00:00 2001 From: Asaph Irabaruta Date: Thu, 10 Oct 2024 10:03:46 +0200 Subject: [PATCH 2/3] infering github account and repo using default environment variables github provides --- .github/workflows/publish-to-dockerhub.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/publish-to-dockerhub.yml b/.github/workflows/publish-to-dockerhub.yml index ba2d4aa68..361184380 100644 --- a/.github/workflows/publish-to-dockerhub.yml +++ b/.github/workflows/publish-to-dockerhub.yml @@ -28,17 +28,22 @@ jobs: - name: Get tags run: git fetch --tags origin + - name: Set GitHub account and container registry repo variables + run: | + echo "GITHUB_ACCOUNT=${GITHUB_REPOSITORY%%/*}" >> $GITHUB_ENV + echo "GH_CONTAINER_REGISTRY_REPO=${GITHUB_REPOSITORY#*/}" >> $GITHUB_ENV + - name: Login to GitHub Container Registry uses: docker/login-action@v3 with: registry: ghcr.io - username: ${{ secrets.GH_USERNAME }} + username: ${{ env.GITHUB_ACCOUNT }} password: ${{ secrets.GH_PAT}} - name: Push image env: - GITHUB_ACCOUNT: ${{ secrets.GITHUB_ACCOUNT }} - GH_CONTAINER_REGISTRY_REPO: ${{ secrets.GH_CONTAINER_REGISTRY_REPO }} + GITHUB_ACCOUNT: ${{ env.GITHUB_ACCOUNT }} + GH_CONTAINER_REGISTRY_REPO: ${{ env.GH_CONTAINER_REGISTRY_REPO }} run: | # Check if the current commit has a tag and use it; otherwise, use the short SHA of the HEAD commit export COUNTRY_CONFIG_VERSION=$(git describe --tags --exact-match 2>/dev/null || git rev-parse --short=7 HEAD) From 4b8c03ee2e0e279e7919961e9059121d580fb631 Mon Sep 17 00:00:00 2001 From: Asaph Irabaruta Date: Mon, 14 Oct 2024 09:36:47 +0200 Subject: [PATCH 3/3] Update publish-release workflow to push image to Github Container Registry --- .github/workflows/publish-release.yml | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index d03dd8251..849b06dbf 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -24,7 +24,10 @@ jobs: run: sudo apt-get install jq -y - name: Set TAG environment variable - run: echo "TAG=${{ github.event.inputs.release_version }}" >> $GITHUB_ENV + run: | + echo "TAG=${{ github.event.inputs.release_version }}" >> $GITHUB_ENV + echo "GITHUB_ACCOUNT=${GITHUB_REPOSITORY%%/*}" >> $GITHUB_ENV + echo "GH_CONTAINER_REGISTRY_REPO=${GITHUB_REPOSITORY#*/}" >> $GITHUB_ENV - uses: trstringer/manual-approval@v1 with: @@ -47,13 +50,14 @@ jobs: - name: Login to DockerHub uses: docker/login-action@v3 with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_TOKEN }} + registry: ghcr.io + username: ${{ env.GITHUB_ACCOUNT }} + password: ${{ secrets.GH_PAT}} - name: Push image env: - DOCKERHUB_ACCOUNT: ${{ secrets.DOCKERHUB_ACCOUNT }} - DOCKERHUB_REPO: ${{ secrets.DOCKERHUB_REPO }} + GITHUB_ACCOUNT: ${{ env.GITHUB_ACCOUNT }} + GH_CONTAINER_REGISTRY_REPO: ${{ env.GH_CONTAINER_REGISTRY_REPO }} run: | export COUNTRY_CONFIG_VERSION=${{ env.TAG }} echo "Publishing a Docker image with a tag $COUNTRY_CONFIG_VERSION"