This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploying to EC2 | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository//download the source code repository | |
uses: actions/checkout@v3 | |
- name: Create private key file and change permissions to read-only | |
run: | | |
echo "${{ secrets.AWS_PEM}}" > myPlayList-key-pair.pem | |
chmod 400 myPlayList-key-pair.pem | |
- name: Install dependencies and build | |
run: | |
ssh -i myPlayList-key-pair.pem -o StrictHostKeyChecking=no ${{vars.AWS_HOST_NAME}}@${{vars.AWS_HOST}} ' | |
export PATH="$PATH:/home/ubuntu/.nvm/versions/node/v20.11.1/bin" && | |
cd Full-Stack-Project-Assessment/server && | |
git pull && | |
if pm2 list | grep -q fullstackproject; then | |
echo "fullstack project process found" && | |
echo "stopping the process" && | |
pm2 stop fullstackproject && | |
echo "deleting the process" && | |
pm2 delete fullstackproject && | |
fi | |
echo "starting the process" && | |
pm2 start server.js --name fullstackproject && | |
pm2 ls | |
' |