From b6ff07f74ae4ded61edf752d9612dfaf88b3156a Mon Sep 17 00:00:00 2001 From: C MARSTON Date: Wed, 12 Jun 2024 14:51:24 +0100 Subject: [PATCH 1/3] feat(terraform): vol5504 add single batch job test --- infra/terraform/environments/dev/main.tf | 6 + infra/terraform/modules/service/batch.tf | 143 +++++++++++++++++++ infra/terraform/modules/service/variables.tf | 5 + 3 files changed, 154 insertions(+) create mode 100644 infra/terraform/modules/service/batch.tf diff --git a/infra/terraform/environments/dev/main.tf b/infra/terraform/environments/dev/main.tf index c30664cad7..c533436f62 100644 --- a/infra/terraform/environments/dev/main.tf +++ b/infra/terraform/environments/dev/main.tf @@ -235,3 +235,9 @@ module "service" { } } } + +module "batchjob" { + source = "../../modules/service" + + job_command = "/opt/dvsa/olcs/api/vendor/bin/laminas --container=/opt/dvsa/olcs/api/config/container-cli.php queue:process-queue" +} \ No newline at end of file diff --git a/infra/terraform/modules/service/batch.tf b/infra/terraform/modules/service/batch.tf new file mode 100644 index 0000000000..1de4bda8a5 --- /dev/null +++ b/infra/terraform/modules/service/batch.tf @@ -0,0 +1,143 @@ + +module "batch" { + source = "terraform-aws-modules/batch/aws" + + instance_iam_role_name = "${var.environment}-batch-test-ecs-instance-role" + instance_iam_role_path = "/batch/" + instance_iam_role_description = "IAM instance role/profile for AWS Batch ECS instance(s)" + instance_iam_role_tags = { + ModuleCreatedRole = "Yes" + } + + service_iam_role_name = "${var.environment}-batch-test-batch-role" + service_iam_role_path = "/batch/" + service_iam_role_description = "IAM service role for AWS Batch" + service_iam_role_tags = { + ModuleCreatedRole = "Yes" + } + + create_spot_fleet_iam_role = false + spot_fleet_iam_role_name = "${var.environment}-batch-test-spot-role" + spot_fleet_iam_role_path = "/batch/" + spot_fleet_iam_role_description = "IAM spot fleet role for AWS Batch" + spot_fleet_iam_role_tags = { + ModuleCreatedRole = "Yes" + } + + compute_environments = { + a_fargate = { + name_prefix = "batch-test-fargate" + + compute_resources = { + type = "FARGATE" + max_vcpus = 4 + + security_group_ids = ["${aws_security_group.api.id}"] + subnets = values(module.subnets_asg_api.subnet_ids_az) + + # `tags = {}` here is not applicable for spot + } + } + + b_fargate_spot = { + name_prefix = "batch-test-fargate_spot" + + compute_resources = { + type = "FARGATE_SPOT" + max_vcpus = 4 + + security_group_ids = ["${aws_security_group.api.id}"] + subnets = values(module.subnets_asg_api.subnet_ids_az) + + # `tags = {}` here is not applicable for spot + } + } + } + + # Job queus and scheduling policies + job_queues = { + low_priority = { + name = "BatchTestLowPriorityFargate" + state = "ENABLED" + priority = 1 + + tags = { + JobQueue = "Low priority job queue" + } + } + + high_priority = { + name = "BatchTestHighPriorityFargate" + state = "ENABLED" + priority = 99 + + fair_share_policy = { + compute_reservation = 1 + share_decay_seconds = 3600 + + share_distribution = [{ + share_identifier = "A1*" + weight_factor = 0.1 + }, { + share_identifier = "A2" + weight_factor = 0.2 + }] + } + + tags = { + JobQueue = "High priority job queue" + } + } + } + + job_definitions = { + example = { + name = "batch-test-job" + propagate_tags = true + platform_capabilities = ["FARGATE"] + + container_properties = jsonencode({ + command = "${var.job_command}" + image = "054614622558.dkr.ecr.eu-west-1.amazonaws.com/vol-app/cli:latest" + fargatePlatformConfiguration = { + platformVersion = "LATEST" + }, + resourceRequirements = [ + { type = "VCPU", value = "1" }, + { type = "MEMORY", value = "2048" } + ], + executionRoleArn = module.iam_assumable_role_vol_api_task_exec_role.iam_role_arn + #### CW Log group to be created later +/* logConfiguration = { + logDriver = "awslogs" + options = { + awslogs-group = local.vol_api_log_group + awslogs-region = var.region + awslogs-stream-prefix = "ecs" + } + }*/ + }) + + attempt_duration_seconds = 60 + retry_strategy = { + attempts = 3 + evaluate_on_exit = { + retry_error = { + action = "RETRY" + on_exit_code = 1 + } + exit_success = { + action = "EXIT" + on_exit_code = 0 + } + } + } + + tags = { + JobDefinition = "BatchTest" + } + } + } + +// tags = local.default_tags +} \ No newline at end of file diff --git a/infra/terraform/modules/service/variables.tf b/infra/terraform/modules/service/variables.tf index fb729bac13..3b8e2172d6 100644 --- a/infra/terraform/modules/service/variables.tf +++ b/infra/terraform/modules/service/variables.tf @@ -40,3 +40,8 @@ variable "services" { description = "The services to deploy" default = {} } + +variable "job_command" { + type = string + description = "The application command to run" +} \ No newline at end of file From ca9df4619402409c05cf1c62c65551e0e245b00d Mon Sep 17 00:00:00 2001 From: C MARSTON Date: Wed, 12 Jun 2024 16:16:16 +0100 Subject: [PATCH 2/3] feat(terraform): vol5504 add single batch job test --- infra/terraform/environments/dev/main.tf | 9 ++++----- infra/terraform/modules/service/batch.tf | 2 +- infra/terraform/modules/service/variables.tf | 6 ++++-- package-lock.json | 2 +- package.json | 2 +- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/infra/terraform/environments/dev/main.tf b/infra/terraform/environments/dev/main.tf index c533436f62..e6b3c01a6c 100644 --- a/infra/terraform/environments/dev/main.tf +++ b/infra/terraform/environments/dev/main.tf @@ -234,10 +234,9 @@ module "service" { listener_rule_host_header = "ssweb.*" } } -} -module "batchjob" { - source = "../../modules/service" + jobs = { + job_command = "/opt/dvsa/olcs/api/vendor/bin/laminas --container=/opt/dvsa/olcs/api/config/container-cli.php queue:process-queue" + } +} - job_command = "/opt/dvsa/olcs/api/vendor/bin/laminas --container=/opt/dvsa/olcs/api/config/container-cli.php queue:process-queue" -} \ No newline at end of file diff --git a/infra/terraform/modules/service/batch.tf b/infra/terraform/modules/service/batch.tf index 1de4bda8a5..b95c95d395 100644 --- a/infra/terraform/modules/service/batch.tf +++ b/infra/terraform/modules/service/batch.tf @@ -97,7 +97,7 @@ module "batch" { platform_capabilities = ["FARGATE"] container_properties = jsonencode({ - command = "${var.job_command}" + command = "${var.jobs.job_command}" image = "054614622558.dkr.ecr.eu-west-1.amazonaws.com/vol-app/cli:latest" fargatePlatformConfiguration = { platformVersion = "LATEST" diff --git a/infra/terraform/modules/service/variables.tf b/infra/terraform/modules/service/variables.tf index 3b8e2172d6..965783e919 100644 --- a/infra/terraform/modules/service/variables.tf +++ b/infra/terraform/modules/service/variables.tf @@ -41,7 +41,9 @@ variable "services" { default = {} } -variable "job_command" { - type = string +variable "jobs" { + type = map(object({ + job_command = string + })) description = "The application command to run" } \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 517d9fda01..5a81e785d3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,7 @@ "@commitlint/cli": "^19.0.3", "@commitlint/config-conventional": "^19.0.3", "@tsconfig/recommended": "^1.0.3", - "husky": "^9.0.10", + "husky": "^9.0.11", "lint-staged": "^15.2.2", "prettier": "~3.3.0", "typescript": "~5.4.2" diff --git a/package.json b/package.json index bc768a903d..35fa66bb24 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "@commitlint/cli": "^19.0.3", "@commitlint/config-conventional": "^19.0.3", "@tsconfig/recommended": "^1.0.3", - "husky": "^9.0.10", + "husky": "^9.0.11", "lint-staged": "^15.2.2", "prettier": "~3.3.0", "typescript": "~5.4.2" From d5b5f4d007a16792573728958a6fba33fd527a47 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 12 Jun 2024 15:18:11 +0000 Subject: [PATCH 3/3] docs: update Terraform docs --- infra/terraform/modules/service/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/infra/terraform/modules/service/README.md b/infra/terraform/modules/service/README.md index 11048e3028..4841b917b9 100644 --- a/infra/terraform/modules/service/README.md +++ b/infra/terraform/modules/service/README.md @@ -17,6 +17,7 @@ | Name | Source | Version | |------|--------|---------| | [acm](#module\_acm) | terraform-aws-modules/acm/aws | ~> 5.0 | +| [batch](#module\_batch) | terraform-aws-modules/batch/aws | n/a | | [cloudfront](#module\_cloudfront) | terraform-aws-modules/cloudfront/aws | ~> 3.4 | | [ecs\_cluster](#module\_ecs\_cluster) | terraform-aws-modules/ecs/aws//modules/cluster | ~> 5.10 | | [ecs\_service](#module\_ecs\_service) | terraform-aws-modules/ecs/aws//modules/service | ~> 5.10 | @@ -45,6 +46,7 @@ | [assets\_version](#input\_assets\_version) | The version of the assets | `string` | n/a | yes | | [domain\_name](#input\_domain\_name) | The domain name for the environment | `string` | n/a | yes | | [environment](#input\_environment) | The environment to deploy to | `string` | n/a | yes | +| [jobs](#input\_jobs) | The application command to run |
map(object({
job_command = string
}))
| n/a | yes | | [services](#input\_services) | The services to deploy |
map(object({
version = string
repository = string
cpu = number
memory = number
task_iam_role_statements = list(object({
effect = string
actions = list(string)
resources = list(string)
}))
add_cdn_url_to_env = optional(bool, false)
lb_listener_arn = string
listener_rule_priority = optional(number, 10)
listener_rule_host_header = optional(string, "*")
security_group_ids = list(string)
subnet_ids = list(string)
vpc_id = optional(string, null)
}))
| `{}` | no | | [vpc\_id](#input\_vpc\_id) | The VPC ID | `string` | n/a | yes |