forked from cisagov/gophish-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
push_readme.sh
executable file
·33 lines (27 loc) · 1.09 KB
/
push_readme.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env bash
# Push the README.md file to the docker hub repository
# Requires the following environment variables to be set:
# DOCKER_PASSWORD, DOCKER_USERNAME, IMAGE_NAME
set -o nounset
set -o errexit
set -o pipefail
echo "Logging in and requesting JWT..."
token=$(curl --silent --request POST \
--header "Content-Type: application/json" \
--data \
'{"username": "'"$DOCKER_USERNAME"'", "password": "'"$DOCKER_PASSWORD"'"}' \
https://hub.docker.com/v2/users/login/ | jq --raw-output .token)
echo "Pushing README file..."
code=$(jq --null-input --arg msg "$(<README.md)" \
'{"registry":"registry-1.docker.io","full_description": $msg }' | \
curl --silent --output /dev/null --location --write-out "%{http_code}" \
https://hub.docker.com/v2/repositories/"${IMAGE_NAME}"/ \
--data @- --request PATCH \
--header "Content-Type: application/json" \
--header "Authorization: JWT ${token}")
if [[ "${code}" = "200" ]]; then
printf "Successfully pushed README to Docker Hub"
else
printf "Unable to push README to Docker Hub, response code: %s\n" "${code}"
exit 1
fi