Skip to content
Open

ok #2

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Nextjs-App Deploy with GitHub Actions

on:
push:
branches:
- master
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v2

- name: SSH into AWS Lightsail and Deploy
uses: appleboy/ssh-action@v1.1.0
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.SSHKEY }}
script: |
set -e
cd /var/www/nextjs-app || exit 1
ls -la
npm i -y
npm audit fix --force
npm run build
pm2 stop next-app || true
pm2 start npm --name "next-app" -- run start
pm2 save
node -v
npm -v
pm2 list
19 changes: 19 additions & 0 deletions ecosystem.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// example ecosystem.config.js
// ecosystem.config.js
module.exports = {
apps: [
{
name: "next-app",
script: "npm",
args: "start -p 3000",
watch: true,

instances: 4,
exec_mode: "cluster",

env: {
NODE_ENV: "production",
},
},
],
};
54 changes: 54 additions & 0 deletions me
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Nextjs-App Deploy with GitHub Actions

on:
push:
branches:
- master

jobs:
deploy:
runs-on: ubuntu-latest

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

- name: SSH into AWS Lightsail and Deploy
uses: appleboy/ssh-action@v1.1.0
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.SSHKEY }}
script: |

# Install dependencies
echo "Installing dependencies..."
sudo apt update
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt install -y nodejs npm nginx

# Clone repository
echo "Cloning repository..."
cd /var/www
git clone https://github.com/devktops/nextjs-app.git /var/www/nextjs-app || true
sudo chown -R $USER:www-data /var/www/nextjs-app

# Install project dependencies and build
echo "Installing project dependencies and building the project..."
npm install
npm audit fix --force
npm run build
sudo chown -R $USER:www-data /var/www/nextjs-app

# Start application with PM2
echo "Starting application with PM2..."
sudo npm install -g pm2
pm2 start next-app
pm2 save
sudo env PATH=$PATH:/usr/bin pm2 startup systemd -u $USER --hp /home/$USER

# Verify setup
echo "Verifying setup..."
node -v
npm -v
pm2 list
2 changes: 1 addition & 1 deletion next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
output: 'export',
//output: 'export',
distDir: 'out',
trailingSlash: true,
};
Expand Down