diff --git a/appspec.yml b/appspec.yml new file mode 100644 index 0000000..bc0edf4 --- /dev/null +++ b/appspec.yml @@ -0,0 +1,12 @@ +version: 0.0 +os: linux +files: + - source: / + destination: /home/ubuntu/song-recognition +hooks: + BeforeInstall: + - location: scripts/BeforeInstall.sh + AfterInstall: + - location: scripts/AfterInstall.sh + - location: scripts/ApplicationStart.sh + runas: ubuntu diff --git a/scripts/AfterInstall.sh b/scripts/AfterInstall.sh new file mode 100644 index 0000000..4ca69b3 --- /dev/null +++ b/scripts/AfterInstall.sh @@ -0,0 +1,3 @@ +sudo chown -R ubuntu:ubuntu /home/ubuntu/song-recognition + +sudo systemctl start mongod diff --git a/scripts/ApplicationStart.sh b/scripts/ApplicationStart.sh new file mode 100644 index 0000000..6584c4b --- /dev/null +++ b/scripts/ApplicationStart.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +start_backend() { + cd /home/ubuntu/song-recognition + touch back.txt + go build -tags netgo -ldflags '-s -w' -o app + nohup ./app > backend.log 2>&1 & +} + +start_client() { + cd /home/ubuntu/song-recognition/client + touch client.txt + + 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" + + nvm install 16 + nvm use 16 + npm install + npm run build + nohup serve -s build > client.log 2>&1 & +} + +start_backend && start_client diff --git a/scripts/BeforeInstall.sh b/scripts/BeforeInstall.sh new file mode 100644 index 0000000..2cedb2d --- /dev/null +++ b/scripts/BeforeInstall.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash + +sudo apt-get -y update + +if [ ! -f "/home/ubuntu/install" ]; then + # install CodeDeploy agent + sudo apt-get -y install ruby + sudo apt-get -y install wget + cd /home/ubuntu + wget https://aws-codedeploy-eu-north-1.s3.amazonaws.com/latest/install + sudo chmod +x ./install + sudo ./install auto +fi + +# install golang +sudo apt-get -y install golang-go + +# install nodeJS, npm, and nvm +sudo apt -y install nodejs +sudo apt -y install npm +wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash + +# Install MongoDB only if not already present +if [ ! -f "/usr/bin/mongod" ]; then + sudo apt-get install gnupg curl + curl -fsSL https://www.mongodb.org/static/pgp/server-7.0.asc | \ + sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg \ + --dearmor + echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list + sudo apt-get update + sudo apt-get install -y mongodb-org + sudo apt-get install -y mongosh +fi