diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..63c3e3046 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,33 @@ +name: Next.js CI (develop → master) + +on: + pull_request: + branches: [ "master" ] + types: [opened, synchronize, reopened] + # Only trigger if PR comes from develop branch + paths-ignore: + - "README.md" + +jobs: + build: + if: github.base_ref == 'master' && github.head_ref == 'develop' + runs-on: ubuntu-latest + + steps: + - name: Checkout Code + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + + - name: Install Dependencies + run: npm install + + - name: Build Next.js App + run: npm run build + + - name: Run Tests (optional) + run: npm test + continue-on-error: true diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 000000000..175f3b994 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,46 @@ +name: Next.js CI/CD + +on: + push: + branches: [ "master" ] # use master branch + pull_request: + branches: [ "master" ] + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + + steps: + # 1️⃣ Checkout the repo + - name: Checkout code + uses: actions/checkout@v4 + + # 2️⃣ Setup Node.js + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: 20 + + # 3️⃣ Install dependencies + - name: Install dependencies + run: npm install --legacy-peer-deps + + # 4️⃣ Build Next.js project + - name: Build Next.js + run: npm run build + + # 5️⃣ Deploy to your server via SSH + - name: Deploy via SSH + uses: appleboy/ssh-action@v0.1.9 + with: + host: ${{ secrets.SERVER_IP }} + username: ${{ secrets.SERVER_USER }} + key: ${{ secrets.SERVER_SSH_KEY }} + port: 22 + script: | + cd /var/www/myproject/website + git reset --hard + git pull origin master + npm install --legacy-peer-deps + npm run build + pm2 restart nextjs-website diff --git a/dockerfile b/dockerfile new file mode 100644 index 000000000..81abe2250 --- /dev/null +++ b/dockerfile @@ -0,0 +1,5 @@ +FORM ubuntu +RUN apt update +RUN apt install apache2 -y +ADD . /var/www/html +ENTRYPOINT apachectl -D FOREGROUND