-
Notifications
You must be signed in to change notification settings - Fork 36
71 lines (59 loc) · 1.96 KB
/
image-pull-and-tag.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
name: Migrate Images to GHCR
on:
push:
branches:
- image-cicd
paths:
- '.original-images.json'
workflow_dispatch:
env:
REGISTRY: ghcr.io
jobs:
setup-matrix:
runs-on: ubuntu-22.04
outputs:
matrix: ${{ steps.parse-json.outputs.matrix }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Read images from .original-images.json
id: parse-json
run: |
IMAGES=$(jq -c '.[]' < .original-images.json | jq -Rs 'split("\n")[:-1]')
# echo "matrix=$IMAGES" >> $GITHUB_OUTPUT
echo "matrix=$IMAGES"
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: |
echo "Pulling image: ${{ matrix.image }}"
docker pull ${{ matrix.image }}
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
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@v6
with:
push: true
tags: ${{ env.GHCR_IMAGE }}
load: true