-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild-and-publish.sh
executable file
·47 lines (37 loc) · 1.38 KB
/
build-and-publish.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
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash
# Decide name and version
VERSION=${TRAVIS_TAG:-"test"}
NAME="testfairy/testfairy-connect"
TAG="${NAME}:${VERSION}"
# Build image
set -x
docker build . \
--no-cache \
-t $TAG \
--build-arg version=$VERSION \
# Don't push images if not a tagged github release, simply finalize CI
echo "Current Tag: ${TRAVIS_TAG}"
if [ -z "$TRAVIS_TAG" ];then
exit 0
fi
# Tag image as latest
IMAGE_ID=$(docker images $TAG --format "{{.ID}}")
docker tag $IMAGE_ID "${NAME}:latest"
# Login to docker hub
docker login -u $DOCKER_USERNAME -p=$DOCKER_PASSWORD
# Push each tag
for T in $(docker images ${NAME} --format "{{.Tag}}");
do
docker push "${NAME}:${T}"
done
# Set readme path to sync
README_FILEPATH="./README.md"
# Acquire a token for the Docker Hub API
echo "Acquiring token"
LOGIN_PAYLOAD="{\"username\": \"${DOCKER_USERNAME}\", \"password\": \"${DOCKER_PASSWORD}\"}"
TOKEN=$(curl -s -H "Content-Type: application/json" -X POST -d ${LOGIN_PAYLOAD} https://hub.docker.com/v2/users/login/ | jq -r .token)
# Send a PATCH request to update the description of the repository
echo "Sending PATCH request"
REPO_URL="https://hub.docker.com/v2/repositories/${NAME}/"
RESPONSE_CODE=$(curl -s --write-out %{response_code} --output /dev/null -H "Authorization: JWT ${TOKEN}" -X PATCH --data-urlencode full_description@${README_FILEPATH} ${REPO_URL})
echo "Received response code: ${RESPONSE_CODE}"