Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve installation script for code deploy #34

Merged
merged 6 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions appspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ files:
- source: /
destination: /home/ubuntu/lisk-across-relayer
hooks:
BeforeInstall:
- location: scripts/installDependencies.sh
AfterInstall:
- location: scripts/installDependencies.sh
- location: scripts/installApplication.sh
runas: root
ApplicationStart:
- location: scripts/runMainnet.sh
runas: root
4 changes: 2 additions & 2 deletions scripts/installApplication.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ app_dir_name=/home/ubuntu/lisk-across-relayer
mkdir $app_dir_name
cd $app_dir_name
echo "Current DIR: $PWD"
sudo yarn install
sudo yarn build
yarn install --frozen-lockfile
yarn build
44 changes: 16 additions & 28 deletions scripts/installDependencies.sh
Original file line number Diff line number Diff line change
@@ -1,52 +1,40 @@
# Install nodejs dependencies
sudo apt update
echo "Current DIR: $PWD"
# Script to install Node.js using NVM on Ubuntu without sudo
# Script to install Node.js using NVM on Ubuntu

# Read node version from .nvmrc file
node_version=$(cat .nvmrc | tr -d "\n")

node_version=v20
# Function to install NVM
install_nvm() {
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash
}

# nvm command is a shell function declared in ~/.nvm/nvm.sh
nvm_path=~/.nvm/nvm.sh

install_node_version() {
# Check if NVM is installed
if [ -s "$nvm_path" ];
export NVM_DIR="$HOME/.nvm"

if [ -s "$NVM_DIR/nvm.sh" ];
then
echo "NVM is already installed."
else
echo "Installing NVM..."
install_nvm
source nvm_path
fi

node_command=`command -v node`
current_node_version=`node -v | awk -F\. '{print $1}'`
# Check if correct version of node is present
if [[ "$node_command" ]] && [[ "$node_version" == "$current_node_version" ]];
then
echo "Correct node version is already installed."
else
echo "Node version $node_version is not installed. Installing..."
nvm install $node_version
nvm use $node_version
fi
# Setting up environment for NVM
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm

echo "Installing Node version $node_version..."
nvm install $node_version
}

install_node_version

echo "Node.js version $node_version has been installed."

sudo apt install npm
echo "***Installed npm***"
sameersubudhi marked this conversation as resolved.
Show resolved Hide resolved
# Install yarn
sudo npm install --global yarn
echo "***Installed yarn***"
npm install --global yarn
# Install pm2
sudo npm install --global pm2@latest
echo "***Installed pm2***"
npm install --global pm2@latest
4 changes: 2 additions & 2 deletions scripts/runMainnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@ echo "All env vars are set."

# PM2 runs on the fall back path when using CodeDeploy agent and we can run with the given fall back path
export PM2_HOME=/etc/.pm2
sudo -E pm2 delete all # Delete any running app
sudo -E pm2 start --name "lisk-across-relayer" "node ${app_dir}/dist/index.js --relayer --wallet awskms --keys "relayerKey""
pm2 delete all # Delete any running app
pm2 start --name "lisk-across-relayer" "node ${app_dir}/dist/index.js --relayer --wallet awskms --keys "relayerKey""
Loading