-
Notifications
You must be signed in to change notification settings - Fork 4
/
sts
executable file
·130 lines (122 loc) · 3.88 KB
/
sts
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
#!/usr/bin/env bash
POSITIONAL=()
STS_NAME=sts-application
STS_BUILD_ENABLED=false
STS_LIVE_ENABLED=false
TXT_NC='\033[0m'
TXT_GREEN='\033[0;32m'
TXT_YELLOW='\033[0;33m'
TXT_RED='\033[0;31m'
while [ $# -gt 0 ]
do
key="$1"
case ${key} in
-n|--name)
STS_NAME="$2"
shift
shift
;;
-v|--volume)
STS_VOLUME_ENABLED=true
shift
;;
-b|--build)
STS_BUILD_ENABLED=true
shift
;;
-p|--prod|-r|--release)
STS_RELEASE_CONFIG_ENABLED=true
shift
;;
-l|--live)
STS_LIVE_ENABLED=true
shift
;;
*) # unknown option
POSITIONAL+=("$1")
shift
;;
esac
done
set -- "${POSITIONAL[@]}"
STS_COMMAND=${POSITIONAL[0]}
STS_COMMAND_ARG=${POSITIONAL[1]}
# volume flag
if [ "$STS_VOLUME_ENABLED" = true ] ; then
STS_VOLUME_FLAG="-v $PWD:/usr/src"
else
STS_VOLUME_FLAG=""
fi
# configuration build arg flag
if [ "$STS_RELEASE_CONFIG_ENABLED" = true ] ; then
STS_BUILD_COMMAND="docker build -t ${STS_NAME} --build-arg CONFIG=release . "
else
STS_BUILD_COMMAND="docker build -t ${STS_NAME} ."
fi
# live flag TODO: Fix conflict edge case with volume and live flags
if [ "$STS_LIVE_ENABLED" = true ] ; then
STS_VOLUME_FLAG="-v $PWD:/usr/src"
STS_LIVE_FLAG="-e LIVE=true"
else
STS_VOLUME_FLAG=""
STS_LIVE_FLAG=""
fi
case ${STS_COMMAND} in
build)
echo -e "[STS][build] Building with: ${TXT_GREEN}${STS_BUILD_COMMAND}${TXT_NC}"
eval ${STS_BUILD_COMMAND}
;;
run)
case ${STS_COMMAND_ARG} in
app)
RUN_COMMAND="docker run --rm -it ${STS_LIVE_FLAG} ${STS_VOLUME_FLAG} ${STS_NAME}"
;;
repl)
if [ "$STS_LIVE_ENABLED" = true ] ; then
echo -e "[STS][run][${STS_COMMAND_ARG}] ignoring unsupported flag: ${TXT_YELLOW}-l|--live${TXT_NC}"
fi
RUN_COMMAND="docker run --rm ${STS_VOLUME_FLAG} --security-opt seccomp:unconfined -it \
--entrypoint /usr/bin/swift \
${STS_NAME} \
-I/usr/lib/swift/clang/include \
-I/usr/lib \
-L/usr/lib \
-lSTSLibrary \
-lswiftPython \
-lswiftTensorFlow"
;;
test|tests)
# TODO: Finish live reloaded tests; need to think about the --entrypoint usage
if [ "$STS_LIVE_ENABLED" = true ] ; then
echo -e "[STS][run][${STS_COMMAND_ARG}] ignoring unsupported flag: ${TXT_YELLOW}-l|--live${TXT_NC}"
fi
RUN_COMMAND="docker run --rm -it ${STS_LIVE_FLAG} ${STS_VOLUME_FLAG} --entrypoint "/usr/bin/swift" ${STS_NAME} test -Xswiftc -O"
;;
xcode)
if [ "$STS_LIVE_ENABLED" = true ] ; then
echo -e "[STS][run][${STS_COMMAND_ARG}] ignoring unsupported flag: ${TXT_YELLOW}-l|--live${TXT_NC}"
fi
RUN_COMMAND="docker run --rm -v ${PWD}:/usr/src \
--entrypoint /usr/bin/swift \
${STS_NAME} \
package generate-xcodeproj \
&& open STSProject.xcodeproj"
;;
*)
echo -e "[STS][run] ${TXT_RED}Unknown or empty argument passed to run: '${STS_COMMAND_ARG}'${TXT_NC}"
;;
esac
if [ -n "$RUN_COMMAND" ] ; then
if [ "$STS_BUILD_ENABLED" = true ] && [ -n "$STS_COMMAND_ARG" ]; then
echo -e "[STS][run] -b|--build was passed; building with: ${TXT_GREEN}${STS_BUILD_COMMAND}${TXT_NC}"
eval ${STS_BUILD_COMMAND}
fi
if [ "$(docker images -q ${STS_NAME} 2> /dev/null)" == "" ] ; then
echo -e "[STS][run][${STS_COMMAND_ARG}] ${TXT_YELLOW}Image with tag '${STS_NAME}' not found;${TXT_NC} building with: ${TXT_GREEN}${STS_BUILD_COMMAND}${TXT_NC}"
eval ${STS_BUILD_COMMAND}
fi
echo -e "[STS][run][${STS_COMMAND_ARG}] running with: ${TXT_GREEN}${RUN_COMMAND}${TXT_NC}"
eval ${RUN_COMMAND}
fi
;;
esac