Unverified Commit ef939f90 authored by Samruddhi Khandale's avatar Samruddhi Khandale Committed by GitHub

Go - Adds `/go/bin` to PATH (#162)

* bug fix

* adds more checks

* adds GOROOT

* revert GOPATH changes
parent 987ebe8e
......@@ -26,8 +26,9 @@
}
},
"containerEnv": {
"GOPATH": "/usr/local/go",
"PATH": "/usr/local/go/bin:${PATH}"
"GOROOT": "/usr/local/go",
"GOPATH": "/go",
"PATH": "/usr/local/go/bin:/go/bin:${PATH}"
},
"capAdd": [
"SYS_PTRACE"
......
......@@ -12,7 +12,6 @@ TARGET_GO_VERSION=${VERSION:-"latest"}
TARGET_GOROOT=${TARGET_GOROOT:-"/usr/local/go"}
TARGET_GOPATH=${TARGET_GOPATH:-"/go"}
USERNAME=${USERNAME:-"automatic"}
UPDATE_RC=${UPDATE_RC:-"true"}
INSTALL_GO_TOOLS=${INSTALL_GO_TOOLS:-"true"}
# https://www.google.com/linuxrepositories/
......@@ -47,17 +46,6 @@ elif [ "${USERNAME}" = "none" ] || ! id -u ${USERNAME} > /dev/null 2>&1; then
USERNAME=root
fi
updaterc() {
if [ "${UPDATE_RC}" = "true" ]; then
echo "Updating /etc/bash.bashrc and /etc/zsh/zshrc..."
if [[ "$(cat /etc/bash.bashrc)" != *"$1"* ]]; then
echo -e "$1" >> /etc/bash.bashrc
fi
if [ -f "/etc/zsh/zshrc" ] && [[ "$(cat /etc/zsh/zshrc)" != *"$1"* ]]; then
echo -e "$1" >> /etc/zsh/zshrc
fi
fi
}
# Figure out correct version of a three part version number is not passed
find_version_from_git_tags() {
local variable_name=$1
......@@ -148,7 +136,7 @@ if ! cat /etc/group | grep -e "^golang:" > /dev/null 2>&1; then
groupadd -r golang
fi
usermod -a -G golang "${USERNAME}"
mkdir -p "${TARGET_GOROOT}" "${TARGET_GOPATH}"
mkdir -p "${TARGET_GOROOT}" "${TARGET_GOPATH}"
if [ "${TARGET_GO_VERSION}" != "none" ] && ! type go > /dev/null 2>&1; then
# Use a temporary locaiton for gpg keys to avoid polluting image
export GNUPGHOME="/tmp/tmp-gnupg"
......@@ -231,14 +219,6 @@ if [ "${INSTALL_GO_TOOLS}" = "true" ]; then
rm -rf /tmp/gotools
fi
# Add GOPATH variable and bin directory into PATH in bashrc/zshrc files (unless disabled)
updaterc "$(cat << EOF
export GOPATH="${TARGET_GOPATH}"
if [[ "\${PATH}" != *"\${GOPATH}/bin"* ]]; then export PATH="\${PATH}:\${GOPATH}/bin"; fi
export GOROOT="${TARGET_GOROOT}"
if [[ "\${PATH}" != *"\${GOROOT}/bin"* ]]; then export PATH="\${PATH}:\${GOROOT}/bin"; fi
EOF
)"
chown -R "${USERNAME}:golang" "${TARGET_GOROOT}" "${TARGET_GOPATH}"
chmod -R g+r+w "${TARGET_GOROOT}" "${TARGET_GOPATH}"
......@@ -246,4 +226,3 @@ find "${TARGET_GOROOT}" -type d -print0 | xargs -n 1 -0 chmod g+s
find "${TARGET_GOPATH}" -type d -print0 | xargs -n 1 -0 chmod g+s
echo "Done!"
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
check "mkcert version" mkcert --version | grep "v1.4.2"
check "mkcert is installed at correct path" which mkcert | grep "/go/bin/mkcert"
# Report result
reportResults
{
"install_go_tool_in_postCreate": {
"image": "ubuntu:focal",
"features": {
"go": {
"version": "latest"
}
},
"postCreateCommand": "go install filippo.io/mkcert@v1.4.2"
}
}
......@@ -6,6 +6,8 @@ set -e
source dev-container-features-test-lib
check "version" go version
check "revive version" revive --version
check "revive is installed at correct path" which revive | grep "/go/bin/revive"
# Report result
reportResults
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment