forked from datopian/ckan-cloud-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cicd_functions.sh
141 lines (131 loc) · 5.12 KB
/
cicd_functions.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
DOCKER_IMAGE=viderum/ckan-cloud-docker
BUILD_APPS="ckan cca-operator jenkins nginx db solr"
BUILD_CKAN_OVERRIDES="1"
BUILD_SOLR_OVERRIDES="1"
touch docker-compose/ckan-secrets.sh docker-compose/datastore-db-secrets.sh docker-compose/db-secrets.sh docker-compose/provisioning-api-db-secrets.sh docker-compose/provisioning-api-secrets.sh
exec_build_apps() {
for APP in $BUILD_APPS; do
APP_LATEST_IMAGE="${DOCKER_IMAGE}:${APP}-latest"
! eval "${1}" && return 1
done
return 0
}
get_ckan_compose_ovverride_name() {
echo "${1}" | python -c "import sys; print(sys.stdin.read().split('.')[2])"
}
exec_ckan_compose_overrides() {
for DOCKER_COMPOSE_OVERRIDE in `ls .docker-compose.*.yaml`; do
OVERRIDE_NAME=$(get_ckan_compose_ovverride_name "${DOCKER_COMPOSE_OVERRIDE}")
echo "OVERRIDE ${OVERRIDE_NAME}"
! eval "${1}" && return 1
done
return 0
}
pull_latest_images() {
echo -e "\n** Pulling latest images **\n"
exec_build_apps 'docker-compose pull $APP'
if [ "${BUILD_CKAN_OVERRIDES}" == "1" ]; then
exec_ckan_compose_overrides 'docker pull "${DOCKER_IMAGE}:ckan-latest-${OVERRIDE_NAME}"'
fi
if [ "${BUILD_SOLR_OVERRIDES}" == "1" ]; then
docker pull "${DOCKER_IMAGE}:solrcloud-latest"
fi
return 0
}
build_latest_images() {
echo -e "\n** Building latest images **\n"
! exec_build_apps 'docker-compose -f docker-compose.yaml -f .docker-compose-db.yaml -f .docker-compose-cache-from.yaml build $APP' && return 1
if [ "${BUILD_CKAN_OVERRIDES}" == "1" ]; then
! exec_ckan_compose_overrides '
docker-compose -f docker-compose.yaml \
-f .docker-compose-db.yaml \
-f .docker-compose-cache-from.yaml \
-f .docker-compose.${OVERRIDE_NAME}.yaml build ckan
' && return 1
fi
if [ "${BUILD_SOLR_OVERRIDES}" == "1" ]; then
! docker-compose -f docker-compose.yaml -f .docker-compose-db.yaml \
-f .docker-compose-cache-from.yaml \
-f .docker-compose-centralized.yaml build solr && return 1
fi
return 0
}
tag_images() {
[ -z "${1}" ] && return 1
export TAG_SUFFIX="${1}"
echo -e "\n** Tagging images with tag suffix ${TAG_SUFFIX} **\n"
! exec_build_apps '
docker tag "${APP_LATEST_IMAGE}" "${DOCKER_IMAGE}:${APP}-${TAG_SUFFIX}" &&\
echo tagged ${APP} latest image: ${DOCKER_IMAGE}:${APP}-${TAG_SUFFIX}
' && return 1
if [ "${BUILD_CKAN_OVERRIDES}" == "1" ]; then
! exec_ckan_compose_overrides '
docker tag "${DOCKER_IMAGE}:ckan-latest-${OVERRIDE_NAME}" \
"${DOCKER_IMAGE}:ckan-${TAG_SUFFIX}-${OVERRIDE_NAME}" &&\
echo tagged ckan override ${OVERRIDE_NAME} latest image: ${DOCKER_IMAGE}:ckan-${TAG_SUFFIX}-${OVERRIDE_NAME}
' && return 1
fi
if [ "${BUILD_SOLR_OVERRIDES}" == "1" ]; then
docker tag "${DOCKER_IMAGE}:solrcloud-latest" \
"${DOCKER_IMAGE}:solrcloud-${TAG_SUFFIX}" &&\
echo tagged solrcloud latest image: ${DOCKER_IMAGE}:solrcloud-${TAG_SUFFIX}
[ "$?" != "0" ] && return 1
fi
return 0
}
push_latest_images() {
echo -e "\n** Pushing latest images **\n"
! exec_build_apps '
docker push "${DOCKER_IMAGE}:${APP}-latest"
' && return 1
if [ "${BUILD_CKAN_OVERRIDES}" == "1" ]; then
! exec_ckan_compose_overrides '
docker push "${DOCKER_IMAGE}:ckan-latest-${OVERRIDE_NAME}"
' && return 1
fi
if [ "${BUILD_SOLR_OVERRIDES}" == "1" ]; then
! docker push "${DOCKER_IMAGE}:solrcloud-latest" && return 1
fi
return 0
}
push_tag_images() {
[ -z "${1}" ] && return 1
export TAG_SUFFIX="${1}"
echo -e "\n** Pushing tag images: ${TAG_SUFFIX} **\n"
! exec_build_apps '
docker push "${DOCKER_IMAGE}:${APP}-${TAG_SUFFIX}"
' && return 1
if [ "${BUILD_CKAN_OVERRIDES}" == "1" ]; then
! exec_ckan_compose_overrides '
docker push "${DOCKER_IMAGE}:ckan-${TAG_SUFFIX}-${OVERRIDE_NAME}"
' && return 1
fi
if [ "${BUILD_SOLR_OVERRIDES}" == "1" ]; then
! docker push "${DOCKER_IMAGE}:solrcloud-${TAG_SUFFIX}" && return 1
fi
return 0
}
print_summary() {
[ -z "${1}" ] && return 1
[ -z "${2}" ] && return 1
export TAG_SUFFIX="${1}"
export PUSHED_LATEST="${2}"
echo -e "\n** Published docker images **\n"
if [ "${PUSHED_LATEST}" == "1" ]; then
exec_build_apps 'echo "${DOCKER_IMAGE}:${APP}-latest"'
if [ "${BUILD_CKAN_OVERRIDES}" == "1" ]; then
exec_ckan_compose_overrides 'echo "${DOCKER_IMAGE}:ckan-latest-${OVERRIDE_NAME}"'
fi
if [ "${BUILD_SOLR_OVERRIDES}" == "1" ]; then
echo "${DOCKER_IMAGE}:solrcloud-latest"
fi
fi
exec_build_apps 'echo "${DOCKER_IMAGE}:${APP}-${TAG_SUFFIX}"'
if [ "${BUILD_CKAN_OVERRIDES}" == "1" ]; then
exec_ckan_compose_overrides 'echo "${DOCKER_IMAGE}:ckan-${TAG_SUFFIX}-${OVERRIDE_NAME}"'
fi
if [ "${BUILD_SOLR_OVERRIDES}" == "1" ]; then
echo "${DOCKER_IMAGE}:solrcloud-${TAG_SUFFIX}"
fi
return 0
}