-
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.
Test deploy access copy lambda to dev
- Loading branch information
Liam Lloyd
committed
Nov 7, 2024
1 parent
6e862e0
commit a450297
Showing
6 changed files
with
200 additions
and
45 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
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 |
---|---|---|
@@ -1,46 +1,48 @@ | ||
name: Unit tests | ||
on: | ||
push: | ||
branches-ignore: | ||
- main | ||
workflow_dispatch: | ||
workflow_call: | ||
push: | ||
branches-ignore: | ||
- main | ||
workflow_dispatch: | ||
workflow_call: | ||
jobs: | ||
run_tests: | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
path: ./stela | ||
- uses: actions/setup-node@v1 | ||
with: | ||
node-version: "18" | ||
- name: Checkout back-end | ||
uses: actions/checkout@v3 | ||
with: | ||
ssh-key: ${{ secrets.BACKEND_ACCESS_PRIVATE_SSH_KEY }} | ||
repository: PermanentOrg/back-end | ||
ref: main | ||
path: ./back-end | ||
- name: Checkout devenv | ||
uses: actions/checkout@v3 | ||
with: | ||
ssh-key: ${{ secrets.DEVENV_ACCESS_PRIVATE_SSH_KEY }} | ||
repository: PermanentOrg/devenv | ||
ref: main | ||
path: ./devenv | ||
- run: (cd stela; npm install --production=false) | ||
- run : (cd stela; npm run build -ws) | ||
- run: touch stela/.env | ||
- run: touch devenv/.env | ||
- run: (cd devenv; docker compose up database_setup -d; docker logs devenv-database_setup-1) | ||
- run: (cd stela/packages/api; npm run start-containers) | ||
- run: (cd stela/packages/api; docker compose run stela npm run test-ci) | ||
- run: (cd stela; npm run test -w @stela/account_space_updater) | ||
- uses: codecov/codecov-action@v2 | ||
- run: (cd stela; npm run test -w @stela/record_thumbnail_attacher) | ||
- uses: codecov/codecov-action@v2 | ||
- run: (cd stela; npm run test -w @stela/archivematica_cleanup) | ||
- uses: codecov/codecov-action@v2 | ||
- run: (cd stela; npm run test -w @stela/thumbnail_refresh) | ||
- uses: codecov/codecov-action@v2 | ||
run_tests: | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
path: ./stela | ||
- uses: actions/setup-node@v1 | ||
with: | ||
node-version: "18" | ||
- name: Checkout back-end | ||
uses: actions/checkout@v3 | ||
with: | ||
ssh-key: ${{ secrets.BACKEND_ACCESS_PRIVATE_SSH_KEY }} | ||
repository: PermanentOrg/back-end | ||
ref: main | ||
path: ./back-end | ||
- name: Checkout devenv | ||
uses: actions/checkout@v3 | ||
with: | ||
ssh-key: ${{ secrets.DEVENV_ACCESS_PRIVATE_SSH_KEY }} | ||
repository: PermanentOrg/devenv | ||
ref: main | ||
path: ./devenv | ||
- run: (cd stela; npm install --production=false) | ||
- run: (cd stela; npm run build -ws) | ||
- run: touch stela/.env | ||
- run: touch devenv/.env | ||
- run: (cd devenv; docker compose up database_setup -d; docker logs devenv-database_setup-1) | ||
- run: (cd stela/packages/api; npm run start-containers) | ||
- run: (cd stela/packages/api; docker compose run stela npm run test-ci) | ||
- run: (cd stela; npm run test -w @stela/account_space_updater) | ||
- uses: codecov/codecov-action@v2 | ||
- run: (cd stela; npm run test -w @stela/record_thumbnail_attacher) | ||
- uses: codecov/codecov-action@v2 | ||
- run: (cd stela; npm run test -w @stela/archivematica_cleanup) | ||
- uses: codecov/codecov-action@v2 | ||
- run: (cd stela; npm run test -w @stela/thumbnail_refresh) | ||
- uses: codecov/codecov-action@v2 | ||
- run: (cd stela; npm run test -w @stela/access_copy_attacher) | ||
- uses: codecov/codecov-action@v2 |
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,114 @@ | ||
resource "aws_sqs_queue" "access_copy_dev_deadletter_queue" { | ||
name = "access-copy-dev-deadletter-queue" | ||
} | ||
|
||
resource "aws_sqs_queue" "access_copy_dev_queue" { | ||
name = "access-copy-dev-queue" | ||
|
||
redrive_policy = jsonencode({ | ||
deadLetterTargetArn = aws_sqs_queue.access_copy_dev_deadletter_queue.arn | ||
maxReceiveCount = 3 | ||
}) | ||
} | ||
|
||
resource "aws_sqs_queue_policy" "access_copy_dev_queue_policy" { | ||
queue_url = aws_sqs_queue.access_copy_dev_queue.id | ||
policy = jsonencode({ | ||
Version = "2012-10-17", | ||
Statement = [ | ||
{ | ||
Effect = "Allow", | ||
Principal = { | ||
Service = "sns.amazonaws.com" | ||
}, | ||
Action = "sqs:SendMessage", | ||
Resource = aws_sqs_queue.access_copy_dev_queue.arn, | ||
Condition = { | ||
ArnEquals = { | ||
"aws:SourceArn" = aws_sns_topic.record_thumbnail_dev_topic.arn | ||
} | ||
} | ||
} | ||
] | ||
}) | ||
} | ||
|
||
resource "aws_sns_topic_subscription" "access_copy_dev_subscription" { | ||
topic_arn = aws_sns_topic.record_thumbnail_dev_topic.arn | ||
protocol = "sqs" | ||
endpoint = aws_sqs_queue.access_copy_dev_queue.arn | ||
} | ||
|
||
data "aws_iam_policy_document" "assume_role" { | ||
statement { | ||
effect = "Allow" | ||
principals { | ||
type = "Service" | ||
identifiers = ["lambda.amazonaws.com"] | ||
} | ||
actions = ["sts:AssumeRole"] | ||
} | ||
} | ||
|
||
resource "aws_iam_role" "access_copy_dev_lambda_role" { | ||
name = "access-copy-dev-lambda-role" | ||
assume_role_policy = data.aws_iam_policy_document.assume_role.json | ||
} | ||
|
||
resource "aws_iam_role_policy" "access_copy_dev_lambda_policy" { | ||
name = "access-copy-lambda-policy" | ||
role = aws_iam_role.access_copy_dev_lambda_role.name | ||
policy = jsonencode({ | ||
Version = "2012-10-17" | ||
Statement = [ | ||
{ | ||
Action = [ | ||
"logs:CreateLogGroup", | ||
"logs:CreateLogStream", | ||
"logs:PutLogEvents", | ||
"ec2:CreateNetworkInterface", | ||
"ec2:DescribeNetworkInterfaces", | ||
"ec2:DeleteNetworkInterface", | ||
"ec2:DescribeSecurityGroups", | ||
"ec2:DescribeSubnets", | ||
"sqs:ReceiveMessage", | ||
"sqs:DeleteMessage", | ||
"sqs:GetQueueAttributes", | ||
] | ||
Effect = "Allow" | ||
Resource = ["*", aws_sqs_queue.access_copy_dev_queue.arn] | ||
}, | ||
] | ||
}) | ||
} | ||
|
||
resource "aws_lambda_function" "access_copy_dev_lambda" { | ||
package_type = "Image" | ||
image_uri = var.access_copy_dev_lambda_image | ||
function_name = "access-copy-dev-lambda" | ||
role = aws_iam_role.access_copy_dev_lambda_role.arn | ||
timeout = 30 | ||
|
||
vpc_config { | ||
security_group_ids = [var.dev_security_group_id] | ||
subnet_ids = var.subnet_ids | ||
} | ||
|
||
environment { | ||
variables = { | ||
ENV = var.dev_env | ||
SENTRY_DSN = var.sentry_dsn | ||
DATABASE_URL = var.dev_database_url | ||
CLOUDFRONT_URL = var.dev_cloudfront_url | ||
CLOUDFRONT_KEY_PAIR_ID = var.cloudfront_key_pair_id | ||
CLOUDFRONT_PRIVATE_KEY = var.cloudfront_private_key | ||
} | ||
} | ||
} | ||
|
||
resource "aws_lambda_event_source_mapping" "record_thumbnail_dev_event_source_mapping" { | ||
event_source_arn = aws_sqs_queue.record_thumbnail_dev_queue.arn | ||
function_name = aws_lambda_function.record_thumbnail_dev_lambda.arn | ||
batch_size = 10 | ||
maximum_batching_window_in_seconds = 0 | ||
} |
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