Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
CodeBuildで動かすecspresso
Search
shonansurvivors
August 08, 2023
Technology
5.8k
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
CodeBuildで動かすecspresso
JAWS-UG コンテナ支部 #24 ecspresso MeetUp
登壇資料
shonansurvivors
August 08, 2023
More Decks by shonansurvivors
See All by shonansurvivors
SREのキャリアから経営に近づく - Enterprise Risk Managementを基に -
shonansurvivors
2
1.6k
Adminaで実現するISMS/SOC2運用の効率化 〜 アカウント管理編 〜
shonansurvivors
4
730
SOC2取得の全体像
shonansurvivors
4
3k
非エンジニアによるDevin開発のためにSREができること
shonansurvivors
0
290
SREによる隣接領域への越境とその先の信頼性
shonansurvivors
2
1k
スタートアップがAWSパートナーになって得られたこと
shonansurvivors
3
1.4k
AWSで構築するCDパイプラインとその改善
shonansurvivors
5
4.3k
Terraformでmoduleを使わずに複数環境を構築して感じた利点
shonansurvivors
3
4.3k
クロステナントアクセスを要件とするsmartroundのマルチテナントSaaSアーキテクチャ
shonansurvivors
0
680
Other Decks in Technology
See All in Technology
顧客に向き合う開発組織へ。リアーキテクチャとフィーチャーチーム化で挑む組織改革
safie
0
2.3k
30座EKS, 180次升級淬煉的EKS Upgrade Skill 的歷程
eric8230
0
210
積み重なった技術負債への挑戦 〜初手としての全社ゴト化〜
techtekt
PRO
0
1.5k
AI時代の「技術的負債」の変質ー概念の終焉と再解釈、エージェントと共に向かう先
nwiizo
1
3.1k
Azure Serverless 2026:Production-ready な AI エージェント基盤 / Azure Serverless 2026: Production-Ready AI Agent Platform
miyake
2
480
銀行勘定系システムにおける開発プロセス刷新×AIによる環境モダナイゼーション / Development Process Transformation and AI-Driven Environment Modernization
muit
1
2.5k
2026_devsumi_ozono.pdf
o3
3
550
Vibe Coding で作ったプロダクトをどう安全に動かすか / How to Safely Run Products Built with Vibe Coding
glidenote
0
450
Why Agent Cost Needs Observability
nttcom
0
110
Oracle Cloud Network Path Analyzerを試してみた/I Tried Out Oracle Cloud Network Path Analyzer
masakiokuda
1
110
あけおめLINE 傾向とその対策
nasa9084
0
190
2026-09-08 そのJavaモダナイゼーション、AIに丸投げで大丈夫?IBM Bobで変わる品質と効率
yutanonaka
1
120
Featured
See All Featured
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.8k
Scaling GitHub
holman
464
140k
Between Models and Reality
mayunak
4
460
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
56
3.5k
Product Roadmaps are Hard
iamctodd
55
13k
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
250
How GitHub (no longer) Works
holman
316
150k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
500
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
250
Building Flexible Design Systems
yeseniaperezcruz
330
41k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
69
65k
sira's awesome portfolio website redesign presentation
elsirapls
0
420
Transcript
JAWS-UG コンテナ支部 #24 ecspresso MeetUp CodeBuildで動かすecspresso 株式会社スマートラウンド 山原 崇史(@shonansurvivors)
自己紹介 株式会社スマートラウンド SRE/コーポレートITチーム エンジニアリングマネージャー 山原 崇史 (やまはら たかし) 経歴等 ・SIer
→ 銀行 → Web系ベンチャー数社 → 現職 ・2023 Japan AWS Top Engineers(Software) ・AWS Startup Community Core Member 好きなAWSサービス IAM Identity Center / Security Hub shonansurvivors
ecspressoと私 実務のほか、過去の登壇、 Zenn、ブログ、書籍等のアウトプットでも取り扱わせていただいています
アジェンダ 1. CodeBuildでecspressoを動かす理由 2. ecspressoのインストールと実行 3. 関連AWSリソース情報取得方法の選択肢 4. ecspresso rollback用のCodeBuild
5. まとめ
1. CodeBuildでecspressoを動かす理由
当社がCodeBuild上でecspressoを動かしている理由 • 元々、CDをCodePipelineで動かしていた (なお、CIはCircleCIを経て現在はGitHub Actions) • Beanstalk→ECSへの基盤移行の際、複数の観点から検討した結果、 CodePipelineを継続採用 • CodePipelineで呼び出し可能なCodeBuild上でecspressoを動かすこととした
2. ecspressoのインストールと実行
ecspressoをCodeBuildにインストールして実行する buildspecの例 version: 0.2 env: variables: ECSPRESSO_VERSION: 2.2.2 phases: install:
commands: - curl -sL -O https://github.com/kayac/ecspresso/releases/download/ v${ECSPRESSO_VERSION}/ecspresso_${ECSPRESSO_VERSION}_linux_amd64.tar.gz - tar xzvf ecspresso_${ECSPRESSO_VERSION}_linux_amd64.tar.gz - sudo install ecspresso /usr/local/bin/ecspresso - ecspresso version # 略 build: commands: - ecspresso deploy
GitHub Actionsのアクションを使う場合 よりシンプルに記述できる version: 0.2 phases: # 略 build: steps:
- uses: kayac/ecspresso@v2 # ecspressoのインストールのみを行うアクション with: version: v2.2.2 - run: ecspresso deploy
CodeBuildの各phaseにおける処理内容について phaseごとに推奨される処理内容がある (お作法のようなもの) phase ビルドを行う場合 テストを行う場合 デプロイを行う場合(※) install 各種パッケージのインストール等 各種パッケージのインストール等
各種パッケージのインストール等 pre_build ・依存関係のインストール ・ECRへのログイン 等 依存関係のインストール 依存関係のインストール build ビルドの実行 テストの実行 デプロイの実行 post_build ・アーティファクトのパッケージ ・イメージをECRにプッシュ 等 - - ※デプロイに関しては AWS公式ドキュメントに記載は無く、筆者の独自解釈
アクションを使う場合はphase分けしない 以下のようにphaseを分けるとエラーになるので注意 version: 0.2 phases: install: steps: - uses: kayac/ecspresso@v2
# ecspressoのインストール with: version: v2.2.2 # 略 build: steps: - run: ecspresso deploy # command not foundになってしまう
3. 関連AWSリソース情報取得の選択肢
ecspressoが管理するファイル ecspressoではECSサービスやタスク定義をファイルで管理する . └── ecspresso ├── buildspec.yml ├── ecspresso.yml #
ecspresso全体の設定ファイル ├── ecs-service-def.json # ECSサービスの定義 └── ecs-task-def.json # タスク定義
関連AWSリソースのARNやIDの取得について ECSサービスの定義ファイル (ecs-service-def.json)には以下の指定が必要 • ターゲットグループの ARN : arn:aws:elasticloadbalancing:region:account_id:targetgroup/name/xxxxxxxxxxxxxxxxxx • サブネットID
: subnet-xxxxxxxxxxxxxxxxx • セキュリティグループ ID: sg-xxxxxxxxxxxxxxxx 👉こうした値を定義ファイルに直接記述すると可読性やメンテナンス性が落ちる懸念がある
あるWebサービスの例で考える . ├── ... ├── batch ├── db ├── ...
└── web ├── buildspec.yml # ビルド用 ├── ... └── ecspresso ├── buildspec.yml # デプロイ用 ├── ecspresso.yml ├── ecs-service-def.json └── ecs-task-def.json . ├── ... └── some_service ├── alb.tf ├── codebuild.tf ├── codebuild_iam.tf ├── ecs.tf ├── ecs_iam.tf ├── ... └── vpc.tf アプリケーションのリポジトリ Terraformのリポジトリ
関連AWSリソースのARNやID取得方法の選択肢 1. ecspressoのtfstate読み込み機能を使ってARNやIDを取得 👉詳しくは「ecspresso handbook v2対応版」を参照(https://zenn.dev/fujiwara/books/ecspresso-handbook-v2) 2. CodeBuildのbuildspec上でAWS CLIを実行し、Nameタグなどを元にARNやIDを取得 👉詳しくは「EC2からのECS移行においてIaCとCDをどう変えたか」を参照
(https://speakerdeck.com/shonansurvivors/transitioning-from-ec2-to-ecs-adapting-iac-and-cd-strategies) 3. CodeBuildのビルドプロジェクトの環境変数に ARNやIDを設定する 👉今回採り上げるのはこちら
ビルドプロジェクトの環境変数経由で取得する ビルドプロジェクトの環境変数に他リソースの属性をセットし、さらに ECS定義ファイルで参照させる resource "aws_codebuild_project" "deploy_webapp" { # 略 environment
{ # 略 environment_variable { name = "TARGET_GROUP_ARN" value = aws_lb_target_group.webapp.arn type = "PLAINTEXT" } # 略 } # 略 } # ecs-service-def.jsonより抜粋 { # 略 "loadBalancers": [ { "containerName": "nginx", "containerPort": 80, "targetGroupArn": "{{ must_env `TARGET_GROUP_ARN` }}" } ], # 略 }
4. ecspresso rollback用のCodeBuild
当初考えた案 「ecspresso rollback」を実行するbuildspecのファイルを用意しておく(実行は手動を想定) . ├── ... ├── db ├── ...
└── web ├── buildspec.yml # ビルド用 ├── ... └── ecspresso ├── buildspec.yml # デプロイ用 ├── buildspec_rollback.yml # ロールバック用 ├── ecspresso.yml ├── ecs-service-def.json └── ecs-task-def.json アプリケーションのリポジトリ version: 0.2 # 略 phases: build: commands: # 略 - ecspresso rollback
ロールバック用のCodeBuildの運用フェーズでの懸念 処理の詳細を知らない人間は、 ソースバージョンの指定に迷うかもしれない 本番環境ではmainブランチのバージョンのECSが動いていて、 それをロールバックしたいのに、 mainブランチを指定して実行して大丈夫なんだっけ? 戻し先のバージョンのタグ等を指定する必要があるのでは?
buildspecをファイルではなくコマンドにする ソースバージョンを指定するフォームが 非表示となり、CodeBuild実行に際し迷う要素は無くなる ソースバージョンの指定フォームは非表示
5. まとめ
まとめ 1. CodeBuildでもecspressoはもちろん動かせる ◦ GitHub Actionsのkayac/ecspressoアクションも利用可能 2. 関連AWSリソースのARN・ID取得に、ビルドプロジェクトの環境変数 を使うという選択肢もあり 3.
ecspresso rollbackを行う場合は、buildspecはファイルではなくコマンドを推したい
ご清聴ありがとうございました! Startup comes first! Join our team! jobs.smartround.com