Logo

dev-resources.site

for different kinds of informations.

Streamlining React CI/CD Pipelines with GitHub Actions

Published at
12/27/2024
Categories
nginx
react
githubactions
linux
Author
solitrix02
Categories
4 categories in total
nginx
open
react
open
githubactions
open
linux
open
Author
10 person written this
solitrix02
open
Streamlining React CI/CD Pipelines with GitHub Actions

In this blog, I am going to go over the steps on how to implement a CI/CD pipeline using GitHub Actions on a Linux Virtual Machine and deploying a simple React js project on it.

Things require before start

You have a basic knowledge of:

  • Git & GitHub

  • Nginx server

  • Linux commands

Steps to Action Runner of Virtual Machine

Before following the steps to set up a pipeline using GitHub actions, you have to check out how to do this manually: Deploying a MERN App on Azure: The Smart Way

React Application

Now that you have done the basic setup (as the first time you have to do the setup manually) we can start by creating a repository on GitHub and pushing your code in it.

Go to the settings tab of you repository and choose the actions option from the left sidebar and choose the runner option. Then click on the New self-hosted runner

New self-hosted runner

After clicking on that, you will have 3 options to choose the Operating Systems. You have to choose the commands based on which operation system you have picked. In my case, I am going to select Linux OS. After selecting the option, you will get some. You don't have to worry about them, just save them securely for future use.

Linux runner

After performing the configuration of action runner, you must have an SSH connection between your github and your virtual machine. To do that, you have to add your virtual machine's SSH key to GitHub.

To create the SSH key into your virtual machine, type the following commands:

sudo ssh-keygen -t ed25519
Enter fullscreen mode Exit fullscreen mode

After that just press enters until the prompt exits to get the key. This command will generate a 2 key files: a private key and a public key of your virtual machine. Make sure you must not share your private key to anyone. You can also give a custom name to your ssh key. In my case, I have defined both name and path of the SSH files: /root/.ssh/id_cicd

SSH key generation

Now type sudo cat /root/.ssh/id_cicd.pub to get your public SSH key into the terminal. You have to copy and paste it into the settings of your GitHub account to prepare a connection between them.

Go to settings of your account and select the SSH and GPG keys and create a new SSH connection and paste your public keys.

key configuration

After the above task, you have to paste the commands into your virtual machine's terminal that was previously generated by your repository.

You have to paste those commands line by line and hit enter everytime. These command will prepare a secure connection between that repository and your vitual machine

github action runner config

Now in the end, type the following commands and hit enter

sudo ./svc.sh install
sudo ./svc.sh start
Enter fullscreen mode Exit fullscreen mode

Steps to setup GitHub Actions for CI/CD

If you are here, that means we have done so much fancy Linux stuff but bare with me, this is one of the important step that will make the automate change whenever you push the code into Github.

Go to Actions tab of your repository and select the suitable action configuration. Since in this tutorial we are hosting a 'React Project', I will select the nodejs action.

Nodejs action instance

Now copy and paste the following text into the nodejs.yml file. This is the configuration that tracks changes and push the code to your virtual machine server everytime some changes are made on 'master' branch.

# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

name: Node.js CI

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

jobs:
  build:

    runs-on: self-hosted

    strategy:
      matrix:
        node-version: [16.x]
        # See supported Node.js release schedule at https://nodejs.org/en/about/releases/

    steps:
    - uses: actions/checkout@v3
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v3
      with:
        node-version: ${{ matrix.node-version }}
        cache: 'npm'
    - run: npm install
    - run: npm run build
    - run: sudo cp -r dist/* /var/www/html/
Enter fullscreen mode Exit fullscreen mode

After configuring that, press on save and wait for the pipeline to execute. After execution, the action tab will show you the build result:

build pipeline setup

Now visit your IP address/domain to see the website that you've hosted using GitHub Action and viola, your changes are reflected🎉

If you have read it till now, thank you so much for reading!, please leave your comments if any ✌️

Don't forget to bookmark this blog for the future 📌

Connect with the author:

nginx Article's
30 articles in total
Favicon
nginx-mod-http-geoip
Favicon
How to run a Nginx-web server
Favicon
ngx whitelist/blacklist module
Favicon
Nginx Simplified: Technical Insights with Real-World Analogies
Favicon
Nginx Configuration Tips for Secure Communication: Enabling mTLS and checking client fingerprint
Favicon
Building a Scalable Reverse Proxy Server like Nginx with Node.js and TypeScript
Favicon
Deploy NestJS and NextJS application in same server using pm2 and Nginx
Favicon
Setting Up an NGINX Reverse Proxy with a Node.js Cluster Using Docker
Favicon
การทำ HTTPS ด้วย Certbot และ Nginx บน Ubuntu Server
Favicon
How to configure Free SSL Certificate on Nginx using Certbot
Favicon
Docker Hands-on: Learn Docker Volume and Bind Mounts with Sample Projects using NGINX
Favicon
自建的git远程仓库,在push时413 Request Entity Too Large
Favicon
Optimize SvelteKit performance with brotli compression
Favicon
I’m running a Spring Boot application inside a Docker container on my VM. The application works fine over HTTP, and I can access all endpoints via http://127.0.0.1:8080. I’ve set up NGINX as a reverse proxy to serve HTTPS requests. No errors for http reqs.
Favicon
Deploying a MERN App on Azure: The Smart Way
Favicon
My First Full-Stack Deployment with Docker and NGINX as Load Balancer
Favicon
Streamlined Release Process for a Web Application: Trunk-Based Development with Feature Flags
Favicon
How to Install NGINX on Ubuntu 22.04
Favicon
Secure Nginx with Let's Encrypt on Ubuntu
Favicon
Kubernetes Ingress Controllers and NGINX Ingress: A Complete Guide
Favicon
What is HTTP 499 Status Code and How to Fix it?
Favicon
Docker Compose Demo: Running Multiple Services with Two Domains on Localhost
Favicon
Building a Production Stack: Docker, Meilisearch, NGINX & NestJS
Favicon
Step-by-Step Guide: Assigning a Namecheap Domain to DigitalOcean Hosting with Nginx
Favicon
Streamlining React CI/CD Pipelines with GitHub Actions
Favicon
Connecting to an EC2 Instance with Ubuntu and Installing NGINX on AWS
Favicon
Installing Nginx Web Server on Linux: A Step-by-Step Guide
Favicon
Hosting multiple Websites on a single Nginx Server
Favicon
Unleashing the Power of NGINX as an API Gateway
Favicon
Installing Wordpress with Nginx in Ubuntu

Featured ones: