Skip to content

Latest commit

 

History

History
314 lines (227 loc) · 7.31 KB

File metadata and controls

314 lines (227 loc) · 7.31 KB

EasyShop Frontend

GitHub Profile Docker Image Stars GitHub last commit

EasyShop 🛍️ is a modern, full-stack e-commerce platform built with Next.js 14, TypeScript, and MongoDB. It features a beautiful UI with Tailwind CSS, secure authentication, real-time cart updates, and a seamless shopping experience.

Table of Contents

  1. Architecture Overview
  2. Prerequisites
  3. Infrastructure Setup
  4. Jenkins Setup
  5. Continuous Deployment Setup (CD)
  6. NGINX Ingress + Cert-Manager
  7. HTTPS Configuration

Architecture Overview

EasyShop uses a GitOps approach with the following components:

  • Infrastructure as Code (IaC): Terraform is used to provision and manage the cloud infrastructure.
  • Containerization: Docker is used to containerize the application and its dependencies.
  • Container Registry: Docker Hub is used as the container registry.
  • CI Pipeline: Jenkins is used for continuous integration.
  • CD Pipeline: ArgoCD is used for continuous delivery.
  • Kubernetes: Kubernetes is used for container orchestration and management.
  • Monitoring: Prometheus and Grafana are used for monitoring the application and infrastructure.

Important

Prerequisites

Before you begin, ensure you have the following prerequisites:

  • AWS Account: You need an AWS account/IAM role with appropriate permissions.
  • Terraform: Install Terraform on your local machine.
  • AWS CLI: Install the AWS Command Line Interface (CLI) on your local machine.

EasyShop is a full-stack e-commerce platform built with:

  • Next.js 14
  • TypeScript
  • MongoDB
  • Tailwind CSS for UI
  • Secure Authentication
  • Real-time Cart Updates

Follow the steps below to get your infrastructure up and running using Terraform:

💻 Project Setup & Initialization

Install & Initialize Terraform

# Add HashiCorp repo & install
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
sudo apt-add-repository "deb [arch=amd64] https://apt.releases. hashicorp.com $(lsb_release -cs) main"
sudo apt-get update && sudo apt-get install terraform

Verify:

terraform -v

Initialize:

terraform init

Install & Configure AWS CLI

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
sudo apt install unzip
unzip awscliv2.zip
sudo ./aws/install
aws configure

Provide:

  • AWS Access Key ID
  • AWS Secret Access Key
  • Default region name
  • Output format

Note

Ensure your IAM role has programmatic access and required permissions.


Getting Started with Terraform

Clone the Repository

git clone https://github.com/iemafzalhassan/easyshop--demo.git
cd terraform

Generate SSH Key

ssh-keygen -f terra-key
chmod 400 terra-key

Infrastructure Setup

terraform init
terraform plan
terraform apply

Confirm with yes

SSH into EC2

ssh -i terra-key ubuntu@<public-ip>

Update Kubeconfig

aws eks --region eu-west-1 update-kubeconfig --name tws-eks-cluster
kubectl get nodes

Jenkins Setup

cd /modules/bastion
./install-tools.sh
./system-service.sh
./deploy-applications.sh

Check Jenkins Status

sudo systemctl status jenkins

Get Initial Admin Password

sudo cat /var/lib/jenkins/secrets/initialAdminPassword

Start Jenkins (If not running)

sudo systemctl enable jenkins
sudo systemctl restart jenkins

Install Plugins

Navigate to: Manage Jenkins → Plugins → Available Plugins

Install:

  • Docker Pipeline
  • Pipeline View

GitHub Credentials:

Jenkins → Manage Jenkins → Credentials → Global → Add Credentials

  • Kind: Username with password
  • ID: github-credentials

DockerHub Credentials:

Same path as above

  • Kind: Username with password
  • ID: docker-hub-credentials

Add Shared Library

Manage Jenkins → Configure System → Global Pipeline Libraries

  • Name: shared
  • Version: main
  • Repo URL: https://github.com/iemafzalhassan/EasyShop-jenkins-shared-lib

Ensure repo has: vars/ directory.

  • Name: EasyShop-jenkins-shared-lib

Triggers

  • GitHub hook trigger for GITScm polling

Pipeline Config

  • Definition: Pipeline script from SCM
  • SCM: Git
  • Branch: master
  • Script Path: Jenkinsfile

Continuous Deployment Setup (CD)

SSH into Bastion

ssh -i terra-key ubuntu@<bastion-ip>

Configure AWS CLI

aws configure

Update kubeconfig

aws eks update-kubeconfig --region eu-west-1 --name tws-eks-cluster

Argo CD Setup

run script to automate setup

./easyshop-deployment.sh

or:

Install Argo CD

kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml

Monitor Pods

watch kubectl get pods -n argocd

Expose Argo CD

kubectl patch svc argocd-server -n argocd -p '{"spec": {"type": "NodePort"}}'
kubectl port-forward svc/argocd-server -n argocd 8080:443 --address=0.0.0.0 &

Get admin password:

kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d; echo

NGINX Ingress + Cert-Manager

NGINX Installation

helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm repo update
kubectl create namespace ingress-nginx

helm install nginx-ingress ingress-nginx/ingress-nginx   --namespace ingress-nginx   --set controller.service.type=LoadBalancer

Cert-Manager Setup

helm repo add jetstack https://charts.jetstack.io
helm repo update

helm install cert-manager jetstack/cert-manager   --namespace cert-manager   --create-namespace   --version v1.12.0   --set installCRDs=true

---

##  HTTPS Configuration

####  `04-configmap.yaml`

> ```yaml
> NEXT_PUBLIC_API_URL: "https://easyshop.letsdeployit.com/api"
> NEXTAUTH_URL: "https://easyshop.letsdeployit.com/"
> ```

####  `10-ingress.yaml`

> ```yaml
> annotations:
>   cert-manager.io/cluster-issuer: "letsencrypt-prod"
>   nginx.ingress.kubernetes.io/ssl-redirect: "true"
> ```

 `Apply Changes:`

> ```bash
> kubectl apply -f 00-cluster-issuer.yaml
> kubectl apply -f 04-configmap.yaml
> kubectl apply -f 10-ingress.yaml
> ```

 `Check Status:`
> ```bash
> kubectl get certificate -n easyshop
> kubectl describe certificate easyshop-tls -n easyshop
> ```

---

##  **Congratulations! Deployment Complete!**

>  Your full-stack e-commerce project is now deployed and live!