This repository has been archived by the owner on May 23, 2024. It is now read-only.
forked from hypoport/docker-kibana-search-guard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeployToDockerhub.sh
executable file
·65 lines (53 loc) · 1.59 KB
/
deployToDockerhub.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
#!/usr/bin/env bash
# fail this script if a command fails
set -e
export DOCKER_TAG_SEPARATOR=' ; '
export kREGEX_TAG='^[0-9]+\.[0-9]+\.[0-9]+$'
if [ -z "$1" ]; then
echo "Tag is required as parameter"
exit 1
fi
GIT_TAG=$1
echo "GIT_TAG='${GIT_TAG}'"
if [ -z "$2" ]; then
echo "Docker image is required as parameter"
exit 1
fi
DOCKER_IMAGE=$2
echo "DOCKER_IMAGE='${DOCKER_IMAGE}'"
if [ -z "$DOCKER_PASSWORD" ]; then
echo "DOCKER_PASSWORD ENV variable is required!"
exit 1
fi
if [ -z "$DOCKER_USERNAME" ]; then
echo "DOCKER_USERNAME ENV variable is required!"
exit 1
fi
get_docker_tags() {
if [ -z "$1" ]; then
echo "git tag not specified to get_docker_tags"
return 1
fi
if [[ $1 =~ $kREGEX_TAG ]]; then
# split the tag
IFS='.' read -r -a array <<<"$1"
echo "latest${DOCKER_TAG_SEPARATOR}${array[0]}${DOCKER_TAG_SEPARATOR}${array[0]}.${array[1]}${DOCKER_TAG_SEPARATOR}$1"
else
# just return the tag
echo "latest${DOCKER_TAG_SEPARATOR}${1}"
fi
}
# DOCKER_USERNAME and DOCKER_PASSWORD have to be set in ENV
echo "login to docker hub..."
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
DOCKER_TAGS=$(get_docker_tags "${GIT_TAG}")
echo "Docker tags='$DOCKER_TAGS'"
export IFS="${DOCKER_TAG_SEPARATOR}"
for docker_tag in ${DOCKER_TAGS}; do
if [[ ${docker_tag} != "latest" ]]; then
echo "tagging docker image with tag='${docker_tag}'..."
docker tag "${DOCKER_IMAGE}:latest" "${DOCKER_IMAGE}:${docker_tag}"
fi
echo "pushing docker image '${DOCKER_IMAGE}:${docker_tag}'..."
docker push "${DOCKER_IMAGE}:${docker_tag}"
done