Skip to content

Commit

Permalink
switch to common install script and pin common utils
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaeltm committed Aug 1, 2024
1 parent 3729651 commit dcfbc66
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 171 deletions.
6 changes: 4 additions & 2 deletions src/defang-cli/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
79 changes: 3 additions & 76 deletions src/defang-cli/install.sh
Original file line number Diff line number Diff line change
@@ -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)
25 changes: 0 additions & 25 deletions test/_global/defang.sh

This file was deleted.

8 changes: 0 additions & 8 deletions test/_global/scenarios.json

This file was deleted.

17 changes: 0 additions & 17 deletions test/defang-cli/defang-cli.sh

This file was deleted.

8 changes: 0 additions & 8 deletions test/defang-cli/scenarios.json

This file was deleted.

36 changes: 1 addition & 35 deletions test/defang-cli/test.sh
Original file line number Diff line number Diff line change
@@ -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 <LABEL> <cmd> [args...]
check "execute command" bash -c "defang version | grep 'Defang CLI'"
check "defang version" 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

0 comments on commit dcfbc66

Please sign in to comment.