diff --git a/Dockerfile b/Dockerfile index befd29c0..c482f2de 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,9 @@ -FROM alpine:latest - -RUN apk update \ - && apk upgrade \ - && apk add --update openjdk11 tzdata curl unzip bash \ - && rm -rf /var/cache/apk/* - -RUN mkdir /opt/rosetta -COPY binary/build/image/binary-linux-x64 /opt/rosetta/ +FROM alpine:latest + +RUN apk update \ + && apk upgrade \ + && apk add --update openjdk11 tzdata curl unzip bash \ + && rm -rf /var/cache/apk/* + +RUN mkdir /opt/rosetta +COPY binary/build/image/binary-linux_x64 /opt/rosetta/ diff --git a/binary/build.gradle b/binary/build.gradle index 4d134250..bf4e81d4 100644 --- a/binary/build.gradle +++ b/binary/build.gradle @@ -40,7 +40,7 @@ runtime { 'jdk.crypto.cryptoki', 'java.security.jgss' ] - targetPlatform("linux-x64") { + targetPlatform("linux_x64") { imageZip = project.ext.imageFile jdkHome = jdkDownload("https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.9.1%2B1/OpenJDK11U-jdk_x64_linux_hotspot_11.0.9.1_1.tar.gz") { downloadDir = "$buildDir/jdklinux" @@ -154,7 +154,7 @@ tasks.register('downloadDrivers') { } } -def bundlePlatforms = ['linux-x64', 'mac_x64', 'mac_aarch64', 'win_x64'] +def bundlePlatforms = ['linux_x64', 'mac_x64', 'mac_aarch64', 'win_x64'] bundlePlatforms.each { platform -> tasks.register("runtimeZipWithDrivers_${platform}", Zip) { diff --git a/docs/markdowns/installation.md b/docs/markdowns/installation.md index 7fa330cf..f749267d 100644 --- a/docs/markdowns/installation.md +++ b/docs/markdowns/installation.md @@ -18,7 +18,7 @@ export ROSETTA_DRIVERS=/Users/adaptivescale/drivers/* 1. Download the rosetta binary for the supported OS ([releases page](https://github.com/AdaptiveScale/rosetta/releases)). ``` - rosetta--linux-x64.zip + rosetta--linux_x64.zip rosetta--mac_aarch64.zip rosetta--mac_x64.zip rosetta--win_x64.zip diff --git a/scripts/github_release.sh b/scripts/github_release.sh index 3d482f2e..30a25422 100755 --- a/scripts/github_release.sh +++ b/scripts/github_release.sh @@ -74,17 +74,23 @@ upload_custom_release_file() { create_release cd binary/build -rename_release_files "rosetta-$APP_VERSION-linux-x64" "linux-x64" +rename_release_files "rosetta-$APP_VERSION-linux_x64" "linux_x64" rename_release_files "rosetta-$APP_VERSION-mac_aarch64" "mac_aarch64" rename_release_files "rosetta-$APP_VERSION-mac_x64" "mac_x64" rename_release_files "rosetta-$APP_VERSION-win_x64" "win_x64" cd ../.. -upload_custom_release_file "rosetta-$APP_VERSION-linux-x64.zip" "binary/build/" +upload_custom_release_file "rosetta-$APP_VERSION-linux_x64.zip" "binary/build/" upload_custom_release_file "rosetta-$APP_VERSION-mac_aarch64.zip" "binary/build/" upload_custom_release_file "rosetta-$APP_VERSION-mac_x64.zip" "binary/build/" upload_custom_release_file "rosetta-$APP_VERSION-win_x64.zip" "binary/build/" -upload_custom_release_file "rosetta-$APP_VERSION-linux-x64-with-drivers.zip" "binary/build/" +upload_custom_release_file "rosetta-$APP_VERSION-linux_x64-with-drivers.zip" "binary/build/" upload_custom_release_file "rosetta-$APP_VERSION-mac_aarch64-with-drivers.zip" "binary/build/" upload_custom_release_file "rosetta-$APP_VERSION-mac_x64-with-drivers.zip" "binary/build/" upload_custom_release_file "rosetta-$APP_VERSION-win_x64-with-drivers.zip" "binary/build/" upload_custom_release_file "cli-$APP_VERSION.jar" "cli/build/libs/" + +mkdir -p build +sed "s/__ROSETTA_VERSION__/$APP_VERSION/" scripts/templates/rosetta_setup.sh > build/rosetta_setup.sh +sed "s/__ROSETTA_VERSION__/$APP_VERSION/" scripts/templates/rosetta_setup.bat > build/rosetta_setup.bat +upload_custom_release_file "rosetta_setup.sh" "build/" +upload_custom_release_file "rosetta_setup.bat" "build/" diff --git a/scripts/templates/rosetta_setup.bat b/scripts/templates/rosetta_setup.bat new file mode 100644 index 00000000..9a251799 --- /dev/null +++ b/scripts/templates/rosetta_setup.bat @@ -0,0 +1,57 @@ +@echo off +REM Define the Rosetta version +set ROSETTA_VERSION=__ROSETTA_VERSION__ +set "ARCH=win_x64" +set ZIP_FILE=rosetta-%ROSETTA_VERSION%-win_x64.zip +set EXTRACTION_DIR=rosetta-%ROSETTA_VERSION%-win_x64 + +set URL=https://github.com/AdaptiveScale/rosetta/releases/download/v%ROSETTA_VERSION%/%ZIP_FILE% + +REM Download the ZIP file using curl (replace with wget if installed) +echo Downloading %ZIP_FILE%... +curl -L -o "%ZIP_FILE%" "%URL%" +if not %errorlevel%==0 ( + echo Download failed. Exiting. + exit /b 1 +) + +REM Extract the ZIP file +echo Extracting %ZIP_FILE%... +powershell -Command "Expand-Archive -Path '%ZIP_FILE%' -DestinationPath '%EXTRACTION_DIR%'" +if not %errorlevel%==0 ( + echo Extraction failed. Exiting. + exit /b 1 +) + +REM Cleanup: Remove the ZIP file +echo Cleaning up... +del "%ZIP_FILE%" + +REM Add the directory to PATH +set "EXTRACTION_DIR=%CD%\%EXTRACTION_DIR%\%EXTRACTION_DIR%\bin" +if exist "%EXTRACTION_DIR%" ( + echo Adding %EXTRACTION_DIR% to PATH... + set "PATH=%NEW_VALUE%;%PATH%" + setx PATH "%EXTRACTION_DIR%;%PATH%" +) else ( + echo Directory %EXTRACTION_DIR% does not exist. Exiting. + exit /b 1 +) + +REM Prompt for project name with a default value +set /p PROJECT_NAME="Enter the project name (default: my_rosetta_project): " +if "%PROJECT_NAME%"=="" set PROJECT_NAME=my_rosetta_project + +REM Run the Rosetta init command +echo Initializing Rosetta project: %PROJECT_NAME%... +rosetta init "%PROJECT_NAME%" +if not %errorlevel%==0 ( + echo Failed to initialize Rosetta project. Please check for errors. + exit /b 1 +) + +echo Rosetta project '%PROJECT_NAME%' initialized successfully. +echo Next steps: +echo 1. Navigate to the project directory: cd %PROJECT_NAME% +echo 2. Configure your database connections in the 'main.conf' file inside the project directory. +echo 3. Start using Rosetta commands. \ No newline at end of file diff --git a/scripts/templates/rosetta_setup.sh b/scripts/templates/rosetta_setup.sh new file mode 100644 index 00000000..596ba8f7 --- /dev/null +++ b/scripts/templates/rosetta_setup.sh @@ -0,0 +1,148 @@ +#!/bin/bash + +# Define the Rosetta version +ROSETTA_VERSION="__ROSETTA_VERSION__" + +# Determine the OS and Architecture +OS=$(uname -s) +ARCH=$(uname -m) + +# Initialize variables +URL="" +ZIP_FILE="" +EXTRACTION_DIR="" + +# Set URL, ZIP_FILE, and EXTRACTION_DIR based on OS and ARCH +if [[ "$OS" == "Darwin" ]]; then + if [[ "$ARCH" == "arm64" ]]; then + echo "Running on macOS (ARM architecture)" + ZIP_FILE="rosetta-${ROSETTA_VERSION}-mac_aarch64.zip" + EXTRACTION_DIR="rosetta-${ROSETTA_VERSION}-mac_aarch64" + elif [[ "$ARCH" == "x86_64" ]]; then + echo "Running on macOS (Intel architecture)" + ZIP_FILE="rosetta-${ROSETTA_VERSION}-mac_x64.zip" + EXTRACTION_DIR="rosetta-${ROSETTA_VERSION}-mac_x64" + else + echo "Unknown architecture on macOS: $ARCH" + exit 1 + fi +elif [[ "$OS" == "Linux" ]]; then + echo "Running on Linux" + if [[ "$ARCH" == "x86_64" ]]; then + ZIP_FILE="rosetta-${ROSETTA_VERSION}-linux_x64.zip" + EXTRACTION_DIR="rosetta-${ROSETTA_VERSION}-linux_x64" + URL="https://github.com/AdaptiveScale/rosetta/releases/download/v${ROSETTA_VERSION}/${ZIP_FILE}" + elif [[ "$ARCH" == "arm64" ]]; then + ZIP_FILE="rosetta-${ROSETTA_VERSION}-linux_aarch64.zip" + EXTRACTION_DIR="rosetta-${ROSETTA_VERSION}-linux_aarch64" + else + echo "Unknown architecture on Linux: $ARCH" + exit 1 + fi +else + echo "Unsupported OS: $OS" + exit 1 +fi + + +URL="https://github.com/AdaptiveScale/rosetta/releases/download/v${ROSETTA_VERSION}/${ZIP_FILE}" + +# Download the ZIP file using wget +echo "Downloading $ZIP_FILE..." +wget -q --show-progress "$URL" -O "$ZIP_FILE" + +# Check if the download was successful +if [ $? -eq 0 ]; then + echo "Download complete." +else + echo "Download failed. Exiting." + exit 1 +fi + +# Extract the ZIP file +echo "Extracting $ZIP_FILE..." +unzip -q "$ZIP_FILE" -d "$EXTRACTION_DIR" + +# Check if the extraction was successful +if [ $? -eq 0 ]; then + echo "Extraction complete. Files are in $EXTRACTION_DIR." +else + echo "Extraction failed. Exiting." + exit 1 +fi + +# Cleanup: Remove the ZIP file (optional) +echo "Cleaning up..." +rm -f "$ZIP_FILE" + +# Define the directory to add to PATH +EXTRACTION_DIR="$PWD/$EXTRACTION_DIR/$EXTRACTION_DIR/bin" + +# Check if the directory exists +if [ -d "$EXTRACTION_DIR" ]; then + echo "Adding $EXTRACTION_DIR to PATH..." +else + echo "Directory $EXTRACTION_DIR does not exist. Exiting." + exit 1 +fi + +# Check if the directory exists +if [ ! -d "$EXTRACTION_DIR" ]; then + echo "Directory $EXTRACTION_DIR does not exist. Exiting." + exit 1 +fi + +# Detect the appropriate shell configuration file +SHELL_CONFIG="" +if [ -n "$ZSH_VERSION" ]; then + SHELL_CONFIG="$HOME/.zshrc" +elif [ -n "$BASH_VERSION" ]; then + SHELL_CONFIG="$HOME/.bashrc" +fi + +if [ -z "$SHELL_CONFIG" ]; then + echo "Could not determine shell configuration file. Add the following line manually:" + echo "export PATH=\"$EXTRACTION_DIR:\$PATH\"" + exit 1 +fi + +# Backup the shell configuration file +echo "Creating a backup of $SHELL_CONFIG..." +cp "$SHELL_CONFIG" "$SHELL_CONFIG.bak" + +# Check for an existing Rosetta PATH line and replace it if found +if grep -q "export PATH=.*rosetta" "$SHELL_CONFIG"; then + echo "Replacing existing Rosetta PATH in $SHELL_CONFIG..." + sed -i.bak "/export PATH=.*rosetta/d" "$SHELL_CONFIG" +else + echo "No existing Rosetta PATH found in $SHELL_CONFIG." +fi + +# Add the new PATH line for Rosetta +echo "Adding new PATH for Rosetta to $SHELL_CONFIG..." +echo "export PATH=\"$EXTRACTION_DIR:\$PATH\"" >> "$SHELL_CONFIG" + +# echo "PATH updated. Restart your terminal or run 'source $SHELL_CONFIG' to apply." + +# Apply the changes to the current session +echo "Sourcing $SHELL_CONFIG..." +source "$SHELL_CONFIG" + +# Prompt for project name with a default value +DEFAULT_PROJECT_NAME="my_rosetta_project" +read -p "Enter the project name (default: $DEFAULT_PROJECT_NAME): " PROJECT_NAME +PROJECT_NAME=${PROJECT_NAME:-$DEFAULT_PROJECT_NAME} + +# Run the Rosetta init command +echo "Initializing Rosetta project: $PROJECT_NAME..." +rosetta init "$PROJECT_NAME" + +if [ $? -eq 0 ]; then + echo "Rosetta project '$PROJECT_NAME' initialized successfully." + echo "Next steps:" + echo "1. Navigate to the project directory: cd $PROJECT_NAME" + echo "2. Configure your database connections in the 'main.conf' file inside the project directory." + echo "3. Start using Rosetta commands" +else + echo "Failed to initialize Rosetta project. Please check for errors." +fi \ No newline at end of file