> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Understanding DevOps Pipeline

> This guide designs a CI/CD pipeline for a Node.js application using GitHub Actions to automate builds, testing, and deployments.

In this guide, we’ll design a CI/CD pipeline for a Node.js application using **GitHub Actions**. Automating each stage ensures consistent builds, rapid feedback, and reliable deployments across development and production clusters.

## Pipeline Overview

| Stage                    | Description                                      |
| ------------------------ | ------------------------------------------------ |
| Source Checkout          | Pull code from GitHub repository                 |
| Unit Testing             | Install dependencies, run tests, archive reports |
| Code Coverage            | Generate coverage metrics (errors ignored)       |
| Containerization         | Build Docker image, smoke test, push to registry |
| Dev Deployment           | Apply Kubernetes manifests, expose via Ingress   |
| Dev Integration Testing  | Validate live endpoint on development cluster    |
| Manual Approval          | Pause for reviewer sign-off                      |
| Prod Deployment          | Deploy to production cluster                     |
| Prod Integration Testing | Verify the production endpoint                   |

***

## 1. Source Checkout

Begin by checking out your repository so that all subsequent jobs have access to your code.

```yaml theme={null}
- name: Checkout source code
  uses: actions/checkout@v3
```

***

## 2. Unit Testing

Install dependencies, execute your test suite, and archive the results. The pipeline will fail on any test errors.

```bash theme={null}
npm ci
npm test
# Archive test reports for review
```

<Callout icon="lightbulb" color="#1CB2FE">
  Use `npm ci` in CI environments for a clean, deterministic install.
</Callout>

***

## 3. Code Coverage

Run coverage in parallel with unit tests. We ignore coverage thresholds to avoid pipeline failures but still collect the reports.

```bash theme={null}
npm ci
npm run coverage || echo "Coverage errors ignored"
# Archive coverage reports for metrics
```

<Callout icon="lightbulb" color="#1CB2FE">
  Storing coverage artifacts helps you track trends over time, even if errors are ignored.
</Callout>

***

## 4. Containerization

Build your Docker image, perform a quick smoke test inside a container, and push it to your Docker registry.

```bash theme={null}
docker build -t $REGISTRY/$REPO:$TAG .
docker run --rm $REGISTRY/$REPO:$TAG npm test
docker push $REGISTRY/$REPO:$TAG
```

***

## 5. Deploy to Development Cluster

Apply Kubernetes manifests to your development cluster and capture the Ingress hostname.

```bash theme={null}
kubectl apply -f k8s/
DEV_HOST=$(kubectl get ingress app-ingress \
  -o jsonpath='{.status.loadBalancer.ingress[0].hostname}')
echo "Development URL: https://$DEV_HOST"
```

***

## 6. Integration Testing on Dev

Verify that the application is live on the development endpoint.

```bash theme={null}
curl -f https://$DEV_HOST/live
```

***

## 7. Manual Approval

Pause the workflow until a reviewer manually approves the release. On rejection, the pipeline stops.

<Callout icon="triangle-alert" color="#FF6B6B">
  Ensure that the reviewer has access to both the GitHub repo and any relevant sprint boards before approving.
</Callout>

***

## 8. Deploy to Production Cluster

Once approved, deploy the same manifests to your production context.

```bash theme={null}
kubectl apply -f k8s/ --context=prod
PROD_HOST=$(kubectl get ingress app-ingress \
  --context=prod \
  -o jsonpath='{.status.loadBalancer.ingress[0].hostname}')
echo "Production URL: https://$PROD_HOST"
```

***

## 9. Post-Deployment Integration Tests

Perform final checks against the production endpoint to validate a successful release.

```bash theme={null}
curl -f https://$PROD_HOST/live
```

***

## Links and References

* [GitHub Actions Documentation](https://docs.github.com/actions)
* [Kubernetes Concepts](https://kubernetes.io/docs/concepts/overview/what-is-kubernetes/)
* [Docker Hub](https://hub.docker.com/)

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/github-actions/module/6136c7b5-8fe0-4a84-ae77-0274623512d5/lesson/4a8b6d38-0341-43fb-acd5-fa2866f89217" />
</CardGroup>
