CI/CD pipeline with GitHub Actions
copied
In this blog, we are going to learn step-by-step how to set up a Serverless CI/CD pipeline on Nimbella using GitHub Actions.
What is CI/CD?
Continuous Integration refers to the practice of creating a build as a new code.Comment end is committed to running automated tests against that build to verify that everything works correctly.
Github-ci-cd: https://docs.github.com/en/actions/guides/about-continuous-integration
Continuous Delivery is the practice of automatically deploying code to production.
CI/CD Flow
CI/CD pipeline is one of the best practices for devops teams to implement, for delivering code changes more frequently and reliably.
CI/CD with GitHub Actions on Nimbella
GitHub Actions let you build, test, and deploy your code right from GitHub.
Nimbella is a modern serverless platform in which CI/CD can be implemented with modern CI/CD Pipeline GitHub actions that result in saving developers time and effort.
CI/CD on Nimbella using GitHub Actions
We can implement CI/CD pipeline on Nimbella using GitHub Actions with the below steps.
- Build the App.
- Write an Automated Test for the App.
- Set-up CI/CD using GitHub Action.
1.Build the App
Please consider that we are going to build a real-time URL shortener app. We can create our shortener app with Node.js as backend and React.js as frontend which can be deployed into Nimbella Serverless Platform as mentioned in the article below.
How to deploy Node.js functions on Nimbella.
We may set up a free mongo DB cluster as Database for our app by referring to Get Started with Atlas.
Please note that to run this application, you'll need to have Git, Node.js, and NPM already installed.
Let's clone the code into our local directory using the below command.
git clone https://github.com/bolt-hub/github-ci-cd-nimbella-shortener.git
The directory having the code for our shortener app looks as below:
Project Directory of Shortener App
2.Write Automated Test for the App
Automated testing enables continuous testing and ensures that bugs get found early and are fixed before the end-users experience any breaks.
Please consider that we are going to write our automated test with the popular Jest Framework. Let's execute the below commands from the root of the project directory to install npm packages for the Jest framework.
npm init -y
npm install --save-dev jest mongoose nanoid dotenv
Create Jest configuration files i.e, jest.config.js & jest.setup.js, and change the test script defined in package.json to run the Jest binary. Now when we run the test script, this Jest command is going to run.
After updating the Jest test run command in package.json, it looks as below.
Package.json after updating test Run command
Create a test file that validates test cases for the app using Jest Framework as below.
const { Mongoose } = require("mongoose");
const app = require("./index");
const mongoose = require('mongoose')
describe("Validates Response when URL Shortener is Requested", () => {
test("Validates Response URL shortener for Positive flow", async () => {
var requestBody = {
actual_url: "https://nimbella.com/blog/how-to-deploy-node-js-functions-on-nimbella",
};
var appResponse = await app.main(requestBody);
expect(appResponse.body.success).toBe(true);
expect(appResponse.statusCode).toBe(200);
});
});
afterAll(async done => {
// Closing the DB connection allows Jest to exit successfully.
mongoose.connection.close();
done();
});
After writing test validation for our serverless action, the directory will look as below:
Directory Structure after Adding Automated Tests
3.Set-up CI/CD using GitHub Action
Create a new Repository in GitHub. Navigate to the Actions tab on this repository and set up a basic workflow.
GitHub Actions Link on Repository
Let's clone our new repo which has default GitHub actions and move the code for Shortener into this.
We can get a non-expiring token to deploy our app into Nimbella by running the below command on nim CLI.
nim auth export --non-expiring
Copy the token generated from the above command and add it as a GitHub secret. Also, add the environment variables of serverless action as GitHub secrets as below.
Configuring GitHub Secrets
The final step of configuring the Specification CI/CD pipeline on Nimbella using GitHub Action is to modify the YAML file under ./GitHub/workflows as per our deployment specifications as below.
GitHub Actions YAML Specification
Once the above configuration is specified, whenever code changes are pushed to the repository, GitHub Action will trigger the configured CI/CD Pipeline/workflow to achieve CI/CD.
Let's test the CI/CD workflow by pushing the code to the repository. After pushing the code changes, if we check-out the "Actions" tab of the repository, it will look as below which indicates that CI/CD workflow has been triggered.
GitHub Actions Triggers Workflow
Successful Job Run through GitHub Actions
In Brief and to Sum-up:
- Build your code as per Nimbella's serverless framework structure
- Create Automated Test to validate serverless action
- Create a GitHub Repo and navigate to Actions tab of the Repo and set up a sample GitHub workflow.
- Configure Nimbella's Auth token & environment variables under GitHub Secrets of the same Repo.
- Modify the GitHub action's YAML file to test deploy the app using nim CLI.
- Push/Pull (as mentioned in the YAML file) the code to trigger the workflow.
GitHub Source: https://github.com/bolt-hub/github-ci-cd-nimbella-shortener.git
Please feel free to experiment with CI/CD workflow on Nimbella using the above example with few steps given below.
- Create a Nimbella Account and install nim CLI.
- Create a new Github Repo and configure the environment variables & Nimbella’s Auth token as GitHub secrets on the same Repo.
- Clone the above code from Git and push it to your newly created Repo. Once the workflow run has been completed, you may check-out your live URL shortener as below.
Deployment Log info
Guest Author: Athithan Raj P.
Follow him on Twitter: @raj_athithan
- Nimbella joins DigitalOcean
- No infrastructure, just code. Learn the simplicity of serverless
- How to Migrate from Containers to Nimbella Serverless Architecture
- Kubernetes in simple words: explained by Eric Swildens
- How to optimize Kubernetes costs with Nimbella
- Step by step guide on how to port from AWS to Nimbella
- How to build and improve your serverless APIs
- Simplifying Kubernetes For Developers
- FaaS Wars Season 2 - Step By Step Instructions
- What is Nimbella and what does it offer?
- Results and Feedback of FaaS Wars - May the FaaS Be with You!
- 28 Serverless Gurus and experts One Must Follow in 2021
- The Faas Wars Alert!
- CI/CD pipeline with GitHub Actions
- How to deploy Node.js functions on Nimbella
- Kick-Start Your Serverless Journey
- AWS re:Invent Serverless Highlights
- Opportunities in the Wake of the AWS Juggernaut
- FaaS Wars: Serverless & Virtual Robot Competition
- #DeveloperIPL Online Hackathon Results & Feedback on Nimbella's Integration for Postman
- How to connect to the 3rd party database such as MySQL at Nimbella (example in Java)
- What can you do with the Nimbella Workbench?
- Deploy your Shopify Storefront to Nimbella
- Not All Serverless Platforms Are Created Equal
- Nimbella + Netlify: Uplevel Your Development Speed
- How we learned to Jamstack, Our Caputron story | Nimbella.com®
- Commander for Microsoft Teams - Your Custom Bot that runs on your Command!
- How to Build a Stateful Cloud App on Nimbella vs. AWS
- Starter Kit and Resources to Build a Serverless Cloud Application
- How to Build Serverless Slack Apps and Commands
- How to Set up your Serverless Environment and Get Started in Less than 2 Minutes!
- How to Quickly Deploy Stateful Serverless Apps with Nimbella?
- What is Serverless Computing? 3 reasons to start now
- How to Build a Serverless Slack App in Minutes.
- How to Manage your Netlify Website from Slack?
- How to Build a Serverless Slack Command in minutes
- How to Build a Stateful Serverless Cloud Web Application?
- How to Create an Optical Character Recognition (OCR) Application?
- Development at the Speed of Innovation – Nimbella, the Serverless Cloud
- Software Security Features on Enterprise Serverless Slack Apps Enabled by Nimbella Commander
- Coronathon India’s first demo day has 18 projects to help fight COVID-19
- See the time in different cities on Slack with Nimbella Commander
- Greet your friends in their native language in Slack with Nimbella Commander
- How to Fetch your Digital Ocean Billing Info on Slack?
- How to Stay Updated with Coronavirus Statistics on Slack?
- How to Fetch your AWS Billing Info on Slack?
- Get your Datadog billing info in Slack with Nimbella Commander
- Serverless Slack Apps and Slash Commands
- How to use Slack Effectively with Nimbella Commander?
- How to Create a multi-user Chatroom Hosted on Serverless Cloud?
- Using Docker actions, running Golang, and other fun things with OpenWhisk
- The duality between serverless functions and APIs
- Serverless HTTP handlers with OpenWhisk
- Serverless functions in your favorite language with OpenWhisk
- Run Swiftly: precompiled Swift actions
- Performance debugging for serverless functions using the Cloud Shell
- Locally debugging OpenWhisk actions
- Composing functions into applications
- A Serverless Composition of Functions
- The Serverless Contract
- The dawn of the Cloud Computer
- Security and Serverless Functions