Skip to content

Update main.yml

Update main.yml #22

Workflow file for this run

name: Deploy to EC2
on:
push:
branches:
- main # adjust the branch name as needed
jobs:
deploy:
runs-on: ubuntu-latest # use the appropriate operating system
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Create SSH directory
run: mkdir -p $HOME/.ssh
- name: Echo SSH key to PEM file
run: echo "${{ secrets.SSH_PRIVATE_KEY_1 }}" > $HOME/.ssh/deploy_key.pem
- name: Set permissions for SSH directory and key
run: chmod 700 $HOME/.ssh && chmod 600 $HOME/.ssh/deploy_key.pem
- name: Deploy to EC2-1
run: |
ssh -o StrictHostKeyChecking=no -i $HOME/.ssh/deploy_key.pem [email protected] 'cd Team2Hackathon && git pull origin main && npm install && sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 5001 && nohup node app.js &'