Skip to content

Commit

Permalink
Merge pull request #8 from cisagov/improvement/publish_readme_to_dock…
Browse files Browse the repository at this point in the history
…er_hub

Improvement/publish readme to docker hub
  • Loading branch information
felddy authored Jun 28, 2019
2 parents cf9f3bc + 60f495c commit 00d1b91
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ env:
global:
- IMAGE_NAME=dhsncats/example
- DOCKER_USER=felddy
# DOCKER_PW
- secure: >-
GWxja6rCcevNRay3uOGEt1wpzGOAoKgfquyror60VtkG07GCJ/rCBa/jNsTRRwwDxYW
MqY6xQlAU+GzNeuBxKAlmyrLRRYZDmcBpPgQQPbiC0b5ftGCzTuhdYAj4Hg+LyHKbNP
Expand Down Expand Up @@ -48,7 +49,8 @@ deploy:
script: docker push "${IMAGE_NAME}:latest" &&
docker push "${IMAGE_NAME}:${version}" &&
docker push "${IMAGE_NAME}:${version_array[0]}.${version_array[1]}" &&
docker push "${IMAGE_NAME}:${version_array[0]}"
docker push "${IMAGE_NAME}:${version_array[0]}" &&
./push_readme.sh
on:
tags: true
python: '3.7'
30 changes: 30 additions & 0 deletions push_readme.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash

# Push the README.md file to the docker hub repository

# Requires the following environment variables to be set:
# DOCKER_PW, DOCKER_USER, IMAGE_NAME

set -o nounset
set -o errexit
set -o pipefail

token=$(curl -s -X POST \
-H "Content-Type: application/json" \
-d '{"username": "'"$DOCKER_USER"'", "password": "'"$DOCKER_PW"'"}' \
https://hub.docker.com/v2/users/login/ | jq -r .token)

code=$(jq -n --arg msg "$(<README.md)" \
'{"registry":"registry-1.docker.io","full_description": $msg }' | \
curl -s -o /dev/null -L -w "%{http_code}" \
https://cloud.docker.com/v2/repositories/"${IMAGE_NAME}"/ \
-d @- -X PATCH \
-H "Content-Type: application/json" \
-H "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

0 comments on commit 00d1b91

Please sign in to comment.