Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Wrapper script #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ spec/
# Ignore bash / IRB / Byebug history files
.*_hist*

# Ignore development executables:
# Ignore development and other executables:
bin/console
bin/setup
bin/wrapper

# Ignore the engine spec documentation - there's no case it should be distributed:
documented-spec/
69 changes: 69 additions & 0 deletions bin/wrapper
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/sh

# This is a script intended to be run on the host, which will launch the Belugas Docker container.
# Blatantly copied from codeclimate/codeclimate.
invalid_setup() {
local reason=$1

cat >&2 <<EOF
Your Docker setup does not support the belugas wrapper script:
> $reason
We require a local Docker daemon that supports communication via the default
socket path.
Please use \`docker run' to run the \`icalialabs/belugas' image directly.
See https://github.com/icalialabs/belugas for more details.
EOF
exit 1
}

socket_missing() {
invalid_setup "/var/run/docker.sock must exist as a Unix domain socket"
}

invalid_docker_host() {
local host=$1

invalid_setup "invalid DOCKER_HOST=$host, must be unset or unix:///var/run/docker.sock"
}

if [ -n "$DOCKER_MACHINE_NAME" ] && command -v docker-machine > /dev/null 2>&1; then
docker-machine ssh $DOCKER_MACHINE_NAME -- \
test -S /var/run/docker.sock > /dev/null 2>&1 || socket_missing

docker-machine ssh $DOCKER_MACHINE_NAME -- \
'test -n "$DOCKER_HOST" -a "$DOCKER_HOST" != "unix:///var/run/docker.sock"' > /dev/null 2>&1 \
&& invalid_docker_host $(docker-machine ssh $DOCKER_MACHINE_NAME -- 'echo "$DOCKER_HOST"')
else
test -S /var/run/docker.sock || socket_missing
test -n "$DOCKER_HOST" -a "$DOCKER_HOST" != "unix:///var/run/docker.sock" \
&& invalid_docker_host "$DOCKER_HOST"
fi

docker_run() {
exec docker run \
--interactive --rm \
--env BELUGAS_CODE \
--env BELUGAS_TMP \
--env BELUGAS_DEBUG \
--env CONTAINER_MAXIMUM_OUTPUT_BYTES \
--env CONTAINER_TIMEOUT_SECONDS \
--env ENGINE_MEMORY_LIMIT_BYTES \
--volume "$BELUGAS_CODE":/code \
--volume "$BELUGAS_TMP":/tmp/cc \
--volume /var/run/docker.sock:/var/run/docker.sock \
"$@"
}

if [ -z "$BELUGAS_CODE" ]; then
export BELUGAS_CODE=$PWD
fi

if [ -z "$BELUGAS_TMP" ]; then
export BELUGAS_TMP=/tmp/fdet
fi

if [ -t 0 ] && [ -t 1 ]; then
docker_run --tty icalialabs/belugas "$@"
else
docker_run icalialabs/belugas "$@"
fi