Update main.yml #22
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: 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 &' |