-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
2,837 additions
and
2 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 |
---|---|---|
@@ -1 +1,11 @@ | ||
{} | ||
{ | ||
"acknowledged-issue-numbers": [ | ||
19836 | ||
], | ||
"availability-zones:account=431229050501:region=us-west-2": [ | ||
"us-west-2a", | ||
"us-west-2b", | ||
"us-west-2c", | ||
"us-west-2d" | ||
] | ||
} |
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,47 @@ | ||
import pathlib | ||
|
||
from aws_cdk import aws_codebuild as codebuild, aws_lambda as lambda_, aws_ecr as ecr, aws_secretsmanager as sm, \ | ||
aws_events as events, aws_events_targets as events_targets, aws_iam as iam, Duration | ||
|
||
from constructs import Construct | ||
from util.metadata import GITHUB_REPO_OWNER, GITHUB_TOKEN_SECRET_NAME, LINUX_X86_ECR_REPO | ||
|
||
|
||
class PruneStaleGitHubBuilds(Construct): | ||
def __init__(self, scope: Construct, id: str, *, project: codebuild.IProject) -> None: | ||
super().__init__(scope, id) | ||
|
||
github_token_secret = sm.Secret.from_secret_name_v2(scope=self, | ||
id="{}-GitHubToken".format(id), | ||
secret_name=GITHUB_TOKEN_SECRET_NAME) | ||
|
||
lambda_function = lambda_.Function(scope=self, | ||
id="LambdaFunction", | ||
code=lambda_.Code.from_asset_image( | ||
directory=str(pathlib.Path().joinpath("..", "lambda")), | ||
target="purge-stale-builds"), | ||
handler=lambda_.Handler.FROM_IMAGE, | ||
runtime=lambda_.Runtime.FROM_IMAGE, | ||
environment={ | ||
"CODEBUILD_PROJECT_NAME": project.project_name, | ||
"GITHUB_REPO_OWNER": GITHUB_REPO_OWNER, | ||
"GITHUB_TOKEN_SECRET_NAME": github_token_secret.secret_name, | ||
"RUST_LOG": "info", | ||
}) | ||
|
||
github_token_secret.grant_read(lambda_function) | ||
|
||
lambda_function.add_to_role_policy( | ||
iam.PolicyStatement(effect=iam.Effect.ALLOW, | ||
actions=[ | ||
"codebuild:BatchGetBuildBatches", | ||
"codebuild:ListBuildBatchesForProject", | ||
"codebuild:StopBuild", | ||
], | ||
resources=[project.project_arn])) | ||
|
||
events.Rule(scope=self, id="PurgeEventRule", | ||
description="Purge stale GitHub codebuild jobs (once per minute)", | ||
enabled=True, | ||
schedule=events.Schedule.rate(Duration.minutes(1)), | ||
targets=[events_targets.LambdaFunction(handler=lambda_function)]) |
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 @@ | ||
/target |
Oops, something went wrong.