Fixes Publish to Github Packages (#18180)

1. Creates a publishPackages function in tools/release/release_utils.sh
2. Uses the publishPackages function in publish_release workflow

Fixes issue 18138

Signed-off-by: Nagesh Bansal <nageshbansal59@gmail.com>
Co-authored-by: Wang Yan <wangyan@vmware.com>
This commit is contained in:
Nageshbansal 2023-03-13 14:56:31 +05:30 committed by GitHub
parent 9b61d34c4c
commit 125daf9cdb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 2 deletions

View File

@ -58,7 +58,10 @@ jobs:
run: |
tar -zxf ${{ env.OFFLINE_PACKAGE_PATH }}
docker load -i ./harbor/harbor.${{ env.BASE_TAG }}.tar.gz
source tools/release/release_utils.sh && publishImages ${{ env.CUR_TAG }} ${{ env.BASE_TAG }} ${{ secrets.DOCKER_HUB_USERNAME }} ${{ secrets.DOCKER_HUB_PASSWORD }}
images="$(docker images --format "{{.Repository}}" --filter=reference='goharbor/*:${{ env.BASE_TAG }}' | xargs)"
source tools/release/release_utils.sh
publishImages ${{ env.CUR_TAG }} ${{ env.BASE_TAG }} ${{ secrets.DOCKER_HUB_USERNAME }} ${{ secrets.DOCKER_HUB_PASSWORD }} $images
publishPackages ${{ env.CUR_TAG }} ${{ env.BASE_TAG }} ${{ github.actor }} ${{ secrets.GITHUB_TOKEN }} $images
- name: Generate release notes
run: |
release_notes_path=$(pwd)/release-notes.txt

View File

@ -59,8 +59,8 @@ function publishImages {
local baseTag=$2
local dockerHubUser=$3
local dockerHubPassword=$4
local images=${@:5}
docker login -u $dockerHubUser -p $dockerHubPassword
local images="$(docker images --format "{{.Repository}}" --filter=reference='goharbor/*:'$baseTag'')"
for image in $images
do
echo "push image: $image"
@ -70,6 +70,22 @@ function publishImages {
docker logout
}
function publishPackages {
local curTag=$1
local baseTag=$2
local ghcrUser=$3
local ghcrPassword=$4
local images=${@:5}
docker login ghcr.io -u $ghcrUser -p $ghcrPassword
for image in $images
do
echo "push image: $image"
docker tag $image:$baseTag "ghcr.io/"$image:$curTag
retry 5 docker push "ghcr.io/"$image:$curTag
done
docker logout ghcr.io
}
function retry {
local -r -i max="$1"; shift
local -i n=1