-
Notifications
You must be signed in to change notification settings - Fork 17
Add scheduled_service and reuploader recurring task #440
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
Open
aagbsn
wants to merge
23
commits into
main
Choose a base branch
from
add_reuploader_builder
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
065b076
Add reuploader builder task to dev
aagbsn ccda78d
fix trigger path
aagbsn 01ab568
Extend ooniapi_service to provide scheduled run
aagbsn e8e191e
add scheduled_service module
aagbsn 1d82bdb
add reuploader scheduled service (hourly)
aagbsn d245b73
set failed reports bucket
aagbsn 4dd954e
reuploader: set DRY_RUN=true
aagbsn b6e2ba7
reuploader: set BATCH_SIZE=10
aagbsn 0b94e88
reuploader: set AWS_SECRET_ACCESS_KEY from module
aagbsn 22f35d5
reuploader: set scheduled_task_cluster
aagbsn 3a0b895
reuploader: remove unused outputs
aagbsn d171d28
reuploader: add first_run to create container definition
aagbsn c2ffbf1
reuploader: pin to tagged container
aagbsn 6964ab5
Merge remote-tracking branch 'origin/main' into add_reuploader_builder
aagbsn d55b502
remove redundant count
aagbsn d9361d9
Merge remote-tracking branch 'origin/main' into add_reuploader_builder
aagbsn dbe872f
singleton requires no index
aagbsn 27f9c59
FIXME: try to add events:PutRule et al to profile
aagbsn 093c98f
Add permission to the ooni_devops role to modify events
LDiazN 94f3638
unmix environment from secrets
aagbsn 92fb38a
use bucket from https://github.com/ooni/devops/issues/398
aagbsn bafa175
update reuploader, fix env
aagbsn ed341e5
add AWS_REGION to task_environment
aagbsn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,154 @@ | ||
| locals { | ||
| name = "scheduled-service-${var.service_name}" | ||
| # We construct a stripped name that is without the "ooni" substring and all | ||
| # vocals are stripped. | ||
| stripped_name = replace(replace(var.service_name, "ooni", ""), "[aeiou]", "") | ||
| # Short prefix should be less than 5 characters | ||
| short_prefix = "O${substr(local.stripped_name, 0, 3)}" | ||
| } | ||
|
|
||
| resource "aws_iam_role" "scheduled_service_task" { | ||
| name = "${local.name}-task-role" | ||
|
|
||
| tags = var.tags | ||
|
|
||
| assume_role_policy = <<EOF | ||
| { | ||
| "Version": "2012-10-17", | ||
| "Statement": [ | ||
| { | ||
| "Sid": "", | ||
| "Effect": "Allow", | ||
| "Principal": { | ||
| "Service": "ecs-tasks.amazonaws.com" | ||
| }, | ||
| "Action": "sts:AssumeRole" | ||
| } | ||
| ] | ||
| } | ||
| EOF | ||
| } | ||
|
|
||
| resource "aws_iam_role_policy" "scheduled_service_task" { | ||
| name = "${local.name}-task-role" | ||
| role = aws_iam_role.scheduled_service_task.name | ||
|
|
||
| policy = templatefile("${path.module}/templates/profile_policy.json", {}) | ||
| } | ||
|
|
||
| resource "aws_iam_role" "events_run_task" { | ||
| name = "${local.name}-events-run-task-role" | ||
|
|
||
| assume_role_policy = <<EOF | ||
| { | ||
| "Version": "2012-10-17", | ||
| "Statement": [{ | ||
| "Effect": "Allow", | ||
| "Principal": {"Service": "events.amazonaws.com"}, | ||
| "Action": "sts:AssumeRole" | ||
| }] | ||
| } | ||
| EOF | ||
|
|
||
| tags = var.tags | ||
| } | ||
|
|
||
| resource "aws_iam_role_policy" "events_run_task_policy" { | ||
| name = "${local.name}-events-run-task-policy" | ||
| role = aws_iam_role.events_run_task.id | ||
|
|
||
| policy = jsonencode({ | ||
| Version = "2012-10-17" | ||
| Statement = [ | ||
| { | ||
| Effect = "Allow" | ||
| Action = [ | ||
| "ecs:RunTask", | ||
| "iam:PassRole", | ||
| "ecs:StartTask", | ||
| "ecs:DescribeClusters", | ||
| "ecs:DescribeTasks", | ||
| "events:TagResource", | ||
| "events:PutRule", | ||
| "events:PutTargets", | ||
| ] | ||
| Resource = "*" | ||
| } | ||
| ] | ||
| }) | ||
| } | ||
|
|
||
| resource "aws_cloudwatch_event_rule" "scheduled_run" { | ||
| name = "${local.name}-schedule" | ||
| schedule_expression = var.schedule_expression | ||
| tags = var.tags | ||
| } | ||
|
|
||
| resource "aws_cloudwatch_event_target" "run_ecs_task" { | ||
| rule = aws_cloudwatch_event_rule.scheduled_run.name | ||
| arn = data.aws_ecs_cluster.target.arn | ||
|
|
||
| role_arn = aws_iam_role.events_run_task.arn | ||
|
|
||
| ecs_target { | ||
| task_definition_arn = aws_ecs_task_definition.scheduled_service.arn | ||
| task_count = 1 | ||
| } | ||
| } | ||
|
|
||
| data "aws_ecs_cluster" "target" { | ||
| cluster_name = var.scheduled_task_cluster | ||
| } | ||
|
|
||
| resource "aws_cloudwatch_log_group" "scheduled_service" { | ||
| name = "ooni-ecs-group/${local.name}" | ||
| } | ||
|
|
||
| // This is done to retrieve the image name of the current task definition | ||
| // It's important to keep aligned the container_name and task_definitions | ||
| data "aws_ecs_container_definition" "scheduled_service_current" { | ||
| task_definition = "${local.name}-td" | ||
| container_name = local.name | ||
| count = var.first_run ? 0 : 1 | ||
| } | ||
|
|
||
| resource "aws_ecs_task_definition" "scheduled_service" { | ||
| family = "${local.name}-td" | ||
| network_mode = "bridge" | ||
|
|
||
| container_definitions = jsonencode([ | ||
| { | ||
| memoryReservation = var.task_memory, | ||
| memory = var.memory_hard_limit | ||
| essential = true, | ||
| image = try( | ||
| data.aws_ecs_container_definition.scheduled_service_current[0].image, | ||
| var.default_docker_image_url | ||
| ), | ||
| name = local.name, | ||
|
|
||
| environment = [ | ||
| for k, v in var.task_environment : { | ||
| name = k, | ||
| value = v | ||
| } | ||
| ], | ||
| secrets = [ | ||
| for k, v in var.task_secrets : { | ||
| name = k, | ||
| valueFrom = v | ||
| } | ||
| ], | ||
| logConfiguration = { | ||
| logDriver = "awslogs", | ||
| options = { | ||
| awslogs-group = aws_cloudwatch_log_group.scheduled_service.name, | ||
| awslogs-region = var.aws_region | ||
| } | ||
| } | ||
| } | ||
| ]) | ||
| execution_role_arn = aws_iam_role.scheduled_service_task.arn | ||
| tags = var.tags | ||
| track_latest = true | ||
| } |
Empty file.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should use the terraform variable for this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm. the default behavior is to createBucket and fail