forked from mozilla/release-services
-
Notifications
You must be signed in to change notification settings - Fork 0
/
please
executable file
·74 lines (65 loc) · 2.1 KB
/
please
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
#!/bin/sh
set -eu
# DEBUG
#set -x
silent() {
out=$("$@" 2>&1) || { echo "$out"; exit 1; }
}
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
USE_DOCKER=1
USE_NIX=${USE_NIX:-0}
if [ -f /.dockerenv ]; then
USE_NIX=1
. /etc/nix/profile.sh;
fi
# Detect OSX
SHASUM="sha256sum"
NETWORK_OPTIONS="--network=host"
if uname -a | grep -q Darwin; then
SHASUM="shasum -a 256"
# Binding to 127.0.0.1 doesn't work on macosx
# --network="host" is not supported on macosx
# Try to minimise the forwarded ports to avoid open file limits.
NETWORK_OPTIONS="-e HOST=0.0.0.0 -p 8000-8040:8000-8040 -p 9000:9000 -p 7000:7000 -p 6379:6379"
fi
if [ "$USE_NIX" = "1" ]; then
drv=$(nix-instantiate nix/default.nix -A please-cli) 2> /dev/null
nix_store_file=$(cut -c17-91 < "$drv")
building_please_cli=0
if [ ! -e "$nix_store_file" ]; then
building_please_cli=1
printf " => Building please command (this might take a minute or two the first time) ... ";
fi
silent nix-build nix/default.nix -A please-cli -o result-please-cli;
if [ "$building_please_cli" = "1" ]; then
echo "${GREEN}DONE${NC}";
fi
exec ./result-please-cli/bin/please "$@";
else
if [ "$USE_DOCKER" = "1" ]; then
DOCKER_HASH="$(pwd)$(git rev-parse --abbrev-ref HEAD)"
DOCKER_NAME="mozilla-releng-services-v$(cat ./VERSION)-$(printf "%s" "$DOCKER_HASH" | $SHASUM | cut -d ' ' -f 1)"
if [ ! "$(docker ps -q -f name="$DOCKER_NAME")" ]; then
if [ ! "$(docker ps -qa -f name="$DOCKER_NAME")" ]; then
docker run \
--privileged \
-td \
--name "$DOCKER_NAME" \
--volume="$(pwd)":/app \
--volume=/var/run/docker.sock:/var/run/docker.sock \
--workdir=/app \
$NETWORK_OPTIONS \
"mozillareleng/services:base-$(cat ./VERSION)"
else
docker start "$DOCKER_NAME"
fi
fi
docker exec --tty --interactive --privileged "$DOCKER_NAME" ./please "$@"
# TODO: stop old docker instances
else
# TODO: better error message and point to documentation
echo "${RED}ERROR: please install nix or docker!${NC}"
fi
fi