Skip to content

Commit

Permalink
Merge pull request #36 from bloxbean/install_script
Browse files Browse the repository at this point in the history
New install script to simplify the installation process
  • Loading branch information
satran004 authored May 6, 2024
2 parents e2a42d2 + 84a4531 commit 79768df
Show file tree
Hide file tree
Showing 19 changed files with 304 additions and 111 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ jobs:
TAG=$(grep "tag=" version | cut -d'=' -f2)
echo "TAG=${TAG}" >> $GITHUB_ENV
- name: Run build
run: earthly +build-all-platforms --tag ${{ env.TAG }}
run: earthly +build-all-platforms --tag dev
27 changes: 13 additions & 14 deletions Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,20 @@ zip:
ARG EARTHLY_GIT_SHORT_HASH
RUN apk add --no-cache zip
RUN mkdir -p /app/yaci-devkit-${tag}
RUN mkdir -p /app/yaci-devkit-${tag}/config
RUN mkdir -p /app/yaci-devkit-${tag}/scripts
RUN echo > /app/yaci-devkit-${tag}/version
RUN echo "tag=${tag}" >> /app/yaci-devkit-${tag}/version
RUN echo "revision=${EARTHLY_GIT_SHORT_HASH}" >> /app/yaci-devkit-${tag}/version
COPY docker-compose.yml \
env \
ssh.sh \
devkit.sh \
start.sh \
stop.sh \
yaci-cli.sh \
cardano-cli.sh \
info.sh \
LICENSE \
README.md \
/app/yaci-devkit-${tag}/
RUN echo "tag=${tag}" >> /app/yaci-devkit-${tag}/config/version
RUN echo "revision=${EARTHLY_GIT_SHORT_HASH}" >> /app/yaci-devkit-${tag}/config/version
COPY config/env /app/yaci-devkit-${tag}/config/

COPY bin/devkit.sh /app/yaci-devkit-${tag}/bin/

COPY LICENSE \
README.md \
/app/yaci-devkit-${tag}/

