Deployment Guideline - nhash46/Tessagon-e-Portfolio GitHub Wiki

CI/CD pipeline

Using Github Actions, we are able to support CI/CD for our web application.

Breakdown of CI/CD pipeline

Sourced from /github/workflows/node.js.yml

name: Node.js CI

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:

    runs-on: windows-latest

    strategy:
      matrix:
        node-version: [ 12.x, 14.x]

    steps:
    - uses: actions/checkout@v2
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v1
      with:
        node-version: ${{ matrix.node-version }}
    - run: npm ci
    - run: npm run build --if-present
    - run: npm test
      env:
        CI: true

    - name: Add remote origin
      run: |
        git remote add heroku https://heroku:${{ secrets.HEROKU_API_KEY }}@git.heroku.com/${{ secrets.HEROKU_APP_NAME }}.git
        git fetch --all --unshallow
    - name: Deploy to Heroku
      run: |
        git push heroku HEAD:master -f
        git fetch --all --unshallow

Lets explains what each of the lines does:

name: CI

This is just specifying a name for the workflow

on: [push]

The on command is used to specify an event that will trigger the workflow, this event can be push, pull_request, etc. It can also be an array of events like this.

Use an array when using more than one event

on: [push, pull_request] 

In our case, we are simply saying trigger this workflow on every push

jobs:

Here we are specifying the job we want to run, in this case, we are setting up a build job.

runs-on: windows-latest

The runs-on is specifying the OS you want your workflow to run on and we are using the latest version of windows

Steps:

Steps just indicate the various steps you want to run on that job

uses: actions/checkout@v2

Github has some already define Actions, we are using version 2 of the checkout action this is responsible for cloning the repo and checking into our project directory.

The other steps just show how to run one or more commands in the shell.

Running a local server

To run the server remotely on your device, enter the following into your terminal:

npm install nodemon 
nodemon app

Then we can access the web application on:

http://localhost:3000/