-
Notifications
You must be signed in to change notification settings - Fork 2
/
make_docker.sh
executable file
·78 lines (64 loc) · 1.98 KB
/
make_docker.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
73
74
75
76
77
78
#!/usr/bin/env bash
#
# Build or push an image.
# Images for staging are pushed to sodalite-private-registry on ${docker_registry_ip}
# Images with production-ready version are pushed to both sodalite-private-registry and dockerhub: sodaliteh2020 repository
# Images from tagged commits are tagged with git tag
# Images from non-tagged commits are tagged with <last_git_tag>-<commits_since_tag>-<abbreviated_commit_sha>
#
# Usage:
# $0 build <image-name> [Dockerfile-filename]
# $0 push <image-name> [production|staging]
# image name is pure name without repository (image-name, not sodaliteh2020/image-name)
build() {
set -x
docker build --build-arg VERSION="${VERSION}" --build-arg DATE="${DATE}" -t "${IMAGE}":latest -f "${FILE}" .
set +x
}
push() {
set -x
docker tag "${IMAGE}":latest "${TARGET_REGISTRY}/${IMAGE}:${VERSION}"
docker tag "${IMAGE}":latest "${TARGET_REGISTRY}/${IMAGE}:latest"
docker push "${TARGET_REGISTRY}/${IMAGE}:${VERSION}"
docker push "${TARGET_REGISTRY}/${IMAGE}:latest"
set +x
}
if [[ $# -gt 3 ]] || [[ $# -lt 2 ]] || \
[[ "$1" != "build" && "$1" != "push" ]] || \
[[ "$1" = "push" && "$3" != "staging" && "$3" != "production" ]]; then
echo "Usage: $0 build <image-name> [Dockerfile-filename]"
echo "Usage: $0 push <image-name> [production|staging]"
exit 1
fi
git fetch --tags
ACTION=$1
IMAGE=$2
if [ "$ACTION" = 'build' ];
then
FILE=${3:-Dockerfile}
else
TARGET=${3:-staging}
fi
if [[ "$ACTION" = 'push' ]]; then
if [[ "$TARGET" = 'production' ]]; then
TARGET_REGISTRY=sodaliteh2020
else
TARGET_REGISTRY=${docker_registry_ip:-localhost}
fi
fi
VERSION=$(git describe --tag --always | sed -e"s/^v//")
DATE=$(date -u +%Y-%m-%dT%H:%M:%S)
# debug section
echo "make_docker.sh:"
echo "ACTION: $ACTION"
echo "IMAGE: $IMAGE"
echo "FILE: $FILE"
echo "VERSION: $VERSION"
echo "DATE: $DATE"
echo "TARGET: $TARGET"
echo "TARGET_REGISTRY: $TARGET_REGISTRY"
if [ "$ACTION" = "build" ]; then
build
else
push
fi