Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
[#JSUG] SmartNews における container friendly な Spr...
Search
KOMIYA Atsushi
May 31, 2019
Programming
1
11k
[#JSUG] SmartNews における container friendly な Spring Boot アプリケーション開発
SmartNews に新たに登場した「タイムセール」のバックエンドシステムの開発の裏側をお話しました。
KOMIYA Atsushi
May 31, 2019
Tweet
Share
More Decks by KOMIYA Atsushi
See All by KOMIYA Atsushi
#JJUG Java における乱数生成器とのつき合い方
komiya_atsushi
5
5.1k
#JJUG Fork/Join フレームワークを効率的に正しく使いたい
komiya_atsushi
0
460
Java のデータ圧縮ライブラリを極める #jjug_ccc #ccc_c7
komiya_atsushi
4
4.7k
#devsumi 自然言語処理・機械学習によるファクトチェック業務の支援
komiya_atsushi
1
4.3k
SmartNews Ads における機械学習の活用とその運用 #mlops
komiya_atsushi
3
19k
GBDT によるクリック率予測を高速化したい #オレシカナイト vol.4
komiya_atsushi
5
1.3k
Maven central repository の artifact をランキングする #渋谷java
komiya_atsushi
0
1.3k
確率的データ構造を Java で扱いたい! #JJUG
komiya_atsushi
6
2.2k
High-performance Jackson #渋谷Java
komiya_atsushi
2
16k
Other Decks in Programming
See All in Programming
talk-with-local-llm-with-web-streams-api
kbaba1001
0
170
From Translations to Multi Dimension Entities
alexanderschranz
2
130
数十万行のプロジェクトを Scala 2から3に完全移行した
xuwei_k
0
260
menu基盤チームによるGoogle Cloudの活用事例~Application Integration, Cloud Tasks編~
yoshifumi_ishikura
0
110
今年のアップデートで振り返るCDKセキュリティのシフトレフト/2024-cdk-security-shift-left
tomoki10
0
190
DevFest Tokyo 2025 - Flutter のアプリアーキテクチャ現在地点
wasabeef
5
900
StarlingMonkeyを触ってみた話 - 2024冬
syumai
3
270
Mermaid x AST x 生成AI = コードとドキュメントの完全同期への道
shibuyamizuho
0
160
Recoilを剥がしている話
kirik
5
6.6k
快速入門可觀測性
blueswen
0
330
これが俺の”自分戦略” プロセスを楽しんでいこう! - Developers CAREER Boost 2024
niftycorp
PRO
0
190
Jakarta EE meets AI
ivargrimstad
0
230
Featured
See All Featured
Fashionably flexible responsive web design (full day workshop)
malarkey
405
66k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.5k
Into the Great Unknown - MozCon
thekraken
33
1.5k
A designer walks into a library…
pauljervisheath
204
24k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
48
2.2k
A Tale of Four Properties
chriscoyier
157
23k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
2
290
Embracing the Ebb and Flow
colly
84
4.5k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Scaling GitHub
holman
458
140k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Transcript
SmartNews ʹ͓͚Δ container friendly ͳ Spring Boot ΞϓϦέʔγϣϯ։ൃ JSUG ษڧձ
2019 ͦͷ5 / 2019-05-31 KOMIYA Atsushi
@komiya_atsushi
SmartNews ʹ͓͚Δ container friendly ͳ Spring Boot ΞϓϦέʔγϣϯ։ൃ
SmartNews ʹ͓͚Δ container friendly ͳ Spring Boot ΞϓϦέʔγϣϯ։ൃ (container friendly
ݴ͏΄Ͳͷൃද༰͡Όͳ͍ͳ ) (Spring Boot ͕ओͱ͍͏ײ͡Ͱͳ͍ͳ… )
Spring Boot Docker Έ͍ͨͳΛظ͞Εͯͨํ ͢Έ·ͤΜ
Docker Λ·͋·͋׆༻ͨ͠ Spring Boot ΞϓϦέʔγϣϯ։ൃ ͷࣄྫΛ͓͠·͢
http://about.smartnews.com/ja/2019/05/21/20190521/
SmartNews ͷ ඪ४తͳٕज़ελοΫ
http://bit.ly/smartnews-tech-stack-2019
None
ૡ͍ఠΜͰΛ͢Δͱ… • AWS + AmazonLinux • ALB/CLB + ASG +
EC2 • nginx + Spring Boot w/ embedded Tomcat • Java 8 (Java, Scala, Kotlin) • Terraform, CircleCI, CodeDeploy, Nexus, Datadog
λΠϜηʔϧ։ൃͷཪ
։ൃॳͷঢ়گ • 2019 Q1 தʹ։࢝ͯ͠ Q1 தʹϦϦʔε༧ఆ • ࣮ࡍʹϦϦʔεͰ͖ͨͷ Q2
಄ • ϦϦʔε·Ͱͷ࣌ؒత༛༧͕গͳ͍ • ׳Ε͠Έɺ։ൃޮΑ͍ϑϨʔϜϫʔΫ / ݴޠΛ બ • Spring Boot + Kotlin
։ൃॳͷঢ়گ • 2019 Q1 ࣌ͷࣾ֎ͷঢ়گ • Java 11 ͕ϦϦʔε͞Εͯ 1Q
Ҏ্ܦա • ࣾతʹ·ͩ Java 8 ͕ݱͷγεςϜ͕େ ΛΊ͍ͯͨ • ৽ن։ൃ͢ΔαʔϏεͳͷͰɺ͍·͞Β Java 8 બͨ͘͠ͳ͍
։ൃॳͷঢ়گ • ࣾͷඪ४తͳٕज़ελοΫ Java 8 લఏ • طଘγεςϜͷ Java 11
ҠߦΛݕ౼ • ඪ४తͳٕज़ελοΫͷԸܙڗड͍ͨ͠ • Spring Boot ΞϓϦέʔγϣϯ & JDK Λ ߹ΘͤͯίϯςφԽͤ͞Δ͜ͱʹͨ͠
͜ͷޙͷ͓ • ։ൃ • Ϗϧυ • σϓϩΠɾࢹ
։ൃ
API ※࣮ࡍͷߏΛҰ෦؆ུԽ͍ͯ͠·͢ όοΫΤϯυγεςϜͷ֓ཁ
։ൃڥͷඋ • ։ൃڥͷݸਓࠩΛ࠷খԽ͍ͨ͠ • MySQL αʔόΛखݩͷڥʹ༻ҙ͢Δ • ଞαʔϏεͰ MySQL Λར༻͍ͯ͠Δ͕ɺ
όʔδϣϯ͕ҟͳΓಘΔͨΊڞ༻͍͠ • Datadog agent (ͷ DogStatsD) ͕ඞཁʹͳΔ • ϝτϦΫεͷࢹʹ Datadog Λར༻͍ͯ͠Δ
։ൃڥͷඋ • Vagrant / VirtualBox Λ༻͍Δखஈ͋Γ͏Δ • ϓϩϏδϣχϯάνϣοτδΧϯΧΧϧ • ࠷ۙ৽نʹ։ൃڥΛߏங͢Δͱ͖ʹ
όʔδϣϯབྷΈͷτϥϒϧʹר͖ࠐ·Ε ͕ͪͳͷͰܟԕ͍ͨ͠
None
# docker-compose.yml version: '3.1' services: db: image: mysql:5.7.25 environment: MYSQL_ROOT_PASSWORD:
password MYSQL_DATABASE: main_db volumes: - ./tmp/mysql:/var/lib/mysql ports: - "13307:3306" dogstatsd: image: datadog/docker-dd-agent:12.7.5321-dogstatsd environment: API_KEY: ${DATADOG_API_KEY} ports: - “8125:8125/udp"
$ docker stack deploy \ -c docker-compose.yml \ stack-name $
docker stack rm stack-name
# application.yml spring: profiles: local-dev datasource: url: jdbc:mysql://127.0.0.1:3306/main_db username: root
password: password management.metrics.export.statsd.host: 127.0.0.1 --- spring: profiles: docker-dev datasource: url: jdbc:mysql://host.docker.internal:3306/main_db username: root password: password management.metrics.export.statsd.host: host.docker.internal
Ϗϧυ
Spring Boot ΞϓϦέʔγϣϯΛ Docker Πϝʔδͱͯ͠Ϗϧυ͢Δ
Ұൠతͳ Spring Boot app ͷϏϧυ • Spring Boot Gradle plugin
Λಋೖ͢Δ • ./gradlew build ͢Δ • fat jar ͕࡞ΒΕΔ
# Dockerfile FROM adoptopenjdk/openjdk11:jdk-11.0.3_7 COPY build/libs/spring-boot-app.jar /app/ CMD ["java", "-jar",
“/app/spring-boot-app.jar”]
Docker Πϝʔδͱͯ͠Ϗϧυ͢Δ • Docker Gradle plugin (Palantir) Λಋೖ͢Δ • ./gradlew
build docker Ͱ Docker ΠϝʔδΛϏϧυ͢Δ • ./gradlew dockerPush Ͱ Docker ΠϝʔδΛϨδετϦʹ push ͢Δ
# build.gradle plugins { id 'org.springframework.boot' id 'com.palantir.docker' id 'net.researchgate.release'
} // ... docker { name “$dockerNamespace/spring-boot-app:$version” copySpec.from(“build/libs/spring-boot-app—${version}.jar”) .into('build/libs') .rename { “spring-boot-app.jar” } } docker.dependsOn(build) // ... afterReleaseBuild.dependsOn(dockerPush)
Docker ϕʔεΠϝʔδΛબͿ
ϕʔεΠϝʔδɺԿΛબͿʁ • ༷ʑͳ৫͕͍ΖΜͳΠϝʔδΛఏڙ͍ͯͯ͠ɺ ͱͯ ΧΦε ଟ༷ੑʹΜͰ͍Δ • OS: Debian, Ubuntu,
Alpine Linux, Oracle Linux, Amazon Linux, … • ৫: Docker official, Oracle, AdoptOpenJDK, Azul systems, … • ͦͷଞ: LTS ͷ༗ແ, JRE/JDK, …
ϕʔεΠϝʔδɺԿΛબͿʁ • AdoptOpenJDK ΛબΜͩ • “LTS ͕͋ͬͯ JDK ͷΠϝʔδͰ͋ΕԿͰΑ͔ͬ ͨɻࠓʹͯ͠ΈΕ
Amazon Corretto ΛબΜͰΑ ͔͔ͬͨ͠Εͳ͍ͱল͍ͯ͠Δ” • OS (Alpine Ͱͳ͘) Ubuntu Λબ, slim બͣ • slim Πϝʔδͩͱ jstack ͳͲ͕ೖ͍ͬͯͳ͍
λΠϜηʔϧͷ ϏϧυύΠϓϥΠϯ
Docker image CodeDeploy artifact Jar git push
ΑΓΑ͍ Docker ΠϝʔδΛ ࡞Δ
ྑ࣭ͳใ͕ͪ͜Βʹ… • https://spring.io/guides/topicals/spring-boot-docker/ • https://spring.io/guides/gs/spring-boot-docker/
ϨΠϠΛ͚͋͑ͯΔ FROM adoptopenjdk/openjdk11:jdk-11.0.3_7 ARG DEPENDENCY=build/dependency COPY ${DEPENDENCY}/BOOT-INF/lib /app/lib COPY ${DEPENDENCY}/META-INF
/app/META-INF COPY ${DEPENDENCY}/BOOT-INF/classes /app CMD ["java", "-cp", "app:app/lib/*", "foo.bar.EntryPoint"]
ϨΠϠΛ͚͋͑ͯΔ $ ./gradlew build $ mkdir build/dependency $ (cd build/dependency;
jar -xf ../libs/spring-boot-app.jar) $ ./gradlew docker
ϨΠϠΛ͚͋͑ͯΔ • ґଘϥΠϒϥϦʹมߋ͕ੜ͡ͳ͍ݶΓɺ ΠϝʔδͷϏϧυߴԽ͕ظͰ͖Δ • JarLauncher Λܦ༝ͤͣ main Ϋϥε͔Β ࣮ߦ͢ΔͷͰɺىಈͷߴԽظͰ͖Δ
None
σϓϩΠɾࢹ
Docker image start.sh CodeDeploy artifact create-deployment docker run
Spring Boot app ͷίϯςφΛಈ͔͢ $ docker run -d —name spring-boot-app
\ -p 8080:8080 \ -e SPRING_PROFILES_ACTIVE=production \ -v /path/to/host/log:/path/to/container/log \ spring-boot-app:X.Y.Z
Spring Boot app ͷίϯςφΛಈ͔͢ $ docker run -d —name spring-boot-app
\ -p 8080:8080 \ -e SPRING_PROFILES_ACTIVE=production \ -v /path/to/host/log:/path/to/container/log \ spring-boot-app:X.Y.Z
# application.yml spring.profiles: production spring: profiles: include: common, aws, prd-db
--- spring.profiles: staging spring: profiles: include: common, aws, stg-db --- spring.profiles: local spring: profiles: include: common, local-db
ϗετͷϑΝΠϧγεςϜʹϩάग़ྗ͢Δ $ docker run -d —name spring-boot-app \ -p 8080:8080
\ -e SPRING_PROFILES_ACTIVE=production \ -v /path/to/host/log:/path/to/container/log \ spring-boot-app:X.Y.Z
Datadog ʹΑΔϝτϦΫεࢹ Datadog agent VEQ
# build.gradle dependencies { // ... implementation ‘org.springframework.boot:spring-boot-starter-actuator’ implementation ‘io.micrometer:micrometer-registry-statsd’
} # application.yml management: metrics: export: statsd: flavor: datadog host: host.docker.internal # 18.03 ΑΓલͷ docker Λ͏߹ --network=host ͷΦϓγϣϯ͚ͯ # docker run ͱ͢Δɻ·ͨ host ͷࢦఆҎԼͷΑ͏ʹ 127.0.0.1 ͱ͢Δ host: 127.0.0.1
jstack ͨ͘͠ͳͬͨͱ͖ʁ $ docker exec spring-boot-app jstack 1
·ͱΊ
·ͱΊ • Java 11 + Spring Boot + Kotlin ͱ͍͏ߏͷ
৽نαʔϏεͷ։ൃͰ Docker Λ׆༻ͨ͠ • ։ൃڥͷඋ • Docker Πϝʔδͷߏஙํ๏ • σϓϩΠɾΞϓϦέʔγϣϯ࣮ߦํ๏