-
Notifications
You must be signed in to change notification settings - Fork 3
/
docker-dev
executable file
·59 lines (51 loc) · 1.31 KB
/
docker-dev
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
#!/usr/bin/env bash
set -euo pipefail
export NICE="nice -14 ionice -c2 -n3"
DOCKER_REPO="nextstrain/flu_frequencies_builder"
DOCKER_IMAGE_NAME_SAFE="${DOCKER_REPO//\//-}"
DOCKER_CONTAINER_NAME="${DOCKER_IMAGE_NAME_SAFE}-$(date +%s)"
USER="user"
GROUP="group"
DOCKER_TARGET="base"
case "${1:-}" in
"py" | "p")
shift
DOCKER_TARGET="py"
COMMAND=${*:-nextstrain build . --profile profiles/flu}
;;
"web" | "a")
shift
COMMAND=${*:-cd web && yarn install && yarn dev}
;;
*)
COMMAND=${*:-bash}
esac
if [ -z "${COMMAND}" ]; then
COMMAND="bash"
fi
${NICE} docker build -q \
--file="docker/docker-dev.dockerfile" \
--target="${DOCKER_TARGET}" \
--tag="${DOCKER_REPO}:${DOCKER_TARGET}" \
--network=host \
--build-arg="UID=$(id -u)" \
--build-arg="GID=$(id -g)" \
--build-arg="USER=${USER}" \
--build-arg="GROUP=${GROUP}" \
"$(pwd)" >/dev/null
${NICE} docker run -it --rm \
--network=host \
--init \
--name="${DOCKER_CONTAINER_NAME}" \
--hostname="${DOCKER_IMAGE_NAME_SAFE}" \
--user="$(id -u):$(id -g)" \
--volume="$(pwd):/workdir" \
--workdir="/workdir" \
--env="UID=$(id -u)" \
--env="GID=$(id -g)" \
--env="USER=${USER}" \
--env="GROUP=${GROUP}" \
--env="PS1=\${USER}@\${HOST}" \
--ulimit core=0 \
"${DOCKER_REPO}:${DOCKER_TARGET}" \
bash -c "set -euo pipefail; ${COMMAND}"