Skip to content

Commit 03b2c83

Browse files
committed
Wrapper script so it can invoked directly from the host
1 parent 179cc7f commit 03b2c83

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

.dockerignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ spec/
3131
# Ignore bash / IRB / Byebug history files
3232
.*_hist*
3333

34-
# Ignore development executables:
34+
# Ignore development and other executables:
3535
bin/console
3636
bin/setup
37+
bin/wrapper
3738

3839
# Ignore the engine spec documentation - there's no case it should be distributed:
3940
documented-spec/

bin/wrapper

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/bin/sh
2+
3+
# This is a script intended to be run on the host, which will launch the Belugas Docker container.
4+
# Blatantly copied from codeclimate/codeclimate.
5+
invalid_setup() {
6+
local reason=$1
7+
8+
cat >&2 <<EOF
9+
Your Docker setup does not support the belugas wrapper script:
10+
> $reason
11+
We require a local Docker daemon that supports communication via the default
12+
socket path.
13+
Please use \`docker run' to run the \`icalialabs/belugas' image directly.
14+
See https://github.com/icalialabs/belugas for more details.
15+
EOF
16+
exit 1
17+
}
18+
19+
socket_missing() {
20+
invalid_setup "/var/run/docker.sock must exist as a Unix domain socket"
21+
}
22+
23+
invalid_docker_host() {
24+
local host=$1
25+
26+
invalid_setup "invalid DOCKER_HOST=$host, must be unset or unix:///var/run/docker.sock"
27+
}
28+
29+
if [ -n "$DOCKER_MACHINE_NAME" ] && command -v docker-machine > /dev/null 2>&1; then
30+
docker-machine ssh $DOCKER_MACHINE_NAME -- \
31+
test -S /var/run/docker.sock > /dev/null 2>&1 || socket_missing
32+
33+
docker-machine ssh $DOCKER_MACHINE_NAME -- \
34+
'test -n "$DOCKER_HOST" -a "$DOCKER_HOST" != "unix:///var/run/docker.sock"' > /dev/null 2>&1 \
35+
&& invalid_docker_host $(docker-machine ssh $DOCKER_MACHINE_NAME -- 'echo "$DOCKER_HOST"')
36+
else
37+
test -S /var/run/docker.sock || socket_missing
38+
test -n "$DOCKER_HOST" -a "$DOCKER_HOST" != "unix:///var/run/docker.sock" \
39+
&& invalid_docker_host "$DOCKER_HOST"
40+
fi
41+
42+
docker_run() {
43+
exec docker run \
44+
--interactive --rm \
45+
--env BELUGAS_CODE \
46+
--env BELUGAS_TMP \
47+
--env BELUGAS_DEBUG \
48+
--env CONTAINER_MAXIMUM_OUTPUT_BYTES \
49+
--env CONTAINER_TIMEOUT_SECONDS \
50+
--env ENGINE_MEMORY_LIMIT_BYTES \
51+
--volume "$BELUGAS_CODE":/code \
52+
--volume "$BELUGAS_TMP":/tmp/cc \
53+
--volume /var/run/docker.sock:/var/run/docker.sock \
54+
"$@"
55+
}
56+
57+
if [ -z "$BELUGAS_CODE" ]; then
58+
export BELUGAS_CODE=$PWD
59+
fi
60+
61+
if [ -z "$BELUGAS_TMP" ]; then
62+
export BELUGAS_TMP=/tmp/fdet
63+
fi
64+
65+
if [ -t 0 ] && [ -t 1 ]; then
66+
docker_run --tty icalialabs/belugas "$@"
67+
else
68+
docker_run icalialabs/belugas "$@"
69+
fi

0 commit comments

Comments
 (0)