2121
2222env :
2323 # Use docker.io for Docker Hub if empty
24- REGISTRY : ghcr.io
24+ GITHUB_REGISTRY : ghcr.io
25+ DOCKER_REGISTRY : docker.io
2526 # github.repository as <account>/<repo>
2627 IMAGE_NAME : ${{ github.repository }}
2728
4546 fi
4647
4748 # Push image to GitHub Packages.
48- push :
49+ push-to-github-packages :
4950
5051 # Ensure test job passes before pushing image.
5152 needs : test
@@ -67,11 +68,11 @@ jobs:
6768
6869 # Login against a Docker registry except on PR
6970 # https://github.com/docker/login-action
70- - name : Log into registry ${{ env.REGISTRY }}
71+ - name : Log into registry ${{ env.GITHUB_REGISTRY }}
7172 if : github.event_name != 'pull_request'
7273 uses : docker/login-action@v1
7374 with :
74- registry : ${{ env.REGISTRY }}
75+ registry : ${{ env.GITHUB_REGISTRY }}
7576 username : ${{ github.actor }}
7677 password : ${{ secrets.GITHUB_TOKEN }}
7778
8182 id : meta
8283 uses : docker/metadata-action@v3
8384 with :
84- images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
85+ images : ${{ env.GITHUB_REGISTRY }}/${{ env.IMAGE_NAME }}
86+
87+ # Build and push Docker image with Buildx (don't push on PR)
88+ # https://github.com/docker/build-push-action
89+ - name : Build and push Docker image
90+ uses : docker/build-push-action@v2
91+ with :
92+ context : .
93+ platforms : linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6
94+ push : ${{ github.event_name != 'pull_request' }}
95+ tags : ${{ steps.meta.outputs.tags }}
96+ labels : ${{ steps.meta.outputs.labels }}
97+
98+ # Push image to Docker Hub.
99+ push-to-docker-hub :
100+
101+ # Ensure test job passes before pushing image.
102+ needs : test
103+
104+ runs-on : ubuntu-latest
105+ permissions :
106+ contents : read
107+ packages : write
108+
109+ steps :
110+ - name : Checkout
111+ uses : actions/checkout@v2
112+
113+ - name : Set up QEMU
114+ uses : docker/setup-qemu-action@v1
115+
116+ - name : Set up Docker Buildx
117+ uses : docker/setup-buildx-action@v1
118+
119+ # Login against a Docker registry except on PR
120+ # https://github.com/docker/login-action
121+ - name : Log into registry ${{ env.DOCKER_REGISTRY }}
122+ if : github.event_name != 'pull_request'
123+ uses : docker/login-action@v1
124+ with :
125+ registry : ${{ env.DOCKER_REGISTRY }}
126+ username : ${{ secrets.DOCKERHUB_USERNAME }}
127+ password : ${{ secrets.DOCKERHUB_TOKEN }}
128+
129+ # Extract metadata (tags, labels) for Docker
130+ # https://github.com/docker/metadata-action
131+ - name : Extract Docker metadata
132+ id : meta
133+ uses : docker/metadata-action@v3
134+ with :
135+ images : ${{ env.IMAGE_NAME }}
85136
86137 # Build and push Docker image with Buildx (don't push on PR)
87138 # https://github.com/docker/build-push-action
92143 platforms : linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6
93144 push : ${{ github.event_name != 'pull_request' }}
94145 tags : ${{ steps.meta.outputs.tags }}
95- labels : ${{ steps.meta.outputs.labels }}
146+ labels : ${{ steps.meta.outputs.labels }}
0 commit comments