-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from docksal/develop
Release 1.3.0
- Loading branch information
Showing
10 changed files
with
454 additions
and
232 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Deletes an image tag from Docker Hub | ||
# | ||
# Expects USER, PASSWORD | ||
# Expects IMAGE:TAG as argument. | ||
# | ||
# Example: docker-tag-delete.sh docksal/cli:php7.3-build-01c92a2-amd64 | ||
|
||
# Credit: | ||
# https://devopsheaven.com/docker/dockerhub/2018/04/09/delete-docker-image-tag-dockerhub.html | ||
|
||
set -euo pipefail | ||
|
||
# Get IMAGE and TAG from first argument | ||
if [[ "${1}" == "" ]]; then | ||
echo "Usage: ${0} image:tag" | ||
exit 1 | ||
else | ||
# Split image:tag | ||
IFS=$':' read IMAGE TAG <<< ${1}; | ||
# Remove registry prefix from image if present | ||
IMAGE=${IMAGE#"docker.io/"} | ||
fi | ||
|
||
login_data() { | ||
cat <<EOF | ||
{ | ||
"username": "${DOCKERHUB_USERNAME}", | ||
"password": "${DOCKERHUB_PASSWORD}" | ||
} | ||
EOF | ||
} | ||
|
||
# Get auth token | ||
TOKEN=$(curl -s -H "Content-Type: application/json" -X POST -d "$(login_data)" "https://hub.docker.com/v2/users/login/" | jq -r .token) | ||
|
||
# Delete tag | ||
output=$(curl -sI "https://hub.docker.com/v2/repositories/${IMAGE}/tags/${TAG}/" \ | ||
-H "Authorization: JWT ${TOKEN}" \ | ||
-X DELETE | ||
) | ||
|
||
# Return and error if HTTP response code is not 204 | ||
echo "${output}" | grep "HTTP/1.1 204 NO CONTENT" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.