Skip to content

Commit 43016d9

Browse files
committed
sinatraアプリをapprunnerで立ち上げるための実装
- 最低限のアプリケーションmyapp.rb追加 - Dockerfile追加 - github actionでECRにpush
1 parent caf10a5 commit 43016d9

File tree

4 files changed

+63
-0
lines changed

4 files changed

+63
-0
lines changed

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/.git/
2+
3+
# Ignore bundler config.
4+
/.bundle

.github/workflows/main.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: ecr push image
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
push:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
id-token: write
13+
contents: read
14+
steps:
15+
- uses: actions/checkout@v3
16+
17+
# AWS 認証
18+
- uses: aws-actions/configure-aws-credentials@v1
19+
with:
20+
aws-region: ap-northeast-1
21+
role-to-assume: arn:aws:iam::765062437422:role/sinatra_app_runner_oidc_role
22+
23+
- uses: aws-actions/amazon-ecr-login@v1
24+
25+
- name: build and push docker image to ecr
26+
env:
27+
REGISTRY_URL: 765062437422.dkr.ecr.ap-northeast-1.amazonaws.com/sinatra_app_runner
28+
run: |
29+
docker build . --tag ${{ env.REGISTRY_URL }}
30+
docker push ${{ env.REGISTRY_URL }}

Dockerfile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FROM ruby:3.2.2-slim as base
2+
3+
WORKDIR /sinatra_app_runner
4+
5+
FROM base as build
6+
7+
RUN apt-get update -qq && \
8+
apt-get install --no-install-recommends -y build-essential && \
9+
gem install sinatra:3.0.6 puma:6.2.2 && \
10+
rm -rf /usr/local/bundle/cache
11+
12+
COPY . .
13+
14+
FROM base
15+
16+
RUN rm -rf /var/lib/apt/lists /var/cache/apt/archives
17+
18+
COPY --from=build /usr/local/bundle /usr/local/bundle
19+
COPY --from=build /sinatra_app_runner /sinatra_app_runner
20+
21+
EXPOSE 4567
22+
CMD ["ruby", "myapp.rb", "-o", "0.0.0.0"]

myapp.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# frozen_string_literal: true
2+
3+
require 'sinatra'
4+
5+
get '/' do
6+
'hello world v3'
7+
end

0 commit comments

Comments
 (0)