I have a scenario where we need our private Docker Registry (v2) to not accept pushes to a tag if it already exists.
For example I have
192.168.0.77:5000/my-project:1.0.0
and someone pushes an update on the endpoint above. It should stop the push.
Then when the user pushes with tag 1.0.1 or any other, it will push successfuly.
I know Docker allows pushing on the same tag, however I wish to have this kind of workflow so we don't override each other's image this way and also these will co-relate with a Jenkins build (for transaction purposes).
Deployment Instructions (in bash)
docker login -u admin -p fakepassword 192.168.0.77:5000
docker tag my-project 192.168.0.77:5000/my-project:1.0.0
docker push 192.168.0.77:5000/my-project:1.0.0
Can someone please advice a way of achieving this?
This is what I use in my CI pipeline.
Check the value of $?, which contains the result of the most recent command - in your case a command that checks if the tag already exists:
#!/bin/bash
docker manifest inspect $IMGNAME:$IMGTAG
RESULT=$?
if [ $RESULT == 0 ]; then
echo success
else
echo failed
fi
Save it as a file and call it script.sh
To run the script:sh ./script.sh
The script will return 'success' if the command is successful otherwise it will return 'failed'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With