Created
May 12, 2023 11:56
-
-
Save kamranahmedse/1e94b412006040f38e24b9443b2da41a to your computer and use it in GitHub Desktop.
Sample Workflow for EC2 Deployment
This file contains hidden or 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: | |
workflow_dispatch: | |
push: | |
branches: | |
- master | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- uses: actions/setup-node@v1 | |
with: | |
node-version: 18 | |
- uses: pnpm/[email protected] | |
with: | |
version: 7.13.4 | |
- name: Install dependencies | |
run: | | |
pnpm install | |
- name: Generate build | |
run: | | |
npm run build | |
# -------------------- | |
# Deploy to EC2 | |
# -------------------- | |
- uses: webfactory/[email protected] | |
with: | |
ssh-private-key: ${{ secrets.EC2_PRIVATE_KEY }} | |
- name: Deploy app to EC2 | |
run: | | |
rsync -avz --exclude "configuration" -e "ssh -o StrictHostKeyChecking=no" -p ./ ${{ secrets.EC2_USERNAME }}@${{ secrets.EC2_HOST }}:/var/www/some-project/ | |
- name: Restart PM2 | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
username: ${{ secrets.EC2_USERNAME }} | |
key: ${{ secrets.EC2_PRIVATE_KEY }} | |
script: | | |
cd /var/www/some-project | |
sudo pm2 restart some-project |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment