-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathdocker.sh
executable file
·35 lines (30 loc) · 1.38 KB
/
docker.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
#!/bin/bash
#
# This file is largely cargo-culted from cockroachdb/cockroach/build/builder.sh.
set -euox pipefail
DOCKER_IMAGE_TAG=cockroachdb/activerecord_test_container:master
# Absolute path to this repository.
repo_root=$(cd "$(dirname "${0}")" && pwd)
# Make a fake passwd file for the invoking user.
#
# This setup is so that files created from inside the container in a mounted
# volume end up being owned by the invoking user and not by root.
# We'll mount a fresh directory owned by the invoking user as /root inside the
# container because the container needs a $HOME (without one the default is /)
# and because various utilities (e.g. bash writing to .bash_history) need to be
# able to write to there.
username=$(id -un)
uid_gid=$(id -u):$(id -g)
container_root=${repo_root}/docker_root
mkdir -p "${container_root}"/{etc,home,home/"${username}"/activerecord-cockroachdb-adapter,home/.gems}
echo "${username}:x:${uid_gid}::/home/${username}:/bin/bash" > "${container_root}/etc/passwd"
exec docker run \
--volume="${container_root}/etc/passwd:/etc/passwd" \
--volume="${container_root}/home/${username}:/home/${username}" \
--volume="${repo_root}:/home/${username}/activerecord-cockroachdb-adapter" \
--workdir="/home/${username}/activerecord-cockroachdb-adapter" \
--env=PIP_USER=1 \
--env=GEM_HOME="/home/${username}/.gems" \
--user="${uid_gid}" \
"${DOCKER_IMAGE_TAG}" \
"$@"