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
CQRS+ES の力を使って効果を感じる / Feel the effects of using the power of CQRS+ES
seike460
PRO
0
130
Semantic Kernelのネイティブプラグインで知識拡張をしてみる
tomokusaba
0
180
数十万行のプロジェクトを Scala 2から3に完全移行した
xuwei_k
0
270
テストコード書いてみませんか?
onopon
2
120
PHPUnitしか使ってこなかった 一般PHPerがPestに乗り換えた実録
mashirou1234
0
200
HTTP compression in PHP and Symfony apps
dunglas
2
1.7k
これでLambdaが不要に?!Step FunctionsのJSONata対応について
iwatatomoya
2
3.7k
Keeping it Ruby: Why Your Product Needs a Ruby SDK - RubyWorld 2024
envek
0
190
PSR-15 はあなたのための ものではない? - phpcon2024
myamagishi
0
130
暇に任せてProxmoxコンソール 作ってみました
karugamo
2
720
創造的活動から切り拓く新たなキャリア 好きから始めてみる夜勤オペレーターからSREへの転身
yjszk
1
130
「Chatwork」Android版アプリを 支える単体テストの現在
okuzawats
0
180
Featured
See All Featured
Gamification - CAS2011
davidbonilla
80
5.1k
The World Runs on Bad Software
bkeepers
PRO
65
11k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
How STYLIGHT went responsive
nonsquared
95
5.2k
We Have a Design System, Now What?
morganepeng
51
7.3k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
66k
A designer walks into a library…
pauljervisheath
204
24k
Building a Scalable Design System with Sketch
lauravandoore
460
33k
Thoughts on Productivity
jonyablonski
67
4.4k
Into the Great Unknown - MozCon
thekraken
33
1.5k
Git: the NoSQL Database
bkeepers
PRO
427
64k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.6k
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 Πϝʔδͷߏஙํ๏ • σϓϩΠɾΞϓϦέʔγϣϯ࣮ߦํ๏