-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker-cargo.sh
executable file
·74 lines (62 loc) · 1.94 KB
/
docker-cargo.sh
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/bash -x
REPO_ROOT=$(readlink -f $(dirname $(readlink -f $0)))
OUTPUT_DIR=docker-cargo/
CARGO_HOME=${CARGO_HOME:-$HOME/.cargo}
DOCKER_BUILDER_IMAGE=${DOCKER_BUILDER_IMAGE:-mangatasolutions/node-builder:0.2}
DOCKER_USER="$(id -u):$(id -g)"
DOCKER_JOB_NAME=cargo-wrapper
if [ -n "${DISABLE_TTY}" ]; then
ALLOCATE_TTY_OR_NOT="-i"
else
ALLOCATE_TTY_OR_NOT="-it"
fi
CARGO_COMMAND=$1
CARGO_ARGS=${@:2}
if [ "$CARGO_COMMAND" == "kill" ]; then
docker kill ${DOCKER_JOB_NAME}
exit 0
fi
if ! which docker > /dev/null; then
echo "docker not installed" >&2
exit -1
fi
if docker inspect ${DOCKER_BUILDER_IMAGE} > /dev/null; then
echo "building using docker image ${DOCKER_BUILDER_IMAGE}"
else
echo "docker image ${DOCKER_BUILDER_IMAGE} not found - pulling" >&2
docker pull ${DOCKER_BUILDER_IMAGE}
fi
if [ -e ${CARGO_HOME} ] ; then
CARGO_CACHE_GIT=${CARGO_HOME}/git
CARGO_CACHE_REGISTRY=${CARGO_HOME}/registry
if [ ! -e ${CARGO_CACHE_GIT} ]; then
mkdir -p ${CARGO_CACHE_GIT}
fi
if [ ! -e ${CARGO_CACHE_REGISTRY} ]; then
mkdir -p ${CARGO_CACHE_REGISTRY}
fi
else
CARGO_CACHE_GIT=${REPO_ROOT}/${OUTPUT_DIR}/cargo_cache_git
CARGO_CACHE_REGISTRY=${REPO_ROOT}/${OUTPUT_DIR}/cargo_cache_registry
if [ ! -e ${CARGO_CACHE_REGISTRY} ]; then
mkdir -p ${CARGO_CACHE_REGISTRY}
fi
if [ ! -e ${CARGO_CACHE_GIT} ]; then
mkdir -p ${CARGO_CACHE_GIT}
fi
fi
if [ -n "${DISABLE_CARGO_CACHE}" ]; then
DOCKER_MOUNT_CACHE_VOLUMES=""
else
DOCKER_MOUNT_CACHE_VOLUMES="-v ${CARGO_CACHE_GIT}:/opt/cargo/git -v ${CARGO_CACHE_REGISTRY}:/opt/cargo/registry"
fi
docker run \
--rm \
--name=${DOCKER_JOB_NAME} \
--user $DOCKER_USER \
-v ${REPO_ROOT}:/code \
${DOCKER_MOUNT_CACHE_VOLUMES} \
${DOCKER_RUN_EXTRA_ARGS} \
-e CARGO_TARGET_DIR="/code/${OUTPUT_DIR}" \
${ALLOCATE_TTY_OR_NOT} ${DOCKER_BUILDER_IMAGE} \
cargo ${CARGO_COMMAND} --manifest-path=/code/Cargo.toml ${CARGO_ARGS}