From dcfbc66916fec839184634ba176d172edd45d4ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Titsworth-Morin?= Date: Thu, 1 Aug 2024 20:17:10 +0000 Subject: [PATCH] switch to common install script and pin common utils --- src/defang-cli/devcontainer-feature.json | 6 +- src/defang-cli/install.sh | 79 +----------------------- test/_global/defang.sh | 25 -------- test/_global/scenarios.json | 8 --- test/defang-cli/defang-cli.sh | 17 ----- test/defang-cli/scenarios.json | 8 --- test/defang-cli/test.sh | 36 +---------- 7 files changed, 8 insertions(+), 171 deletions(-) delete mode 100644 test/_global/defang.sh delete mode 100644 test/_global/scenarios.json delete mode 100644 test/defang-cli/defang-cli.sh delete mode 100644 test/defang-cli/scenarios.json diff --git a/src/defang-cli/devcontainer-feature.json b/src/defang-cli/devcontainer-feature.json index 83c990a..048bc95 100644 --- a/src/defang-cli/devcontainer-feature.json +++ b/src/defang-cli/devcontainer-feature.json @@ -1,9 +1,11 @@ { "name": "Defang CLI", "id": "defang-cli", - "version": "1.0.1", + "version": "1.0.2", "description": "A devcontainer feature that installs the Defang CLI", "dependsOn": { - "ghcr.io/devcontainers/features/common-utils": {} + "ghcr.io/devcontainers/features/common-utils": { + "version": "2.4.5" + } } } \ No newline at end of file diff --git a/src/defang-cli/install.sh b/src/defang-cli/install.sh index de6a476..827da6f 100644 --- a/src/defang-cli/install.sh +++ b/src/defang-cli/install.sh @@ -1,79 +1,6 @@ #!/bin/bash -# Define the GitHub API URL for the latest release -RELEASE_API_URL="https://api.github.com/repos/defang-io/defang/releases/latest" +export CI=true +export INSTALL_DIR=/usr/local/bin -# Use curl to fetch the latest release data -echo "Fetching the latest release information..." -RELEASE_JSON=$(curl -s $RELEASE_API_URL) - -# Check for curl failure -if [ $? -ne 0 ]; then - echo "Error fetching release information. Please check your connection or if the URL is correct." - exit 1 -fi - -# Determine system architecture -ARCH=$(uname -m) - -# Adjust the architecture string to match the naming convention in the download URLs -case $ARCH in - x86_64) ARCH_SUFFIX="amd64" ;; - arm64) ARCH_SUFFIX="arm64" ;; - aarch64) ARCH_SUFFIX="arm64" ;; - *) echo "Unsupported architecture: $ARCH"; exit 1 ;; -esac - -# Filter the download URL for Linux -DOWNLOAD_URL=$(echo "$RELEASE_JSON" | grep -o "https://github.com/defang-io/defang/releases/download/v[0-9.]*/defang_[0-9.]*_linux_${ARCH_SUFFIX}.tar.gz" | head -n 1) - -# Abort if the download URL is not found -if [ -z "$DOWNLOAD_URL" ]; then - echo "Could not find a download URL for your architecture ($ARCH_SUFFIX)." - exit 1 -fi - -echo "Downloading $DOWNLOAD_URL..." - -# Define the output file name -FILENAME="defang_latest.tar.gz" - -# Download the file -if ! curl -s -L "$DOWNLOAD_URL" -o "$FILENAME"; then - echo "Download failed. Please check your internet connection and try again." - exit 1 -fi - -# Create a temporary directory for extraction -EXTRACT_DIR=$(mktemp -d) - -# Extract the downloaded file to the temporary directory -echo "Extracting the downloaded file to $EXTRACT_DIR..." -if ! tar -xzf "$FILENAME" -C "$EXTRACT_DIR"; then - echo "Failed to extract the downloaded file. The file might be corrupted." - exit 1 -fi - -# Define a global installation directory that should be in the PATH -INSTALL_DIR="/usr/local/bin" - -# Move the binary or application to the installation directory from the temporary directory -BINARY_NAME='defang' # Adjust this based on actual content -echo "Moving defang to $INSTALL_DIR" -if ! mv "$EXTRACT_DIR/$BINARY_NAME" "$INSTALL_DIR"; then - echo "Failed to move defang. Please check your permissions and try again." - exit 1 -fi - -# Make the binary executable -if ! chmod +x "$INSTALL_DIR/$BINARY_NAME"; then - echo "Failed to make defang executable. Please check your permissions and try again." - exit 1 -fi - -# Cleanup: Remove the temporary directory and the originally downloaded file -echo "Cleaning up..." -rm -r "$EXTRACT_DIR" -rm "$FILENAME" - -echo "Installation completed. You can now use defang by typing '$BINARY_NAME' in the terminal." +. <(curl -Ls https://s.defang.io/install) diff --git a/test/_global/defang.sh b/test/_global/defang.sh deleted file mode 100644 index 46854cb..0000000 --- a/test/_global/defang.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash - -# The 'test/_global' folder is a special test folder that is not tied to a single feature. -# -# This test file is executed against a running container constructed -# from the value of 'defang-cli' in the tests/_global/scenarios.json file. -# -# The value of a scenarios element is any properties available in the 'devcontainer.json'. -# Scenarios are useful for testing specific options in a feature, or to test a combination of features. -# -# This test can be run with the following command (from the root of this repo) -# devcontainer features test --global-scenarios-only . - -set -e - -# Optional: Import test library bundled with the devcontainer CLI -source dev-container-features-test-lib - -echo -e "The result of the 'defang version' command will be:\n" -defang version -echo -e "\n" - -# Report result -# If any of the checks above exited with a non-zero exit code, the test will fail. -reportResults diff --git a/test/_global/scenarios.json b/test/_global/scenarios.json deleted file mode 100644 index 8f319eb..0000000 --- a/test/_global/scenarios.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "defang": { - "image": "mcr.microsoft.com/devcontainers/base:ubuntu", - "features": { - "defang-cli": {} - } - } -} \ No newline at end of file diff --git a/test/defang-cli/defang-cli.sh b/test/defang-cli/defang-cli.sh deleted file mode 100644 index c8a6c3d..0000000 --- a/test/defang-cli/defang-cli.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -# This test file will be executed against one of the scenarios devcontainer.json test that -# includes the 'defang' feature with "greeting": "hello" option. - -set -e - -# Optional: Import test library bundled with the devcontainer CLI -source dev-container-features-test-lib - -# Feature-specific tests -# The 'check' command comes from the dev-container-features-test-lib. -check "execute command" bash -c "defang version | grep 'Defang CLI'" - -# Report results -# If any of the checks above exited with a non-zero exit code, the test will fail. -reportResults diff --git a/test/defang-cli/scenarios.json b/test/defang-cli/scenarios.json deleted file mode 100644 index 0978b63..0000000 --- a/test/defang-cli/scenarios.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "defang-cli": { - "image": "mcr.microsoft.com/devcontainers/base:ubuntu", - "features": { - "defang-cli": {} - } - } -} diff --git a/test/defang-cli/test.sh b/test/defang-cli/test.sh index 6f8fd42..78f329f 100644 --- a/test/defang-cli/test.sh +++ b/test/defang-cli/test.sh @@ -1,47 +1,13 @@ #!/bin/bash -# This test file will be executed against an auto-generated devcontainer.json that -# includes the 'hello' Feature with no options. -# -# For more information, see: https://github.com/devcontainers/cli/blob/main/docs/features/test.md -# -# Eg: -# { -# "image": "<..some-base-image...>", -# "features": { -# "hello": {} -# }, -# "remoteUser": "root" -# } -# -# Thus, the value of all options will fall back to the default value in -# the Feature's 'devcontainer-feature.json'. -# For the 'hello' feature, that means the default favorite greeting is 'hey'. -# -# These scripts are run as 'root' by default. Although that can be changed -# with the '--remote-user' flag. -# -# This test can be run with the following command: -# -# devcontainer features test \ -# --features hello \ -# --remote-user root \ -# --skip-scenarios \ -# --base-image mcr.microsoft.com/devcontainers/base:ubuntu \ -# /path/to/this/repo - set -e -# Optional: Import test library bundled with the devcontainer CLI # See https://github.com/devcontainers/cli/blob/HEAD/docs/features/test.md#dev-container-features-test-lib # Provides the 'check' and 'reportResults' commands. source dev-container-features-test-lib # Feature-specific tests -# The 'check' command comes from the dev-container-features-test-lib. Syntax is... -# check