devcontainers-community / features-dart-sdk

🎯 Installs the Dart SDK
MIT License
0 stars 2 forks source link

Ask original authors #1

Open jcbhmr opened 1 year ago

jcbhmr commented 1 year ago

Hello @jarrodcolburn and @t-kozak! 👋

I notice that you'd created a Dart SDK feature for devcontainers but it wasn't on the https://containers.dev/features list. I figured you might be interested in this repo.

t-kozak commented 1 year ago

Hi @jcbhmr, thanks for reaching out.

Jarrod's repo contains a Flutter and Android feature. Since it's my first time playing with these features, I've used it as a starting point and converted it into Dart SDK.

That script of mine is mostly a copy of a script in the official Dart docker container image. Unfortunately, since the Dart team does not have an official pointer to what's "latest" version of the Dart SDK, the versions, URLs and package checksums are hardcoded in the script.

I could potentially improve the script to pull these from devcontainer.json, but in this form, this feature's configuration would always have to be manually updated to catch up with the release rollout of Dart SDK, which is kind of meh experience IMO.

Let me know your thoughts.

jcbhmr commented 1 year ago

I think it might be possible to use something like this? https://github.com/devcontainers/features/blob/main/src/github-cli/install.sh#L80 find_version_from_git_tags or something to get the latest version from https://github.com/dart-lang/sdk/tags ?? maybe not idk.

jcbhmr commented 1 year ago

i tried using apt to install it as described in the docs and didn't get very far 😅 #2

jcbhmr commented 1 year ago

@t-kozak There's also @eitsupi's https://github.com/devcontainers-community/features/blob/8522fe1bf77b027373dbf10b332010599afc0633/src/dart/install.sh Dart feature that worked, but I don't know if it fits your (exemplifying the typical Dart user 😅 you're the Dart-expert here 🤣) use case.

https://github.com/devcontainers-community/features/blob/8522fe1bf77b027373dbf10b332010599afc0633/src/dart/install.sh

By eitsupi https://github.com/eitsupi Dev Container expert ```sh #!/usr/bin/env bash VERSION=${VERSION:-"latest"} CHANNEL=${CHANNEL:-"stable"} DART_SDK="/usr/lib/dart" 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 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/* 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:-""} if [ "$(echo "${requested_version}" | grep -o "." | wc -l)" != "2" ]; then local escaped_separator=${separator//./\\.} local last_part if [ -n "${last_part_optional}" ]; then last_part=".*${last_part_optional}" else last_part="" fi 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 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" ;; arm64) SDK_ARCH="arm64" ;; esac 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="" 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/" "." "${LAST_PART}" URL="https://storage.googleapis.com/dart-archive/channels/${CHANNEL}/release/${VERSION}/sdk/dartsdk-linux-${SDK_ARCH}-release.zip" fi echo "Downloading Dart..." mkdir "${DART_SDK}" # Working directory mkdir /tmp/dvcf-dart pushd /tmp/dvcf-dart 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 # Clean up rm -rf /var/lib/apt/lists/* echo "Done!" ```

It downloads the Dart zip archive, but it doesn't do the magic checksum that the current feature does. idk if this is a requirement 🤷‍♀️

https://github.com/devcontainers-community/features-dart-sdk/blob/4e19d6a3d15823543501c949b49faa25b2b7a2d9/install.sh#L34

anyways, just thought now that there's discussion on improvement, itd be good to bring the another Dart installation magician into the conversation.

Oh, and thanks for participating in this discussion about something you probably wrote once and forgot about 🤣

jarrodcolburn commented 12 months ago

IMO, I think that using the apt is the way to go (not zip). However!... Hot take... I probably wouldn't follow the instructions at either dart's site or dart repo wiki. Instead...

Because the dart files are held on a Google storage drive, I would probably

  1. download deb files locally
  2. install local deb

An example, for 3.1.2 current stable...

  1. curl -O https://storage.googleapis.com/dart-archive/channels/stable/release/3.1.2/linux_packages/dart_3.1.2-1_amd64.deb
  2. (with super user) sudo apt install -y -f ./dart_3.1.2-1_amd64.deb

(be careful of thr -1 that follows version in deb filenames, example 3.1.2-1)


Everything above is my main comment. Here bellow are just some extra thoughts...

