-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sh
76 lines (64 loc) · 1.26 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
#!/usr/bin/env bash
set -eu
cd "$(dirname "$0")"
DOCKER_REPO=dplusic/stack-ghcjs
PUSH=false
DRY=false
LATEST=false
usage() {
echo "$0: $1" >&2
echo
echo "Usage: $0 [--push] [--dry-run] [--latest] tag"
echo
exit 1
}
dry() {
echo ">>> $*"
[[ $DRY = true ]] || "$@"
}
push() {
[[ $PUSH = false ]] || dry docker push "$1"
}
tagpush() {
dry docker tag "$1" "$2"
push "$2"
}
LTS_SLUG=
while [[ $# -gt 0 ]]; do
case "$1" in
--push)
PUSH=true
shift
;;
--dry-run)
DRY=true
shift
;;
--latest)
LATEST=true
shift
;;
-*)
usage "Unknown option: $1"
;;
*)
if [[ -n "$LTS_SLUG" ]]; then
usage "Cannot specify multiple tags: $1"
fi
LTS_SLUG="$1"
shift
;;
esac
done
if [[ "$LTS_SLUG" = "" ]]; then
usage "Missing argument: tag"
fi
if [ ! -d "$LTS_SLUG" ]; then
echo "$0: Cannot find tag: $LTS_SLUG" >&2
exit 1
fi
dry docker build -t "$DOCKER_REPO:$LTS_SLUG" $LTS_SLUG
push "$DOCKER_REPO:$LTS_SLUG"
if [[ $LATEST = true ]]; then
tagpush "$DOCKER_REPO:$LTS_SLUG" "$DOCKER_REPO:latest"
fi