Building a DevOps Pipeline with NodeJS and GitHub Actions for complete beginners
How to set up a production server
Using Git Hub Action as the Continuous Integration Tool
Connecting with a Self-Hosted Runner
Pre-requisites
NodeJS Application and its Dependencies
Cloud-Hosted Server
Implementation Steps
Create a repository having the following app.js files and its dependencies as shown below
Add content to the file and commit changes on app.js files
Goto Repo main page and click “Actions” tab
Navigate to the Continuous Integration Section and locate the Node.js section and click "Configure" button
Proceed to edit the project name as shown
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
Commit Changes
Immediate Check and final check of the Git Action workflows
1st Workflow
Errors displayed and checking the state of the 3 jobs which represents the 3 versions of NodeJS as shown below
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
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.
Finally the job succeeded.
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 .
Navigate back to your NodeJs yml file and make sure its running on "self-hosted" and commit the changes
4th Workflow
Immediate Check and final check of the Git Action workflows
It would be noticed that the build is waiting for a runner to pick up the job since it is self-hosted.
Click on Settings and Click on the Actions Tab and proceed to Click Runners as shown below
CLICK THE "New Self-hosted runner" button and specify its a Linux with the commands below
Navigate back to the terminal and perform the actions below
Authenticate and connect to Git Hub and ensure Runner us successfully added and settings saved
Notice Our server is Populated in the runners section after refreshing it .
Once that is done , Check the files in the action-runner directory and locate the ./svc.sh file and proceed to install and start
Now let us get into the _work and NodeJS Sample directories check the file in the
Then go ahead to make a change on the content in the app.js file and commit it
5th Workflow
Check the status on the terminal to observe it showed succeeded
View the app.js file and see the changes as reflected on GitHub
Update and Install NodeJS, and npm packages
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
Once done run the command node app.js
Take note it should be running on port:3000
Navigate back to the server and ensure it is inserted in the security group section as shown below
Type the ip address and port on the web browser .Successfully displayed
We can try again to ensure its working as expected and can see its successfully displayed
If this post was helpful, Would be great if you could click the clap button 👏below to show your support.
Thank you for reading💚👏
Subscribe to my newsletter
Read articles from Emmanuel Yewande directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by