-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevshell
executable file
·46 lines (37 loc) · 1.02 KB
/
devshell
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
#!/usr/bin/env bash
set -euo pipefail
project_name="new-project"
script_dir=$(dirname $(readlink -f $0))
base_dir=$(git rev-parse --show-toplevel)
image_source_files=(
Dockerfile
entrypoint.sh
entrypoint-user.sh
)
image_source_mtime=$(
for file in ${image_source_files[@]}; do
stat -c %Y $script_dir/$file
done \
| sort -nr | head -n1
)
image_name="$project_name-dev:latest"
need_to_build=true
if [[ -n $(docker images -q $image_name) ]]; then
image_mtime=$(docker image inspect $image_name | jq ".[0].Created" | xargs date +%s -d)
if [[ $image_mtime -gt $image_source_mtime ]]; then
need_to_build=false
fi
fi
if $need_to_build; then
echo "Building docker image..."
docker build -t $image_name $script_dir
fi
docker_opts=${DEVSHELL_DOCKER_OPTS:-"-it"}
exec docker run --rm $docker_opts \
--volume $base_dir:$base_dir \
--volume ~/.zprezto:/usr/local/lib/prezto:ro \
--volume ${project_name}-dev-home:/home/user \
--env TERM=$TERM \
--env HOST_PROJECT_DIR=$base_dir \
${project_name}-dev \
"$@"