From 11d8d38c9a93ae3b1f38a26df33eedfa695cd9fb Mon Sep 17 00:00:00 2001 From: Samruddhi Khandale Date: Fri, 16 Sep 2022 10:30:25 -0700 Subject: [PATCH 1/4] bug fix --- src/go/install.sh | 35 ++++-------------------- test/go/install_go_tool_in_postCreate.sh | 11 ++++++++ test/go/scenarios.json | 11 ++++++++ test/go/test.sh | 1 + 4 files changed, 29 insertions(+), 29 deletions(-) create mode 100644 test/go/install_go_tool_in_postCreate.sh create mode 100644 test/go/scenarios.json diff --git a/src/go/install.sh b/src/go/install.sh index 3b0ff2626..40feec09a 100755 --- a/src/go/install.sh +++ b/src/go/install.sh @@ -10,9 +10,7 @@ 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 +45,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 +135,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}" 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" @@ -210,7 +197,7 @@ GO_TOOLS="\ if [ "${INSTALL_GO_TOOLS}" = "true" ]; then echo "Installing common Go tools..." export PATH=${TARGET_GOROOT}/bin:${PATH} - mkdir -p /tmp/gotools /usr/local/etc/vscode-dev-containers ${TARGET_GOPATH}/bin + mkdir -p /tmp/gotools /usr/local/etc/vscode-dev-containers ${TARGET_GOROOT}/bin cd /tmp/gotools export GOPATH=/tmp/gotools export GOCACHE=/tmp/gotools/cache @@ -226,24 +213,14 @@ if [ "${INSTALL_GO_TOOLS}" = "true" ]; then (echo "${GO_TOOLS}" | xargs -n 1 go ${go_install_command} -v )2>&1 | tee -a /usr/local/etc/vscode-dev-containers/go.log # Move Go tools into path and clean up - mv /tmp/gotools/bin/* ${TARGET_GOPATH}/bin/ + mv /tmp/gotools/bin/* ${TARGET_GOROOT}/bin/ 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}" + +chown -R "${USERNAME}:golang" "${TARGET_GOROOT}" +chmod -R g+r+w "${TARGET_GOROOT}" 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 000000000..b63874106 --- /dev/null +++ b/test/go/install_go_tool_in_postCreate.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +set -e + +# Optional: Import test library +source dev-container-features-test-lib + +check "mkcert version" mkcert --version | grep "v1.4.2" + +# Report result +reportResults diff --git a/test/go/scenarios.json b/test/go/scenarios.json new file mode 100644 index 000000000..295dbe053 --- /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 87cc950ad..28a674bbf 100755 --- a/test/go/test.sh +++ b/test/go/test.sh @@ -6,6 +6,7 @@ set -e source dev-container-features-test-lib check "version" go version +check "revive version" revive --version # Report result reportResults \ No newline at end of file From f86ca33a783572fe2c9069a653b5844900544298 Mon Sep 17 00:00:00 2001 From: Samruddhi Khandale Date: Fri, 16 Sep 2022 18:02:24 +0000 Subject: [PATCH 2/4] adds more checks --- test/go/install_go_tool_in_postCreate.sh | 1 + test/go/test.sh | 1 + 2 files changed, 2 insertions(+) diff --git a/test/go/install_go_tool_in_postCreate.sh b/test/go/install_go_tool_in_postCreate.sh index b63874106..1a4db24e7 100644 --- a/test/go/install_go_tool_in_postCreate.sh +++ b/test/go/install_go_tool_in_postCreate.sh @@ -6,6 +6,7 @@ set -e 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 "/usr/local/go/bin/mkcert" # Report result reportResults diff --git a/test/go/test.sh b/test/go/test.sh index 28a674bbf..d6609bfbe 100755 --- a/test/go/test.sh +++ b/test/go/test.sh @@ -7,6 +7,7 @@ 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 "/usr/local/go/bin/revive" # Report result reportResults \ No newline at end of file From 2d1fa245202fbeba7620c155b904a29b96dec633 Mon Sep 17 00:00:00 2001 From: Samruddhi Khandale Date: Fri, 16 Sep 2022 18:21:39 +0000 Subject: [PATCH 3/4] adds GOROOT --- src/go/devcontainer-feature.json | 1 + 1 file changed, 1 insertion(+) diff --git a/src/go/devcontainer-feature.json b/src/go/devcontainer-feature.json index f7ee1ad9c..f1939d224 100644 --- a/src/go/devcontainer-feature.json +++ b/src/go/devcontainer-feature.json @@ -26,6 +26,7 @@ } }, "containerEnv": { + "GOROOT": "/usr/local/go", "GOPATH": "/usr/local/go", "PATH": "/usr/local/go/bin:${PATH}" }, From 6f1ce1f1b9495bddae392d9a9731a12d1c2e6840 Mon Sep 17 00:00:00 2001 From: Samruddhi Khandale Date: Fri, 16 Sep 2022 18:39:53 +0000 Subject: [PATCH 4/4] revert GOPATH changes --- src/go/devcontainer-feature.json | 4 ++-- src/go/install.sh | 12 +++++++----- test/go/install_go_tool_in_postCreate.sh | 2 +- test/go/test.sh | 2 +- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/go/devcontainer-feature.json b/src/go/devcontainer-feature.json index f1939d224..cb30c5b60 100644 --- a/src/go/devcontainer-feature.json +++ b/src/go/devcontainer-feature.json @@ -27,8 +27,8 @@ }, "containerEnv": { "GOROOT": "/usr/local/go", - "GOPATH": "/usr/local/go", - "PATH": "/usr/local/go/bin:${PATH}" + "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 40feec09a..86bdbc64a 100755 --- a/src/go/install.sh +++ b/src/go/install.sh @@ -10,6 +10,7 @@ TARGET_GO_VERSION=${VERSION:-"latest"} TARGET_GOROOT=${TARGET_GOROOT:-"/usr/local/go"} +TARGET_GOPATH=${TARGET_GOPATH:-"/go"} USERNAME=${USERNAME:-"automatic"} INSTALL_GO_TOOLS=${INSTALL_GO_TOOLS:-"true"} @@ -135,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}" +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" @@ -197,7 +198,7 @@ GO_TOOLS="\ if [ "${INSTALL_GO_TOOLS}" = "true" ]; then echo "Installing common Go tools..." export PATH=${TARGET_GOROOT}/bin:${PATH} - mkdir -p /tmp/gotools /usr/local/etc/vscode-dev-containers ${TARGET_GOROOT}/bin + mkdir -p /tmp/gotools /usr/local/etc/vscode-dev-containers ${TARGET_GOPATH}/bin cd /tmp/gotools export GOPATH=/tmp/gotools export GOCACHE=/tmp/gotools/cache @@ -213,14 +214,15 @@ if [ "${INSTALL_GO_TOOLS}" = "true" ]; then (echo "${GO_TOOLS}" | xargs -n 1 go ${go_install_command} -v )2>&1 | tee -a /usr/local/etc/vscode-dev-containers/go.log # Move Go tools into path and clean up - mv /tmp/gotools/bin/* ${TARGET_GOROOT}/bin/ + mv /tmp/gotools/bin/* ${TARGET_GOPATH}/bin/ rm -rf /tmp/gotools fi -chown -R "${USERNAME}:golang" "${TARGET_GOROOT}" -chmod -R g+r+w "${TARGET_GOROOT}" +chown -R "${USERNAME}:golang" "${TARGET_GOROOT}" "${TARGET_GOPATH}" +chmod -R g+r+w "${TARGET_GOROOT}" "${TARGET_GOPATH}" 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 index 1a4db24e7..7d4bc7bd9 100644 --- a/test/go/install_go_tool_in_postCreate.sh +++ b/test/go/install_go_tool_in_postCreate.sh @@ -6,7 +6,7 @@ set -e 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 "/usr/local/go/bin/mkcert" +check "mkcert is installed at correct path" which mkcert | grep "/go/bin/mkcert" # Report result reportResults diff --git a/test/go/test.sh b/test/go/test.sh index d6609bfbe..ee9f171af 100755 --- a/test/go/test.sh +++ b/test/go/test.sh @@ -7,7 +7,7 @@ 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 "/usr/local/go/bin/revive" +check "revive is installed at correct path" which revive | grep "/go/bin/revive" # Report result reportResults \ No newline at end of file