From 3d554a890809be78dab906c889354457a9323a72 Mon Sep 17 00:00:00 2001
From: Lukasz Dorau <lukasz.dorau@intel.com>
Date: Fri, 9 Oct 2020 21:54:02 +0200
Subject: [PATCH] common: migrate from Docker Hub to GitHub Container Registry

---
 .github/workflows/coverity.yml        |  4 +++-
 .github/workflows/gha.yml             |  6 +++---
 .travis.yml                           |  2 +-
 utils/docker/README                   |  4 ++--
 utils/docker/build-local.sh           |  2 +-
 utils/docker/images/push-image.sh     | 14 +++++++-------
 utils/docker/pull-or-rebuild-image.sh | 19 ++++++++++++-------
 7 files changed, 29 insertions(+), 22 deletions(-)

diff --git a/.github/workflows/coverity.yml b/.github/workflows/coverity.yml
index 4e942f7bf..ca85df500 100644
--- a/.github/workflows/coverity.yml
+++ b/.github/workflows/coverity.yml
@@ -8,7 +8,9 @@ on:
 
 env:
   GITHUB_REPO: pmem/pmdk
-  DOCKER_REPO: pmem/pmdk
+  DOCKER_REPO: ghcr.io/pmem/pmdk
+  GH_CR_USER:  ${{ secrets.GH_CR_USER }}
+  GH_CR_PAT:   ${{ secrets.GH_CR_PAT }}
   COVERITY_SCAN_NOTIFICATION_EMAIL:  ${{ secrets.COVERITY_SCAN_NOTIFICATION_EMAIL }}
   COVERITY_SCAN_TOKEN:               ${{ secrets.COVERITY_SCAN_TOKEN }}
   HOST_WORKDIR:   /home/runner/work/pmdk/pmdk
diff --git a/.github/workflows/gha.yml b/.github/workflows/gha.yml
index dfdaf281b..e8861597e 100644
--- a/.github/workflows/gha.yml
+++ b/.github/workflows/gha.yml
@@ -4,15 +4,15 @@ on: [push, pull_request]
 
 env:
     GITHUB_REPO: pmem/pmdk
-    DOCKER_REPO: pmem/pmdk
+    DOCKER_REPO: ghcr.io/pmem/pmdk
+    GH_CR_USER:  ${{ secrets.GH_CR_USER }}
+    GH_CR_PAT:   ${{ secrets.GH_CR_PAT }}
 
 jobs:
   linux:
     name: Linux
     runs-on: ubuntu-latest
     env:
-      DOCKERHUB_USER:          ${{ secrets.DOCKERHUB_USER }}
-      DOCKERHUB_PASSWORD:      ${{ secrets.DOCKERHUB_PASSWORD }}
       DOC_UPDATE_GITHUB_TOKEN: ${{ secrets.DOC_UPDATE_GITHUB_TOKEN }}
       HOST_WORKDIR:   /home/runner/work/pmdk/pmdk
       WORKDIR:        utils/docker
diff --git a/.travis.yml b/.travis.yml
index e5de2ab16..d1af3b155 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -11,7 +11,7 @@ services:
 env:
   global:
     - GITHUB_REPO=pmem/pmdk
-    - DOCKER_REPO=pmem/pmdk
+    - DOCKER_REPO=ghcr.io/pmem/pmdk
     - OS=ubuntu
     - OS_VER=19.10
     - MAKE_PKG=0
diff --git a/utils/docker/README b/utils/docker/README
index b4a271359..57c3a7d3e 100644
--- a/utils/docker/README
+++ b/utils/docker/README
@@ -15,5 +15,5 @@ subdirectory and then do git-rebase before pushing your commits to the
 repository, make sure that you do not squash the commit which is the head in
 your repository. This will let Travis and GitHub Actions CIs recreate
 Docker images used during the build before the build. Otherwise the not-updated
-Docker image will be pulled from the Docker Hub and used during the build on
-Travis and GitHub Actions CIs.
+Docker image will be pulled from GitHub Container Registry and used during
+the build on Travis and GitHub Actions CIs.
diff --git a/utils/docker/build-local.sh b/utils/docker/build-local.sh
index f80550175..fea48b014 100755
--- a/utils/docker/build-local.sh
+++ b/utils/docker/build-local.sh
@@ -34,7 +34,7 @@ export PMDK_CC=${PMDK_CC:-gcc}
 export PMDK_CXX=${PMDK_CXX:-g++}
 export EXPERIMENTAL=${EXPERIMENTAL:-n}
 export VALGRIND=${VALGRIND:-1}
