-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DP-187 Provision Orchestrator's core componenets
- Initiate deploy job in Github workflow
- Loading branch information
Showing
24 changed files
with
312 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
name: Deploy | ||
|
||
on: | ||
push: | ||
branches: [DP-187] | ||
pull_request: | ||
branches: [DP-187] | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
env: | ||
CDP_ORGANISATION_APP_PORT: 8888 | ||
CDP_TENANT_PORT: 8811 | ||
CDP_ORGANISATION_PORT: 8822 | ||
CDP_PERSON_PORT: 8833 | ||
CDP_FORMS_PORT: 8844 | ||
CDP_DATA_SHARING_PORT: 8855 | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Setup .NET | ||
uses: actions/setup-dotnet@v4 | ||
with: | ||
dotnet-version: '8.0.x' | ||
|
||
- name: Build and Test .NET Project | ||
run: | | ||
dotnet tool restore | ||
dotnet restore | ||
dotnet build | ||
dotnet test --logger trx --results-directory TestResults | ||
- name: Build Docker Images | ||
run: make build-docker | ||
|
||
- name: Start services | ||
run: make up | ||
|
||
- name: Stop services | ||
run: make down | ||
|
||
- name: Set up AWS CLI | ||
uses: aws-actions/configure-aws-credentials@v1 | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
aws-region: eu-west-2 | ||
|
||
- name: Login to Amazon ECR | ||
id: login-ecr | ||
uses: aws-actions/amazon-ecr-login@v1 | ||
|
||
- name: Tag and Push Docker Images | ||
run: | | ||
IMAGE_VERSION=$(date +%Y%m%d%H%M%S) | ||
for image in cabinetoffice/cdp-organisation-information-migrations cabinetoffice/cdp-data-sharing cabinetoffice/cdp-forms cabinetoffice/cdp-organisation-app cabinetoffice/cdp-organisation cabinetoffice/cdp-person cabinetoffice/cdp-tenant cabinetoffice/cdp-authority; do | ||
CLEAN_IMAGE_NAME=$(echo $image | sed 's/^cabinetoffice\///') | ||
docker tag $image:latest ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.eu-west-2.amazonaws.com/$CLEAN_IMAGE_NAME:$IMAGE_VERSION | ||
docker push ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.eu-west-2.amazonaws.com/$CLEAN_IMAGE_NAME:$IMAGE_VERSION | ||
done | ||
- name: Create Git Tag | ||
run: | | ||
IMAGE_VERSION=$(date +%Y%m%d%H%M%S) | ||
git config --global user.name "github-actions" | ||
git config --global user.email "[email protected]" | ||
git tag ${IMAGE_VERSION} | ||
git push origin ${IMAGE_VERSION} | ||
- name: Store Version in SSM Parameter Store | ||
run: | | ||
IMAGE_VERSION=$(date +%Y%m%d%H%M%S) | ||
aws ssm put-parameter --name "cdp-sirsi-service-version" --value "${IMAGE_VERSION}" --type String --overwrite |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
terraform { | ||
source = local.global_vars.locals.environment == "orchestrator" ? "../../../modules//orchestrator/ecr" : null | ||
} | ||
|
||
include { | ||
path = find_in_parent_folders() | ||
} | ||
|
||
locals { | ||
|
||
global_vars = read_terragrunt_config(find_in_parent_folders("terragrunt.hcl")) | ||
core_vars = read_terragrunt_config(find_in_parent_folders("orchestrator.hcl")) | ||
|
||
tags = merge( | ||
local.global_vars.inputs.tags, | ||
local.core_vars.inputs.tags, | ||
{ | ||
component = "orchestrator-ecr" | ||
} | ||
) | ||
} | ||
|
||
inputs = { | ||
service_configs = local.global_vars.locals.service_configs | ||
tags = local.tags | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
terraform { | ||
source = local.global_vars.locals.environment == "orchestrator" ? "../../../modules//orchestrator/iam" : null | ||
} | ||
|
||
include { | ||
path = find_in_parent_folders() | ||
} | ||
|
||
locals { | ||
|
||
global_vars = read_terragrunt_config(find_in_parent_folders("terragrunt.hcl")) | ||
core_vars = read_terragrunt_config(find_in_parent_folders("orchestrator.hcl")) | ||
|
||
tags = merge( | ||
local.global_vars.inputs.tags, | ||
local.core_vars.inputs.tags, | ||
{ | ||
component = "orchestrator-iam" | ||
} | ||
) | ||
} | ||
|
||
inputs = { | ||
tags = local.tags | ||
terraform_operators = local.global_vars.locals.terraform_operators | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
locals { | ||
tags = { | ||
component_root = "orchestrator" | ||
} | ||
} | ||
|
||
inputs = { | ||
tags = local.tags | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
locals { | ||
|
||
name_prefix = var.product.resource_name | ||
|
||
repositories = concat( | ||
[ | ||
for name, config in var.service_configs : | ||
config.name | ||
], | ||
["cdp-grafana"]) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
resource "aws_ecr_repository" "this" { | ||
for_each = toset(local.repositories) | ||
|
||
name = "cdp-${each.value}" | ||
image_tag_mutability = "IMMUTABLE" | ||
|
||
image_scanning_configuration { | ||
scan_on_push = true | ||
} | ||
|
||
tags = var.tags | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
variable "environment" { | ||
description = "The environment we are provisioning" | ||
type = string | ||
} | ||
|
||
variable "product" { | ||
description = "product's common attributes" | ||
type = object({ | ||
name = string | ||
resource_name = string | ||
public_hosted_zone = string | ||
}) | ||
} | ||
|
||
variable "service_configs" { | ||
description = "Map of services to their ports" | ||
type = map(object({ | ||
cpu = number | ||
memory = number | ||
name = string | ||
port = number | ||
port_host = number | ||
})) | ||
} | ||
|
||
variable "tags" { | ||
description = "Tags to apply to all resources in this module" | ||
type = map(string) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../core-iam/ci-datasource.tf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../core-iam/ci.tf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
data "aws_caller_identity" "current" {} | ||
|
||
data "aws_region" "current" {} | ||
|
||
data "aws_iam_policy_document" "ecr_push_policy" { | ||
statement { | ||
actions = [ | ||
"ecr:GetDownloadUrlForLayer", | ||
"ecr:BatchGetImage", | ||
"ecr:BatchCheckLayerAvailability", | ||
"ecr:PutImage", | ||
"ecr:InitiateLayerUpload", | ||
"ecr:UploadLayerPart", | ||
"ecr:CompleteLayerUpload" | ||
] | ||
resources = ["arn:aws:ecr:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:repository/cdp-*"] | ||
effect = "Allow" | ||
} | ||
} | ||
|
||
data "aws_iam_policy_document" "ssm_update_policy" { | ||
statement { | ||
actions = [ | ||
"ssm:PutParameter", | ||
"ssm:GetParameter", | ||
"ssm:DeleteParameter" | ||
] | ||
resources = ["*"] # @TODO: (ABN) Limit me | ||
effect = "Allow" | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
resource "aws_iam_user" "github_user" { | ||
name = "github-user" | ||
tags = var.tags | ||
} | ||
|
||
resource "aws_iam_user_policy" "ecr_push_policy" { | ||
name = "ECRPushPolicy" | ||
user = aws_iam_user.github_user.name | ||
policy = data.aws_iam_policy_document.ecr_push_policy.json | ||
} | ||
|
||
resource "aws_iam_user_policy" "ssm_update_policy" { | ||
name = "SSMUpdatePolicy" | ||
user = aws_iam_user.github_user.name | ||
policy = data.aws_iam_policy_document.ssm_update_policy.json | ||
} | ||
|
||
resource "aws_iam_access_key" "github_user_access_key" { | ||
user = aws_iam_user.github_user.name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
locals { | ||
name_prefix = var.product.resource_name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
output "github_user_access_key_id" { | ||
value = aws_iam_access_key.github_user_access_key.id | ||
} | ||
|
||
output "github_user_secret_access_key" { | ||
value = aws_iam_access_key.github_user_access_key.secret | ||
sensitive = true | ||
} | ||
|
||
output "terraform_role_arn" { | ||
value = aws_iam_role.terraform.arn | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
variable "environment" { | ||
description = "The environment we are provisioning" | ||
type = string | ||
} | ||
|
||
variable "product" { | ||
description = "product's common attributes" | ||
type = object({ | ||
name = string | ||
resource_name = string | ||
public_hosted_zone = string | ||
}) | ||
} | ||
|
||
variable "terraform_operators" { | ||
description = "List of IAM user ARNs allowed to assume terraform roles" | ||
type = list(string) | ||
} | ||
|
||
variable "tags" { | ||
description = "Tags to apply to all resources in this module" | ||
type = map(string) | ||
} |