From f656df632fe1ac8f13a92b57919f181daaac8c4e Mon Sep 17 00:00:00 2001 From: Jacob Hummer Date: Wed, 17 May 2023 00:12:38 -0500 Subject: [PATCH 01/29] add basic installer --- src/dart/_common.sh | 24 ++++++++++++++++++++++++ src/dart/install.sh | 17 +++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 src/dart/_common.sh create mode 100644 src/dart/install.sh diff --git a/src/dart/_common.sh b/src/dart/_common.sh new file mode 100644 index 0000000..2a3b009 --- /dev/null +++ b/src/dart/_common.sh @@ -0,0 +1,24 @@ +updaterc() { + 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 +} + +apt_get_update() { + if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then + echo "Running apt-get update..." + apt-get update -y + fi +} + +# 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 +} diff --git a/src/dart/install.sh b/src/dart/install.sh new file mode 100644 index 0000000..6f1d7a4 --- /dev/null +++ b/src/dart/install.sh @@ -0,0 +1,17 @@ +#!/bin/bash +set -e +source _common.sh + +# https://dart.dev/get-dart +# "Perform the following one-time setup:" +sudo apt-get update +sudo apt-get install apt-transport-https +wget -qO- https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo gpg --dearmor -o /usr/share/keyrings/dart.gpg +echo 'deb [signed-by=/usr/share/keyrings/dart.gpg arch=amd64] https://storage.googleapis.com/download.dartlang.org/linux/debian stable main' | sudo tee /etc/apt/sources.list.d/dart_stable.list +# "Then install the Dart SDK:" +sudo apt-get update +sudo apt-get install dart + +# Now that we have Dart installed to /usr/lib/dart/bin, we need to expose that +# to future shell sessions via $PATH. +updaterc 'export PATH="$PATH:/usr/lib/dart/bin"' From 99992f896c244af0e4c7d382079afb0681156266 Mon Sep 17 00:00:00 2001 From: Jacob Hummer Date: Wed, 17 May 2023 00:12:51 -0500 Subject: [PATCH 02/29] add manifest --- src/dart/devcontainer-feature.json | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/dart/devcontainer-feature.json diff --git a/src/dart/devcontainer-feature.json b/src/dart/devcontainer-feature.json new file mode 100644 index 0000000..8746716 --- /dev/null +++ b/src/dart/devcontainer-feature.json @@ -0,0 +1,13 @@ +{ + "id": "dart", + "name": "Dart", + "description": "Installs the Dart SDK", + "version": "1.0.0", + "options": { + "version": { + "description": "Dart version", + "type": "string", + "default": "latest" + } + } +} From dd0b3e41b0e263129fda62a788a46df9ed60f9c4 Mon Sep 17 00:00:00 2001 From: Jacob Hummer Date: Tue, 30 May 2023 16:23:37 -0500 Subject: [PATCH 03/29] Add $VERSION switch --- src/dart/install.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/dart/install.sh b/src/dart/install.sh index 6f1d7a4..5fd5e1e 100644 --- a/src/dart/install.sh +++ b/src/dart/install.sh @@ -10,7 +10,11 @@ wget -qO- https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo gpg --dea echo 'deb [signed-by=/usr/share/keyrings/dart.gpg arch=amd64] https://storage.googleapis.com/download.dartlang.org/linux/debian stable main' | sudo tee /etc/apt/sources.list.d/dart_stable.list # "Then install the Dart SDK:" sudo apt-get update -sudo apt-get install dart +if [[ -z $VERSION || $VERSION == latest ]]; then + sudo apt-get install dart +else + sudo apt-get install "dart=$VERSION" +fi # Now that we have Dart installed to /usr/lib/dart/bin, we need to expose that # to future shell sessions via $PATH. From 165ef48b0a16b87c320748b3dc9fb5e911898630 Mon Sep 17 00:00:00 2001 From: Jacob Hummer Date: Tue, 30 May 2023 16:24:22 -0500 Subject: [PATCH 04/29] Add todo note --- src/dart/install.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/dart/install.sh b/src/dart/install.sh index 5fd5e1e..bf4a2ad 100644 --- a/src/dart/install.sh +++ b/src/dart/install.sh @@ -2,6 +2,8 @@ set -e source _common.sh +# TODO: Do we need to "check_packages" here? + # https://dart.dev/get-dart # "Perform the following one-time setup:" sudo apt-get update From 434ee35c68132f60f0ac9a7aaeae268bf44b3d67 Mon Sep 17 00:00:00 2001 From: Jacob Hummer Date: Tue, 30 May 2023 16:36:10 -0500 Subject: [PATCH 05/29] Add notes page --- src/dart/NOTES.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/dart/NOTES.md diff --git a/src/dart/NOTES.md b/src/dart/NOTES.md new file mode 100644 index 0000000..6e595a4 --- /dev/null +++ b/src/dart/NOTES.md @@ -0,0 +1,18 @@ + + +
+ +[![Dart website](https://thum.io/get/width/800/crop/600/noanimate/https://dart.dev/)](https://dart.dev/) + +
+ +> Dart is a client-optimized language for fast apps on any platform + +— [Dart programming language | Dart] + +This feature installs the Dart SDK using the official installer script. You can +choose to pin a specific version with the `version` input. You might also want +to check out [Flutter] if you're interested in Dart. + +[Dart programming language | Dart]: https://dart.dev/ +[Flutter]: https://flutter.dev/ From daf5c8be1108f74073903a07c59b1a8cf9d4cd21 Mon Sep 17 00:00:00 2001 From: Jacob Hummer Date: Tue, 30 May 2023 16:38:46 -0500 Subject: [PATCH 06/29] Add note about getting help --- src/dart/NOTES.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/dart/NOTES.md b/src/dart/NOTES.md index 6e595a4..3498020 100644 --- a/src/dart/NOTES.md +++ b/src/dart/NOTES.md @@ -14,5 +14,12 @@ This feature installs the Dart SDK using the official installer script. You can choose to pin a specific version with the `version` input. You might also want to check out [Flutter] if you're interested in Dart. +🆘 If you're having trouble with this feature, [open a Discussion] or [open an +Issue]! We'd be happy to fix bugs! 🐛 + + [Dart programming language | Dart]: https://dart.dev/ [Flutter]: https://flutter.dev/ +[open a Discussion]: https://github.com/devcontainers-community/features/discussions/new?category=q-a +[open an Issue]: https://github.com/devcontainers-community/features/issues/new + From 3d87c4cc257a28a5309d3864baec33667f27d498 Mon Sep 17 00:00:00 2001 From: Jacob Hummer Date: Wed, 31 May 2023 14:07:56 -0500 Subject: [PATCH 07/29] Don't use sudo --- src/dart/install.sh | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/dart/install.sh b/src/dart/install.sh index bf4a2ad..02221de 100644 --- a/src/dart/install.sh +++ b/src/dart/install.sh @@ -5,17 +5,16 @@ source _common.sh # TODO: Do we need to "check_packages" here? # https://dart.dev/get-dart -# "Perform the following one-time setup:" -sudo apt-get update -sudo apt-get install apt-transport-https +apt-get update +apt-get install apt-transport-https wget -qO- https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo gpg --dearmor -o /usr/share/keyrings/dart.gpg echo 'deb [signed-by=/usr/share/keyrings/dart.gpg arch=amd64] https://storage.googleapis.com/download.dartlang.org/linux/debian stable main' | sudo tee /etc/apt/sources.list.d/dart_stable.list -# "Then install the Dart SDK:" + sudo apt-get update if [[ -z $VERSION || $VERSION == latest ]]; then - sudo apt-get install dart + apt-get install dart else - sudo apt-get install "dart=$VERSION" + apt-get install "dart=$VERSION" fi # Now that we have Dart installed to /usr/lib/dart/bin, we need to expose that From b64d49df070659d6634883d63e66bc8d456a7b20 Mon Sep 17 00:00:00 2001 From: Jacob Hummer Date: Wed, 31 May 2023 14:08:14 -0500 Subject: [PATCH 08/29] Add check_packages for wget --- src/dart/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dart/install.sh b/src/dart/install.sh index 02221de..8849d3b 100644 --- a/src/dart/install.sh +++ b/src/dart/install.sh @@ -2,7 +2,7 @@ set -e source _common.sh -# TODO: Do we need to "check_packages" here? +check_packages wget # https://dart.dev/get-dart apt-get update From 15fa07ab183a25952a3a33198355566d4e741677 Mon Sep 17 00:00:00 2001 From: Jacob Hummer Date: Wed, 31 May 2023 14:11:03 -0500 Subject: [PATCH 09/29] Add dart --version test --- test/dart/test.sh | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 test/dart/test.sh diff --git a/test/dart/test.sh b/test/dart/test.sh new file mode 100644 index 0000000..38cfc95 --- /dev/null +++ b/test/dart/test.sh @@ -0,0 +1,7 @@ +#!/bin/bash +set -e +source dev-container-features-test-lib + +check 'dart' dart --version + +reportResults From 979a386fbf1ce3486523023dcccf848053f253fe Mon Sep 17 00:00:00 2001 From: Jacob Hummer Date: Wed, 31 May 2023 14:14:31 -0500 Subject: [PATCH 10/29] Add dart extension --- src/dart/devcontainer-feature.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/dart/devcontainer-feature.json b/src/dart/devcontainer-feature.json index 8746716..3e8e963 100644 --- a/src/dart/devcontainer-feature.json +++ b/src/dart/devcontainer-feature.json @@ -9,5 +9,10 @@ "type": "string", "default": "latest" } + }, + "customizations": { + "vscode": { + "extensions": ["dart-code.dart-code"] + } } } From b436f652cc699601b71f832665a613dc9e5384b7 Mon Sep 17 00:00:00 2001 From: Jacob Hummer Date: Wed, 31 May 2023 14:17:54 -0500 Subject: [PATCH 11/29] Add "dart" to test.yml list --- .github/workflows/test.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bc9d869..475b0ad 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,8 +13,7 @@ jobs: strategy: matrix: features: - # - color - # - hello + - dart baseImage: - debian:latest - ubuntu:latest @@ -34,8 +33,7 @@ jobs: strategy: matrix: features: - # - color - # - hello + - dart steps: - uses: actions/checkout@v3 From da8e4ee6cbbfec70a8fdf4dd6557befa129dbd86 Mon Sep 17 00:00:00 2001 From: Jacob Hummer Date: Wed, 31 May 2023 14:19:53 -0500 Subject: [PATCH 12/29] =?UTF-8?q?Remove=20more=20sudos=20=F0=9F=A4=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/dart/install.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/dart/install.sh b/src/dart/install.sh index 8849d3b..937da7f 100644 --- a/src/dart/install.sh +++ b/src/dart/install.sh @@ -7,10 +7,10 @@ check_packages wget # https://dart.dev/get-dart apt-get update apt-get install apt-transport-https -wget -qO- https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo gpg --dearmor -o /usr/share/keyrings/dart.gpg -echo 'deb [signed-by=/usr/share/keyrings/dart.gpg arch=amd64] https://storage.googleapis.com/download.dartlang.org/linux/debian stable main' | sudo tee /etc/apt/sources.list.d/dart_stable.list +wget -qO- https://dl-ssl.google.com/linux/linux_signing_key.pub | gpg --dearmor -o /usr/share/keyrings/dart.gpg +echo 'deb [signed-by=/usr/share/keyrings/dart.gpg arch=amd64] https://storage.googleapis.com/download.dartlang.org/linux/debian stable main' | tee /etc/apt/sources.list.d/dart_stable.list -sudo apt-get update +apt-get update if [[ -z $VERSION || $VERSION == latest ]]; then apt-get install dart else From 26961b8b8ad7f24d5387186622411d57ae2bc6bd Mon Sep 17 00:00:00 2001 From: Jacob Hummer Date: Wed, 31 May 2023 14:26:42 -0500 Subject: [PATCH 13/29] Add gpg install --- src/dart/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dart/install.sh b/src/dart/install.sh index 937da7f..eafe660 100644 --- a/src/dart/install.sh +++ b/src/dart/install.sh @@ -2,7 +2,7 @@ set -e source _common.sh -check_packages wget +check_packages wget gpg # https://dart.dev/get-dart apt-get update From 1cce3c706988dafd3332a56da22e81911cca8d48 Mon Sep 17 00:00:00 2001 From: Jacob Hummer Date: Tue, 6 Jun 2023 00:26:22 -0500 Subject: [PATCH 14/29] Move apt deps into check_packages --- src/dart/install.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/dart/install.sh b/src/dart/install.sh index eafe660..47e8ceb 100644 --- a/src/dart/install.sh +++ b/src/dart/install.sh @@ -2,11 +2,9 @@ set -e source _common.sh -check_packages wget gpg +check_packages wget gpg apt-transport-https ca-certificates # https://dart.dev/get-dart -apt-get update -apt-get install apt-transport-https wget -qO- https://dl-ssl.google.com/linux/linux_signing_key.pub | gpg --dearmor -o /usr/share/keyrings/dart.gpg echo 'deb [signed-by=/usr/share/keyrings/dart.gpg arch=amd64] https://storage.googleapis.com/download.dartlang.org/linux/debian stable main' | tee /etc/apt/sources.list.d/dart_stable.list From e81b162e244e99f931d8911a63d5a7c010b74526 Mon Sep 17 00:00:00 2001 From: eitsupi <50911393+eitsupi@users.noreply.github.com> Date: Tue, 6 Jun 2023 08:19:18 +0000 Subject: [PATCH 15/29] rewrite --- src/dart/_common.sh | 10 +---- src/dart/devcontainer-feature.json | 3 ++ src/dart/install.sh | 66 ++++++++++++++++++++++++------ 3 files changed, 57 insertions(+), 22 deletions(-) diff --git a/src/dart/_common.sh b/src/dart/_common.sh index 2a3b009..5491d05 100644 --- a/src/dart/_common.sh +++ b/src/dart/_common.sh @@ -1,12 +1,4 @@ -updaterc() { - 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 -} +#!/usr/bin/env bash apt_get_update() { if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then diff --git a/src/dart/devcontainer-feature.json b/src/dart/devcontainer-feature.json index 3e8e963..48a8a80 100644 --- a/src/dart/devcontainer-feature.json +++ b/src/dart/devcontainer-feature.json @@ -10,6 +10,9 @@ "default": "latest" } }, + "containerEnv": { + "PATH": "/usr/lib/dart/bin:${PATH}" + }, "customizations": { "vscode": { "extensions": ["dart-code.dart-code"] diff --git a/src/dart/install.sh b/src/dart/install.sh index 47e8ceb..f6b043c 100644 --- a/src/dart/install.sh +++ b/src/dart/install.sh @@ -1,20 +1,60 @@ -#!/bin/bash +#!/usr/bin/env bash + +VERSION=${VERSION:-"latest"} + +DART_SDK="/usr/lib/dart" + set -e source _common.sh -check_packages wget gpg apt-transport-https ca-certificates +if [ "$(id -u)" -ne 0 ]; then + echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.' + exit 1 +fi + +architecture="$(dpkg --print-architecture)" +if [ "${architecture}" != "amd64" ] && [ "${architecture}" != "arm64" ]; then + echo "(!) Architecture $architecture unsupported" + exit 1 +fi + +# Clean up +rm -rf /var/lib/apt/lists/* + +export DEBIAN_FRONTEND=noninteractive -# https://dart.dev/get-dart -wget -qO- https://dl-ssl.google.com/linux/linux_signing_key.pub | gpg --dearmor -o /usr/share/keyrings/dart.gpg -echo 'deb [signed-by=/usr/share/keyrings/dart.gpg arch=amd64] https://storage.googleapis.com/download.dartlang.org/linux/debian stable main' | tee /etc/apt/sources.list.d/dart_stable.list +check_packages curl ca-certificates -apt-get update -if [[ -z $VERSION || $VERSION == latest ]]; then - apt-get install dart -else - apt-get install "dart=$VERSION" +case "$architecture" in +amd64) + SDK_ARCH="x64" + ;; +arm64) + SDK_ARCH="arm64" + ;; +esac + + +if [ "${VERSION}" = "latest" ]; then + URL="https://storage.googleapis.com/dart-archive/channels/be/raw/latest/sdk/dartsdk-linux-${SDK_ARCH}-release.zip" fi -# Now that we have Dart installed to /usr/lib/dart/bin, we need to expose that -# to future shell sessions via $PATH. -updaterc 'export PATH="$PATH:/usr/lib/dart/bin"' +echo "Downloading Dart..." + +mkdir "${DART_SDK}" + +# Working directory +mkdir /tmp/dvcf-dart +pushd /tmp/dvcf-dart + +curl -sL "${URL}" -o dart.zip +unzip dart.zip +mv dart-sdk "${DART_SDK}" + +popd +rm -rf /tmp/dvcf-dart + +# Clean up +rm -rf /var/lib/apt/lists/* + +echo "Done!" From e58fee57405ade5ea84d3c180b7dbfa0729ae605 Mon Sep 17 00:00:00 2001 From: eitsupi <50911393+eitsupi@users.noreply.github.com> Date: Tue, 6 Jun 2023 08:34:50 +0000 Subject: [PATCH 16/29] needs unzip --- src/dart/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dart/install.sh b/src/dart/install.sh index f6b043c..3efe0a3 100644 --- a/src/dart/install.sh +++ b/src/dart/install.sh @@ -23,7 +23,7 @@ rm -rf /var/lib/apt/lists/* export DEBIAN_FRONTEND=noninteractive -check_packages curl ca-certificates +check_packages curl ca-certificates unzip case "$architecture" in amd64) From 4a9f769e351f9a563f1f51837ff75eb7a95f3f97 Mon Sep 17 00:00:00 2001 From: eitsupi <50911393+eitsupi@users.noreply.github.com> Date: Tue, 6 Jun 2023 08:38:46 +0000 Subject: [PATCH 17/29] test: temporally fix path --- test/dart/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/dart/test.sh b/test/dart/test.sh index 38cfc95..1aae3f7 100644 --- a/test/dart/test.sh +++ b/test/dart/test.sh @@ -2,6 +2,6 @@ set -e source dev-container-features-test-lib -check 'dart' dart --version +check 'dart' /usr/lib/dart/bin/dart --version reportResults From 46d073835a54f3832c5e3e7fe6dae14f61933a85 Mon Sep 17 00:00:00 2001 From: eitsupi <50911393+eitsupi@users.noreply.github.com> Date: Tue, 6 Jun 2023 08:40:24 +0000 Subject: [PATCH 18/29] Revert "test: temporally fix path" This reverts commit 4a9f769e351f9a563f1f51837ff75eb7a95f3f97. --- test/dart/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/dart/test.sh b/test/dart/test.sh index 1aae3f7..38cfc95 100644 --- a/test/dart/test.sh +++ b/test/dart/test.sh @@ -2,6 +2,6 @@ set -e source dev-container-features-test-lib -check 'dart' /usr/lib/dart/bin/dart --version +check 'dart' dart --version reportResults From aea8235856f5692eb1e2a93b44caedd4c416a176 Mon Sep 17 00:00:00 2001 From: eitsupi <50911393+eitsupi@users.noreply.github.com> Date: Tue, 6 Jun 2023 08:41:03 +0000 Subject: [PATCH 19/29] not to echo --- src/dart/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dart/install.sh b/src/dart/install.sh index 3efe0a3..766c214 100644 --- a/src/dart/install.sh +++ b/src/dart/install.sh @@ -48,7 +48,7 @@ mkdir /tmp/dvcf-dart pushd /tmp/dvcf-dart curl -sL "${URL}" -o dart.zip -unzip dart.zip +unzip -q dart.zip mv dart-sdk "${DART_SDK}" popd From 6660830e3469278e5b451b72a46f992648bf1739 Mon Sep 17 00:00:00 2001 From: eitsupi <50911393+eitsupi@users.noreply.github.com> Date: Tue, 6 Jun 2023 08:55:52 +0000 Subject: [PATCH 20/29] fix mv --- src/dart/install.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/dart/install.sh b/src/dart/install.sh index 766c214..ac86177 100644 --- a/src/dart/install.sh +++ b/src/dart/install.sh @@ -34,7 +34,6 @@ arm64) ;; esac - if [ "${VERSION}" = "latest" ]; then URL="https://storage.googleapis.com/dart-archive/channels/be/raw/latest/sdk/dartsdk-linux-${SDK_ARCH}-release.zip" fi @@ -49,7 +48,7 @@ pushd /tmp/dvcf-dart curl -sL "${URL}" -o dart.zip unzip -q dart.zip -mv dart-sdk "${DART_SDK}" +mv dart-sdk/* "${DART_SDK}"/. popd rm -rf /tmp/dvcf-dart From 0bfd31c4401d8e9e613266b2dbbd960be98dd74e Mon Sep 17 00:00:00 2001 From: eitsupi <50911393+eitsupi@users.noreply.github.com> Date: Tue, 6 Jun 2023 09:35:08 +0000 Subject: [PATCH 21/29] channel option --- src/dart/_common.sh | 8 +++- src/dart/devcontainer-feature.json | 11 ++++- src/dart/install.sh | 72 +++++++++++++++++++++++++----- 3 files changed, 78 insertions(+), 13 deletions(-) diff --git a/src/dart/_common.sh b/src/dart/_common.sh index 5491d05..a87e86a 100644 --- a/src/dart/_common.sh +++ b/src/dart/_common.sh @@ -9,8 +9,14 @@ apt_get_update() { # Checks if packages are installed and installs them if not check_packages() { - if ! dpkg -s "$@" > /dev/null 2>&1; then + if ! dpkg -s "$@" >/dev/null 2>&1; then apt_get_update apt-get -y install --no-install-recommends "$@" fi } + +check_git() { + if [ ! -x "$(command -v git)" ]; then + check_packages git + fi +} diff --git a/src/dart/devcontainer-feature.json b/src/dart/devcontainer-feature.json index 48a8a80..749a5b0 100644 --- a/src/dart/devcontainer-feature.json +++ b/src/dart/devcontainer-feature.json @@ -5,9 +5,16 @@ "version": "1.0.0", "options": { "version": { - "description": "Dart version", + "description": "Select version of Dart SDK", "type": "string", - "default": "latest" + "default": "latest", + "proposals": ["latest", "3"] + }, + "channel": { + "description": "Select build channel of Dart SDK", + "type": "string", + "default": "stable", + "enum": ["stable", "beta", "dev", "main"] } }, "containerEnv": { diff --git a/src/dart/install.sh b/src/dart/install.sh index ac86177..75a6c94 100644 --- a/src/dart/install.sh +++ b/src/dart/install.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash VERSION=${VERSION:-"latest"} +CHANNEL=${CHANNEL:-"stable"} DART_SDK="/usr/lib/dart" @@ -8,34 +9,85 @@ set -e source _common.sh if [ "$(id -u)" -ne 0 ]; then - echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.' - exit 1 + echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.' + exit 1 fi architecture="$(dpkg --print-architecture)" if [ "${architecture}" != "amd64" ] && [ "${architecture}" != "arm64" ]; then - echo "(!) Architecture $architecture unsupported" - exit 1 + echo "(!) Architecture $architecture unsupported" + exit 1 fi # Clean up rm -rf /var/lib/apt/lists/* +find_version_from_git_tags() { + local variable_name=$1 + local requested_version=${!variable_name} + if [ "${requested_version}" = "none" ]; then return; fi + local repository=$2 + local prefix=${3:-"tags/v"} + local separator=${4:-"."} + local last_part_optional=${5:-"false"} + if [ "$(echo "${requested_version}" | grep -o "." | wc -l)" != "2" ]; then + local escaped_separator=${separator//./\\.} + local last_part + if [ "${last_part_optional}" != "false" ]; then + last_part="(${escaped_separator}[0-9]+)*.*${last_part_optional}" + else + last_part="${escaped_separator}[0-9]+" + fi + local regex="${prefix}\\K[0-9]+${escaped_separator}[0-9]+${last_part}$" + local version_list + check_git + check_packages ca-certificates + version_list="$(git ls-remote --tags "${repository}" | grep -oP "${regex}" | tr -d ' ' | tr "${separator}" "." | sort -rV)" + if [ "${requested_version}" = "latest" ] || [ "${requested_version}" = "current" ] || [ "${requested_version}" = "lts" ]; then + declare -g "${variable_name}"="$(echo "${version_list}" | head -n 1)" + else + set +e + declare -g "${variable_name}"="$(echo "${version_list}" | grep -E -m 1 "^${requested_version//./\\.}([\\.\\s]|$)")" + set -e + fi + fi + if [ -z "${!variable_name}" ] || ! echo "${version_list}" | grep "^${!variable_name//./\\.}$" >/dev/null 2>&1; then + echo -e "Invalid ${variable_name} value: ${requested_version}\nValid values:\n${version_list}" >&2 + exit 1 + fi + echo "${variable_name}=${!variable_name}" +} + export DEBIAN_FRONTEND=noninteractive check_packages curl ca-certificates unzip case "$architecture" in amd64) - SDK_ARCH="x64" - ;; + SDK_ARCH="x64" + ;; arm64) - SDK_ARCH="arm64" - ;; + SDK_ARCH="arm64" + ;; esac -if [ "${VERSION}" = "latest" ]; then - URL="https://storage.googleapis.com/dart-archive/channels/be/raw/latest/sdk/dartsdk-linux-${SDK_ARCH}-release.zip" +if [ "${CHANNEL}" = "main" ]; then + URL="https://storage.googleapis.com/dart-archive/channels/be/raw/latest/sdk/dartsdk-linux-${SDK_ARCH}-release.zip" +else + if [ "${CHANNEL}" = "stable" ]; then + LAST_PART="false" + elif [ "${CHANNEL}" = "beta" ]; then + LAST_PART="beta" + elif [ "${CHANNEL}" = "dev" ]; then + LAST_PART="dev" + else + echo "(!) Channel ${CHANNEL} unsupported" + exit 1 + fi + # Soft version matching + find_version_from_git_tags VERSION "https://github.com/dart-lang/sdk" "tags/v" "." "${LAST_PART}" + + URL="https://storage.googleapis.com/dart-archive/channels/${CHANNEL}/release/${VERSION}/sdk/dartsdk-linux-${SDK_ARCH}-release.zip" fi echo "Downloading Dart..." From e011bc7b479a6ba16e1ac00ed720a112f0ace393 Mon Sep 17 00:00:00 2001 From: eitsupi <50911393+eitsupi@users.noreply.github.com> Date: Tue, 6 Jun 2023 09:37:09 +0000 Subject: [PATCH 22/29] check if the latest version --- test/dart/test.sh | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/test/dart/test.sh b/test/dart/test.sh index 38cfc95..53c1320 100644 --- a/test/dart/test.sh +++ b/test/dart/test.sh @@ -2,6 +2,26 @@ set -e source dev-container-features-test-lib -check 'dart' dart --version +# Clean up +rm -rf /var/lib/apt/lists/* + +apt_get_update() { + if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then + echo "Running apt-get update..." + apt-get update -y + fi +} + +check_packages() { + if ! dpkg -s "$@" >/dev/null 2>&1; then + apt_get_update + apt-get -y install --no-install-recommends "$@" + fi +} + +check_packages git +LATEST_VERSION="$(git ls-remote --tags https://github.com/dart-lang/sdk | grep -oP "[0-9]+\\.[0-9]+\\.[0-9]+" | sort -V | tail -n 1)" + +check 'dart' dart --version | grep "${LATEST_VERSION}" reportResults From ba26e896a8b85aed4e95f5e0c6ea4982998a983a Mon Sep 17 00:00:00 2001 From: eitsupi <50911393+eitsupi@users.noreply.github.com> Date: Tue, 6 Jun 2023 09:57:34 +0000 Subject: [PATCH 23/29] fix version matching --- src/dart/install.sh | 14 +++++++------- test/dart/test.sh | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/dart/install.sh b/src/dart/install.sh index 75a6c94..15e202d 100644 --- a/src/dart/install.sh +++ b/src/dart/install.sh @@ -29,16 +29,16 @@ find_version_from_git_tags() { local repository=$2 local prefix=${3:-"tags/v"} local separator=${4:-"."} - local last_part_optional=${5:-"false"} + local last_part_optional=${5:-""} if [ "$(echo "${requested_version}" | grep -o "." | wc -l)" != "2" ]; then local escaped_separator=${separator//./\\.} local last_part - if [ "${last_part_optional}" != "false" ]; then - last_part="(${escaped_separator}[0-9]+)*.*${last_part_optional}" + if [ -n "${last_part_optional}" ]; then + last_part=".*${last_part_optional}" else - last_part="${escaped_separator}[0-9]+" + last_part="" fi - local regex="${prefix}\\K[0-9]+${escaped_separator}[0-9]+${last_part}$" + local regex="${prefix}\\K[0-9]+${escaped_separator}[0-9]+${escaped_separator}[0-9]+${last_part}$" local version_list check_git check_packages ca-certificates @@ -75,7 +75,7 @@ if [ "${CHANNEL}" = "main" ]; then URL="https://storage.googleapis.com/dart-archive/channels/be/raw/latest/sdk/dartsdk-linux-${SDK_ARCH}-release.zip" else if [ "${CHANNEL}" = "stable" ]; then - LAST_PART="false" + LAST_PART="" elif [ "${CHANNEL}" = "beta" ]; then LAST_PART="beta" elif [ "${CHANNEL}" = "dev" ]; then @@ -85,7 +85,7 @@ else exit 1 fi # Soft version matching - find_version_from_git_tags VERSION "https://github.com/dart-lang/sdk" "tags/v" "." "${LAST_PART}" + find_version_from_git_tags VERSION "https://github.com/dart-lang/sdk" "tags/" "." "${LAST_PART}" URL="https://storage.googleapis.com/dart-archive/channels/${CHANNEL}/release/${VERSION}/sdk/dartsdk-linux-${SDK_ARCH}-release.zip" fi diff --git a/test/dart/test.sh b/test/dart/test.sh index 53c1320..97d5202 100644 --- a/test/dart/test.sh +++ b/test/dart/test.sh @@ -20,7 +20,7 @@ check_packages() { } check_packages git -LATEST_VERSION="$(git ls-remote --tags https://github.com/dart-lang/sdk | grep -oP "[0-9]+\\.[0-9]+\\.[0-9]+" | sort -V | tail -n 1)" +LATEST_VERSION="$(git ls-remote --tags https://github.com/dart-lang/sdk | grep -oP "refs/tags/[0-9]+\\.[0-9]+\\.[0-9]+$" | sort -V | tail -n 1)" check 'dart' dart --version | grep "${LATEST_VERSION}" From c062fca508a1e255e61759aa60746a9a41464e93 Mon Sep 17 00:00:00 2001 From: eitsupi <50911393+eitsupi@users.noreply.github.com> Date: Tue, 6 Jun 2023 10:00:11 +0000 Subject: [PATCH 24/29] fix test --- test/dart/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/dart/test.sh b/test/dart/test.sh index 97d5202..f066690 100644 --- a/test/dart/test.sh +++ b/test/dart/test.sh @@ -22,6 +22,6 @@ check_packages() { check_packages git LATEST_VERSION="$(git ls-remote --tags https://github.com/dart-lang/sdk | grep -oP "refs/tags/[0-9]+\\.[0-9]+\\.[0-9]+$" | sort -V | tail -n 1)" -check 'dart' dart --version | grep "${LATEST_VERSION}" +check 'dart' bash -c "dart --version | grep ${LATEST_VERSION}" reportResults From c24efa2454bbd9a646ef75149faf5ac41783ff49 Mon Sep 17 00:00:00 2001 From: eitsupi <50911393+eitsupi@users.noreply.github.com> Date: Tue, 6 Jun 2023 10:03:27 +0000 Subject: [PATCH 25/29] fix test --- test/dart/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/dart/test.sh b/test/dart/test.sh index f066690..d5dd173 100644 --- a/test/dart/test.sh +++ b/test/dart/test.sh @@ -20,7 +20,7 @@ check_packages() { } check_packages git -LATEST_VERSION="$(git ls-remote --tags https://github.com/dart-lang/sdk | grep -oP "refs/tags/[0-9]+\\.[0-9]+\\.[0-9]+$" | sort -V | tail -n 1)" +LATEST_VERSION="$(git ls-remote --tags https://github.com/dart-lang/sdk | grep -oP "(?<=refs/tags)/[0-9]+\\.[0-9]+\\.[0-9]+$" | sort -V | tail -n 1)" check 'dart' bash -c "dart --version | grep ${LATEST_VERSION}" From 3c5af9a8a31157667c78dabbdf644ea422fa1479 Mon Sep 17 00:00:00 2001 From: eitsupi <50911393+eitsupi@users.noreply.github.com> Date: Tue, 6 Jun 2023 10:07:41 +0000 Subject: [PATCH 26/29] fix test --- test/dart/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/dart/test.sh b/test/dart/test.sh index d5dd173..b2b1cb9 100644 --- a/test/dart/test.sh +++ b/test/dart/test.sh @@ -20,7 +20,7 @@ check_packages() { } check_packages git -LATEST_VERSION="$(git ls-remote --tags https://github.com/dart-lang/sdk | grep -oP "(?<=refs/tags)/[0-9]+\\.[0-9]+\\.[0-9]+$" | sort -V | tail -n 1)" +LATEST_VERSION="$(git ls-remote --tags https://github.com/dart-lang/sdk | grep -oP "(?<=refs/tags/)[0-9]+\\.[0-9]+\\.[0-9]+$" | sort -V | tail -n 1)" check 'dart' bash -c "dart --version | grep ${LATEST_VERSION}" From 1cbfc41ce1db9915fb25057ca0158eb108ee85f8 Mon Sep 17 00:00:00 2001 From: eitsupi <50911393+eitsupi@users.noreply.github.com> Date: Tue, 6 Jun 2023 10:21:09 +0000 Subject: [PATCH 27/29] more tests --- test/dart/channel-beta.sh | 10 ++++++++++ test/dart/channel-main.sh | 8 ++++++++ test/dart/scenarios.json | 26 ++++++++++++++++++++++++++ test/dart/test.sh | 3 ++- test/dart/version-3.sh | 10 ++++++++++ 5 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 test/dart/channel-beta.sh create mode 100644 test/dart/channel-main.sh create mode 100644 test/dart/scenarios.json create mode 100644 test/dart/version-3.sh diff --git a/test/dart/channel-beta.sh b/test/dart/channel-beta.sh new file mode 100644 index 0000000..2c16de8 --- /dev/null +++ b/test/dart/channel-beta.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +set -e +source dev-container-features-test-lib + +LATEST_VERSION="$(git ls-remote --tags https://github.com/dart-lang/sdk | grep -oP "(?<=refs/tags/)[0-9]+\\.[0-9]+\\.[0-9]+.*beta$" | sort -V | tail -n 1)" + +check 'dart' bash -c "dart --version | grep ${LATEST_VERSION}" + +reportResults diff --git a/test/dart/channel-main.sh b/test/dart/channel-main.sh new file mode 100644 index 0000000..c9e76e8 --- /dev/null +++ b/test/dart/channel-main.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +set -e +source dev-container-features-test-lib + +check 'dart' bash -c "dart --version" + +reportResults diff --git a/test/dart/scenarios.json b/test/dart/scenarios.json new file mode 100644 index 0000000..1b2f9e2 --- /dev/null +++ b/test/dart/scenarios.json @@ -0,0 +1,26 @@ +{ + "version-3": { + "image": "mcr.microsoft.com/devcontainers/base:debian", + "features": { + "dart": { + "version": "3" + } + } + }, + "channel-beta": { + "image": "mcr.microsoft.com/devcontainers/base:debian", + "features": { + "dart": { + "channel": "beta" + } + } + }, + "channel-main": { + "image": "mcr.microsoft.com/devcontainers/base:debian", + "features": { + "dart": { + "channel": "main" + } + } + } +} diff --git a/test/dart/test.sh b/test/dart/test.sh index b2b1cb9..4f4be27 100644 --- a/test/dart/test.sh +++ b/test/dart/test.sh @@ -1,4 +1,5 @@ -#!/bin/bash +#!/usr/bin/env bash + set -e source dev-container-features-test-lib diff --git a/test/dart/version-3.sh b/test/dart/version-3.sh new file mode 100644 index 0000000..efae003 --- /dev/null +++ b/test/dart/version-3.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +set -e +source dev-container-features-test-lib + +LATEST_VERSION="$(git ls-remote --tags https://github.com/dart-lang/sdk | grep -oP "(?<=refs/tags/)3\\.[0-9]+\\.[0-9]+$" | sort -V | tail -n 1)" + +check 'dart' bash -c "dart --version | grep ${LATEST_VERSION}" + +reportResults From c08fcbcc510949ec97c92b503afd701304df9971 Mon Sep 17 00:00:00 2001 From: eitsupi <50911393+eitsupi@users.noreply.github.com> Date: Tue, 6 Jun 2023 10:35:44 +0000 Subject: [PATCH 28/29] update docs --- src/dart/NOTES.md | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/dart/NOTES.md b/src/dart/NOTES.md index 3498020..7608082 100644 --- a/src/dart/NOTES.md +++ b/src/dart/NOTES.md @@ -10,15 +10,35 @@ — [Dart programming language | Dart] -This feature installs the Dart SDK using the official installer script. You can -choose to pin a specific version with the `version` input. You might also want -to check out [Flutter] if you're interested in Dart. +This feature installs the Dart SDK. 🆘 If you're having trouble with this feature, [open a Discussion] or [open an Issue]! We'd be happy to fix bugs! 🐛 +## Supported platforms + +`linux/amd64` and `linux/arm64` platforms `debian` and `ubuntu`. + +## How to specify extensions? + +This feature installs any version with the `version` option and `channel` option. +Check [Dart SDK archive] for channel details. + +```json +"features": { + "ghcr.io/devcontainers-community/features/dart:1": { + "version": "3", + "channel": "beta" + } +} +``` + +Note that the beta and dev channels use suffix-based version matching, +so only versions ending with channel name (e.g. `3.1.0-63.1.beta`) can be installed. + [Dart programming language | Dart]: https://dart.dev/ +[Dart SDK archive]: https://dart.dev/get-dart/archive [Flutter]: https://flutter.dev/ [open a Discussion]: https://github.com/devcontainers-community/features/discussions/new?category=q-a [open an Issue]: https://github.com/devcontainers-community/features/issues/new From 92c653e700758389237f05c9199430cae04a4744 Mon Sep 17 00:00:00 2001 From: eitsupi <50911393+eitsupi@users.noreply.github.com> Date: Tue, 6 Jun 2023 11:26:18 +0000 Subject: [PATCH 29/29] fix permission --- src/dart/install.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/dart/install.sh b/src/dart/install.sh index 15e202d..11339a6 100644 --- a/src/dart/install.sh +++ b/src/dart/install.sh @@ -102,6 +102,8 @@ curl -sL "${URL}" -o dart.zip unzip -q dart.zip mv dart-sdk/* "${DART_SDK}"/. +chmod 755 "${DART_SDK}" "${DART_SDK}/bin" + popd rm -rf /tmp/dvcf-dart