Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/go/devcontainer-feature.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
23 changes: 1 addition & 22 deletions src/go/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -231,19 +219,10 @@ 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}"
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!"

12 changes: 12 additions & 0 deletions test/go/install_go_tool_in_postCreate.sh
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions test/go/scenarios.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
2 changes: 2 additions & 0 deletions test/go/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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