From d5d2685c4b3cc35a4bfa3691ae5e7aface50c0f6 Mon Sep 17 00:00:00 2001 From: Jacob Hummer Date: Thu, 31 Aug 2023 14:57:47 -0500 Subject: [PATCH 1/6] default latest instead of pinned --- devcontainer-feature.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/devcontainer-feature.json b/devcontainer-feature.json index a2b049f..e468609 100644 --- a/devcontainer-feature.json +++ b/devcontainer-feature.json @@ -6,8 +6,9 @@ "options": { "version": { "type": "string", - "default": "0.28.1", - "description": "Specify a version of Tiny Go" + "proposals": ["latest", "0.29.0", "0.28.1"], + "default": "latest", + "description": "A specific 1.2.3 version number of TinyGo to install" } }, "installsAfter": [ From eb048fe8494e50d4ffc2f088637c9f728a0df244 Mon Sep 17 00:00:00 2001 From: Jacob Hummer Date: Thu, 31 Aug 2023 14:59:05 -0500 Subject: [PATCH 2/6] add lib.sh with funcs from devcontainers/features https://github.com/devcontainers/features/blob/038bed3d58a84885da8a008b80905da17d57a543/src/node/install.sh#L66-L79 --- lib.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 lib.sh diff --git a/lib.sh b/lib.sh new file mode 100644 index 0000000..3981f47 --- /dev/null +++ b/lib.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +# https://github.com/devcontainers/features/blob/038bed3d58a84885da8a008b80905da17d57a543/src/node/install.sh#L66 +apt_get_update() { + if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then + echo "Running apt-get update..." + apt-get update -y + fi +} + +# https://github.com/devcontainers/features/blob/038bed3d58a84885da8a008b80905da17d57a543/src/node/install.sh#L74 +# Checks if packages are installed and installs them if not +check_packages() { + if ! dpkg -s "$@" > /dev/null 2>&1; then + apt_get_update + apt-get -y install --no-install-recommends "$@" + fi +} From 9da047b20f828c0542bf810973fd3f19e794fddf Mon Sep 17 00:00:00 2001 From: Jacob Hummer Date: Thu, 31 Aug 2023 14:59:24 -0500 Subject: [PATCH 3/6] replace latest with actual "1.2.3" from github releases latest tagged version --- install.sh | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/install.sh b/install.sh index 2860152..2a7adbc 100644 --- a/install.sh +++ b/install.sh @@ -1,22 +1,25 @@ #!/bin/bash set -ex +source lib.sh -echo "Activating feature 'Tiny Go'" +check_packages curl ca-certificates -# Tiny Go version -VERSION=${VERSION:-"0.28.1"} -ARCHITECTURE="amd64" +arch=$(dpkg --print-architecture) -if [ "$(dpkg --print-architecture)" == "arm64" ]; then - ARCHITECTURE="arm64" +if [[ ${VERSION:-latest} == latest ]]; then + # .../releases/latest redirects to /releases/tag/v1.2.3 + # https://stackoverflow.com/questions/58379142/grep-how-to-output-only-the-content-of-a-capturing-group + VERSION=$(curl \ + -fsSL https://github.com/tinygo-org/tinygo/releases/latest \ + -w '%{url_effective}' -o /dev/null \ + | sed -nr 's/\/v(.*)$/\1/p') fi -apt update -apt install -y curl +url="https://github.com/tinygo-org/tinygo/releases/download/v$VERSION/tinygo_${VERSION}_$arch.deb" -LOCALFILE="/tmp/tinygo_${VERSION}_${ARCHITECTURE}.deb" -TINYURL="https://github.com/tinygo-org/tinygo/releases/download/v${VERSION}/tinygo_${VERSION}_${ARCHITECTURE}.deb" +curl -fsSL "$url" -o tinygo.deb +dpkg -i tinygo.deb +rm tinygo.deb -curl -Lo ${LOCALFILE} ${TINYURL} -dpkg -i ${LOCALFILE} -rm ${LOCALFILE} +# Clean up +rm -rf /var/lib/apt/lists/* From 95b582f2931e22602123cd21d459eae18ea31346 Mon Sep 17 00:00:00 2001 From: Jacob Hummer Date: Thu, 31 Aug 2023 15:02:46 -0500 Subject: [PATCH 4/6] combine lib.sh into install.sh its just simpler that way --- install.sh | 18 +++++++++++++++++- lib.sh | 18 ------------------ 2 files changed, 17 insertions(+), 19 deletions(-) delete mode 100644 lib.sh diff --git a/install.sh b/install.sh index 2a7adbc..3a68645 100644 --- a/install.sh +++ b/install.sh @@ -1,6 +1,22 @@ #!/bin/bash set -ex -source lib.sh + +# https://github.com/devcontainers/features/blob/038bed3d58a84885da8a008b80905da17d57a543/src/node/install.sh#L66 +apt_get_update() { + if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then + echo "Running apt-get update..." + apt-get update -y + fi +} + +# https://github.com/devcontainers/features/blob/038bed3d58a84885da8a008b80905da17d57a543/src/node/install.sh#L74 +# Checks if packages are installed and installs them if not +check_packages() { + if ! dpkg -s "$@" > /dev/null 2>&1; then + apt_get_update + apt-get -y install --no-install-recommends "$@" + fi +} check_packages curl ca-certificates diff --git a/lib.sh b/lib.sh deleted file mode 100644 index 3981f47..0000000 --- a/lib.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -# https://github.com/devcontainers/features/blob/038bed3d58a84885da8a008b80905da17d57a543/src/node/install.sh#L66 -apt_get_update() { - if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then - echo "Running apt-get update..." - apt-get update -y - fi -} - -# https://github.com/devcontainers/features/blob/038bed3d58a84885da8a008b80905da17d57a543/src/node/install.sh#L74 -# Checks if packages are installed and installs them if not -check_packages() { - if ! dpkg -s "$@" > /dev/null 2>&1; then - apt_get_update - apt-get -y install --no-install-recommends "$@" - fi -} From ae596f85dd33e3b67e2965f91b4e8f17a5c5557b Mon Sep 17 00:00:00 2001 From: Jacob Hummer Date: Thu, 31 Aug 2023 15:04:34 -0500 Subject: [PATCH 5/6] better comment with SO links --- install.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index 3a68645..ae506f0 100644 --- a/install.sh +++ b/install.sh @@ -23,8 +23,9 @@ check_packages curl ca-certificates arch=$(dpkg --print-architecture) if [[ ${VERSION:-latest} == latest ]]; then - # .../releases/latest redirects to /releases/tag/v1.2.3 - # https://stackoverflow.com/questions/58379142/grep-how-to-output-only-the-content-of-a-capturing-group + # /releases/latest redirects to /releases/tag/v1.2.3 on GitHub. + # https://stackoverflow.com/a/3077316/19522682 + # https://stackoverflow.com/a/58379307/19522682 VERSION=$(curl \ -fsSL https://github.com/tinygo-org/tinygo/releases/latest \ -w '%{url_effective}' -o /dev/null \ From 9fd94b859fecf166920e4769cf538e050a9c7032 Mon Sep 17 00:00:00 2001 From: Jacob Hummer Date: Thu, 31 Aug 2023 15:29:24 -0500 Subject: [PATCH 6/6] use simpler grep instead of sed --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index ae506f0..9b4dbe5 100644 --- a/install.sh +++ b/install.sh @@ -29,7 +29,7 @@ if [[ ${VERSION:-latest} == latest ]]; then VERSION=$(curl \ -fsSL https://github.com/tinygo-org/tinygo/releases/latest \ -w '%{url_effective}' -o /dev/null \ - | sed -nr 's/\/v(.*)$/\1/p') + | grep -oP '\d+\.\d+\.\d+$') fi url="https://github.com/tinygo-org/tinygo/releases/download/v$VERSION/tinygo_${VERSION}_$arch.deb"