Mirror Docker Image to GHCR #5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Mirror Docker Image to GHCR | |
on: | |
workflow_dispatch: | |
inputs: | |
image_name: | |
description: 'Docker image name (e.g., myorg/myimage:tag)' | |
required: true | |
env: | |
REGISTRY: ghcr.io | |
jobs: | |
publish-to-ghcr: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: 'Set up skopeo' | |
uses: warjiang/[email protected] | |
with: | |
version: latest | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v1 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Validate image | |
run: | | |
IMAGE="${{ github.event.inputs.image_name }}" | |
if [[ "$IMAGE" == *.* ]]; then | |
echo "Image name contains a domain, exiting. Only short dockerhub image names are allowed" | |
exit 1 | |
fi | |
- name: Copy image to GHCR | |
env: | |
IMAGE: ${{ github.event.inputs.image_name }} | |
run: | | |
skopeo copy \ | |
--dest-creds="${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}" \ | |
"docker://${{ github.event.inputs.image_name }}" \ | |
"docker://${{ env.REGISTRY }}/1mgr/${{ github.event.inputs.image_name }}" |