forked from qltysh/qlty
-
Notifications
You must be signed in to change notification settings - Fork 0
/
codeclimate-wrapper
executable file
·71 lines (56 loc) · 1.89 KB
/
codeclimate-wrapper
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
invalid_setup() {
local reason=$1
cat >&2 <<EOF
Your Docker setup does not support the codeclimate wrapper script:
> $reason
We require a local Docker daemon that supports communication via the default
socket path.
Please use \`docker run' to run the \`codeclimate/codeclimate' image directly.
See https://github.com/codeclimate/codeclimate 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 CODECLIMATE_CODE \
--env CODECLIMATE_TMP \
--env CODECLIMATE_DEBUG \
--env CONTAINER_MAXIMUM_OUTPUT_BYTES \
--env CONTAINER_TIMEOUT_SECONDS \
--env ENGINE_MEMORY_LIMIT_BYTES \
--volume "$CODECLIMATE_CODE":/code \
--volume "$CODECLIMATE_TMP":/tmp/cc \
--volume /var/run/docker.sock:/var/run/docker.sock \
"$@"
}
if [ -z "$CODECLIMATE_CODE" ]; then
export CODECLIMATE_CODE=$PWD
fi
if [ -z "$CODECLIMATE_TMP" ]; then
export CODECLIMATE_TMP=/tmp/cc
fi
if [ -t 0 ] && [ -t 1 ]; then
docker_run --tty codeclimate/codeclimate "$@"
else
docker_run codeclimate/codeclimate "$@"
fi