# TBI ACC ceetiz-connector - CI/CD Pipeline

CircleCI pipeline configuration for tbi-acc-ceetiz-connector.

## Service Information

- **Service Name**: tbi-acc-ceetiz-connector
- **Technology**: Node.js 20 + NestJS
- **Entry Point**: `dist/main.js`
- **Namespace**: access
- **Environments**: dev, qa, uat, prod

## Repository Structure

```
dev/tbi-acc-ceetiz-connector/
├── .circleci/
│   └── config.yml          # CircleCI pipeline configuration
├── docker/
│   └── Dockerfile          # Multi-stage Docker build
├── scripts/
│   ├── setup-kubectl.sh    # kubectl and helm-secrets setup
│   └── deploy-services.sh  # Deployment automation
├── charts/
│   └── tbi-acc-ceetiz-connector/
│       ├── Chart.yaml
│       ├── values.yaml
│       └── templates/      # Kubernetes manifests
└── README.md
```

## Pipeline Stages

### 1. Lint and Test
- Runs on Node.js 20.4
- Installs dependencies with `npm ci`
- Runs linting (`npm run lint`)
- Runs tests (`npm run test`)
- Validates build (`npm run build`)

### 2. Build and Push Images
- Builds Docker image using multi-stage build
- Tags with format: `{VERSION}-{BRANCH}-{BUILD_NUM}`
- Pushes to AWS ECR with immutable tags
- Repository: `{AWS_ACCOUNT_ID}.dkr.ecr.ca-central-1.amazonaws.com/tbi-acc-ceetiz-connector`

### 3. Deploy to Kubernetes
- Packages Helm chart
- Pushes chart to S3 Helm repository
- Updates values and requirements in tbi-environments
- Deploys using helm-secrets to access namespace

## Environments and Branches

| Environment | Branch | Context | Cluster |
|-------------|--------|---------|---------|
| Development | develop | devops-mgt | dev |
| QA | qa | devops-mgt | qa |
| UAT | uat | devops-mgt | uat |
| Production | master | devops-mgt | tbi-prod |

## Required CircleCI Environment Variables

Set in CircleCI context `devops-mgt`:

- `AWS_ACCOUNT_ID` - AWS account ID for ECR
- `AWS_REGION` - AWS region (ca-central-1)
- `CLUSTER_NAME` - Kubernetes cluster name
- `DEPLOY_ENV` - Deployment environment (dev/qa/uat/prod)
- `GITHUB_TOKEN` - GitHub personal access token
- `HELM_S3_BUCKET` - S3 bucket for Helm charts (tbi-charts)

## Related Repositories

- **Application Code**: https://github.com/redlabelvacations/tbi-acc-ceetiz-connector
- **Values & Secrets**: https://github.com/redlabelvacations/tbi-environments
- **DevOps Configs**: https://github.com/redlabelvacations/tbi-devops-environments (this repo)

## Deployment Process

1. Developer pushes code to branch (develop/qa/uat/master)
2. CircleCI triggers pipeline automatically
3. Pipeline runs lint, test, build stages
4. Docker image is built and pushed to ECR
5. Helm chart is packaged and pushed to S3
6. Values file in tbi-environments is updated with new image tag
7. Service is deployed to Kubernetes using helm-secrets
8. Deployment is verified

## Manual Deployment

To manually trigger a deployment:

```bash
# Trigger via git push
git commit --allow-empty -m "Trigger deployment"
git push origin develop
```

## Troubleshooting

### Pipeline Fails at Lint Stage
- Check linting errors in CircleCI logs
- Run `npm run lint` locally to fix issues

### Pipeline Fails at Build Stage
- Check build errors in CircleCI logs
- Verify package.json dependencies
- Run `npm run build` locally

### Image Push Fails
- Verify AWS credentials in CircleCI context
- Check ECR repository exists and has correct permissions

### Deployment Fails
- Check kubectl logs in CircleCI
- Verify values file exists in tbi-environments
- Check secrets file is properly encrypted
- Verify Helm chart syntax: `helm lint charts/tbi-acc-ceetiz-connector`

### Pod CrashLoopBackOff
- Check pod logs: `kubectl logs -n redtag deployment/tbi-acc-ceetiz-connector`
- Verify environment variables are loaded from secrets
- Check entry point in Dockerfile matches package.json

## Monitoring

- **CircleCI Dashboard**: https://app.circleci.com/pipelines/github/redlabelvacations/tbi-acc-ceetiz-connector
- **Pod Status**: `kubectl get pods -n access | grep tbi-acc-ceetiz-connector`
- **Pod Logs**: `kubectl logs -n access deployment/tbi-acc-ceetiz-connector`
- **Ingress**: `kubectl get ingress -n access | grep tbi-acc-ceetiz-connector`

## Support

For issues or questions:
- Check CircleCI logs
- Review this documentation
- Contact DevOps team

---

**Last Updated**: 2026-03-05
**Pipeline Version**: 1.0.0
