Skip to content

Commit 0c58956

Browse files
committed
Fix go.env to work with windows containers
1 parent ab38f95 commit 0c58956

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

.go-env.sh

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,27 @@ set -Eeuo pipefail
44
dir="$(dirname "$BASH_SOURCE")"
55
dir="$(readlink -ve "$dir")"
66

7-
user="$(id -u):$(id -g)"
7+
src="$dir"
8+
dst="$dir"
9+
msys=
10+
if [ "$(uname -o)" = 'Msys' ]; then
11+
msys=1
12+
if command -v cygpath > /dev/null; then
13+
src="$(cygpath --windows "$dst")"
14+
fi
15+
fi
16+
windowsContainers=
17+
serverOs="$(docker version --format '{{ .Server.Os }}')"
18+
if [ "$serverOs" = 'windows' ]; then
19+
windowsContainers=1
20+
# normally we'd want this to match $src so error messages, traces, etc are easier to follow, but $src might be on a non-C: drive letter and not be usable in the container as-is 😭
21+
dst='C:\app'
22+
fi
23+
824
args=(
925
--interactive --rm --init
10-
--user "$user"
11-
--mount "type=bind,src=$dir,dst=$dir"
12-
--workdir "$dir"
26+
--mount "type=bind,src=$src,dst=$dst"
27+
--workdir "$dst"
1328
--tmpfs /tmp,exec
1429
--env HOME=/tmp
1530

@@ -32,9 +47,21 @@ args=(
3247
--env DOCKERHUB_PUBLIC_PROXY
3348
--env DOCKERHUB_PUBLIC_PROXY_HOST
3449
)
50+
51+
if [ -z "$windowsContainers" ]; then
52+
user="$(id -u)"
53+
user+=":$(id -g)"
54+
args+=( --user "$user" )
55+
fi
56+
57+
winpty=()
3558
if [ -t 0 ] && [ -t 1 ]; then
3659
args+=( --tty )
60+
if [ -n "$msys" ]; then
61+
winpty=( winpty )
62+
fi
3763
fi
64+
3865
go="$(awk '$1 == "go" { print $2; exit }' "$dir/go.mod")"
3966
if [[ "$go" == *.*.* ]]; then
4067
go="${go%.*}" # strip to just X.Y
@@ -43,5 +70,6 @@ args+=(
4370
"golang:$go"
4471
"$@"
4572
)
73+
4674
set -x
47-
exec docker run "${args[@]}"
75+
exec "${winpty[@]}" docker run "${args[@]}"

0 commit comments

Comments
 (0)