Skip to content

Commit

Permalink
Merge pull request #1050 from hngprojects/Ravencodess-patch-1
Browse files Browse the repository at this point in the history
Ravencodess patch 1
  • Loading branch information
Ravencodess authored Aug 21, 2024
2 parents e1051b3 + e053056 commit 9b02be2
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 57 deletions.
31 changes: 27 additions & 4 deletions .github/workflows/dev-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Dev Deployment

on:
workflow_run:
workflows: ["Build-and-Upload"]
workflows: ["Buil and Upload"]
types:
- completed

Expand All @@ -16,13 +16,36 @@ jobs:
url: ${{ vars.URL }}

steps:
- name: Download build artifact
uses: actions/download-artifact@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ github.event.workflow_run.id }}
name: boilerplate-build
path: .

- name: Decode and create .env file
run: |
echo ${{ secrets.ENV_BASE64 }} | base64 -d > .env
- name: Copy Artifacts to server
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
source: ".env,boilerplate.tar.gz"
target: "~/hng_boilerplate_nextjs"

- name: Deploy on server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
script: |
cd hng_boilerplate_nextjs
chmod +x ./scripts/*.sh
./scripts/dev_deploy.sh
cd ~/hng_boilerplate_nextjs
tar -xzf boilerplate.tar.gz
rm -f boilerplate.tar.gz
cp -r .next/standalone/* .
# pm2 restart nextjs_boilerplate --update-env
108 changes: 56 additions & 52 deletions .github/workflows/production-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,58 +11,62 @@ on:
jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Build Docker image
run: docker build -t hngdevops/nextjs-boilerplate:prod -f docker/prod/Dockerfile .

- name: Save and compress Docker image
run: |
docker save hngdevops/nextjs-boilerplate:prod > nextjs-prod.tar
gzip nextjs-prod.tar
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: docker-image
path: nextjs-prod.tar.gz

deploy_to_prod:
if: github.event.repository.fork == false
runs-on: ubuntu-latest
- uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: "20"

environment:
name: "prod"
url: ${{ vars.URL }}
- name: Cache pnpm modules
uses: actions/cache@v3
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-
steps:
- name: Download artifact
uses: actions/download-artifact@v2
with:
name: docker-image
path: .

- name: Copy to server
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
source: "nextjs-prod.tar.gz"
target: "/tmp/nextjs"

- name: Deploy on server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
script: |
cd /tmp/nextjs
gunzip nextjs-prod.tar.gz
docker load < nextjs-prod.tar
rm -f nextjs-prod.tar
cd /home/${{ secrets.USERNAME }}/hng_boilerplate_nextjs
chmod +x ./scripts/*.sh
./scripts/prod_deploy.sh
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 9

- name: Decode and create .env file
run: |
echo ${{ secrets.ENV_BASE64 }} | base64 -d > .env
- name: Install dependencies
run: pnpm install

- name: Build Next.js application
run: pnpm build

- name: Archive production artifacts
run: tar -czf nextjs-prod.tar.gz .next public .env

- name: Copy to server
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
source: "nextjs-prod.tar.gz"
target: "~/hng_boilerplate_nextjs"

- name: Delete zip file
run: rm -f nextjs-prod.tar.gz

- name: Deploy on server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
script: |
cd ~/hng_boilerplate_nextjs
tar -xzf nextjs-prod.tar.gz
rm -f nextjs-prod.tar.gz
cp -r .next/standalone/* .
pm2 restart nextjs_boilerplateg --update-env
2 changes: 1 addition & 1 deletion .github/workflows/staging-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ jobs:
tar -xzf nextjs-staging.tar.gz
rm -f nextjs-staging.tar.gz
cp -r .next/standalone/* .
pm2 restart boilerplate-staging --update-env
pm2 restart nextjs_boilerplate --update-env

0 comments on commit 9b02be2

Please sign in to comment.