File tree Expand file tree Collapse file tree 3 files changed +100
-33
lines changed
Expand file tree Collapse file tree 3 files changed +100
-33
lines changed Original file line number Diff line number Diff line change @@ -11,12 +11,9 @@ ADD ./ /usr/src
1111WORKDIR /usr/src
1212
1313# user can pass in CONFIG=release to override
14- ARG CONFIG=debug
14+ ENV CONFIG=debug
1515
16- RUN swift build --configuration ${CONFIG}
16+ # user can pass in LIVE=true
17+ ENV LIVE=false
1718
18- RUN cp ./.build/${CONFIG}/libSTSLibrary.so /usr/lib/libSTSLibrary.so
19- RUN cp ./.build/${CONFIG}/STSLibrary.swiftmodule /usr/lib/STSLibrary.swiftmodule
20- RUN cp ./.build/${CONFIG}/STSApplication /usr/bin/STSApplication
21-
22- ENTRYPOINT /usr/bin/STSApplication
19+ ENTRYPOINT ./entrypoint $CONFIG $LIVE
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+
3+ CONFIG=$1
4+ LIVE=$2
5+ KILL=false
6+
7+ handle_interrupt () {
8+ KILL=true
9+ }
10+
11+ build () {
12+ swift build --configuration ${CONFIG}
13+ }
14+
15+ installApplication () {
16+ cp ./.build/${CONFIG} /libSTSLibrary.so /usr/lib/libSTSLibrary.so
17+ cp ./.build/${CONFIG} /STSLibrary.swiftmodule /usr/lib/STSLibrary.swiftmodule
18+ cp ./.build/${CONFIG} /STSApplication /usr/bin/STSApplication
19+ }
20+
21+ runApplication () {
22+ /usr/bin/STSApplication
23+ }
24+
25+ buildAndRun () {
26+ build && installApplication && runApplication
27+ }
28+
29+ detectChangesLoop () {
30+ while [[ " $KILL " != true ]]
31+ do
32+ files=` find Sources* -type f -newer /usr/bin/STSApplication`
33+ if [[ ${files} != " " ]] ; then
34+ echo " Changes in files: $files , building..."
35+ buildAndRun
36+ echo " Waiting for changes to run application again."
37+ fi
38+ sleep 2
39+ done
40+ }
41+
42+ entrypoint () {
43+ buildAndRun
44+ }
45+
46+ liveEntrypoint () {
47+ buildAndRun
48+ echo " Waiting for changes to run application again."
49+ detectChangesLoop &
50+ wait
51+ }
52+
53+ if [ " $LIVE " = true ] ; then
54+ liveEntrypoint
55+ else
56+ entrypoint
57+ fi
Original file line number Diff line number Diff line change 33POSITIONAL=()
44STS_NAME=sts-application
55STS_BUILD_ENABLED=false
6+ STS_LIVE_ENABLED=false
67
78TXT_NC=' \033[0m'
89TXT_GREEN=' \033[0;32m'
@@ -11,31 +12,34 @@ TXT_RED='\033[0;31m'
1112
1213while [[ $# -gt 0 ]]
1314do
14- key=" $1 "
15-
16- case ${key} in
17- -n|--name)
18- STS_NAME=" $2 "
19- shift
20- shift
21- ;;
22- -v|--volume)
23- STS_VOLUME_ENABLED=true
24- shift
25- ;;
26- -b|--build)
27- STS_BUILD_ENABLED=true
28- shift
29- ;;
30- -p|--prod|-r|--release)
31- STS_RELEASE_CONFIG_ENABLED=true
32- shift
33- ;;
34- * ) # unknown option
35- POSITIONAL+=(" $1 " )
36- shift
37- ;;
38- esac
15+ key=" $1 "
16+ case ${key} in
17+ -n|--name)
18+ STS_NAME=" $2 "
19+ shift
20+ shift
21+ ;;
22+ -v|--volume)
23+ STS_VOLUME_ENABLED=true
24+ shift
25+ ;;
26+ -b|--build)
27+ STS_BUILD_ENABLED=true
28+ shift
29+ ;;
30+ -p|--prod|-r|--release)
31+ STS_RELEASE_CONFIG_ENABLED=true
32+ shift
33+ ;;
34+ -l|--live)
35+ STS_LIVE_ENABLED=true
36+ shift
37+ ;;
38+ * ) # unknown option
39+ POSITIONAL+=(" $1 " )
40+ shift
41+ ;;
42+ esac
3943done
4044set -- " ${POSITIONAL[@]} "
4145
5660 STS_BUILD_COMMAND=" docker build -t ${STS_NAME} ."
5761fi
5862
63+ # live flag
64+ if [ " $STS_LIVE_ENABLED " = true ] ; then
65+ STS_VOLUME_FLAG=" -v $PWD :/usr/src"
66+ STS_LIVE_FLAG=" -e LIVE=true"
67+ else
68+ STS_VOLUME_FLAG=" "
69+ STS_LIVE_FLAG=" "
70+ fi
71+
5972case ${STS_COMMAND} in
6073 build)
6174 echo -e " [STS][build] Building with: ${TXT_GREEN}${STS_BUILD_COMMAND}${TXT_NC} "
@@ -64,7 +77,7 @@ case ${STS_COMMAND} in
6477 run)
6578 case ${STS_COMMAND_ARG} in
6679 app)
67- RUN_COMMAND=" docker run --rm ${STS_VOLUME_FLAG} ${STS_NAME} "
80+ RUN_COMMAND=" docker run --rm -it ${STS_LIVE_FLAG} ${STS_VOLUME_FLAG} ${STS_NAME} "
6881 ;;
6982 repl)
7083 RUN_COMMAND=" docker run --rm ${STS_VOLUME_FLAG} --security-opt seccomp:unconfined -it \
You can’t perform that action at this time.
0 commit comments