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 a leading provider of Cloud Training and Consulting services with a global presence in India, the USA, Asia, Europe, and Africa. Specializing in AWS, Microsoft Azure, GCP, VMware, Databricks, and more, the company serves mid-market and enterprise clients, offering comprehensive expertise in Cloud Migration, Data Platforms, DevOps, IoT, AI/ML, and more.

CloudThat is the first Indian Company to win the prestigious Microsoft Partner 2024 Award and is recognized as a top-tier partner with AWS and Microsoft, including the prestigious ‘Think Big’ partner award from AWS and the Microsoft Superstars FY 2023 award in Asia & India. Having trained 850k+ professionals in 600+ cloud certifications and completed 500+ consulting projects globally, CloudThat is an official AWS Advanced Consulting Partner, Microsoft Gold Partner, AWS Training PartnerAWS Migration PartnerAWS Data and Analytics PartnerAWS DevOps Competency PartnerAWS GenAI Competency PartnerAmazon QuickSight Service Delivery PartnerAmazon EKS Service Delivery Partner AWS Microsoft Workload PartnersAmazon EC2 Service Delivery PartnerAmazon ECS Service Delivery PartnerAWS Glue Service Delivery PartnerAmazon Redshift Service Delivery PartnerAWS Control Tower Service Delivery PartnerAWS WAF Service Delivery PartnerAmazon CloudFront Service Delivery PartnerAmazon OpenSearch Service Delivery PartnerAWS DMS Service Delivery PartnerAWS Systems Manager Service Delivery PartnerAmazon RDS Service Delivery PartnerAWS CloudFormation Service Delivery PartnerAWS ConfigAmazon EMR and many more.

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!