Skip to content

Commit

Permalink
initial deploy.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
0xEdouard committed Dec 10, 2024
1 parent 951b957 commit dbd23c7
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Deploy to AWS EC2

on:
push:
branches:
- pipeline

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Install Dependencies
run: |
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
source ~/.bashrc
nvm install --lts
npm ci
- name: Build Next.js App
run: npm run build

- name: Copy Files to EC2
env:
EC2_HOST: [email protected]
run: |
mkdir -p deploy
tar -czf deploy/app.tar.gz .next package.json package-lock.json
scp -i ~/.ssh/deploy_key deploy/app.tar.gz $EC2_HOST:~/app.tar.gz
- name: Deploy on EC2
env:
EC2_HOST: [email protected]
run: |
ssh -i ~/.ssh/deploy_key $EC2_HOST << EOF
mkdir -p ~/app && tar -xzf ~/app.tar.gz -C ~/app && cd ~/app
npm install --production
pm2 stop all || true
pm2 start npm --name "nextjs-app" -- start
EOF

0 comments on commit dbd23c7

Please sign in to comment.