-export DOCKER_REPO=${DOCKER_REPO:-pmem/pmdk}
+export DOCKER_REPO=${DOCKER_REPO:-ghcr.io/pmem/pmdk}
 export GITHUB_REPO=${GITHUB_REPO:-pmem/pmdk}
 
 if [[ -z "$OS" || -z "$OS_VER" ]]; then
diff --git a/utils/docker/images/push-image.sh b/utils/docker/images/push-image.sh
index 77292d4cc..a7bd4cc7c 100755
--- a/utils/docker/images/push-image.sh
+++ b/utils/docker/images/push-image.sh
@@ -3,11 +3,11 @@
 # Copyright 2016-2020, Intel Corporation
 
 #
-# push-image.sh - pushes the Docker image to the Docker Hub.
+# push-image.sh - pushes the Docker image to GitHub Container Registry.
 #
-# The script utilizes $DOCKERHUB_USER and $DOCKERHUB_PASSWORD variables
-# to log in to Docker Hub. The variables can be set in the Travis project's
-# configuration for automated builds.
+# The script utilizes $GH_CR_USER and $GH_CR_PAT variables
+# to log in to GitHub Container Registry. The variables can be set
+# in the Travis project's configuration for automated builds.
 #
 
 set -e
@@ -44,8 +44,8 @@ then
 	exit 1
 fi
 
-# Log in to the Docker Hub
-docker login -u="$DOCKERHUB_USER" -p="$DOCKERHUB_PASSWORD"
+# Log in to GitHub Container Registry
+docker login https://ghcr.io -u="$GH_CR_USER" -p="$GH_CR_PAT"
 
-# Push the image to the repository
+# Push the image to GitHub Container Registry
 docker push ${DOCKER_REPO}:${TAG}
diff --git a/utils/docker/pull-or-rebuild-image.sh b/utils/docker/pull-or-rebuild-image.sh
index 79c63ad16..8ce16ae4b 100755
--- a/utils/docker/pull-or-rebuild-image.sh
+++ b/utils/docker/pull-or-rebuild-image.sh
@@ -12,11 +12,11 @@
 #
 # If the Travis build is not of the "pull_request" type (i.e. in case of
 # merge after pull_request) and it succeed, the Docker image should be pushed
-# to the Docker Hub repository. An empty file is created to signal that to
-# further scripts.
+# to GitHub Container Registry repository. An empty file is created to signal
+# that to further scripts.
 #
 # If the Docker image does not have to be rebuilt, it will be pulled from
-# Docker Hub.
+# GitHub Container Registry.
 #
 
 set -e
@@ -82,7 +82,7 @@ for file in $files; do
 		./build-image.sh ${OS}-${OS_VER} ${CI_CPU_ARCH}
 		popd
 
-		# Check if the image has to be pushed to Docker Hub
+		# Check if the image has to be pushed to GitHub Container Registry
 		# (i.e. the build is triggered by commits to the $GITHUB_REPO
 		# repository's stable-* or master branch, and the Travis build is not
 		# of the "pull_request" type). In that case, create the empty
@@ -92,10 +92,10 @@ for file in $files; do
 			&& $CI_EVENT_TYPE != "pull_request" \
 			&& $PUSH_IMAGE == "1" ]]
 		then
-			echo "The image will be pushed to Docker Hub"
+			echo "The image will be pushed to GitHub Container Registry"
 			touch $CI_FILE_PUSH_IMAGE_TO_REPO
 		else
-			echo "Skip pushing the image to Docker Hub"
+			echo "Skip pushing the image to GitHub Container Registry"
 		fi
 
 		if [[ $PUSH_IMAGE == "1" ]]
@@ -108,5 +108,10 @@ for file in $files; do
 done
 
 # Getting here means rebuilding the Docker image is not required.
-# Pull the image from Docker Hub.
+# The image will be pulled from GitHub Container Registry.
+
+# Log in to GitHub Container Registry
+docker login https://ghcr.io -u="$GH_CR_USER" -p="$GH_CR_PAT"
+
+# Pull the image from GitHub Container Registry.
 docker pull ${DOCKER_REPO}:1.10-${OS}-${OS_VER}-${CI_CPU_ARCH}
-- 
GitLab