This repository has been archived by the owner on Apr 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 947
/
test-in-docker
executable file
·200 lines (172 loc) · 4.62 KB
/
test-in-docker
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/usr/bin/env zsh
set -eu
# The default ZSH to use; it can just be the first few characters.
# This should be the oldest version we support.
default_version='4.'
setopt extended_glob glob_subst numeric_glob_sort
setopt warn_create_global warn_nested_var 2> /dev/null
cd "${${(%):-%x}:A:h}"
# TODO: Crazy Logic to munge TERM to something supported in Ubuntu 14.04
term=screen-256color
# Note: If versions and frameworks looks complicated, it isn't that bad...
# ...see Modifiers in zshexpn(1) for details.
# List of ZSH versions
typeset -aU versions
versions=( docker/base-*/Dockerfile(N.on:h:t:s/base-//) )
typeset -r versions
# List of frameworks
typeset -aU frameworks
frameworks=( docker/*/Dockerfile(N.on:h:t) )
for i in {$#frameworks..1}; do
# Remove all base entries
[[ "${frameworks[$i]}" == base-* ]] && frameworks[$i]=()
done
typeset -r frameworks
# Known Issues
typeset -A known_issues
known_issues["4.3.11-antigen"]="Antigen commands that need git won't work; it needs a newer version of git."
known_issues["4.3.11-zim"]="BROKEN: Zim wants ZSH 5.2 or newer."
known_issues["5.0.3-zim"]="DEPRECATED: Zim wants ZSH 5.2 or newer."
known_issues["5.1.1-zim"]="DEPRECATED: Zim wants ZSH 5.2 or newer."
known_issues["4.3.11-zulu"]="Zulu doesn't work; it needs a newer version of git."
typeset -r known_issues
err()
{
print -P "%F{red}Error:%f $*"
exit 2
}
resolve_framework() {
local f=$1 found
found=${frameworks[(In:-1:)$f*]}
if (( found <= $#frameworks )); then
echo "${frameworks[$found]}"
fi
}
resolve_version() {
local v=$1 found
found=${versions[(In:-1:)$v*]}
if (( found <= $#versions )); then
echo "${versions[$found]}"
fi
}
check_for_known_issues() {
local version="$1"
local framework="$2"
local name="${version}-${framework}"
if (( ${+known_issues["$name"]} )); then
echo
print -P "%F{red}Known Issue: %F{yellow}${known_issues["$name"]}%f"
echo
fi
}
cmd() {
if (( dry_run )); then
echo "${(@q)*}" 1>&2
else
"${(@)*}"
fi
}
build_and_run() {
local version="$1"
local framework="$2"
local name="${version}-${framework}"
check_for_known_issues "$version" "$framework"
print -P "%F{green}Preparing containers...%f"
echo -n "p9k:base-${version}: "
cmd docker build \
--quiet \
--tag "p9k:base-${version}" \
--file "docker/base-${version}/Dockerfile" \
.
echo -n "p9k:${version}-${framework}: "
cmd docker build \
--quiet \
--build-arg="base=base-${version}" \
--tag "p9k:${version}-${framework}" \
--file "docker/${framework}/Dockerfile" \
.
print -P "%F{green}Starting ${name} container...%f"
cmd docker run \
--rm \
--interactive \
--tty \
--hostname="${name//./_}" \
--env="TERM=${term}" \
"p9k:${version}-${framework}"
}
show_help() {
local f v
echo "Usage: ${(%):-%x} <framework>|--list"
echo
echo "Loads up a docker image with powershell9k configured in <framework>"
echo
echo " -f --frameworks Lists all available frameworks, newline separated."
echo " -v --versions Lists all available ZSH versions, newline separated."
echo " -z --zsh VER Uses ZSH with version VER."
echo " -n --dry-run Just prints the docker commands that would be run."
echo " --help You're soaking in it."
echo
echo "ZSH versions:"
for v in "${(@)versions}"; do
echo " $v"
done
echo
echo "Framework containers:"
for f in "${(@)frameworks}"; do
echo " $f"
done
}
# No arguments
if (( $# == 0 )); then
show_help
exit
fi
# Parse flags and such.
asked_for_version=$default_version
asked_for_framework=
dry_run=0
while (( $# > 0 )); do
case "$1" in
-f | --frameworks )
print -l "${(@)frameworks}"
exit
;;
-v | --versions )
print -l "${(@)versions}"
exit
;;
-z | --zsh )
shift
asked_for_version=$1
;;
-n | --dry-run ) dry_run=1 ;;
-h | --help )
show_help
exit
;;;
-* )
err "Unknown option ${1}"
show_help
exit 1
;;
* )
if [[ -z "$asked_for_framework" ]]; then
asked_for_framework=$1
else
err "You can only specify one framework at a time; you already specified '${asked_for_framework}'"
fi
;;
esac
shift
done
typeset -r asked_for_version asked_for_framework
typeset -r use_version="$(resolve_version "${asked_for_version}")"
if [[ -z "$use_version" ]]; then
err "No such ZSH version '${asked_for_version}'"
fi
typeset -r use_framework="$(resolve_framework "${asked_for_framework}")"
if [[ -z "$use_framework" ]]; then
err "No such framework '${asked_for_framework}'"
fi
build_and_run "$use_version" "$use_framework"
# EOF