Skip to content

Commit 0732817

Browse files
committed
ci: deploy to lambda
1 parent 7e1c541 commit 0732817

File tree

3 files changed

+56
-8
lines changed

3 files changed

+56
-8
lines changed

.github/workflows/ci.yml

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ jobs:
5757
context: '.'
5858
push: true
5959
tags: "${{ steps.login-ecr.outputs.registry }}/rko-router:${{ github.sha }},${{ steps.login-ecr.outputs.registry }}/rko-router:latest"
60-
deploy:
61-
name: deploy
60+
61+
deploy-apprunner:
62+
name: deploy-apprunner
6263
if: "github.ref == 'refs/heads/master'"
6364
environment:
6465
name: apprunner-prod
@@ -89,3 +90,27 @@ jobs:
8990
memory: '0.5' # GB
9091
port: "8080"
9192

93+
deploy-lambda:
94+
name: deploy-lambda
95+
if: "github.ref == 'refs/heads/test'"
96+
environment:
97+
name: lambda-prod
98+
url: https://rko-router.rubykaigi.org
99+
concurrency:
100+
group: lambda-prod
101+
permissions:
102+
contents: read
103+
id-token: write
104+
runs-on: ubuntu-slim
105+
needs:
106+
- ci
107+
steps:
108+
- uses: aws-actions/configure-aws-credentials@v4
109+
with:
110+
aws-region: "us-west-2"
111+
role-skip-session-tagging: true
112+
role-to-assume: "arn:aws:iam::005216166247:role/GhaRkoRouterDeploy"
113+
mask-aws-account-id: 'false' # only string works
114+
- run: 'aws lambda update-function-code --function-name rko-router --image-uri "$IMAGE_URI"'
115+
env:
116+
IMAGE_URI: "${{needs.ci.outputs.image-tag}}"

tf/iam_GhaRkoRouterDeploy.tf

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ data "aws_iam_policy_document" "rko-router-deploy-trust" {
1717
variable = "token.actions.githubusercontent.com:sub"
1818
values = [
1919
"repo:ruby-no-kai/rko-router:environment:apprunner-prod",
20+
"repo:ruby-no-kai/rko-router:environment:lambda-prod",
2021
"repo:ruby-no-kai/rko-router:ref:refs/heads/master",
2122
"repo:ruby-no-kai/rko-router:ref:refs/heads/test",
2223
]
@@ -109,4 +110,26 @@ data "aws_iam_policy_document" "rko-router-deploy-apprunner" {
109110
]
110111
resources = ["*"]
111112
}
113+
114+
statement {
115+
effect = "Allow"
116+
actions = [
117+
"lambda:UpdateFunctionCode",
118+
]
119+
resources = [
120+
aws_lambda_function.rko-router.arn,
121+
]
122+
}
123+
124+
statement {
125+
effect = "Allow"
126+
actions = [
127+
"ecr:BatchGetImage",
128+
"ecr:GetDownloadUrlForLayer",
129+
]
130+
resources = [
131+
aws_ecr_repository.rko-router.arn,
132+
]
133+
}
134+
112135
}

tf/lambda.tf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ resource "aws_lambda_function" "rko-router" {
22
function_name = "rko-router"
33

44
package_type = "Image"
5-
image_uri = "${aws_ecr_repository.rko-router.repository_url}:3285c10bdd196708e97523c116baeba981b8b8a7"
5+
image_uri = "${aws_ecr_repository.rko-router.repository_url}:7e1c5410f5b39e9be0d8396509b44dfcdb77d43d"
66
architectures = ["x86_64"]
77

88
role = aws_iam_role.LambdaRkoRouter.arn
@@ -23,11 +23,11 @@ resource "aws_lambda_function" "rko-router" {
2323
Name = "rko-router"
2424
}
2525

26-
# lifecycle {
27-
# ignore_changes = [
28-
# image_uri,
29-
# ]
30-
# }
26+
lifecycle {
27+
ignore_changes = [
28+
image_uri,
29+
]
30+
}
3131
}
3232

3333
resource "aws_lambda_function_url" "rko-router" {

0 commit comments

Comments
 (0)