diff options
author | Samruddhi Khandale <skhandale@microsoft.com> | 2022-09-16 23:51:35 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-16 23:51:35 +0300 |
commit | ef939f908c43bf89ade5d2153a751c7ee47989cc (patch) | |
tree | 922b6ab76def08ccaed7e0b74f362493ae3e0041 | |
parent | 987ebe8ea69f59e543e9f961eba5d4a1d0c2821f (diff) |
Go - Adds `/go/bin` to PATH (#162)
* bug fix
* adds more checks
* adds GOROOT
* revert GOPATH changes
-rw-r--r-- | src/go/devcontainer-feature.json | 5 | ||||
-rwxr-xr-x | src/go/install.sh | 23 | ||||
-rw-r--r-- | test/go/install_go_tool_in_postCreate.sh | 12 | ||||
-rw-r--r-- | test/go/scenarios.json | 11 | ||||
-rwxr-xr-x | test/go/test.sh | 2 |
5 files changed, 29 insertions, 24 deletions
diff --git a/src/go/devcontainer-feature.json b/src/go/devcontainer-feature.json index f7ee1ad..cb30c5b 100644 --- a/src/go/devcontainer-feature.json +++ b/src/go/devcontainer-feature.json @@ -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" diff --git a/src/go/install.sh b/src/go/install.sh index 3b0ff26..86bdbc6 100755 --- a/src/go/install.sh +++ b/src/go/install.sh @@ -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!" - diff --git a/test/go/install_go_tool_in_postCreate.sh b/test/go/install_go_tool_in_postCreate.sh new file mode 100644 index 0000000..7d4bc7b --- /dev/null +++ b/test/go/install_go_tool_in_postCreate.sh @@ -0,0 +1,12 @@ +#!/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 diff --git a/test/go/scenarios.json b/test/go/scenarios.json new file mode 100644 index 0000000..295dbe0 --- /dev/null +++ b/test/go/scenarios.json @@ -0,0 +1,11 @@ +{ + "install_go_tool_in_postCreate": { + "image": "ubuntu:focal", + "features": { + "go": { + "version": "latest" + } + }, + "postCreateCommand": "go install filippo.io/mkcert@v1.4.2" + } +} diff --git a/test/go/test.sh b/test/go/test.sh index 87cc950..ee9f171 100755 --- a/test/go/test.sh +++ b/test/go/test.sh @@ -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 |