-
Notifications
You must be signed in to change notification settings - Fork 1
/
build-general
executable file
·73 lines (63 loc) · 1.92 KB
/
build-general
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
#!/bin/bash
runhelp() {
echo ""
echo "Purpose: General component build template"
echo ""
echo "Expected User-defined Variables:"
echo " - LATEST: Image tag for the latest image to use as cache"
echo " - CURR: Image tag for current image"
echo " - COMPONENT: Component name (context for the build)"
echo " - VUFIND_VERSION: The current version of Vufind"
echo ""
echo "Failure Scenarios:"
echo " - If the build fails"
echo " - If the push fails"
echo ""
}
if [[ -n "$1" || $1 == "-h" || $1 == "--help" || $1 == "help" ]]; then
runhelp
exit 0
fi
main() {
echo "Pulling image to use as cache"
docker pull "${LATEST}" || true;
echo "Building image"
docker build \
--tag "${CURR}" \
--build-arg VUFIND_VERSION="${VUFIND_VERSION}" \
--cache-from "${LATEST}" \
"${COMPONENT}"/;
EC=$?;
if [[ ${EC} -ne 0 ]]; then
echo "Failed to build ${COMPONENT}. Sleeping to add delay before potential retry.";
sleep 3;
exit 1;
fi;
echo "Pushing image"
docker push "${CURR}";
EC=$?;
if [[ ${EC} -ne 0 ]]; then
echo "Failed to push ${COMPONENT}. Sleeping to add delay before potential retry.";
sleep 3;
exit 1;
fi;
if [[ ${CI_DEFAULT_BRANCH} == "${CI_COMMIT_BRANCH}" || ${CI_COMMIT_BRANCH} == "catalog-preview" ]]; then
echo "Pushing new unique main image tag"
docker tag "${CURR}" "${CURR}-main";
docker push "${CURR}-main";
echo "Pushing new image with :latest tag"
docker tag "${CURR}" "${LATEST}";
docker push "${LATEST}";
fi;
EC=$?;
if [[ ${EC} -ne 0 ]]; then
echo "Failed to add latest tag for ${COMPONENT}. Sleeping to add delay before potential retry.";
sleep 3;
exit 1;
fi;
}
# exit script if any command fails
set -e;
# set xtrace to show commands being run in the CI job logs
set -o xtrace
main;