Skip to content

Commit ef939f9

Browse files
Go - Adds /go/bin to PATH (devcontainers#162)
* bug fix * adds more checks * adds GOROOT * revert GOPATH changes
1 parent 987ebe8 commit ef939f9

5 files changed

Lines changed: 29 additions & 24 deletions

File tree

src/go/devcontainer-feature.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@
2626
}
2727
},
2828
"containerEnv": {
29-
"GOPATH": "/usr/local/go",
30-
"PATH": "/usr/local/go/bin:${PATH}"
29+
"GOROOT": "/usr/local/go",
30+
"GOPATH": "/go",
31+
"PATH": "/usr/local/go/bin:/go/bin:${PATH}"
3132
},
3233
"capAdd": [
3334
"SYS_PTRACE"

src/go/install.sh

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ TARGET_GO_VERSION=${VERSION:-"latest"}
1212
TARGET_GOROOT=${TARGET_GOROOT:-"/usr/local/go"}
1313
TARGET_GOPATH=${TARGET_GOPATH:-"/go"}
1414
USERNAME=${USERNAME:-"automatic"}
15-
UPDATE_RC=${UPDATE_RC:-"true"}
1615
INSTALL_GO_TOOLS=${INSTALL_GO_TOOLS:-"true"}
1716

1817
# https://www.google.com/linuxrepositories/
@@ -47,17 +46,6 @@ elif [ "${USERNAME}" = "none" ] || ! id -u ${USERNAME} > /dev/null 2>&1; then
4746
USERNAME=root
4847
fi
4948

50-
updaterc() {
51-
if [ "${UPDATE_RC}" = "true" ]; then
52-
echo "Updating /etc/bash.bashrc and /etc/zsh/zshrc..."
53-
if [[ "$(cat /etc/bash.bashrc)" != *"$1"* ]]; then
54-
echo -e "$1" >> /etc/bash.bashrc
55-
fi
56-
if [ -f "/etc/zsh/zshrc" ] && [[ "$(cat /etc/zsh/zshrc)" != *"$1"* ]]; then
57-
echo -e "$1" >> /etc/zsh/zshrc
58-
fi
59-
fi
60-
}
6149
# Figure out correct version of a three part version number is not passed
6250
find_version_from_git_tags() {
6351
local variable_name=$1
@@ -148,7 +136,7 @@ if ! cat /etc/group | grep -e "^golang:" > /dev/null 2>&1; then
148136
groupadd -r golang
149137
fi
150138
usermod -a -G golang "${USERNAME}"
151-
mkdir -p "${TARGET_GOROOT}" "${TARGET_GOPATH}"
139+
mkdir -p "${TARGET_GOROOT}" "${TARGET_GOPATH}"
152140
if [ "${TARGET_GO_VERSION}" != "none" ] && ! type go > /dev/null 2>&1; then
153141
# Use a temporary locaiton for gpg keys to avoid polluting image
154142
export GNUPGHOME="/tmp/tmp-gnupg"
@@ -231,19 +219,10 @@ if [ "${INSTALL_GO_TOOLS}" = "true" ]; then
231219
rm -rf /tmp/gotools
232220
fi
233221

234-
# Add GOPATH variable and bin directory into PATH in bashrc/zshrc files (unless disabled)
235-
updaterc "$(cat << EOF
236-
export GOPATH="${TARGET_GOPATH}"
237-
if [[ "\${PATH}" != *"\${GOPATH}/bin"* ]]; then export PATH="\${PATH}:\${GOPATH}/bin"; fi
238-
export GOROOT="${TARGET_GOROOT}"
239-
if [[ "\${PATH}" != *"\${GOROOT}/bin"* ]]; then export PATH="\${PATH}:\${GOROOT}/bin"; fi
240-
EOF
241-
)"
242222

243223
chown -R "${USERNAME}:golang" "${TARGET_GOROOT}" "${TARGET_GOPATH}"
244224
chmod -R g+r+w "${TARGET_GOROOT}" "${TARGET_GOPATH}"
245225
find "${TARGET_GOROOT}" -type d -print0 | xargs -n 1 -0 chmod g+s
246226
find "${TARGET_GOPATH}" -type d -print0 | xargs -n 1 -0 chmod g+s
247227

248228
echo "Done!"
249-
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Optional: Import test library
6+
source dev-container-features-test-lib
7+
8+
check "mkcert version" mkcert --version | grep "v1.4.2"
9+
check "mkcert is installed at correct path" which mkcert | grep "/go/bin/mkcert"
10+
11+
# Report result
12+
reportResults

test/go/scenarios.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"install_go_tool_in_postCreate": {
3+
"image": "ubuntu:focal",
4+
"features": {
5+
"go": {
6+
"version": "latest"
7+
}
8+
},
9+
"postCreateCommand": "go install filippo.io/mkcert@v1.4.2"
10+
}
11+
}

test/go/test.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ set -e
66
source dev-container-features-test-lib
77

88
check "version" go version
9+
check "revive version" revive --version
10+
check "revive is installed at correct path" which revive | grep "/go/bin/revive"
911

1012
# Report result
1113
reportResults

0 commit comments

Comments
 (0)