-
Notifications
You must be signed in to change notification settings - Fork 9
/
run_front_end
executable file
·97 lines (77 loc) · 2.77 KB
/
run_front_end
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
#! /bin/bash
# Run the tests before we do anything else.
cd front_end/tests
echo "Running automated tests..."
./run.sh > /tmp/test.out
# See whether the tests passed.
if ! grep -q "All tests passed" /tmp/test.out
then
echo "At least one of the tests failed."
echo "The output is in /tmp/test.out."
exit 1
else
echo "All tests passed"
fi
cd ../../
# Now let's build everything...
mkdir -p front_end/database front_end/logs
mode=$(grep "^mode: " Settings.yaml | sed "1s/mode: //")
f_port=$(grep "^f_port: " Settings.yaml | sed "1s/f_port: //")
m_port=$(grep "^m_port: " Settings.yaml | sed "1s/m_port: //")
#f_num_processes=$(grep "^f_num_processes: " Settings.yaml | sed "1s/f_num_processes: //")
f_memory_gb=$(grep "^f_memory_gb: " Settings.yaml | sed "1s/f_memory_gb: //")
f_run_in_background=$(grep "^f_run_in_background: " Settings.yaml | sed "1s/f_run_in_background: //")
#args="-e NUM_PROCESSES=${f_num_processes} -e PORT=${f_port} -e MPORT=${m_port} -v $(pwd)/front_end/database:/app/database -v $(pwd)/front_end/logs:/app/logs -v $(pwd)/front_end/secrets:/app/secrets"
args="-v $(pwd)/front_end/database:/app/database -v $(pwd)/front_end/logs:/app/logs -v $(pwd)/front_end/secrets:/app/secrets"
# If MacOS, set the MHOST environment variable and bind the port
if [[ $(uname) == "Darwin" ]]
then
# Otherwise, assume Linux and use the network host which does not work on Docker for Mac
args="-p ${f_port}:${f_port} -e MHOST=host.docker.internal $args"
else
args="--network host $args"
fi
echo "ARGS: ${args}"
container_name=front_end_${mode}_${USER}
docker container stop ${container_name} 2> /dev/null
# We run this after the stop command; otherwise, it will not continue past this point if there is no container running. There's probably a better way.
set -o errexit
image_name=codebuddy/front_end_${mode}
cp Settings.yaml front_end/
cp VERSION front_end/
cp -r back_ends front_end/
cp -r misc front_end/
docker build -t ${image_name}:version$(cat VERSION) \
-t ${image_name}:latest \
-f front_end/Containerfile \
--build-arg USER_ID=$(id -u ${USER}) \
--build-arg GROUP_ID=$(id -g ${USER}) \
./front_end
#docker system prune -f
rm -f front_end/Settings.yaml front_end/VERSION
mkdir -p tmp
rm -rf tmp/*
if [[ "${f_run_in_background}" = "yes" ]]
then
docker run -d \
--restart "unless-stopped" \
--memory=${f_memory_gb}g \
--cap-drop=ALL \
--log-driver=none \
--name ${container_name} \
--read-only \
-v "$(pwd)"/tmp:/tmp \
${args} \
${image_name}
else
docker run -i -t \
--rm \
--memory=${f_memory_gb}g \
--cap-drop=ALL \
--log-driver=none \
--name ${container_name} \
--read-only \
-v "$(pwd)"/tmp:/tmp \
${args} \
${image_name} /bin/bash
fi