Cloud Computing, DevOps

3 Mins Read

Building a GitOps CI/CD Pipeline for React Vite Apps with Argo CD

Voiced by Amazon Polly

Introduction

GitOps uses Git as the single source of truth for both application code and infrastructure. You can automate your deployment pipeline with traceability and resilience by integrating GitHub Actions, GitHub Container Registry (GHCR), Kubernetes, and Argo CD. This post outlines setting up a GitOps-driven CI/CD workflow for a React Vite app, from code push to production deployment.

Pioneers in Cloud Consulting & Migration Services

  • Reduced infrastructural costs
  • Accelerated application deployment
Get Started

GitHub Actions Workflow

This workflow automates the CI and triggers CD via Argo CD.

Step 1: Build the React Application

Purpose: Compile and bundle the React application.

  • Check out the source code from the repository.
  • Sets up js v18 environment.
  • Installs pnpm and project dependencies.
  • Executes the build command: pnpm run build.

Note: Using pnpm instead of npm or yarn reduced the build time by approximately 40%.

Step 2: Build and Push Docker Image

Purpose: Containerize the application and push the image to a container registry.

  • Uses Docker Buildx for optimized multi-stage builds.
  • Authenticates with GitHub Container Registry (GHCR).
  • Builds the Docker image and tags it using the Git commit SHA.
  • Pushes the image to GHCR for versioned storage and deployment.

Step 3: Update Kubernetes Manifest and Trigger Deployment

Purpose: Update the Kubernetes deployment with the new image version and trigger a GitOps-based deployment.

  • Check out the gitops-infra repository containing Kubernetes manifests.
  • Uses sed to update the image tag in deployment.yaml.
  • Commits and pushes the updated manifest if any changes are detected.
  • Argo CD automatically detects the commit and syncs the changes to the Kubernetes cluster, completing the deployment pipeline.

MultiStage Dockerfile

First stage

  • Based on node:18-alpine. Installs dependencies and runs npm run build to generate /app/dist.

Second stage

Based on a minimal nginx:1.23-alpine. Copies static files from the build stage into Nginx’s default root. Exposes port 80. The final image size is small, containing no build tools or Node runtime.

Kubernetes Manifests

These manifests define how the application runs in Kubernetes.

deployment.yaml

This Deployment runs 4 replicas of a stateless React app served via Nginx, using a specific image from GitHub Container Registry (GHCR). It authenticates using an imagePullSecret and exposes port 80 for HTTP traffic.

service.yaml

Exposes the app via NodePort on port 31000.

Conclusion

We have created a  GitOps pipeline for zero-touch deployments of a React Vite app by combining GitHub Actions, Docker, Argo CD, and Kubernetes. Each code push triggers a full CI/CD pipeline, build, image publish, manifest update, and deployment without manual steps.

This setup enhances developer productivity, ensures versioned deployments, and brings traceable, auditable automation to your delivery workflow, which is ideal for modern cloud-native teams.

Drop a query if you have any questions regarding ArgoCD and we will get back to you quickly.

Making IT Networks Enterprise-ready – Cloud Management Services

  • Accelerated cloud migration
  • End-to-end view of the cloud environment
Get Started

About CloudThat

CloudThat is an award-winning company and the first in India to offer cloud training and consulting services worldwide. As a Microsoft Solutions Partner, AWS Advanced Tier Training Partner, and Google Cloud Platform Partner, CloudThat has empowered over 850,000 professionals through 600+ cloud certifications winning global recognition for its training excellence including 20 MCT Trainers in Microsoft’s Global Top 100 and an impressive 12 awards in the last 8 years. CloudThat specializes in Cloud Migration, Data Platforms, DevOps, IoT, and cutting-edge technologies like Gen AI & AI/ML. It has delivered over 500 consulting projects for 250+ organizations in 30+ countries as it continues to empower professionals and enterprises to thrive in the digital-first world.

FAQs

1. How do I roll back a bad deployment?

ANS: – Simply revert the Git commit that updated the image tag in your Kubernetes manifest. Once pushed, Argo CD will detect the change and automatically redeploy the previous version to the cluster, no manual intervention is required.

2. Why use a multistage Dockerfile?

ANS: – To produce lean and secure Docker images. The first stage handles building the application, while the second serves it using a minimal Nginx image. This approach removes unnecessary build tools and dependencies from the final image, reducing the size and surface area for vulnerabilities

WRITTEN BY Karthick S

Share

Comments

    Click to Comment

Get The Most Out Of Us

Our support doesn't end here. We have monthly newsletters, study guides, practice questions, and more to assist you in upgrading your cloud career. Subscribe to get them all!