# UAT and PROD Deployment Configuration Plan

**Date**: 2026-03-06
**Status**: Files copied, configs need updating

---

## Current Status

✅ **Copied**: All 20 ACC services copied to `uat/` and `prod/` directories
⏳ **Pending**: CircleCI config updates for production approval workflow

---

## Directory Structure

```
tbi-devops-environments/
├── dev/          # 20 services ✅ Complete
├── uat/          # 20 services ✅ Copied (configs need minor updates)
└── prod/         # 20 services ✅ Copied (configs need major updates)
```

---

## Services in Each Environment

All 20 services now exist in dev/, uat/, and prod/:

1. tbi-acc-booking-service
2. tbi-acc-ceetiz-connector
3. tbi-acc-cron-service
4. tbi-acc-exotiktours-connector
5. tbi-acc-gimmonix-automation
6. tbi-acc-hotel-mapping-service
7. tbi-acc-hotel-service
8. tbi-acc-hotel-service-connector
9. tbi-acc-mybff
10. tbi-acc-mybooking-frontend
11. tbi-acc-mybooking-service
12. tbi-acc-notification-service
13. tbi-acc-package-cron
14. tbi-acc-package-service
15. tbi-acc-profile-service
16. tbi-acc-profile-sync-service
17. tbi-acc-quotes-service
18. tbi-acc-sabreapi
19. tbi-acc-travelbrands
20. tbi-acc-travelbrandsagent

---

## Configuration Updates Needed

### UAT Environment

**Changes Required**: Minimal
- Branch filters: `uat` instead of `dev/develop`
- Cluster name: `tbi-uat-eks`
- Context: `devops-mgt-uat` (if different from dev)

**Workflow**: Same as dev (no approval gates)

### PROD Environment

**Changes Required**: Significant
Based on `prod/tbi-package-travelbrands/.circleci/config.yml` pattern:

#### 1. Add New Jobs

```yaml
notify-await-build-approval:
  # Sends SNS notification that BUILD approval is needed
  
notify-await-deploy-approval:
  # Sends SNS notification that DEPLOY approval is needed
```

#### 2. Update Existing Jobs

**lint-and-test**:
- Add context: `devops-mgt-prod`
- Filter: `master` or `main` branch only

**build-and-push-images**:
- Add context: `devops-mgt-prod`
- Update image tagging logic:
  ```yaml
  # Production uses clean version tag (no branch/build suffix)
  if [ "${CIRCLE_BRANCH}" == "master" ] || [ "${CIRCLE_BRANCH}" == "main" ]; then
    IMAGE_TAG="${BASE_VERSION}"
  fi
  ```
- Set ECR to IMMUTABLE tags
- Stage Dockerfile from tbi-devops-environments repo

**deploy-to-kubernetes**:
- Add context: `devops-mgt-prod`
- Use resource_class: `tbi-local-runner/prod-win`
- Stage scripts from tbi-devops-environments repo
- Add SNS success notification
- Add SNS failure notification (on_fail)
- Optional: Trigger downstream deployments

#### 3. Update Workflow

```yaml
workflows:
  deploy-[service-name]:
    jobs:
      # Step 1: Run tests
      - lint-and-test:
          context: devops-mgt-prod
          filters:
            branches:
              only: master

      # Step 2: Notify BUILD approval needed
      - notify-await-build-approval:
          context: devops-mgt-prod
          requires:
            - lint-and-test

      # Step 3: Manual approval (BUILD)
      - approve-build:
          type: approval
          requires:
            - notify-await-build-approval

      # Step 4: Build image
      - build-and-push-images:
          context: devops-mgt-prod
          requires:
            - approve-build

      # Step 5: Notify DEPLOY approval needed
      - notify-await-deploy-approval:
          context: devops-mgt-prod
          requires:
            - build-and-push-images

      # Step 6: Manual approval (DEPLOY)
      - approve-deploy:
          type: approval
          requires:
            - notify-await-deploy-approval

      # Step 7: Deploy to prod
      - deploy-to-kubernetes:
          context: devops-mgt-prod
          requires:
            - approve-deploy
```

---

## SNS Notification Configuration

All prod deployments send notifications to:
```
arn:aws:sns:ca-central-1:489176460030:DevOps-alert
```

**Notification Points**:
1. Awaiting BUILD approval (after tests pass)
2. Awaiting DEPLOY approval (after image built)
3. Deployment success
4. Deployment failure (on_fail)