A. I wouldn't recommend copying the dart-docker repo because it is....

  1. tightly coupled to the current dart version, with dart's hashes hardcoded in the Dockerfile
  2. trying to provide a small container for running (not developing) dart apps.

B. I would recommend querying the Dart archive on googleapis...

If you only want to know the version number of the latest (stable) version... https://storage.googleapis.com/dart-archive/channels/stable/release/latest/VERSION (just replace stable with dev or beta in above url to see those instead)

You can investigate the https://storage.googleapis.com/storage/v1/b/dart-archive/ to see what's in there. Make sure you set your delmiter and ask for json in response. So for instance, to ask for folders (prefix) in stable...

So this link https://storage.googleapis.com/storage/v1/b/dart-archive/o?delimiter=/&alt=json&prefix=channels/stable/release/ (again, replace stable with dev or beta if desired) returns the following...

{
  "kind": "storage#objects",
  "prefixes": [
    "channels/stable/release/1.11.0/",
    "channels/stable/release/1.11.1/",
   // truncated ...
    "channels/stable/release/3.0.6/",
    "channels/stable/release/3.0.7/",
    "channels/stable/release/3.1.0/",
    "channels/stable/release/3.1.1/",
    "channels/stable/release/3.1.2/",
  ]
}

Which list's all folders (prefix), made up of versions. (stable, in above example). Those version numbers may be all you need, or you can traverse into the folders by appending to the prefix in the url. So for instance, if you wanted to know about version 2.9.3 specifically...

https://storage.googleapis.com/storage/v1/b/dart-archive/o?delimiter=/&alt=json&prefix=channels/stable/release/2.9.3/ and you see it has 3 folders api-docs, linux_packages, sdk

Side note: if you do want to use zip (instead of deb) so that you can target more than just amd65 platform, the zips and sha hashes are in sdk (as opposed to debs in linux_packages).

C. In your repo it uses latest as the proposal, would stable be better? As stable more closely follows the dart versioning. But i haven't pulled around with deaf containers in a while, latest may be the common convention

D. I see that you are including versions within the proposals, (currently 3.0.7 in your devcontainer-feature.json) which is very nice of you but I wouldn't stress yourself out about itinitially. For now, just provide 'latest' or 'stable'/'beta', as that's what most people are going to use. Down the road if you want... the simplest way to keep that version up to date is to set up a github action, fired via nightly a cron job, to check an if condition to run based on either the current version file, or if the version file's (stable/beta/dev) have been updated since a time condition...

Example: Sep 14th... curl --time-cond '14 Sep 2023' https://storage.googleapis.com/dart-archive/channels/{stable,dev,beta}/release/latest/VERSION

"1 days ago" (aka yesterday) curl --time-cond "$(date -d 1 days ago" +"%d %b %Y")" https://storage.googleapis.com/dart-archive/channels/{stabble,dev,beta}/release/latest/VERSION

^above command returns only the ones updated after provided date. You can confirm this by inspect the last-modified date of (stable) VERSION... curl -s -I https://storage.googleapis.com/dart-archive/channels/stable/release/latest/VERSION | grep -i Last-Modified which currently returns... "last-modified: Wed, 13 Sep 2023 15:12:48 GMT"

If you check for any updates since yesterday, using the curl -v flag and anything comes back you know there's been an update. To get all versions for all channels...

(needs jq command)... curl -s "https://storage.googleapis.com/storage/v1/b/dart-archive/o?delimiter=/&alt=json&prefix=channels/{stable,beta,dev}/release/" | jq '.prefixes[] | split("/")[-2]' | grep -E '[3-9]+\.[0-9]+\.[0-9]+' ^ filters only for dart version 3+

jarrodcolburn commented 12 months ago

Ya know.... After looking at it again, I may have changed my mind. Maybe the dart-docker and zip is the right approach. It would support M1 macs.🤔

jarrodcolburn commented 11 months ago

Yea, after looking at it some more. I like the way you were doing it best. https://github.com/jarrodcolburn/features-dart-sdk/blob/patch-1/install.sh Look at my PR. I try to rewrite file it so hashes aren't hardcoded and should work with any dart version.

I'm not on a computer that's setup to test this at the moment. Please git it a try.