Building a DevOps Pipeline with NodeJS and GitHub Actions for complete beginners

How to set up a production server

  1. Using Git Hub Action as the Continuous Integration Tool

  2. Connecting with a Self-Hosted Runner

Pre-requisites

  1. NodeJS Application and its Dependencies

  2. Cloud-Hosted Server

Implementation Steps

Create a repository having the following app.js files and its dependencies as shown below

image

Add content to the file and commit changes on app.js files

image

Goto Repo main page and click “Actions” tab

image

Navigate to the Continuous Integration Section and locate the Node.js section and click "Configure" button

image

Proceed to edit the project name as shown

image

Pay attention to the sections pointed

  • Jobs section : These are the collection of steps

  • Strategy section : We intend to use the 3 versions of node.js

  • Steps : These are actions to be taken , commands ,scripts steps

image

Commit Changes

image

image

Immediate Check and final check of the Git Action workflows

image

1st Workflow

Errors displayed and checking the state of the 3 jobs which represents the 3 versions of NodeJS as shown below

image

image

image

2nd Workflow

Next we amend the node version section to allow only one node version 18 and the same check of the Git Action workflows

image

image

image

3rd Workflow

A new error is generated and this is because there are no tests to be done in the yml file . Hence we would remove the test section to allow the completion.

image

image

Finally the job succeeded.

image

We have successfully implemented using GitHub Action but you should take note that the ubuntu latest image used was created by GitHub. If we decide to have it self-hosted. There's a different approach we have to take to actualize it.

SELF-HOSTED APPROACH

We create an instance on any cloud-hosted server .In this case AWS and ensure its running .

image

Navigate back to your NodeJs yml file and make sure its running on "self-hosted" and commit the changes

image

image

4th Workflow

Immediate Check and final check of the Git Action workflows

image

It would be noticed that the build is waiting for a runner to pick up the job since it is self-hosted.

image

Click on Settings and Click on the Actions Tab and proceed to Click Runners as shown below

image

image

image

CLICK THE "New Self-hosted runner" button and specify its a Linux with the commands below

image

image

Navigate back to the terminal and perform the actions below

image

Authenticate and connect to Git Hub and ensure Runner us successfully added and settings saved

image

Notice Our server is Populated in the runners section after refreshing it .

image

Once that is done , Check the files in the action-runner directory and locate the ./svc.sh file and proceed to install and start

image

image

image

image

Now let us get into the _work and NodeJS Sample directories check the file in the

image

Then go ahead to make a change on the content in the app.js file and commit it

image

5th Workflow

image

Check the status on the terminal to observe it showed succeeded

image

image

View the app.js file and see the changes as reflected on GitHub

image

Update and Install NodeJS, and npm packages

image

image

image

image

Ensure to install pm2 which servers as the process manager to allow us to use the terminal for other tasks while the server is running nodeJs

image

image

Once done run the command node app.js

Take note it should be running on port:3000

image

Navigate back to the server and ensure it is inserted in the security group section as shown below

image

image

Type the ip address and port on the web browser .Successfully displayed

image

We can try again to ensure its working as expected and can see its successfully displayed

image

image

image

If this post was helpful, Would be great if you could click the clap button 👏below to show your support.

Thank you for reading💚👏