Skip to content

Commit

Permalink
Single-step SDK install in docker container. (dart-lang#7335)
Browse files Browse the repository at this point in the history
  • Loading branch information
isoos authored Jan 3, 2024
1 parent f196259 commit dddcd3a
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 25 deletions.
12 changes: 4 additions & 8 deletions Dockerfile.worker
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,12 @@ WORKDIR /home/worker/pub-dev
RUN mkdir -p /home/worker/config/preview

# Setup Dart SDK into /home/worker/dart/{stable,preview}/
RUN tool/setup-dart.sh /home/worker/dart 3.2.3
RUN mv /home/worker/dart/dart-sdk /home/worker/dart/stable
RUN XDG_CONFIG_HOME=/home/worker/config/preview tool/setup-dart.sh /home/worker/dart 3.3.0-174.2.beta
RUN mv /home/worker/dart/dart-sdk /home/worker/dart/preview
RUN tool/setup-dart.sh /home/worker/dart/stable 3.2.3
RUN XDG_CONFIG_HOME=/home/worker/config/preview tool/setup-dart.sh /home/worker/dart/preview 3.3.0-174.2.beta

# Setup Flutter SDK into /home/worker/flutter/{stable,preview}/
RUN tool/setup-flutter.sh /home/worker/flutter 3.16.4
RUN mv /home/worker/flutter/flutter /home/worker/flutter/stable
RUN XDG_CONFIG_HOME=/home/worker/config/preview tool/setup-flutter.sh /home/worker/flutter 3.18.0-0.2.pre
RUN mv /home/worker/flutter/flutter /home/worker/flutter/preview
RUN tool/setup-flutter.sh /home/worker/flutter/stable 3.16.4
RUN XDG_CONFIG_HOME=/home/worker/config/preview tool/setup-flutter.sh /home/worker/flutter/preview 3.18.0-0.2.pre

# Setup webp
RUN tool/setup-webp.sh /home/worker/bin
Expand Down
12 changes: 10 additions & 2 deletions app/test/shared/versions_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,23 @@ void main() {
expect(
dockerfileContent,
contains(
'RUN tool/setup-dart.sh /home/worker/dart $toolStableDartSdkVersion'));
'RUN tool/setup-dart.sh /home/worker/dart/stable $toolStableDartSdkVersion'));
expect(
dockerfileContent,
contains(
'tool/setup-dart.sh /home/worker/dart/preview $toolPreviewDartSdkVersion'));
});

test('Flutter SDK versions should match Dockerfile.worker', () async {
final dockerfileContent = await File('../Dockerfile.worker').readAsString();
expect(
dockerfileContent,
contains(
'RUN tool/setup-flutter.sh /home/worker/flutter $toolStableFlutterSdkVersion'));
'RUN tool/setup-flutter.sh /home/worker/flutter/stable $toolStableFlutterSdkVersion'));
expect(
dockerfileContent,
contains(
'tool/setup-flutter.sh /home/worker/flutter/preview $toolPreviewFlutterSdkVersion'));
});

test('analyzer version should match resolved pana version', () async {
Expand Down
56 changes: 45 additions & 11 deletions tool/setup-dart.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,61 @@ then
exit 1
fi

# Expected version argument formats:
# - stable/raw/hash/<hash>
# - 3.2.5 (stable/release/<version>)
# - 3.2.5-beta (beta/release/<version>)
# - 3.2.5-dev (dev/release/<version>)
if [[ -z "$2" ]];
then
echo "Version argument is missing."
exit 1
fi

CHANNEL="stable"
if [[ "$2" == *beta ]]
# Infer the download URL
if [[ "$2" == */raw/hash/* ]]
then
CHANNEL="beta"
elif [[ "$2" == *dev ]]
DOWNLOAD_URL="https://storage.googleapis.com/dart-archive/channels/$2/sdk/dartsdk-linux-x64-release.zip"
elif [[ "$2" == *.* ]]
then
CHANNEL="dev"
elif [[ "$2" == "latest" ]]
CHANNEL="stable"
if [[ "$2" == *beta ]]
then
CHANNEL="beta"
elif [[ "$2" == *dev ]]
then
CHANNEL="dev"
fi
DOWNLOAD_URL="https://storage.googleapis.com/dart-archive/channels/$CHANNEL/release/$2/sdk/dartsdk-linux-x64-release.zip"
fi

if [[ -z "$DOWNLOAD_URL" ]];
then
CHANNEL="be"
echo "Unable to infer download URL."
exit 1
fi

mkdir -p "$1"
cd "$1"
curl -sS "https://storage.googleapis.com/dart-archive/channels/$CHANNEL/raw/$2/sdk/dartsdk-linux-x64-release.zip" >dartsdk.zip
# Create a temporary directory to extract the archive to.
WORK_DIR=`mktemp -d`
if [[ ! "$WORK_DIR" || ! -d "$WORK_DIR" ]]; then
echo "Could not create temporary directory."
exit 1
fi

# Download and extract Dart SDK
cd "$WORK_DIR"
curl -sS "$DOWNLOAD_URL" >dartsdk.zip
unzip -q dartsdk.zip
rm -f dartsdk.zip
./dart-sdk/bin/dart --disable-analytics

# Move from temp to destination.
DEST_PARENT=`dirname "$1"`
mkdir -p "$DEST_PARENT"
mv "$WORK_DIR/dart-sdk" "$1"

# Initialize and set first run settings
cd "$1"
./bin/dart --disable-analytics

# Cleanup
rm -rf "$WORK_DIR"
8 changes: 4 additions & 4 deletions tool/setup-flutter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ then
exit 1
fi

mkdir -p "$1"
cd "$1"
git clone -b "$2" --single-branch https://github.com/flutter/flutter.git flutter
# Download and extract Flutter SDK into the target directory.
git clone -b "$2" --single-branch https://github.com/flutter/flutter.git "$1"

# Downloads the Dart SDK and disables analytics tracking – which we always want.
# This will add 400 MB.
./flutter/bin/flutter --no-version-check config --no-analytics
cd "$1"
./bin/flutter --no-version-check config --no-analytics

0 comments on commit dddcd3a

Please sign in to comment.