Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vol5504 batch jobs module #130

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions infra/terraform/environments/dev/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,9 @@ module "service" {
listener_rule_host_header = "ssweb.*"
}
}

jobs = {
job_command = "/opt/dvsa/olcs/api/vendor/bin/laminas --container=/opt/dvsa/olcs/api/config/container-cli.php queue:process-queue"
}
}

2 changes: 2 additions & 0 deletions infra/terraform/modules/service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
| Name | Source | Version |
|------|--------|---------|
| <a name="module_acm"></a> [acm](#module\_acm) | terraform-aws-modules/acm/aws | ~> 5.0 |
| <a name="module_batch"></a> [batch](#module\_batch) | terraform-aws-modules/batch/aws | n/a |
| <a name="module_cloudfront"></a> [cloudfront](#module\_cloudfront) | terraform-aws-modules/cloudfront/aws | ~> 3.4 |
| <a name="module_ecs_cluster"></a> [ecs\_cluster](#module\_ecs\_cluster) | terraform-aws-modules/ecs/aws//modules/cluster | ~> 5.10 |
| <a name="module_ecs_service"></a> [ecs\_service](#module\_ecs\_service) | terraform-aws-modules/ecs/aws//modules/service | ~> 5.10 |
Expand Down Expand Up @@ -45,6 +46,7 @@
| <a name="input_assets_version"></a> [assets\_version](#input\_assets\_version) | The version of the assets | `string` | n/a | yes |
| <a name="input_domain_name"></a> [domain\_name](#input\_domain\_name) | The domain name for the environment | `string` | n/a | yes |
| <a name="input_environment"></a> [environment](#input\_environment) | The environment to deploy to | `string` | n/a | yes |
| <a name="input_jobs"></a> [jobs](#input\_jobs) | The application command to run | <pre>map(object({<br> job_command = string<br> }))</pre> | n/a | yes |
| <a name="input_services"></a> [services](#input\_services) | The services to deploy | <pre>map(object({<br> version = string<br> repository = string<br> cpu = number<br> memory = number<br> task_iam_role_statements = list(object({<br> effect = string<br> actions = list(string)<br> resources = list(string)<br> }))<br> add_cdn_url_to_env = optional(bool, false)<br> lb_listener_arn = string<br> listener_rule_priority = optional(number, 10)<br> listener_rule_host_header = optional(string, "*")<br> security_group_ids = list(string)<br> subnet_ids = list(string)<br> vpc_id = optional(string, null)<br> }))</pre> | `{}` | no |
| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | The VPC ID | `string` | n/a | yes |

Expand Down
143 changes: 143 additions & 0 deletions infra/terraform/modules/service/batch.tf
Original file line number Diff line number Diff line change
@@ -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.jobs.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
}
7 changes: 7 additions & 0 deletions infra/terraform/modules/service/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,10 @@ variable "services" {
description = "The services to deploy"
default = {}
}

variable "jobs" {
type = map(object({
job_command = string
}))
description = "The application command to run"
}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down