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
とある会社のビルドデプロイ / A certain company's application...
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
hayasshi
April 14, 2020
Programming
390
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
とある会社のビルドデプロイ / A certain company's application building
hayasshi
April 14, 2020
More Decks by hayasshi
See All by hayasshi
Chatwork で Akka をどうつかっているのか なぜつかっているのか / Why Akka, How Akka in Chatwork
hayasshi
1
620
Scala / refined で`型く`表明プログラミング / Programing with type level assertion
hayasshi
2
990
Akka Typed - 型安全にメッセージパッシングする! / Akka Typed - typesafe messaging
hayasshi
6
3k
AWS Dev Day Challenge (2018-11-02) - ChatWork Suita
hayasshi
2
780
Scala and Akka apps on Kubernetes in ChatWork
hayasshi
0
2.7k
Other Decks in Programming
See All in Programming
Seven New Principles of Software Engineering
yegor256
0
440
作れるエンジニアから、価値を届けるエンジニアへ
ryunakayama
1
120
自作Discord音声botをLambda MicroVMsに移行した話 / Migrating My Discord Voice Bot to Lambda MicroVMs
akihisaikeda
1
270
ChromeでローカルLLM
ryu1013
0
190
エージェントを使い続けるためのメタワーク / Meta-work for keeping using the agent
rkaga
6
2.2k
Modernizing iOS Apps
seyfoyun
0
150
graphql-ruby を Spinel で速くしようとした話
mtsmfm
0
140
Railsのためのパスキー実践入門 〜マルチテナントSaaSでの意思決定〜
utakaha
4
3k
Web Framework Benchmark Battle 2026, Any%
a_matsuda
3
3.1k
Groovy as a human and AI friendly programming language
paulk
0
180
PumaからFalconに移行したRailsアプリケーションでの実践
falcon8823
0
340
JIS keyboard support in Omarchy
lef237
0
180
Featured
See All Featured
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
320
Why You Should Never Use an ORM
jnunemaker
PRO
61
10k
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
300
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
370
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
6
1.3k
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
970
The SEO identity crisis: Don't let AI make you average
varn
0
630
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
320
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
660
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
33
5.6k
Utilizing Notion as your number one productivity tool
mfonobong
4
640
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
450
Transcript
Scala関西勉強会 2020年4月14日 hayasshi とある会社のビルド・デプロイ
自己紹介 • こんにちは。林です。 ◦ Twitter: @hayasshi_ ◦ GitHub: hayasshi •
Chatwork株式会社 • 最近は既存のScalaプロダクトのお手入れ 2
Scala関西勉強会 2020年4月14日 hayasshi とある会社のビルド・デプロイ
今日お話すること 1. とある会社のScalaアプリケーションのビルドについて ◦ パッケージング方式 ◦ ビルド実行 4
今日お話しないこと 1. とある会社のデプロイメントについて 2. とある会社のCI/CDの詳細 3. とある会社の開発フローの詳細 5
01 Scalaアプリケーションの パッケージングについて
前提 とある会社は、Scalaアプリケーションを、 Kubernetes上でDockerコンテナとして、動作させています なので本日は、 Scalaアプリケーションを どのようにDockerイメージにするか を話します 7
sbt-native-packager https://sbt-native-packager.readthedocs.io/en/stable/index.html https://github.com/sbt/sbt-native-packager 各プラットフォーム向けのパッケージングを行ってくれるsbtプラグイン Dockerイメージに加え、最近はGraalVMによるネイティブイメージ化にも対応 8
sbt-native-packager とある build.sbt (https://github.com/hayasshi/sbt-native-packager-sample ) 公式ドキュメント (https://sbt-native-packager.readthedocs.io/en/stable/formats/docker.html ) 9
sbt-native-packager `sbt docker:stage`をすると、`docker build`する前の状態が確認できます 10
sbt-native-packager `sbt docker:stage`をすると、`docker build`する前の状態が確認できます 11
sbt-native-packager `sbt docker:stage`をすると、`docker build`する前の状態が確認できます 12
sbt-native-packager `sbt docker:stage`をすると、`docker build`する前の状態が確認できます 13 起動スクリプト この例では AshScriptPlugin が使われているため ash
sbt-native-packager `sbt docker:stage`をすると、`docker build`する前の状態が確認できます 14 依存ライブラリjar
sbt-native-packager `sbt docker:stage`をすると、`docker build`する前の状態が確認できます 15 アプリケーション
sbt-native-packager `sbt docker:stage`をすると、`docker build`する前の状態が確認できます 16 起動スクリプトから読まれる設定ファイ ル
とある会社の工夫 アプリケーションの設定情報は全て環境変数から渡せるようにしている • なぜ? ◦ コンテナ実行時に注入することで設定変更による再ビルドを避ける • 良い点 ◦ 同じイメージをつかって環境ごとに異なる設定情報で動作できる
(ポータビリティの向上) ◦ コンテナランタイムは環境変数での値の受け渡しがよく使われる • 悪い点 ◦ 設定しないといけない環境変数が多くなりがち 17
とある会社の工夫 アプリケーションの設定情報は全て環境変数から渡せるようにしている Typesafe Config • 環境ごとに異なるアプリケーション設定はすべて環境変数からも渡せるように ◦ e.g. JDBC URL、ポート、各種タイムアウト値、固有のしきい値など
• ローカルで動作させるための設定をデフォルト値に置いている 18
とある会社の工夫 アプリケーションの設定情報は全て環境変数から渡せるようにしている JVMオプション • 起動スクリプト内関数の`addJava`を使うことで`java`コマンドのオプション引数を 追加できる • そこに環境変数を指定することで起動スクリプト実行時の環境変数が使われる つまり`docker run
-e`で指定した環境変数でJVMの設定値も調整できる • シェルのデフォルト値付き変数展開をつかってデフォルト値を設定 19
とある会社の工夫 アプリケーションの設定情報は全て環境変数から渡せるようにしている JVMオプション (起動スクリプト) 20
とある会社の注意点 • コンテナでjdk8を使っている場合、アップデートバージョンに注意 ◦ jdk8u191より前は、コンテナにかけられたCGroupのCPUやメモリを見ずに、 ホストマシンのものを見ていたため、スレッド数計算やヒープ計算が適切にな らない可能性がある ◦ https://bugs.openjdk.java.net/browse/JDK-8146115 ▪
jdk10からjdk8u191にバックポートされている ◦ jdk8u191以降を利用する 21
02 ビルドについて
とある会社のビルド • ビルド内容はいたって普通です ◦ CIサーバー上でシェルスクリプトを実行してScalaアプリケーションのパッキ ングをおこない、Dockerイメージを作成する ▪ ビルドに対してイメージタグを付与 ◦ Dockerイメージタグに対応したGitタグを作成し、
どの時点のコミットでビルドしたものかを追跡できるようにしている • 一点だけ工夫している点としては、CIサーバーの実行モデルに合わせた sbtのビルドキャッシュを作成管理している ◦ ~/.ivy2/cache (ivy cache) ◦ ~/.sbt (boot directory) ◦ ~/cache/.coursier (coursier cache, sbt 1.3.X) 23
とある会社のビルドの工夫 • とある会社のCIサーバーでのシェルスクリプトの実行はDockerコンテナ上でおこな われる • sbtビルドキャッシュのファイル・システムのみのDockerイメージを作成してお き、実行するDockerコンテナにマウントすることで、ビルドキャッシュを利用して いる • 問題点も...
◦ アプリケーションビルドのたびにキャッシュ更新しているとビルドが遅くなる ◦ 定期的な手動更新の必要性 • 対策(検証検討中) ◦ Docker レイヤーキャッシュ ◦ ビルドのみCI SaaS等に切り出す 24
03 まとめ
まとめ • sbt-native-packager ◦ Dockerfileのプラクティスがよくわからないアプリケーション開発者でも正し いDockerイメージをつくってくれる ◦ とある会社ではパッケージングされたアプリケーションを様々な場所で動かせ れるような工夫を行っている ◦
コンテナベースイメージには jdk8u191 以降を利用する • ビルド ◦ ビルドキャッシュの管理をいかに楽に正しくおこなえるかで 全体のビルド体験がよくなる ◦ ビルドはSaaSに乗れるのであればのるのが良さそう ▪ キャッシュの扱い等がやはり優れている 26
働くをもっと楽しく、創造的に