COPY scripts/*.* /app/yaci-devkit-${tag}/scripts/

RUN cd /app && zip -r yaci-devkit-${tag}.zip .
SAVE ARTIFACT yaci-devkit-${tag}.zip AS LOCAL build/yaci-devkit-${tag}.zip
Expand Down
57 changes: 27 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,23 +87,33 @@ Yaci DevKit provides API endpoints that can be used in your off-chain code (e.g.

Download the latest zip from [release section](https://github.com/bloxbean/yaci-devkit/releases) and unzip it.

## To start the DevKit docker compose

To start the DevKit containers and yaci-cli, you can use `devkit.sh` script. It takes two arguments, `start` and `stop`.
## DevKit Script
You can find `devkit.sh` script under the `bin` folder. This script is used to manage the DevKit containers and Yaci CLI.

```shell
./devkit.sh start
Options:
start Start the DevKit containers and CLI.
stop Stop the DevKit containers.
cli Query the Cardano node in the DevKit container using cardano-cli.
ssh Establish an SSH connection to the DevKit container.
info Display information about the Dev Node.
version Display the version of the DevKit.
help Display this help message.

```

Alternatively, you can only start DevKit containers using the following command.
## To start the DevKit docker compose

To start the DevKit containers and yaci-cli.

```shell
./start.sh
./bin/devkit.sh start
```
**Note:** If you have some **ports** already in use, please make sure the mentioned ports in ```env``` file are free.
You can also change the ports in ```env``` file. Any changes to ```env``` file will be applied when you restart the docker compose.

## Update env file to fund test accounts (Optional)
**Note:** If you have some **ports** already in use, please make sure the mentioned ports in ```config/env``` file are free.
You can also change the ports in ```config/env``` file. Any changes to ```env``` file will be applied when you restart the docker compose.

## Update config/env file to fund test accounts (Optional)

Update ```env``` file to include your test Cardano addresses to automatically topup Ada.

Expand All @@ -117,33 +127,20 @@ topup_addresses=<address1>:<ada_value>,<address2><ada_value>
topup_addresses=addr_test1qzlwg5c3mpr0cz5td0rvr5rvcgf02al05cqgd2wzv7pud6chpzk4elx4jh2f7xtftjrdxddr88wg6sfszu8r3gktpjtqrr00q9:20000,addr_test1qqwpl7h3g84mhr36wpetk904p7fchx2vst0z696lxk8ujsjyruqwmlsm344gfux3nsj6njyzj3ppvrqtt36cp9xyydzqzumz82:10000
```

**Important:** After updating env file, you need to restart the docker compose using ```./stop.sh``` and ```./start.sh```
**Important:** After updating env file, you need to restart the docker compose using ```devkit.sh stop``` and ```devkit.sh start``` options.

**Note:** You can also use the ``topup`` command in Yaci CLI to fund your test addresses later.

## Enable Ogmios and Kupo Support (Optional)
Yaci DevKit bundles both Ogmios and Kupo. However, they are not enabled by default. To activate Ogmios and Kupo support,
set ``ogmios_enabled`` flag in ``env`` file to true. Alternatively, you can enable Ogmios support using ``enable-ogmios`` command in Yaci CLI.

## To start yaci-cli

Once the docker compose is up, start Yaci CLI using ```yaci-cli.sh```

```shell
./yaci-cli.sh
```
Yaci DevKit bundles both Ogmios and Kupo. However, Kupo is not enabled by default. To activate both Ogmios and Kupo support,
set `ogmios_enabled` & `kupo_enabled` flag in `env` file to true. Alternatively, you can enable both Ogmios & Kupo support using ``enable-kupomios`` command in Yaci CLI.

## To stop DevKit

Use `devkit.sh` script to stop the DevKit containers.

```shell
./devkit.sh stop
```
Alternatively, you can use ``stop.sh`` script to stop the DevKit containers.

```shell
./stop.sh
./bin/devkit.sh stop
```

## Yaci CLI - Few Key Commands
Expand Down Expand Up @@ -243,15 +240,15 @@ which is already registered in the devnet.

## Query Devnet's Cardano Node using cardano-cli

`cardano-cli.sh` is a wrapper script to query the Cardano node running in the devnet. You can use this script to query the Cardano node like
DevKit script has a wrapper script to query the Cardano node running in the devnet. You can use this script to query the Cardano node like
you usually do with cardano-cli command line tool. You don't need to install cardano-cli in your local machine or use protocol magic number in the command.

**For example:**

To query protocol parameters, you can use the following command.
To query protocol parameters, you can use `cli` option with devkit script.

```shell
./cardano-cli.sh query protocol-parameters
./bin/devkit.sh cli query protocol-parameters
```

### Videos
Expand Down Expand Up @@ -289,7 +286,7 @@ This is the simplest way to build all components and create Docker images. You n
- Run the following Earthly command to build the Docker images:

```shell
earthly --arg-file-path=version +build
earthly --arg-file-path=config/version +build
```
This will build the Yaci DevKit Docker image from `application/cli` and the Yaci Viewer Docker image from `application/viewer`.

Expand Down
86 changes: 86 additions & 0 deletions bin/devkit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/bin/bash

cd "$(dirname "$0")"

SCRIPT_DIR="../scripts"
CONFIG_DIR="../config"

# This is the wrapper script for starting and stopping services and running yaci-cli.sh

# Function to display help message
function display_help() {
echo "Usage: $0 [option]"
echo
echo "Options:"
echo " start Start the DevKit containers and CLI."
echo " stop Stop the DevKit containers."
echo " cli Query the Cardano node in the DevKit container using cardano-cli."
echo " Usage: $0 cli <command>. For example, $0 cli query tip"
echo " ssh Establish an SSH connection to the DevKit container."
echo " info Display information about the Dev Node"
echo " version Display the version of the DevKit"
echo " help Display this help message."
echo
echo "Please provide one of the above options."
}

# Check if an argument is provided
if [ $# -eq 0 ]; then
display_help
exit 1
fi

# Process the argument
case $1 in
start)
echo "Attempting to start the service..."
sh $SCRIPT_DIR/start.sh

# Check if start.sh was successful
if [ $? -eq 0 ]; then
echo "start.sh executed successfully. Running yaci-cli.sh..."
first_arg="$1"
shift
sh $SCRIPT_DIR//yaci-cli.sh "$@"
else
echo "start.sh failed. Not executing yaci-cli.sh."
fi
;;
stop)
echo "Stopping the service..."
sh $SCRIPT_DIR/stop.sh
;;
ssh)
echo "ssh to Devkit container..."
sh $SCRIPT_DIR//ssh.sh
;;
info)
echo "Info of Devkit"
sh $SCRIPT_DIR/info.sh
;;
cli)
echo "Run cardano-cli in Devkit container..."
# Discard the first argument
first_arg="$1"
shift
sh $SCRIPT_DIR//cardano-cli.sh "$@"
;;
version)
# Show version information
if [ -f $CONFIG_DIR/version ]; then
source $CONFIG_DIR/version
echo "DevKit Version: $tag"
[ -n "$revision" ] && echo "Revision: $revision"
else
echo "Version file not found."
fi
;;
help)
display_help
;;
*)
echo "Invalid argument: $1"
display_help
exit 1
;;
esac
8 changes: 0 additions & 8 deletions cardano-cli.sh

This file was deleted.

File renamed without changes.
2 changes: 2 additions & 0 deletions config/version
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tag=0.8.0-preview2
revision=
34 changes: 0 additions & 34 deletions devkit.sh

This file was deleted.

107 changes: 107 additions & 0 deletions docs/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#!/bin/bash

# Function to check if a command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}

# Check for required commands: curl and unzip
if ! command_exists curl; then
echo "Error: curl is not installed. Please install curl and try again."
exit 1
fi

if ! command_exists unzip; then
echo "Error: unzip is not installed. Please install unzip and try again."
exit 1
fi

# Determine version and artifact based on user input or fetch latest
if [ -z "$1" ]; then
# Fetch the latest release version from GitHub
VERSION=$(curl -s "https://api.github.com/repos/bloxbean/yaci-devkit/releases/latest" | jq -r '.tag_name')
ARTIFACT=$(curl -s "https://api.github.com/repos/bloxbean/yaci-devkit/releases/latest" | jq -r '.assets[0].name')
echo "No version specified. Fetching latest version: $VERSION"
else
VERSION=$1
if [[ "$VERSION" == v* ]]; then
echo "Error: Version parameter should not start with 'v'. Please provide the version number without 'v', e.g., 0.5.0."
exit 1
fi
ARTIFACT="yaci-devkit-$VERSION.zip"
echo "Fetching specified version: $VERSION"
fi

if [[ "$VERSION" == "null" ]] || [[ -z "$VERSION" ]]; then
echo "Latest version not found. Please try again later or specify a version."
exit 1
fi

if [[ "$ARTIFACT" == "null" ]] || [[ -z "$ARTIFACT" ]]; then
echo "File not found for latest release"
exit 1
fi


# Configuration
INSTALL_DIR="$HOME/.yaci-devkit"
REPO_URL="https://github.com/bloxbean/yaci-devkit/releases/download/v$VERSION/$ARTIFACT"
SCRIPT_NAME="devkit.sh"

echo "Downloading from: $REPO_URL"

# Check for existing installation
if [ -d "$INSTALL_DIR/bin" ]; then
echo "Existing installation detected at $INSTALL_DIR/bin"
read -p "Do you want to delete the existing installation and proceed? (y/n): " response
if [[ "$response" == "y" ]]; then
echo "Removing existing installation..."
rm -rf "$INSTALL_DIR"
else
echo "Installation aborted."
exit 1
fi
fi

# Create the install directory if it doesn't exist
mkdir -p $INSTALL_DIR

# Download the latest scripts
echo "Downloading the DevKit scripts..."
if ! curl -L $REPO_URL -o "$INSTALL_DIR/devkit.zip"; then
echo "Error downloading the DevKit scripts. Please check your connection and the URL."
exit 1
fi

# Unzip and remove the archive
echo "Installing..."
if ! unzip "$INSTALL_DIR/devkit.zip" -d $INSTALL_DIR; then
echo "Error unzipping the file. Please check the downloaded file and your unzip tool."
rm "$INSTALL_DIR/devkit.zip"
exit 1
fi
rm "$INSTALL_DIR/devkit.zip"

# Move and set up new installation
mkdir -p "$INSTALL_DIR/bin"
mv "$INSTALL_DIR/yaci-devkit-$VERSION"/* "$INSTALL_DIR/bin"
rm -rf "$INSTALL_DIR/yaci-devkit-$VERSION" # Clean up leftover directory

# Create a symbolic link for easier access
ln -s "$INSTALL_DIR/bin/$SCRIPT_NAME" "$INSTALL_DIR/bin/devkit"

# Make scripts executable
chmod +x $INSTALL_DIR/bin/*.sh

echo "Yaci DevKit version $VERSION installed to $INSTALL_DIR"
echo "Trying to add the install directory to the PATH in .bashrc. If you encounter any issues, please add the following line manually:"
echo 'export PATH="$HOME/.yaci-devkit/bin:$PATH"'

# Add the install directory to the PATH in .bashrc
echo "Updating environment..."
if ! grep -q 'export PATH="$HOME/.yaci-devkit/bin:$PATH"' "$HOME/.bashrc"; then
echo 'export PATH="$HOME/.yaci-devkit/bin:$PATH"' >> "$HOME/.bashrc"
echo "Please log out and log back in to refresh your environment."
fi

echo "Installation complete."
Loading

0 comments on commit 79768df

Please sign in to comment.