Skip to content

Update deploy.yaml

Update deploy.yaml #55

Workflow file for this run

name: Deploy
on:
push:
branches:
- main
jobs:
build:
if: github.repository == 'ECE46100/group21-phase2'
name: deploy
runs-on: ubuntu-latest
steps:
- name: fetch code
uses: actions/checkout@v4
with:
submodules: true
- name: Setup Node.js (backend)
uses: actions/setup-node@v3
with:
node-version: 20.18.1
- name: install dependencies (backend)
run: npm install
working-directory: backend
- name: install dependencies (frontend)
run: npm install
working-directory: frontend
- name: install dependencies (phase1 handoff)
run: npm install
working-directory: backend/group21-phase1-handoff
- name: build backend
run: npm run build
working-directory: backend
- name: build frontend
run: npm run build
env:
CI: false
working-directory: frontend
- name: build phase1 handoff
run: npx tsc
working-directory: backend/group21-phase1-handoff
- name: deploy with rsync
uses: burnett01/[email protected]
with:
switches: -avzr --delete
path: ./*
remote_path: ~/app_deployment
remote_host: ${{ secrets.SSH_HOST }}
remote_user: ${{ secrets.SSH_USER }}
remote_key: ${{ secrets.SSH_KEY }}
- name: configure env and run
run: |
echo "${{ secrets.SSH_KEY }}" > private_key
chmod 600 private_key
ssh -o StrictHostKeyChecking=no -i private_key ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} '
cd ~/app_deployment/backend
# npm install
# npm run build
# cd group21-phase1-handoff
# npm install
# npx tsc
# cd ../
# configure env
touch .env
echo DB_HOST=${{ secrets.DB_HOST }} >> .env
echo DB_USER=${{ secrets.DB_USER }} >> .env
echo DB_NAME=${{ secrets.DB_NAME }} >> .env
echo DB_PASS=${{ secrets.DB_PASS }} >> .env
echo AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY }} >> .env
echo AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_KEY }} >> .env
echo AWS_REGION='us-east-2' >> .env
echo GITHUB_TOKEN=${{ secrets.GH_TOKEN }} >> .env
echo JWT_SECRET=${{ secrets.JWT_SECRET }} >> .env
cd ../frontend
# npm install
touch .env
echo PORT=4000 >> .env
cd ../backend
if tmux has-session -t backend 2>/dev/null; then
tmux kill-session -t backend
fi
tmux new-session -d -s backend
tmux send-keys -t backend "npm run start" C-m
sleep 30
cd ../frontend
if tmux has-session -t frontend 2>/dev/null; then
tmux kill-session -t frontend
fi
tmux new-session -d -s frontend
tmux send-keys -t frontend "npx serve -s build -l tcp://0.0.0.0:4000" C-m
'