|
| 1 | +# Copy images between registries |
| 2 | + |
| 3 | +Multi-platform images built using buildx can be copied from one registry to another without |
| 4 | +changing the image SHA using the [tag-push-action](https://github.com/akhilerm/tag-push-action). |
| 5 | + |
| 6 | +The following workflow will first push the image to dockerhub, run some tests using the images |
| 7 | +and then push to quay and ghcr |
| 8 | + |
| 9 | +```yaml |
| 10 | +name: ci |
| 11 | + |
| 12 | +on: |
| 13 | + push: |
| 14 | + branches: |
| 15 | + - 'master' |
| 16 | + |
| 17 | +jobs: |
| 18 | + docker: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + steps: |
| 21 | + - |
| 22 | + name: Checkout |
| 23 | + uses: actions/checkout@v2 |
| 24 | + - |
| 25 | + name: Set up QEMU |
| 26 | + uses: docker/setup-qemu-action@v1 |
| 27 | + - |
| 28 | + name: Set up Docker Buildx |
| 29 | + uses: docker/setup-buildx-action@v1 |
| 30 | + - # quay and ghcr logins for pushing image after testing |
| 31 | + name: Login to Quay Registry |
| 32 | + uses: docker/login-action@v1 |
| 33 | + with: |
| 34 | + registry: quay.io |
| 35 | + username: ${{ secrets.QUAY_USERNAME }} |
| 36 | + password: ${{ secrets.QUAY_TOKEN }} |
| 37 | + - |
| 38 | + name: Login to GitHub Container Registry |
| 39 | + uses: docker/login-action@v1 |
| 40 | + with: |
| 41 | + registry: ghcr.io |
| 42 | + username: ${{ github.repository_owner }} |
| 43 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 44 | + - |
| 45 | + name: Login to DockerHub |
| 46 | + uses: docker/login-action@v1 |
| 47 | + with: |
| 48 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 49 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 50 | + - |
| 51 | + name: Build and push |
| 52 | + uses: docker/build-push-action@v2 |
| 53 | + with: |
| 54 | + context: . |
| 55 | + platforms: linux/amd64,linux/arm64 |
| 56 | + push: true |
| 57 | + tags: | |
| 58 | + user/app:latest |
| 59 | + user/app:1.0.0 |
| 60 | + - # run tests using image from docker hub |
| 61 | + name: Run Tests |
| 62 | + run: make tests |
| 63 | + - # copy multiplatform image from dockerhub to quay and ghcr |
| 64 | + name: Push Image to multiple registries |
| 65 | + uses: akhilerm/tag-push-action@v1.0.0 |
| 66 | + with: |
| 67 | + src: docker.io/user/app:1.0.0 |
| 68 | + dst: | |
| 69 | + quay.io/user/app:latest |
| 70 | + quay.io/user/app:1.0.0 |
| 71 | + ghcr.io/user/app:latest |
| 72 | + ghcr.io/user/app:1.0.0 |
| 73 | +``` |
0 commit comments