Skip to content

Commit

Permalink
ci: check image exists with Docker Hub API (#1151)
Browse files Browse the repository at this point in the history
* ci: check image exists with Docker Hub API

* reword message when stopping

Co-authored-by: Bill Glesias <[email protected]>

---------

Co-authored-by: Bill Glesias <[email protected]>
  • Loading branch information
MikeMcC399 and AtofStryker authored Jul 8, 2024
1 parent 9dd7668 commit 6a0ce0a
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,31 @@ commands:
parameters:
target:
type: string
description: docker compose target being tested
description: cypress/* repo name (factory, base, browser or included)
steps:
- run:
name: Check if image for << parameters.target >> exists or Docker hub does not respond
# using https://github.com/cypress-io/docker-image-not-found
# to check if Docker hub definitely does not have this image
name: Check if image for << parameters.target >> exists on Docker Hub
# using Docker HUB API https://docs.docker.com/docker-hub/api/latest/
# to check if Docker Hub definitely does not have this image
command: |
DOCKER_NAMESPACE='cypress'
DOCKER_REPO=<< parameters.target >>
DOCKER_TAG=''
if [ << parameters.target >> == factory ]; then DOCKER_TAG=cypress/factory:${FACTORY_VERSION}; fi
if [ << parameters.target >> == base ]; then DOCKER_TAG=cypress/base:${BASE_IMAGE_TAG}; fi
if [ << parameters.target >> == browsers ]; then DOCKER_TAG=cypress/browsers:${BROWSERS_IMAGE_TAG}; fi
if [ << parameters.target >> == included ]; then DOCKER_TAG=cypress/included:${INCLUDED_IMAGE_TAG}; fi
if [ ${DOCKER_REPO} == factory ]; then DOCKER_TAG=${FACTORY_VERSION}; fi
if [ ${DOCKER_REPO} == base ]; then DOCKER_TAG=${BASE_IMAGE_TAG}; fi
if [ ${DOCKER_REPO} == browsers ]; then DOCKER_TAG=${BROWSERS_IMAGE_TAG}; fi
if [ ${DOCKER_REPO} == included ]; then DOCKER_TAG=${INCLUDED_IMAGE_TAG}; fi
DOCKER_NAME=${DOCKER_NAMESPACE}/${DOCKER_REPO}:${DOCKER_TAG}
if npx docker-image-not-found --repo $DOCKER_TAG; then
echo Docker hub says image $DOCKER_TAG does not exist
if curl -s https://hub.docker.com/v2/namespaces/${DOCKER_NAMESPACE}/repositories/${DOCKER_REPO}/tags/${DOCKER_TAG} \
| grep -iq 'httperror 404'; then
echo Docker Hub says image $DOCKER_NAME does not exist - HTTP status 404 returned
echo $DOCKER_NAME available for publishing
else
echo Docker hub has image $DOCKER_TAG or not responding
echo We should stop in this case
echo Docker Hub found image $DOCKER_NAME - or error occurred
echo Stopping to avoid republishing
circleci-agent step halt
fi
Expand Down

0 comments on commit 6a0ce0a

Please sign in to comment.