Skip to content

Commit e6e3369

Browse files
authored
Merge pull request #139 from ruby-no-kai/lambda
app runner -> lambda
2 parents d64f8b8 + 6432888 commit e6e3369

20 files changed

+518
-114
lines changed

.github/workflows/ci.yml

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- uses: actions/checkout@v4
1818
- uses: ruby/setup-ruby@v1
1919
with:
20-
ruby-version: '3.2'
20+
ruby-version: '3.4'
2121
bundler-cache: true
2222
- uses: aws-actions/configure-aws-credentials@v4
2323
with:
@@ -57,8 +57,10 @@ 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
63+
if: "github.ref == 'refs/heads/master'"
6264
environment:
6365
name: apprunner-prod
6466
url: https://rko-router.rubykaigi.org
@@ -88,3 +90,27 @@ jobs:
8890
memory: '0.5' # GB
8991
port: "8080"
9092

93+
deploy-lambda:
94+
name: deploy-lambda
95+
if: "github.ref == 'refs/heads/master'"
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}}"

Dockerfile

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,36 @@
1-
FROM public.ecr.aws/nginx/nginx:1.23
2-
RUN apt-get update \
3-
&& apt-get install -y --no-install-recommends ruby \
4-
&& rm -rf /var/lib/apt/lists/*
5-
COPY docker-entrypoint.d.sh /docker-entrypoint.d/rko-router.sh
6-
COPY config/nginx.conf.erb /etc/nginx/nginx.conf.erb
7-
COPY config/force_https.conf /etc/nginx/force_https.conf
8-
RUN /docker-entrypoint.d/rko-router.sh
9-
RUN nginx -c /etc/nginx/nginx.conf
1+
FROM public.ecr.aws/nginx/nginx:1.29
2+
3+
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
4+
--mount=type=cache,target=/var/lib/apt,sharing=locked \
5+
apt-get update \
6+
&& apt-get install -y --no-install-recommends ruby
7+
8+
COPY --from=public.ecr.aws/awsguru/aws-lambda-adapter:0.9.1 /lambda-adapter /opt/extensions/lambda-adapter
9+
10+
# Replace /etc/nginx with a temporary directory for Lambda, where /etc/nginx is read-only
11+
# /run is for /run/nginx.pid
12+
RUN mv /etc/nginx /etc/nginx.base \
13+
&& rm -rf /run && ln -s /tmp/run /run \
14+
&& ln -s /tmp/run/etc-nginx /etc/nginx \
15+
&& rm -rf /etc/nginx.base/conf.d/default.conf \
16+
&& rm -v /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh # We don't use conf.d/default.conf
17+
18+
COPY config/nginx.conf.erb /etc/nginx.base/nginx.conf.erb
19+
COPY config/github_pages.conf /etc/nginx.base/github_pages.conf
20+
COPY config/force_https.conf /etc/nginx.base/force_https.conf
21+
22+
COPY docker/entrypoint.d/00-rk-tmp-etc-nginx.sh /docker-entrypoint.d/
23+
COPY docker/entrypoint.d/90-rko-router.sh /docker-entrypoint.d/
24+
25+
ENV AWS_LWA_PORT 8080
26+
ENV AWS_LWA_READINESS_CHECK_PATH /healthz
27+
ENV AWS_LWA_PASS_THROUGH_PATH /_events
28+
1029
ENV PRIMARY_HOST rko-router.rubykaigi.org
30+
31+
RUN --mount=type=tmpfs,target=/tmp/run \
32+
/docker-entrypoint.d/00-rk-tmp-etc-nginx.sh \
33+
&& /docker-entrypoint.d/90-rko-router.sh \
34+
&& nginx -c /etc/nginx/nginx.conf
35+
1136
EXPOSE 8080

config/github_pages.conf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
proxy_hide_header age;
2+
proxy_hide_header via;
3+
proxy_hide_header x-cache-hits;
4+
proxy_hide_header x-cache;
5+
proxy_hide_header x-proxy-cache;
6+
proxy_hide_header x-timer;
7+
proxy_hide_header x-fastly-request-id;
8+
proxy_hide_header x-github-request-id;
9+
proxy_hide_header x-served-by;
10+
11+
add_header via "1.1 rko-router.rubykaigi.org";
12+
add_header x-rk-ghp "fi=\"$upstream_http_x_fastly_request_id\",fs=\"$upstream_http_x_served_by\",ghi=\"$upstream_http_x_github_request_id\",cache=\"$upstream_http_x_cache\",cache-hits=\"$upstream_http_x_cache_hits\"";
13+
add_header server-timing "rko-router;dur=$upstream_response_time,$fastly_timer_as_server_timing";

0 commit comments

Comments
 (0)