---

## Implementation Options

### Option 1: Update All 20 Services Now (Recommended)
- Pros: Complete setup, ready to use
- Cons: Large commit (will add ~400+ files)
- Time: ~15-20 minutes

### Option 2: Update in Batches
- Batch 1: Critical services (5 services)
- Batch 2: Standard services (10 services)
- Batch 3: Remaining services (5 services)

### Option 3: Update On-Demand
- Keep current configs
- Update individual services as needed for deployment

---

## Differences by Service Type

### Node.js Services (Most services)
- Docker image: `cimg/node:20.4`
- Build command: `npm run build`
- Test command: `npm run test`

### PHP Services (hotel, package, travelbrandsagent, etc.)
- Docker image: `cimg/php:8.0`
- Build command: `composer install`
- Test command: `vendor/bin/phpunit` or skip

### Webpack Services (mybff, sabreapi, travelbrands)
- Docker image: `cimg/node:20.4`
- Build command: `npm run build` (webpack)
- Additional: May need frontend asset building

### CronJob Services (cron-service, package-cron)
- Same as above but deployed as CronJob
- No ingress needed
- Schedule configuration in values.yaml

---

## CircleCI Context Requirements

### Contexts Needed

**devops-mgt-prod** context must contain:
- `AWS_ACCESS_KEY_ID`
- `AWS_SECRET_ACCESS_KEY`
- `AWS_REGION` (ca-central-1)
- `AWS_ACCOUNT_ID` (489176460030)
- `GITHUB_TOKEN`
- `DEPLOY_ENV` (prod)

**devops-mgt-uat** context must contain:
- Same variables as prod but with `DEPLOY_ENV=uat`

---

## Resource Classes

### Dev/UAT
- `small` - For lint/test jobs
- `medium` - For build jobs
- Standard CircleCI cloud runners

### Prod
- `small` - For lint/test/notification jobs
- `tbi-local-runner/prod-win` - For deploy jobs
- Uses self-hosted runner for production deployments

---

## Staging Dockerfile and Scripts

Production deployments pull Dockerfile and scripts from this repo:

```bash
# Clone tbi-devops-environments
repoURL="https://${GITHUB_TOKEN}@github.com/redlabelvacations/tbi-devops-environments"
git clone $repoURL -b master --single-branch tbi-devops-environments

# Map branch to environment
case ${CIRCLE_BRANCH} in
  develop) envFolder="dev" ;;
  qa) envFolder="qa" ;;
  uat) envFolder="uat" ;;
  master|main) envFolder="prod" ;;
esac

# Copy Dockerfile
cp tbi-devops-environments/${envFolder}/${SERVICE}/docker/Dockerfile ./Dockerfile

# Copy scripts
cp tbi-devops-environments/${envFolder}/${SERVICE}/scripts/*.sh scripts/
```

This ensures production always uses the approved Dockerfile/scripts from this repo.

---

## Testing Strategy

### Dev Environment
- Automatic deployment on push to `dev`/`develop` branch
- No approvals needed
- Fast iteration

### UAT Environment
- Automatic deployment on push to `uat` branch
- No approvals needed
- Pre-production testing

### Prod Environment
- Triggered on push to `master`/`main` branch
- **Requires 2 manual approvals**:
  1. Approve BUILD (after tests pass)
  2. Approve DEPLOY (after image built)
- SNS notifications at each stage
- Immutable image tags

---

## Next Steps

1. ✅ Services copied to uat/ and prod/
2. ⏳ Update UAT CircleCI configs (20 services)
3. ⏳ Update PROD CircleCI configs (20 services)
4. ⏳ Stage all changes
5. ⏳ Commit and push
6. ⏳ Configure CircleCI contexts
7. ⏳ Test deployments

---

## Estimated File Changes

- **UAT**: 20 config files (minor updates)
- **PROD**: 20 config files (major updates)
- **Total**: ~40 files to update
- **Current staged**: 265 files
- **After updates**: ~305 files

---

## Decision Point

**Question**: Should I proceed with updating all 20 services for UAT and PROD now?

**If YES**: I'll update all CircleCI configs with proper approval workflows
**If NO**: We can commit current state and update configs later as needed

---

**Prepared By**: Kiro AI
**Date**: 2026-03-06
**Status**: Awaiting decision on config updates

