Skip to content

Commit

Permalink
test 3
Browse files Browse the repository at this point in the history
  • Loading branch information
aedan committed Jan 3, 2025
1 parent a0e9a6e commit e434523
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 53 deletions.
95 changes: 45 additions & 50 deletions .github/workflows/image-pull-and-tag.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Retag and Build Images to GHCR
name: Migrate Images to GHCR

on:
push:
Expand All @@ -10,73 +10,68 @@ on:

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
prepare-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.prepare.outputs.matrix }}
migrate-images:
runs-on: ubuntu-22.04

steps:
- name: Checkout repository
uses: actions/checkout@v4
# Step 1: Checkout the repository to access the .original-images.yaml file
- name: Checkout code
uses: actions/checkout@v3

- name: Install Tools
# Step 2: Parse the .original-images.yaml file and set up the matrix
- name: Read images from .original-images.yaml
id: parse_images
run: |
sudo apt-get update && sudo apt-get install -y jq
sudo wget -O /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
sudo chmod +x /usr/local/bin/yq
IMAGES=$(yq '.images | join(",")' .original-images.yaml)
echo "images=$IMAGES" >> $GITHUB_ENV
- name: Read images from file
id: prepare
run: |
if [ ! -f .original-images.yaml ]; then
echo "File .original-images.yaml not found!"
exit 1
fi
images=$(yq '.[]' .original-images.yaml)
matrix=$(echo "$images" | jq -R -s -c 'split("\n") | map(select(length > 0) | {path: ., tag: "latest"})')
echo "matrix=$matrix" >> $GITHUB_OUTPUT
# Step 3: Set up a dynamic matrix for the images
- name: Set up matrix
uses: actions/github-script@v6
id: create_matrix
with:
script: |
const images = process.env.images.split(",");
return { matrix: { image: images } };
result-encoding: string

retag-images:
runs-on: ubuntu-latest
needs: prepare-matrix
# Define the matrix strategy dynamically
strategy:
fail-fast: false
max-parallel: 3
matrix:
image: ${{ fromJson(needs.prepare-matrix.outputs.matrix) }}
matrix: ${{ fromJson(steps.create_matrix.outputs.result).matrix }}

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Docker
uses: docker/setup-buildx-action@v2
# Step 4: Pull the image from the Source Registry
- name: Pull image from Source Registry
run: |
docker pull ${{ matrix.image }}
- name: Log in to the Container registry
# Step 5: Log in to GitHub Container Registry
- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Pull and retag
# Step 6: Retag the Image for GHCR
- name: Retag Image for GHCR
run: |
ORIGINAL_IMAGE=${{ matrix.image.path }}
TAGGED_IMAGE="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/$(basename ${ORIGINAL_IMAGE})"
docker pull $ORIGINAL_IMAGE
docker tag $ORIGINAL_IMAGE $TAGGED_IMAGE
echo "TAGGED_IMAGE=$TAGGED_IMAGE" >> $GITHUB_OUTPUT
- name: Push Docker Image
uses: macbre/push-to-ghcr@master
with:
image_name: ${{ steps.pull-and-retag.outputs.tagged_image }}
github_token: ${{ secrets.GITHUB_TOKEN }}
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="ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME_ONLY:$IMAGE_TAG"
- name: Logout from Docker
run: docker logout ${{ env.REGISTRY }}
echo "Retagging ${{ matrix.image }} to $GHCR_IMAGE"
docker tag ${{ matrix.image }} $GHCR_IMAGE
echo "GHCR_IMAGE=$GHCR_IMAGE" >> $GITHUB_ENV
# Step 7: Push the Retagged Image to GHCR
- name: Push to GHCR
uses: docker/build-push-action@v4
with:
push: true
tags: ${{ env.GHCR_IMAGE }}
load: true
7 changes: 4 additions & 3 deletions .original-images.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
- docker.io/openstackhelm/heat:2024.1-ubuntu_jammy
- docker.io/openstackhelm/glance:2024.1-ubuntu_jammy
#- docker.io/openstackhelm/ceph-config-helper:latest-ubuntu_jammy
images:
- docker.io/openstackhelm/heat:2024.1-ubuntu_jammy
- docker.io/openstackhelm/glance:2024.1-ubuntu_jammy
- docker.io/openstackhelm/ceph-config-helper:latest-ubuntu_jammy

0 comments on commit e434523

Please sign in to comment.