-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublish.sh
executable file
·72 lines (64 loc) · 2.1 KB
/
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env sh
# Exit on first error
set -e
# Read parameters
. `dirname $0`/parseargs.sh
# Parameters check
if [ "$SHOW_HELP" = "true" ] || [ -z "$IMAGE_NAME" ]; then
echo "Usage: $0 [options]"
echo
echo "Options:"
echo " -n, --name, --image-name <name> The name of the docker image to build. REQUIRED"
echo " -o, --owner, --image-owner <owner> The owner of the image to pull from the hub"
echo " -l, --local-name <name> The name of the local image to tag. Defaults to the image name"
echo " -t, --tags, --image-tags <tags> A list of tags, separated with spaces, the first of which is pulled"
echo " -h, --help Display this message"
echo
echo "Environment variables:"
echo " HUB_USERNAME: The username to use to connect to the Docker Hub"
echo " HUB_PASSWORD: The username to use to connect to the Docker Hub"
echo " HUB_EMAIL: The username to use to connect to the Docker Hub"
echo
echo "The image is published only if the imagename, owner, tags, and the hub parameters, are all set."
echo
if [ "$SHOW_HELP" = "true" ]; then
exit
else
exit 1
fi
fi
# Publish
if [ -n "$HUB_USERNAME" ] && [ -n "$HUB_PASSWORD" ] && [ -n "$IMAGE_OWNER" ] && [ -n "$IMAGE_NAME" ] && [ -n "$IMAGE_TAGS" ]; then
echo
echo "###"
echo "### Logging in to Docker Hub"
echo "###"
docker login -u ${HUB_USERNAME} -p ${HUB_PASSWORD} -e ${HUB_EMAIL}
# Publish every tag
for IMAGE_TAG in ${IMAGE_TAGS}; do
echo
echo "###"
echo "### Building tag $IMAGE_OWNER/$IMAGE_NAME:$IMAGE_TAG"
echo "###"
docker tag -f ${LOCAL_NAME} ${IMAGE_OWNER}/${IMAGE_NAME}:${IMAGE_TAG}
echo
echo "###"
echo "### Pushing tag $IMAGE_OWNER/$IMAGE_NAME:$IMAGE_TAG"
echo "###"
docker push ${IMAGE_OWNER}/${IMAGE_NAME}:${IMAGE_TAG}
echo
echo "###"
echo "### Tag $IMAGE_TAG sucessfully published"
echo "###"
done
echo
echo "###"
echo "### Logging out from Docker Hub"
echo "###"
docker logout
else
echo
echo "###"
echo "### Not publishing! (Did you set HUB_USERNAME, HUB_PASSWORD and HUB_EMAIL?)"
echo "###"
fi