-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtravis.sh
More file actions
executable file
·76 lines (64 loc) · 1.81 KB
/
Copy pathtravis.sh
File metadata and controls
executable file
·76 lines (64 loc) · 1.81 KB
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
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
# From https://stackoverflow.com/a/8574392/437583.
includes()
{
local match="$1"
local element
shift
for element; do
[[ "$element" == "$match" ]] && return 0
done
return 1
}
# Logic for checking required variables inspired by
# http://unix.stackexchange.com/a/278974/72230.
required_vars=(
DOCKER_USER
DOCKER_PASSWORD
DOCKERFILE_DIR
)
missing_vars=()
# According to "Shell Parameter Expansion", the "!" in ${!...} introduces a
# level of indirection; it basically uses the *value* of the variable to access
# another variable.
for var in "${required_vars[@]}"; do
if [[ -z "${!var:+x}" ]]; then
missing_vars+=("$var")
fi
done
if (( ${#missing_vars[@]} != 0 )); then
echo "The following variables are not set, or are set to the empty string:" >&2
printf ' %q\n' "${missing_vars[@]}" >&2
exit 1
fi
if [[ ! -d $DOCKERFILE_DIR ]]; then
"directory \`$DOCKERFILE_DIR' does not exist "
exit 1
fi
to_push=(
# Only push the Docker image built in the "texlive" subdirectory.
texlive
)
pushd "${DOCKERFILE_DIR}"
echo "### Building container"
./build_container.sh
echo "### Testing"
./test.sh
if includes "${DOCKERFILE_DIR}" "${to_push[@]}"; then
# For those images we want to push, we must be provided an explicit tag
# to use for pushing.
if [[ -z "${DOCKERFILE_TAG:-}" ]]; then
echo "image push: missing \$DOCKERFILE_TAG" >&2
exit 1
fi
# Only push images for master branch. This way "next" branch can be
# used purely for testing only.
if [[ $(git rev-parse --abbrev-ref HEAD) == "master" ]]; then
docker login -u "$DOCKER_USER" -p "$DOCKER_PASSWORD"
docker push "$DOCKERFILE_TAG"
fi
fi
popd