Skip to content

Commit 71e8d4b

Browse files
committed
change to inotify for hot reloads; add build and install back to dockerfile to get REPL third-party support working correctly
1 parent 571ee8f commit 71e8d4b

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

Dockerfile

+8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ LABEL Description="An STS Application"
44

55
WORKDIR /usr/src
66

7+
RUN apt-get update && apt-get install inotify-tools -y && rm -rf /var/cache/apk/*
8+
79
# Cache this step
810
COPY Package.swift /usr/src
911
RUN swift package update
@@ -17,4 +19,10 @@ ENV CONFIG=debug
1719
# user can pass in LIVE=true
1820
ENV LIVE=false
1921

22+
RUN swift build --configuration ${CONFIG}
23+
24+
RUN cp ./.build/${CONFIG}/libSTSLibrary.so /usr/lib/libSTSLibrary.so
25+
RUN cp ./.build/${CONFIG}/STSLibrary.swiftmodule /usr/lib/STSLibrary.swiftmodule
26+
RUN cp ./.build/${CONFIG}/STSApplication /usr/bin/STSApplication
27+
2028
ENTRYPOINT ./entrypoint $CONFIG $LIVE

entrypoint

+6-13
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22

33
CONFIG=$1
44
LIVE=$2
5-
KILL=false
6-
7-
handle_interrupt() {
8-
KILL=true
9-
}
105

116
build() {
127
swift build --configuration ${CONFIG}
@@ -27,18 +22,16 @@ build_and_run() {
2722
}
2823

2924
watch_files() {
30-
while [ ${KILL} != true ]
31-
do
32-
files=`find *.swift -type f -newer /usr/bin/STSApplication`
33-
if [[ ${files} != "" ]] ; then
34-
echo "Changes in files: $files, building..."
35-
if [[ ${files} = *"Package.swift" ]] ; then
25+
inotifywait --quiet --recursive --monitor --event modify --format "%w%f" . \
26+
| while read file change; do
27+
if [[ ${file} = *".swift" ]] ; then
28+
echo "Changes in file: $file, building..."
29+
if [[ ${file} = *"Package.swift" ]] ; then
3630
swift package update
3731
fi
3832
build_and_run
3933
echo "Waiting for changes to run application again."
4034
fi
41-
sleep 2
4235
done
4336
}
4437

@@ -47,7 +40,7 @@ entrypoint() {
4740
}
4841

4942
live_entrypoint() {
50-
build_and_run
43+
run_application
5144
echo "Waiting for changes to run application again."
5245
watch_files &
5346
wait

sts

+12-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ else
6060
STS_BUILD_COMMAND="docker build -t ${STS_NAME} ."
6161
fi
6262

63-
# live flag
63+
# live flag TODO: Fix conflict edge case with volume and live flags
6464
if [ "$STS_LIVE_ENABLED" = true ] ; then
6565
STS_VOLUME_FLAG="-v $PWD:/usr/src"
6666
STS_LIVE_FLAG="-e LIVE=true"
@@ -80,6 +80,9 @@ case ${STS_COMMAND} in
8080
RUN_COMMAND="docker run --rm -it ${STS_LIVE_FLAG} ${STS_VOLUME_FLAG} ${STS_NAME}"
8181
;;
8282
repl)
83+
if [ "$STS_LIVE_ENABLED" = true ] ; then
84+
echo -e "[STS][run][${STS_COMMAND_ARG}] ignoring unsupported flag: ${TXT_YELLOW}-l|--live${TXT_NC}"
85+
fi
8386
RUN_COMMAND="docker run --rm ${STS_VOLUME_FLAG} --security-opt seccomp:unconfined -it \
8487
--entrypoint /usr/bin/swift \
8588
${STS_NAME} \
@@ -91,9 +94,16 @@ case ${STS_COMMAND} in
9194
-lswiftTensorFlow"
9295
;;
9396
test|tests)
94-
RUN_COMMAND="docker run --rm ${STS_VOLUME_FLAG} --entrypoint "/usr/bin/swift" ${STS_NAME} test"
97+
# TODO: Finish live reloaded tests; need to think about the --entrypoint usage
98+
if [ "$STS_LIVE_ENABLED" = true ] ; then
99+
echo -e "[STS][test][${STS_COMMAND_ARG}] ignoring unsupported flag: ${TXT_YELLOW}-l|--live${TXT_NC}"
100+
fi
101+
RUN_COMMAND="docker run --rm -it ${STS_LIVE_FLAG} ${STS_VOLUME_FLAG} --entrypoint "/usr/bin/swift" ${STS_NAME} test"
95102
;;
96103
xcode)
104+
if [ "$STS_LIVE_ENABLED" = true ] ; then
105+
echo -e "[STS][run][${STS_COMMAND_ARG}] ignoring unsupported flag: ${TXT_YELLOW}-l|--live${TXT_NC}"
106+
fi
97107
RUN_COMMAND="docker run --rm -v ${PWD}:/usr/src \
98108
--entrypoint /usr/bin/swift \
99109
${STS_NAME} \

0 commit comments

Comments
 (0)