Skip to content

test 5

test 5 #10

name: Migrate Images to GHCR
on:
push:
branches:
- image-cicd
paths:
- '.original-images.yaml'
workflow_dispatch:
env:
REGISTRY: ghcr.io
jobs:
setup-matrix:
runs-on: ubuntu-22.04
outputs:
matrix: ${{ steps.create_matrix.outputs.matrix }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Read images from .original-images.yaml
id: parse_images
run: |
IMAGES=$(yq '.images | join(",")' .original-images.yaml)
echo "matrix=$(echo $IMAGES | jq -R -s -c 'split(",")')" >> $GITHUB_ENV
- name: Create matrix
id: create_matrix
run: |
echo "::set-output name=matrix::$(echo $IMAGES | jq -R -s -c 'split(",")')"
migrate-images:
needs: setup-matrix
runs-on: ubuntu-22.04
strategy:
fail-fast: false
max-parallel: 3
matrix:
image: ${{ fromJson(needs.setup-matrix.outputs.matrix) }}
steps:
- name: Pull image from Source Registry
run: |
docker pull ${{ matrix.image }}
- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Retag Image for GHCR
run: |
IMAGE_FULL="${{ matrix.image }}"
IMAGE_NAME_WITH_TAG="${IMAGE_FULL#*/}" # Remove registry prefix
IMAGE_NAME_ONLY="$(echo $IMAGE_NAME_WITH_TAG | cut -d/ -f2 | cut -d: -f1)" # Extract image name
IMAGE_TAG="$(echo $IMAGE_NAME_WITH_TAG | cut -d: -f2)" # Extract tag
GHCR_IMAGE="${{ env.REGISTRY }}/${{ github.repository_owner }}/$IMAGE_NAME_ONLY:$IMAGE_TAG"
echo "Retagging ${{ matrix.image }} to $GHCR_IMAGE"
docker tag ${{ matrix.image }} $GHCR_IMAGE
echo "GHCR_IMAGE=$GHCR_IMAGE" >> $GITHUB_ENV
- name: Push to GHCR
uses: docker/build-push-action@v4
with:
push: true
tags: ${{ env.GHCR_IMAGE }}
load: true