This repository was archived by the owner on Dec 14, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRUN.sh
More file actions
executable file
·71 lines (60 loc) · 1.39 KB
/
RUN.sh
File metadata and controls
executable file
·71 lines (60 loc) · 1.39 KB
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
#!/bin/sh
set -ex
# check if has required arguments
if [ $# -ne 2 ]; then
echo "Usage: "
echo " $ judge [image] [script]"
exit 0
fi
# parse input
REPO=$(echo $1 | awk -F '/' '{print $1}')
IMAGE=$(echo $1 | awk -F '/' '{print $2}')
if [ -z "$IMAGE" ]; then
IMAGE=$REPO
REPO=""
echo "Running judge for: $IMAGE"
else
echo "Running judge for: $REPO/$IMAGE"
fi
# find a free port to use for the image registry
read LOWERPORT UPPERPORT < /proc/sys/net/ipv4/ip_local_port_range
while :
do
PORT="`shuf -i $LOWERPORT-$UPPERPORT -n 1`"
ss -lpn | grep -q ":$PORT " || break
done
# create local image registry
REGISTRY_PORT=$PORT
REGISTRY_ID=$(
docker run -d \
-p $REGISTRY_PORT:5000 \
--restart=always \
--name judge-registry \
registry:2
)
echo "Registry running at port: $PORT"
echo "Registry container id: $REGISTRY_ID"
REGISTRY_ADDRESS=$(
docker inspect \
-f "{{ .NetworkSettings.IPAddress }}" \
$REGISTRY_ID
)
# copy image to registry
docker tag \
$1 \
localhost:$REGISTRY_PORT/$IMAGE
docker push \
localhost:$REGISTRY_PORT/$IMAGE
# start judge
echo "Starting up judge"
docker run --privileged \
-it \
--name judge \
--env "REGISTRY_ADDRESS=$REGISTRY_ADDRESS" \
--env "TEST_IMAGE=$IMAGE" \
-v "$2:/app/test.js" \
multipl/judge:latest
# # kill registry
# docker container kill $REGISTRY_ID
# docker container remove $REGISTRY_ID
# echo "Registry shutdown"