-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
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
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 |