A registry stores images, so a server can pull one by name. Docker Hub is one; registry.monster.market is the shop's own. Pushing to it needs a login, and its password, in ~/registry-password.txt, belongs in a secret:
gh secret set REGISTRY_PASSWORD < ~/registry-password.txtPush from the job that built the image, after its tests: a failed step stops the job, so an image whose tests fail never gets this far.
- name: Push
if: github.ref == 'refs/heads/main'
env:
PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
run: |
echo "$PASSWORD" | docker login registry.monster.market \
-u shop-ci --password-stdin
docker push registry.monster.market/shop:${{ github.sha }}--password-stdin reads the password from the pipe, so it's never part of a command line. A \ at the end of a line continues the command on the next one.
Only main pushes. Branches still build and test their image, so a pull request shows whether it would work.
Objectives
- Push main's image.
- Branches don't push.