# Core infrastructure

## ECR docker repo

### Description

`terraform-ecr` folder contains terraform code that creates an ECR repo in AWS and allows EKS clusters to pull images from it.

```
terraform-ecr/
├── dev.tfvars
├── ecr.tf
├── main.tf
└── variables.tf
```

### Variables

You should already have created an entry in the Service Catalogue for your project. The following info is used to tag the AWS resources:

- `<% SERVICE_CATALOGUE_ID >`
- `<% SERVICE_NAME >`
- `<% ENVIRONMENT >`

`<% PROJECT_NAME >` is used to name the ECR repo and usually is the same as the git repo name

## Helm

### Description

Defines a helm chart for deploying the kubernetes resources needed for the project

```
helm
├── Chart.yaml
├── templates
│   ├── _helpers.tpl
│   ├── deployment.yaml
│   ├── horizontalpodautoscaler.yaml
│   ├── ingress.yaml
│   ├── networkpolicy.yaml
│   ├── secret.yaml
│   └── service.yaml
├── values-dev.yaml
├── values-local.yaml
├── values-pr.yaml
├── values-prod.yaml
├── values-staging.yaml
└── values.yaml
```

`templates` folder includes the generalized templates for kubernetes resources and a helpers file defining common variables used in them
Different values files include specific values for those templates for different environments.

### Variables

- `<% PROJECT_NAME >` - is used to name the chart and k8s resources and usually is the same as the git repo name
- `<% REPOSITORY_NAME >` - Name of the repository created with the ECR terraform code
- `<% SERVICE_NAME >` - Service name from the Service Catalogue

## CircleCI

### Description

Provides a sample CircleCI configuration file.

```
.circleci/
└── config.yml
```

The configuration uses an inline orb to define most of the job needed for a proper build and deploy workflow.

There are 3 workflows:

- pull_request - should be triggered on on pull requests and create separate environment used by devs for features

![pull_request](pull_request.png)

- remove_pr - remove PR environment after merge

![remove_pr](remove_pr.png)

- build_and_depoy - main workflow after feature branch merge to build test and deploy the product

![build_and_deploy](build_and_deploy.png)

### Variables

This configuration relies on getting values from CircleCI contexts. There should be one context per environment in the format: `<% PROJECT_NAME >-<% ENVIRONMENT >`

- stage
  - `AWS_ACCESS_KEY_ID` - AWS credentials for EKS cluster
  - `AWS_SECRET_ACCESS_KEY` - AWS credentials for EKS cluster
  - `AWS_EKS_CLUSTER`- name of eks cluster - ceng-eng-dev
  - `AWS_ASSUME_ROLE_ARN` - user role used in EKS cluster
  - `AWS_DEFAULT_REGION` - usually eu-west-1
  - `GIT_EMAIL` - Github user configuration
  - `GIT_USERNAME` - Github user configuration
  - `NEWSKIT_API_ENV_URL` - Newskit API configuration
  - `NEWSKIT_API_X_API_KEY` - Newskit API configuration
- dev - same as stage plus the following:
  - `AWS_ACCOUNT_ID` - The account id for ECR repo
  - `ECR_AWS_ACCESS_KEY_ID` - AWS credentials for ECR
  - `ECR_AWS_SECRET_ACCESS_KEY` - AWS credentials for ECR
  - `ECR_AWS_ASSUME_ROLE_ARN` - AWS role for ECR
  - `PACT_BROKER_TOKEN` - pact broker configuration
  - `PACT_BROKER_URL` - pact broker configuration
- prod - same as stage plus the following
  - `BOOK_RELEASE_ROLE_ARN` - AWS IAM role giving access to S3 bucket with release sheet credentials
  - `GIT_ACCESS_TOKEN` - Github personal access token used to created releases
  - `GIT_EMAIL` - Email for user creating releases
  - `GIT_USERNAME` - Username for user creating releases
  - `PRODUCT_OWNER` - Product owner used for releases - needs to be in Remedy on Demand
  - `RELEASE_AWS_ACCESS_KEY_ID` - AWS credentials for release role
  - `RELEASE_AWS_SECRET_ACCESS_KEY` - AWS credentials for release role
  - `SLACK_RELEASES_WEBHOOK` - Webhook for releases slack channel

The following placeholders are used in the CircleCI `config.yml` configuration:

- `<% HELM_BUCKET_NAME >` - S3 bucket that is going to host helm charts
- `<% HELM_RELEASE_NAME >` - Name of the helm release. Usually alligns with `<% PROJECT_NAME >`
- `<% TEAM >`- Used to generate the S3 bucket key i.e. product-platforms
- `<% PACKAGE_MANAGER >` - package manage i.e. yarn or npm
- `<% PACKAGE_MANAGER_LOCK_FILE >` - lock file i.e. yarn.lock or package-lock.json
- `<% PACKAGE_INSTALL >` - install command for package manager
- `<% PACKAGE_RUN > ` - run command for package manager
- `<% K8S_NAMESPACE >`- Kubernetes namespace without environment suffix
- `<% TERRAFORM_FOLDER >` - folder inside the package containing terraform code
- `<% GIT_REPO` > - URL for the Github repo used in link to release info
- `<% SSH_KEY `> - Fingerprint for SSH key with write access used by CircleCI

## Release-documentation-cli

### Description

The release-documentation-cli tool is used in NewsUK for automating the release process. Further usage information can be found here: https://github.com/newsuk/release-documentation-cli

There is a configuration file that specifies the release details according to the [Release Request Form](https://docs.google.com/forms/d/e/1FAIpQLSc_6O1hWIStREGZOEelg9P5D-kxnZaddStwed1CUx0KxTCjxw/formResponse) that should be in the root of the project/ package: [release-documentation-cli.config.json](./release-documentation-cli.config.json). Check the form for possible values.

> [!Note]
> The `rodConfigurationItemName` and `rodConfigurationItemReconId` need to be created in Remedy on Demand system.
