Skip to content
name: Retag and Build Images to GHCR
on:
push:
branches:
- image-cicd
paths:
- '.original-images.yaml'
workflow_dispatch:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
prepare-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.prepare.outputs.matrix }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Tools
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
- 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
retag-images:
runs-on: ubuntu-latest
needs: prepare-matrix
strategy:
fail-fast: false
max-parallel: 3
matrix:
image: ${{ fromJson(needs.prepare-matrix.outputs.matrix) }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker
uses: docker/setup-buildx-action@v2
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Pull and retag
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 }}
- name: Logout from Docker
run: docker logout ${{ env.REGISTRY }}