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
役立つログに取り組もう
irof
28
9.6k
Generative AI Use Cases JP (略称:GenU)奮闘記
hideg
1
290
Why Jakarta EE Matters to Spring - and Vice Versa
ivargrimstad
0
1.1k
Amazon Bedrock Agentsを用いてアプリ開発してみた!
har1101
0
330
受け取る人から提供する人になるということ
little_rubyist
0
230
CSC509 Lecture 11
javiergs
PRO
0
180
Outline View in SwiftUI
1024jp
1
330
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
190
色々なIaCツールを実際に触って比較してみる
iriikeita
0
330
ふかぼれ!CSSセレクターモジュール / Fukabore! CSS Selectors Module
petamoriken
0
150
イベント駆動で成長して委員会
happymana
1
320
見せてあげますよ、「本物のLaravel批判」ってやつを。
77web
7
7.7k
Featured
See All Featured
BBQ
matthewcrist
85
9.3k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
0
88
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
4
370
Docker and Python
trallard
40
3.1k
Testing 201, or: Great Expectations
jmmastey
38
7.1k
The World Runs on Bad Software
bkeepers
PRO
65
11k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
93
16k
Optimising Largest Contentful Paint
csswizardry
33
2.9k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
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 Πϝʔδͷߏஙํ๏ • σϓϩΠɾΞϓϦέʔγϣϯ࣮ߦํ๏