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
2 changes: 1 addition & 1 deletion src/go/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "go",
"version": "1.1.0",
"version": "1.1.1",
"name": "Go",
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/go",
"description": "Installs Go and common Go utilities. Auto-detects latest version and installs needed dependencies.",
Expand Down
11 changes: 7 additions & 4 deletions src/go/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ if ! cat /etc/group | grep -e "^golang:" > /dev/null 2>&1; then
fi
usermod -a -G golang "${USERNAME}"
mkdir -p "${TARGET_GOROOT}" "${TARGET_GOPATH}"
if [ "${TARGET_GO_VERSION}" != "none" ] && ! type go > /dev/null 2>&1; then

if [[ "${TARGET_GO_VERSION}" != "none" ]] && [[ "$(go version)" != *"${TARGET_GO_VERSION}"* ]]; then
# Use a temporary locaiton for gpg keys to avoid polluting image
export GNUPGHOME="/tmp/tmp-gnupg"
mkdir -p ${GNUPGHOME}
Expand Down Expand Up @@ -186,7 +187,7 @@ if [ "${TARGET_GO_VERSION}" != "none" ] && ! type go > /dev/null 2>&1; then
tar -xzf /tmp/go.tar.gz -C "${TARGET_GOROOT}" --strip-components=1
rm -rf /tmp/go.tar.gz /tmp/go.tar.gz.asc /tmp/tmp-gnupg
else
echo "Go already installed. Skipping."
echo "(!) Go is already installed with version ${TARGET_GO_VERSION}. Skipping."
fi

# Install Go tools that are isImportant && !replacedByGopls based on
Expand Down Expand Up @@ -218,8 +219,10 @@ 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/
rm -rf /tmp/gotools
if [ -d /tmp/gotools/bin ]; then
mv /tmp/gotools/bin/* ${TARGET_GOPATH}/bin/
rm -rf /tmp/gotools
fi

# Install golangci-lint from precompiled binares
if [ "$GOLANGCILINT_VERSION" = "latest" ] || [ "$GOLANGCILINT_VERSION" = "" ]; then
Expand Down
6 changes: 3 additions & 3 deletions test/go/install_go_tool_in_postCreate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ 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"
check "golangci-lint version" golangci-lint --version | grep "golangci-lint has version 1.50.0"
check "mkcert version" bash -c "mkcert --version | grep v1.4.2"
check "mkcert is installed at correct path" bash -c "which mkcert | grep /go/bin/mkcert"
check "golangci-lint version" bash -c "golangci-lint --version | grep 'golangci-lint has version 1.50.0'"

# Report result
reportResults
11 changes: 11 additions & 0 deletions test/go/install_go_twice.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

set -e

# Optional: Import test library
source dev-container-features-test-lib

check "go-version" bash -c "go version | grep 1.19"

# Report result
reportResults
8 changes: 8 additions & 0 deletions test/go/scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,13 @@
}
},
"postCreateCommand": "go install filippo.io/mkcert@v1.4.2"
},
"install_go_twice": {
"image": "mcr.microsoft.com/devcontainers/go:1.18",
"features": {
"go": {
"version": "1.19"
}
}
}
}
2 changes: 1 addition & 1 deletion test/go/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 "/go/bin/revive"
check "revive is installed at correct path" bash -c "which revive | grep /go/bin/revive"

# Report result
reportResults