Skip to content

Commit

Permalink
Merge branch 'dev' into feat/fix-authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
incredible-phoenix246 authored Aug 6, 2024
2 parents c137c3b + e00021f commit 1fab00f
Show file tree
Hide file tree
Showing 17 changed files with 276 additions and 118 deletions.
32 changes: 0 additions & 32 deletions .github/workflows/build-and-push.yml

This file was deleted.

63 changes: 63 additions & 0 deletions .github/workflows/build-and-upload.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Build and Upload

on:
push:
branches:
- dev

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

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

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

copy-and-load-image:
needs: build
runs-on: ubuntu-latest
if: github.event.repository.fork == false

environment:
name: "dev"
url: ${{ vars.URL }}

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-dev.tar.gz"
target: "/tmp/nextjs"

- name: Load image in server
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
script: |
cd /tmp/nextjs
gunzip nextjs-dev.tar.gz
docker load < nextjs-dev.tar
rm -f nextjs-dev.tar
6 changes: 6 additions & 0 deletions .github/workflows/build-lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,9 @@ jobs:

- name: Run tests
run: pnpm run test:ci

- name: Upload coverage reports
uses: actions/upload-artifact@v3
with:
name: coverage-report
path: coverage/
10 changes: 7 additions & 3 deletions .github/workflows/coverage-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Coverage Report

on:
workflow_run:
workflows: ["build-lint-test"]
workflows: ["Build, Lint and Test"]
types:
- completed

Expand All @@ -15,10 +15,14 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4

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

- name: "Coverage Report"
if: always()
uses: davelosert/vitest-coverage-report-action@v2
11 changes: 6 additions & 5 deletions .github/workflows/dev-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,27 @@ name: Dev Deployment

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

jobs:
jobs:
deploy_to_dev:
if: github.event.repository.fork == false
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest

environment:
name: "dev"
url: ${{ vars.URL }}

steps:
- name: Deploy to dev environment
uses: appleboy/ssh-action@v1.0.3
- 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
71 changes: 42 additions & 29 deletions .github/workflows/production-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,47 +9,60 @@ on:
- .github/workflows/**

jobs:
build_and_push:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
uses: docker/login-action@v3
- 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:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v6
with:
file: docker/prod/Dockerfile
push: true
tags: hngdevops/nextjs-boilerplate:prod

deploy_to_production:
needs: build_and_push
name: docker-image
path: nextjs-prod.tar.gz

deploy_to_prod:
if: github.event.repository.fork == false
runs-on: ubuntu-latest

environment:
name: "production"
name: "prod"
url: ${{ vars.URL }}

steps:
- name: Deploy to production environment
uses: appleboy/[email protected]
- 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 hng_boilerplate_nextjs
./scripts/prod_deploy.sh
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
67 changes: 40 additions & 27 deletions .github/workflows/staging-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,26 @@ on:
- .github/workflows/**

jobs:
build_and_push:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
uses: docker/login-action@v3
- uses: actions/checkout@v2

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

- name: Save and compress Docker image
run: |
docker save hngdevops/nextjs-boilerplate:staging > nextjs-staging.tar
gzip nextjs-staging.tar
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v6
with:
file: docker/staging/Dockerfile
push: true
tags: hngdevops/nextjs-boilerplate:staging

name: docker-image
path: nextjs-staging.tar.gz

deploy_to_staging:
needs: build_and_push
if: github.event.repository.fork == false
runs-on: ubuntu-latest

Expand All @@ -44,12 +37,32 @@ jobs:
url: ${{ vars.URL }}

steps:
- name: Deploy to staging environment
uses: appleboy/[email protected]
- 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-staging.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 hng_boilerplate_nextjs
./scripts/staging_deploy.sh
cd /tmp/nextjs
gunzip nextjs-staging.tar.gz
docker load < nextjs-staging.tar
rm -f nextjs-staging.tar
cd /home/${{ secrets.USERNAME }}/hng_boilerplate_nextjs
chmod +x ./scripts/*.sh
./scripts/staging_deploy.sh
Loading

0 comments on commit 1fab00f

Please sign in to comment.