61 lines
1.3 KiB
Bash
61 lines
1.3 KiB
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
scripts_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
repo_dir="$(dirname "$scripts_dir")"
|
|
image="${LUPHOTO_DEV_IMAGE:-luphoto-dev}"
|
|
|
|
case "$(uname -s)" in
|
|
MINGW*|MSYS*|CYGWIN*)
|
|
export MSYS_NO_PATHCONV=1
|
|
scripts_host="$(cygpath -w "$scripts_dir")"
|
|
repo_host="$(cygpath -w "$repo_dir")"
|
|
;;
|
|
*)
|
|
scripts_host="$scripts_dir"
|
|
repo_host="$repo_dir"
|
|
;;
|
|
esac
|
|
|
|
image_present() {
|
|
local attempt
|
|
for attempt in 1 2 3; do
|
|
if [ -n "$(docker images -q "$image" 2>/dev/null)" ]; then
|
|
return 0
|
|
fi
|
|
sleep 1
|
|
done
|
|
return 1
|
|
}
|
|
|
|
if [ "${LUPHOTO_DEV_REBUILD:-0}" = "1" ] || ! image_present; then
|
|
if [ "$image" != "luphoto-dev" ] && [ "${LUPHOTO_DEV_REBUILD:-0}" != "1" ]; then
|
|
echo "dev.sh: image $image not found" >&2
|
|
exit 1
|
|
fi
|
|
docker build -t "$image" -f "$scripts_host/dev.Dockerfile" "$scripts_host"
|
|
fi
|
|
|
|
tty_args=()
|
|
if [ -t 0 ] && [ -t 1 ]; then
|
|
tty_args=(-it)
|
|
fi
|
|
|
|
extra_args=()
|
|
if [ -n "${LUPHOTO_DEV_ARGS:-}" ]; then
|
|
read -r -a extra_args <<<"$LUPHOTO_DEV_ARGS"
|
|
fi
|
|
|
|
if [ "$#" -eq 0 ]; then
|
|
set -- bash
|
|
fi
|
|
|
|
exec docker run --rm "${tty_args[@]}" \
|
|
-v "$repo_host:/src" \
|
|
-v luphoto-gomod:/root/go/pkg/mod \
|
|
-v luphoto-gocache:/root/.cache/go-build \
|
|
-e GOFLAGS="${GOFLAGS:-}" \
|
|
-w /src \
|
|
"${extra_args[@]}" \
|
|
"$image" "$@"
|