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
440
Java のデータ圧縮ライブラリを極める #jjug_ccc #ccc_c7
komiya_atsushi
4
4.6k
#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
2万ページのSSG運用における工夫と注意点 / Vue Fes Japan 2024
chinen
3
1.3k
Vaporモードを大規模サービスに最速導入して学びを共有する
kazukishimamoto
4
4.3k
とにかくAWS GameDay!AWSは世界の共通言語! / Anyway, AWS GameDay! AWS is the world's lingua franca!
seike460
PRO
1
510
cXML という電子商取引の トランザクションを支える プロトコルと向きあっている話
phigasui
3
2.2k
讓數據說話:用 Python、Prometheus 和 Grafana 講故事
eddie
0
350
Vitest Browser Mode への期待 / Vitest Browser Mode
odanado
PRO
2
1.7k
アジャイルを支えるテストアーキテクチャ設計/Test Architecting for Agile
goyoki
7
2.7k
組織に自動テストを書く文化を根付かせる戦略(2024秋版) / Building Automated Test Culture 2024 Autumn Edition
twada
PRO
10
4.5k
From Subtype Polymorphism To Typeclass-based Ad hoc Polymorphism- An Example
philipschwarz
PRO
0
160
Vue.js学習の振り返り
hiro_xre
2
130
Honoの来た道とこれから
yusukebe
19
3k
リリース8年目のサービスの1800個のERBファイルをViewComponentに移行した方法とその結果
katty0324
5
3.5k
Featured
See All Featured
The Cost Of JavaScript in 2023
addyosmani
45
6.6k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
31
2.7k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Building Your Own Lightsaber
phodgson
102
6k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.8k
We Have a Design System, Now What?
morganepeng
50
7.2k
The Power of CSS Pseudo Elements
geoffreycrofte
72
5.3k
The World Runs on Bad Software
bkeepers
PRO
65
11k
Designing on Purpose - Digital PM Summit 2013
jponch
115
6.9k
Facilitating Awesome Meetings
lara
49
6k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
9
680
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 Πϝʔδͷߏஙํ๏ • σϓϩΠɾΞϓϦέʔγϣϯ࣮ߦํ๏