Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pushing docker images to GitHub Container Registry rather than DockerHub #291

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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"
Expand Down
20 changes: 13 additions & 7 deletions .github/workflows/publish-to-dockerhub.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
name: Publish image to Dockerhub

name: Publish image to GitHub Container Registry
on:
push:
branches:
Expand Down Expand Up @@ -29,15 +28,22 @@ jobs:
- name: Get tags
run: git fetch --tags origin

- name: Login to DockerHub
- 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:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
registry: ghcr.io
username: ${{ env.GITHUB_ACCOUNT }}
password: ${{ secrets.GH_PAT}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could replace this with GH_TOKEN too which is currently collected from the developer as part of the "setup environment" script 🤔

https://github.com/opencrvs/opencrvs-countryconfig/blob/develop/infrastructure/environments/setup-environment.ts#L271-L282

Suggested change
password: ${{ secrets.GH_PAT}}
password: ${{ secrets.GH_TOKEN}}


- 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: |
# 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)
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: .