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
450
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.2k
確率的データ構造を Java で扱いたい! #JJUG
komiya_atsushi
6
2.2k
High-performance Jackson #渋谷Java
komiya_atsushi
2
16k
Other Decks in Programming
See All in Programming
色々なIaCツールを実際に触って比較してみる
iriikeita
0
330
Hotwire or React? ~アフタートーク・本編に含めなかった話~ / Hotwire or React? after talk
harunatsujita
1
120
macOS でできる リアルタイム動画像処理
biacco42
9
2.4k
C++でシェーダを書く
fadis
6
4.1k
OSSで起業してもうすぐ10年 / Open Source Conference 2024 Shimane
furukawayasuto
0
110
TypeScriptでライブラリとの依存を限定的にする方法
tutinoko
3
690
Tauriでネイティブアプリを作りたい
tsucchinoko
0
370
エンジニアとして関わる要件と仕様(公開用)
murabayashi
0
300
ペアーズにおけるAmazon Bedrockを⽤いた障害対応⽀援 ⽣成AIツールの導⼊事例 @ 20241115配信AWSウェビナー登壇
fukubaka0825
6
2k
初めてDefinitelyTypedにPRを出した話
syumai
0
420
Macとオーディオ再生 2024/11/02
yusukeito
0
370
Jakarta EE meets AI
ivargrimstad
0
650
Featured
See All Featured
The Language of Interfaces
destraynor
154
24k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Writing Fast Ruby
sferik
627
61k
The Cost Of JavaScript in 2023
addyosmani
45
6.8k
Git: the NoSQL Database
bkeepers
PRO
427
64k
Designing for Performance
lara
604
68k
Imperfection Machines: The Place of Print at Facebook
scottboms
265
13k
Raft: Consensus for Rubyists
vanstee
136
6.6k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
130
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
44
2.2k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
GitHub's CSS Performance
jonrohan
1030
460k
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 Πϝʔδͷߏஙํ๏ • σϓϩΠɾΞϓϦέʔγϣϯ࣮ߦํ๏