Skip to content

Update deploy.yml

Update deploy.yml #43

Workflow file for this run

name: Deploy Next Branch to Server
on:
push:
branches:
- next
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
ref: next
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: 18
- name: Install dependencies
run: yarn install
- name: Build the app
run: yarn build
- name: Copy files via SSH
env:
SSH_HOST: ${{ secrets.SSH_HOST }}
SSH_USERNAME: ${{ secrets.SSH_USERNAME }}
SSH_PASSWORD: ${{ secrets.SSH_PASSWORD }}
run: |
sudo apt-get update
sudo apt-get install -y sshpass
sshpass -p "$SSH_PASSWORD" ssh -o StrictHostKeyChecking=no $SSH_USERNAME@$SSH_HOST "
if [ ! -d /home/$SSH_USERNAME/next ]; then
git clone -b next https://github.com/citizenweb3/validatorinfo.git /home/$SSH_USERNAME/next
else
cd /home/$SSH_USERNAME/next && git pull origin next
fi
"
- name: Deploy application
env:
SSH_HOST: ${{ secrets.SSH_HOST }}
SSH_USERNAME: ${{ secrets.SSH_USERNAME }}
SSH_PASSWORD: ${{ secrets.SSH_PASSWORD }}
run: |
sshpass -p "$SSH_PASSWORD" ssh -o StrictHostKeyChecking=no $SSH_USERNAME@$SSH_HOST "
cd /home/$SSH_USERNAME/next &&
if [ \$(docker ps -q -f name=next_app_1) ]; then
docker stop next_app_1
docker rm next_app_1
fi &&
# Stop old
if [ \$(docker ps -q -f name=next_app_1) ]; then
docker stop next_app_1
docker rm next_app_1
fi &&
# Start new
echo -e 'DATABASE_URL="postgresql://validatorinfo:password@localhost:5432/mydb?schema=public"\nSERVER_PORT="6666"' > .env
make start-db
docker compose down &&
docker compose up -d --build
"