# TBI ACC Hotel Service - CI/CD Pipeline

This directory contains the CircleCI pipeline configuration and deployment resources for the TBI ACC Hotel Service (PHP Lumen).

## Service Information

- **Service Name**: tbi-acc-hotel-service
- **Technology**: PHP 8.0 + Lumen Framework
- **Namespace**: access
- **Environments**: dev, qa, uat, prod, tbi-acc-his, tbi-acc-gx (6 environments)

## Directory Structure

```
dev/tbi-acc-hotel-service/
├── .circleci/
│   └── config.yml              # CircleCI pipeline configuration
├── docker/
│   ├── Dockerfile              # Multi-stage PHP Dockerfile
│   ├── nginx.conf              # Nginx configuration
│   ├── default.conf            # Nginx server block
│   └── supervisord.conf        # Supervisor configuration
├── scripts/
│   ├── setup-kubectl.sh        # kubectl installation script
│   └── deploy-services.sh      # Deployment script
├── charts/
│   └── tbi-acc-hotel-service/  # Helm chart
│       ├── Chart.yaml
│       ├── values.yaml
│       └── templates/
│           ├── deployment.yaml
│           ├── service.yaml
│           ├── ingress.yaml
│           ├── hpa.yaml
│           ├── pdb.yaml
│           └── secrets.yaml
└── README.md                   # This file
```

## Pipeline Stages

1. **Lint**: PHP syntax checking
2. **Test**: Run PHPUnit tests
3. **Build**: Build and push Docker image to ECR
4. **Deploy**: Deploy to Kubernetes using Helm

## Triggering Deployments

Deployments are triggered via CircleCI API with environment-specific parameters:

### Dev Environment
```bash
curl -X POST https://circleci.com/api/v2/project/github/ORG/tbi-acc-hotel-service/pipeline \
  -H "Circle-Token: $CIRCLE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"parameters":{"deploy_dev":true}}'
```

### QA Environment
```bash
curl -X POST https://circleci.com/api/v2/project/github/ORG/tbi-acc-hotel-service/pipeline \
  -H "Circle-Token: $CIRCLE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"parameters":{"deploy_qa":true}}'
```

### UAT Environment
```bash
curl -X POST https://circleci.com/api/v2/project/github/ORG/tbi-acc-hotel-service/pipeline \
  -H "Circle-Token: $CIRCLE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"parameters":{"deploy_uat":true}}'
```

### Production Environment
```bash
curl -X POST https://circleci.com/api/v2/project/github/ORG/tbi-acc-hotel-service/pipeline \
  -H "Circle-Token: $CIRCLE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"parameters":{"deploy_prod":true}}'
```

### TBI ACC HIS Environment
```bash
curl -X POST https://circleci.com/api/v2/project/github/ORG/tbi-acc-hotel-service/pipeline \
  -H "Circle-Token: $CIRCLE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"parameters":{"deploy_tbi_acc_his":true}}'
```

### TBI ACC GX Environment
```bash
curl -X POST https://circleci.com/api/v2/project/github/ORG/tbi-acc-hotel-service/pipeline \
  -H "Circle-Token: $CIRCLE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"parameters":{"deploy_tbi_acc_gx":true}}'
```

## Required CircleCI Contexts

Each environment requires specific contexts:

- **dev**: aws-dev, k8s-dev
- **qa**: aws-qa, k8s-qa
- **uat**: aws-uat, k8s-uat
- **prod**: aws-prod, k8s-prod
- **tbi-acc-his**: aws-tbi-acc-his, k8s-tbi-acc-his
- **tbi-acc-gx**: aws-tbi-acc-gx, k8s-tbi-acc-gx

## Docker Image

The service uses a multi-stage Dockerfile optimized for PHP Lumen:

- **Base Image**: php:8.0-fpm-alpine
- **Web Server**: Nginx
- **Process Manager**: Supervisor
- **PHP Extensions**: PDO, MySQL, PostgreSQL, Redis, GD, Intl, Zip, etc.

## Deployment

The deployment script (`scripts/deploy-services.sh`) performs:

1. Configures kubectl with appropriate credentials
2. Deploys using Helm to the `access` namespace
3. Sets image tag to `{environment}-{git-sha}`
4. Waits for rollout completion

## Environment-Specific Configuration

Configuration is managed through:

1. **tbi-environments repository**: values.yaml, secrets.yaml per environment
2. **Kubernetes Secrets**: Managed via GitHub Actions in service repository
3. **Environment Variables**: Set in Helm values

## Next Steps

1. Copy `.circleci/config.yml` to service repository
2. Copy `.github/workflows/manage-secrets.yml` to service repository
3. Update values files in tbi-environments repository
4. Configure CircleCI contexts
5. Test deployment in dev environment

## Support

For issues or questions, contact the DevOps team.
