forked from keitaroinc/docker-ckan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·122 lines (99 loc) · 2.46 KB
/
build.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env bash
set -Eeuo pipefail
deb=no
dry_run=no
build_ckan=yes
nocache=no
target_image=
target_image_fullname=
namespace=${DOCKERHUB_NAMESPACE:=ehealthafrica}
version=$(git describe --tags --exact-match 2>/dev/null || echo latest)
function show_help {
echo """
Build Alpine or Debian based CKAN image
Usage:
./build.sh [options]
Options:
--build-datapusher build image for datapusher (default: build ckan image)
--deb | -d build Debain image.
--dry-run performs a dry-run to show configs.
--help | -h show this message.
--namespace docker hub account name.
--no-cache build image without using cache.
--tag | -t the image tag.
"""
}
function _build_image_name {
local deb=$1
local build_ckan=$2
local namespace=$3
local tag=$4
target_image=ckan
target_image_fullname="${namespace}/${target_image}:${tag}"
if [[ ${build_ckan} = "no" ]]; then
target_image=datapusher
target_image_fullname="${namespace}/ckan-${target_image}:${tag}"
fi
if [[ ${deb} = "no" ]]; then
target_image_fullname="${target_image_fullname}-alpine"
fi
}
function build {
local deb=$1
local image=$2
local image_fullname=$3
local nocache=$4
local filename=Dockerfile
if [[ ${deb} = "yes" ]]; then
filename=Dockerfile.deb
fi
echo ">> Building CKAN Image '${image_fullname}' (using ${filename}) ..."
echo ""
if [[ ${nocache} = "yes" ]]; then
docker build -f rootfs/${image}/${filename} -t ${image_fullname} rootfs/${image}
else
docker build --no-cache -f rootfs/${image}/${filename} -t ${image_fullname} rootfs/${image}
fi
}
while [[ $# -gt 0 ]]; do
case "$1" in
--build-datapusher )
build_ckan=no
shift
;;
-d | --deb )
deb=yes
shift
;;
--dry-run )
dry_run=yes
shift
;;
--namespace )
shift
namespace=$1
shift
;;
--no-cache )
nocache=yes
shift
;;
-h | --help )
show_help
exit 0
;;
-t | --tag )
shift
version=$1
shift
;;
esac
done
# build image name which is stored in global var: result
_build_image_name ${deb} ${build_ckan} ${namespace} ${version}
if [[ $dry_run = "yes" ]]; then
echo "deb=${deb} build-ckan=${build_ckan} namespace=${namespace} tag=${version}"
echo ${target_image_fullname}
else
build ${deb} ${target_image} ${target_image_fullname} ${nocache}
fi