Get Docker Image #32
This file contains hidden or 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: Get Docker Image | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| image_path: | |
| description: 'Full image path (e.g., docker.io/test/xxx:0.1.0)' | |
| required: true | |
| platform: | |
| description: 'Platform for the Docker image (e.g., linux/amd64, linux/arm64)' | |
| required: true | |
| jobs: | |
| pull-and-push: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v2 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Login to Alibaba Container Registry | |
| uses: docker/login-action@v2 | |
| with: | |
| registry: registry.cn-hangzhou.aliyuncs.com | |
| username: ${{ secrets.ACR_ACCOUNT }} | |
| password: ${{ secrets.ACR_PWD }} | |
| - name: Pull and Retag the Image | |
| run: | | |
| ORIGINAL_IMAGE="${{ github.event.inputs.image_path }}" | |
| PLATFORM="${{ github.event.inputs.platform }}" | |
| IMAGE_NAME=$(basename $ORIGINAL_IMAGE) | |
| # Pull the original image | |
| docker pull --platform $PLATFORM $ORIGINAL_IMAGE | |
| # Retag for GHCR | |
| NEW_IMAGE="ghcr.io/${{ github.repository_owner }}/${IMAGE_NAME}" | |
| docker tag $ORIGINAL_IMAGE $NEW_IMAGE | |
| echo "Image retagged from $ORIGINAL_IMAGE to $NEW_IMAGE for platform $PLATFORM" | |
| # Push to GHCR | |
| docker push $NEW_IMAGE | |
| # Retag for ACR | |
| NEW_IMAGE_ACR="registry.cn-hangzhou.aliyuncs.com/acrreg/${IMAGE_NAME}" | |
| docker tag $NEW_IMAGE $NEW_IMAGE_ACR | |
| # Push to ACR | |
| docker push $NEW_IMAGE_ACR | |