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
Practical Hexaville(ja)
Search
Yuki Takei
July 05, 2017
Technology
0
460
Practical Hexaville(ja)
Tokyo Server Side Swift Meetup #8
Yuki Takei
July 05, 2017
Tweet
Share
More Decks by Yuki Takei
See All by Yuki Takei
VAR モデルによる OSS プロジェクト同士が生存性に与える 影響の分析
noppoman
0
250
Server Side Swift の個人的な利用シーン
noppoman
2
580
Serverless Server Side Swift
noppoman
2
1.6k
実践Server Side Swift
noppoman
13
4.1k
Server Side Swiftを使った サービス開発とその運用を考える
noppoman
4
1.3k
Swiftに適したサーバーアーキテクチャを再考して実装までしてみる
noppoman
7
2.8k
Swift3 Framework Slimane and Server Side Swift (ja)
noppoman
2
2.2k
About Deploying and Process Management for Slimane
noppoman
2
410
Server Side Framework Slimaneの紹介
noppoman
1
1.1k
Other Decks in Technology
See All in Technology
マルチプロダクトな開発組織で 「開発生産性」に向き合うために試みたこと / Improving Multi-Product Dev Productivity
sugamasao
1
300
Python(PYNQ)がテーマのAMD主催のFPGAコンテストに参加してきた
iotengineer22
0
470
信頼性に挑む中で拡張できる・得られる1人のスキルセットとは?
ken5scal
2
530
リンクアンドモチベーション ソフトウェアエンジニア向け紹介資料 / Introduction to Link and Motivation for Software Engineers
lmi
4
300k
データプロダクトの定義からはじめる、データコントラクト駆動なデータ基盤
chanyou0311
2
300
Shopifyアプリ開発における Shopifyの機能活用
sonatard
4
250
これまでの計測・開発・デプロイ方法全部見せます! / Findy ISUCON 2024-11-14
tohutohu
3
370
TanStack Routerに移行するのかい しないのかい、どっちなんだい! / Are you going to migrate to TanStack Router or not? Which one is it?
kaminashi
0
580
【若手エンジニア応援LT会】ソフトウェアを学んできた私がインフラエンジニアを目指した理由
kazushi_ohata
0
150
スクラム成熟度セルフチェックツールを作って得た学びとその活用法
coincheck_recruit
1
140
Application Development WG Intro at AppDeveloperCon
salaboy
0
180
iOSチームとAndroidチームでブランチ運用が違ったので整理してます
sansantech
PRO
0
130
Featured
See All Featured
Become a Pro
speakerdeck
PRO
25
5k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
246
1.3M
Gamification - CAS2011
davidbonilla
80
5k
Typedesign – Prime Four
hannesfritz
40
2.4k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
8.2k
The Art of Programming - Codeland 2020
erikaheidi
52
13k
5 minutes of I Can Smell Your CMS
philhawksworth
202
19k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.5k
Testing 201, or: Great Expectations
jmmastey
38
7.1k
Visualization
eitanlees
145
15k
Transcript
࣮ફHexaville Yuki Takei@Tokyo Server Side Swift Meetup #8 27 Jun,
2017 ʙ 5Ͱ࡞ΔαʔόʔϨεͳSwiftSNSೝূαʔόʔ ʙ
ࣗݾհ
• Hexavilleͷհ • 5Ͱ࡞ΔSwiftSNSೝূαʔόʔ • HexavilleͰwebαʔϏεΛ࡞Δ্Ͱͷϊϋ • CIɺσϓϩΠͷࣗಈԽ • ࠓޙͷϩʔυϚοϓ
ΞδΣϯμ
Hexavilleͷհ
None
ࠓྲྀߦΓͷαʔόʔϨε αʔόʔϨείϯϐϡʔςΟϯάͱɺΫϥ υϓϩόΠμʔ͕ΞϓϦέʔγϣϯʹඞཁͳϚ γϯϦιʔεͷׂΓͯΛಈతʹཧ͠ɺࣄલ ʹߪೖ͞Εͨ͜ͱʹجͮ͘ٻͰͳ͘ɺ֤Ξ ϓϦέʔγϣϯཁٻΛຬͨͨ͢Ίʹ༻͞ΕΔ ݸʑͷϦιʔεྔʹج͍ͮͨٻΛߦ͏Α͏ͳ ΫϥυίϯϐϡʔςΟϯάϞσϧɻ wikipedia αʔόϨεɾίϯϐϡʔςΟϯά
ΑΓ
Hexavilleͱ • SwiftͷαʔόʔϨεڥΛߏங͢ΔϑϨʔϜϫʔΫͱͦͷ πʔϧ܈ (ݱࡏAWS Lambda + API GatewayͷΈ) •
ίʔυϕʔε͕SwiftͷͨΊɺiOSΞϓϦέʔγϣϯΛॻ͘Ԇ ͰαʔόʔϓϩάϥϜΛهड़Ͱ͖Δɻ • ී௨ͷwebΞϓϦέʔγϣϯΛ࡞ͬͯσϓϩΠ͢Δ͚ͩ • ίϚϯυҰͭͰΫϥυ্ʹσϓϩΠ͞Εɺαʔόʔӡ༻ͳ ͠ͰαʔϏεΛ։࢝Ͱ͖Δ • XcodeͰͷ։ൃڥΛఏڙɺInstrumentsɺLLDBΛͬͨσ όοάՄೳ
Πϯετʔϧ
1ίϚϯυͰΠϯετʔϧՄೳ
HexavilleͷϓϩδΣΫτΛ࡞͢Δ
HexavilleͷϓϩδΣΫτΛ࡞͢Δ
ઃఆϑΝΠϧ(Hexavillefile.yml)
HexavilleΛͬͨWebΞϓϦέʔγϣϯͷهड़ํ๏
HexavilleΛͬͨWebΞϓϦέʔγϣϯͷهड़ํ๏ ϑϨʔϜϫʔΫͷΠϯελϯεΛ࡞
HexavilleΛͬͨWebΞϓϦέʔγϣϯͷهड़ํ๏ MiddlewareͷొʢඞਢͰͳ͍ʣ
HexavilleΛͬͨWebΞϓϦέʔγϣϯͷهड़ํ๏ RoutingͱͦͷURIͷϓϩάϥϜͷ࣮
HexavilleΛͬͨWebΞϓϦέʔγϣϯͷهड़ํ๏ ΞϓϦέʔγϣϯͷىಈ
$ hexaville deploy Hello σϓϩΠ
$ hexaville deploy Hello Start to build swift... Building application....
Generating Routing Manifest file.... Sending build context to Docker daemon 176 MB Step 1/11 : FROM ubuntu:14.04 ---> 132b7427a3b4 Step 2/11 : RUN apt-get update -y ---> Using cache ---> fd9a040329d6 Step 3/11 : RUN apt-get install -y clang libicu-dev libbsd-dev uuid-dev git libxml2-dev libxslt1-dev python-dev libcurl4-openssl-dev wget ---> Using cache ---> c4890f13de61 Step 4/11 : ENV SWIFT_DOWNLOAD_URL https://swift.org/builds/swift-3.1-release/ ubuntu1404/swift-3.1-RELEASE/swift-3.1-RELEASE-ubuntu14.04.tar.gz ---> Using cache ---> a5ac353284e3 Step 5/11 : ENV SWIFTFILE swift-3.1-RELEASE-ubuntu14.04 ---> Using cache Ϗϧυ։࢝ σϓϩΠ
σϓϩΠͷྃ Deploying to staging ###################################################### Information ApplicationName: AuthService Endpoint: https://bma4gjwu36.execute-api.ap-northeast-1.amazonaws.com/staging
Stage: staging ###################################################### All Done.
Routingͷ֬ೝ $ hexaville routes
Routingͷ֬ೝ $ hexaville routes Endpoint: https://bma4gjwu36.execute-api.ap-northeast-1.amazonaws.com/staging Routes: GET /auth/twitter/callback GET
/auth/twitter GET / GET /auth/facebook GET /auth/facebook/callback
XcodeΛͬͨɺMac্Ͱͷ։ൃͱDebugαʔόʔͷىಈ https://youtu.be/Lj7Jg_XlmIU σϞ
None
5Ͱ࡞ΔSwiftSNSೝূαʔόʔ
webαʔϏεΛ࡞Δ্ͰɺSNSΞΧϯτΛͬͨ ϩάΠϯػೳࠓແͯ͘ͳΒͳ͍ͷʹ…
ͨͩɺຖຖ࡞Δͷ໘
֤αʔϏε͕SNSೝূػೳΛ͍࣋ͬͯΔέʔε Service 1 Service 2 DB DB
Service3, Service4ͱ૿͍͑ͯͬͨΒͲ͏ͳͬͪΌ͏ʁ
ͦΜͳͱ͖ɺαʔόʔϨεͷग़൪
HexavilleΛͬͯೝূαʔϏεΛαʔόʔϨεԽ DB Hexaville Auth Service Service 2 DB Service 1
DB Hexaville Auth Service Service 2 DB Service 1 ֤αʔϏε͕ೝূϓϩάϥϜΛ࣋ͨͳ͍͍ͯ͘
HexavilleΛͬͯೝূαʔϏεΛαʔόʔϨεԽ
DB Hexaville Auth Service Service 2 DB Service 1 ೝূαʔϏε͕Ұͭʹ·ͱ·Δ্ɺӡ༻ෆཁʹʂ
HexavilleΛͬͯೝূαʔϏεΛαʔόʔϨεԽ
ೝূϓϩάϥϜΛ֤αʔϏεʹ࣮͢Δ࣌ɺ ͏ऴΘΓͭͭ͋Δ
Ͱૣɺ5Ͱαʔόʔӡ༻͕ෆཁͳೝূαʔϏεΛ ࡞ͬͯΈ·͠ΐ͏
None
• Hexavilleʹ༷ʑͳೝূػೳΛఏڙ͢ΔϓϥάΠϯ • OAuth1, OAuth2ΫϥΠΞϯτΛఏڙ • FacebookɺGithubɺGoogle, TwitterͷOAuthΛσϑΥϧτͰ ఏڙ •
HexavilleͷRouterͱͯ͠ಈ࡞͢Δ • ηογϣϯΛར༻Մೳ(Memory, Redis, Dynamodb(࣮த)) • ಠࣗͷOAuthΫϥΠΞϯτΛϓϩτίϧʹԊͬͯ؆୯ʹ࡞ Մೳ HexavilleAuth
Facebook(OAuth2)ͷྫ
HexavilleAuthͷΠϯελϯε࡞ Facebook(OAuth2)ͷྫ
FacebookAuthorizationProviderͷΠϯελϯε࡞ Facebook(OAuth2)ͷྫ
PATHɿೝূURL(͜͜ʹདྷͨΒfacebookʹϦμΠϨΫτ) Facebook(OAuth2)ͷྫ
consumerKey, SecretɿFBΞϓϦ༻ͷΫϨσϯγϟϧ Facebook(OAuth2)ͷྫ
callbackURL: OAuthޭޙͷભҠઌ Facebook(OAuth2)ͷྫ
scope: OAuth2ͷείʔϓ Facebook(OAuth2)ͷྫ
OAuth2ͷೝՄ͕௨ͬͨ߹ͷcallbackɻ credential(access-token)ɺೝՄuserͳͲͷใ ͕औಘͰ͖Δ Facebook(OAuth2)ͷྫ
HexavilleAuthͷΠϯελϯεʹ facebookProviderΛՃ Facebook(OAuth2)ͷྫ
Facebook(OAuth2)ͷྫ HexavilleAuthͷΠϯελϯεΛrouting͢Δ
͋ͱhexaville deployίϚϯυͰɺ σϓϩΠ͢Δ͚ͩʂ
https://youtu.be/Uv-vma234UQ σϞ
5ͰೝূαʔϏε͕࡞Εͯ͠·͍·ͨ͠ ͔͠SwiftͰʂ
https://github.com/Hexaville/HexavilleAuth/blob/master/ Sources/HexavilleAuthExample/main.swift ͦͷଞɺTwitterGoogleͳͲͷαϯϓϧͪ͜Β͔Β
• device tokenͳͲͷొαʔόʔ • CRUDͷAPIJSON-RPCαʔόʔ • HTML৴αʔόʔ • ը૾ϦαΠζαʔόʔ(SwiftͱCϥΠϒϥϦͱͷ ੑͷߴ͞˓)
ͦͷଞʹHexaville͕͍͍ͯΔαʔϏε
αʔόʔϨεརΛ্͛ΕΩϦ͕ͳ͍Ͱ͕͢ɺ໘ɺ ͍͔ͭ͘ଘࡏ͠·͢ɻ
HexavilleͰαʔόʔϨεΞϓϦέʔγϣϯΛ࡞Δࡍʹɺ ؾΛ͚ͭΔͦͷଞͷϊϋΛ͝հ͠·͢ɻ
HexavilleͰwebαʔϏεΛ࡞Δ্Ͱͷϊϋ
Server ैདྷͷwebΞϓϦέʔγϣϯͷ࣮ߦϞσϧ DB connection pool
Lambda Function Lambda Function Lambda Function Lambda Function Lambda Function
αʔόʔϨε ίϯϐϡʔςΟϯάͷ࣮ߦϞσϧ
DB Lambda Function Lambda Function Lambda Function Lambda Function Lambda
Function αʔόʔϨε ίϯϐϡʔςΟϯάͷ࣮ߦϞσϧ(DBଓ༗Γ)
αʔόʔϨε ίϯϐϡʔςΟϯάͷ࣮ߦϞσϧ(DBଓ༗Γ) DB Lambda Function Lambda Function Lambda Function Lambda
Function Lambda Function ΫϥΠΞϯτͷίωΫγϣϯ || DBͷίωΫγϣϯଓ
αʔόʔϨε ίϯϐϡʔςΟϯάͷ࣮ߦϞσϧ(DBଓ༗Γ) DB Lambda Function Lambda Function Lambda Function Lambda
Function Lambda Function DB1connection = 1threadͰ ड͚͚Δ࣮͕ଟ͍
αʔόʔϨε ίϯϐϡʔςΟϯάͷ࣮ߦϞσϧ(DBଓ༗Γ) DB Lambda Function Lambda Function Lambda Function Lambda
Function Lambda Function ॏ͍ΫΤϦΛ͍͛ͯͳͯ͘ɺ େͨ͠ͷΫΤϦΛ͍͛ͯͳͯ͘ɺ ͋ͳͨͷDB൵໐Λ্͛Δ͜ͱʹͳΓ·͢ɻ
αʔόʔϨε ίϯϐϡʔςΟϯάͷ࣮ߦϞσϧ(DBଓ༗Γ) DB Lambda Function Lambda Function Lambda Function Lambda
Function Lambda Function RedisͳͲͷϊϯϒϩοΩϯάͳNoSQLσʔλ ϕʔεྫ֎ʹΕͣɺίωΫγϣϯಉ࣮࣌ ߦ͕૿͑ΕͦͷDBͷෛՙ্͕Δɻ ·ͨɺଓՄೳͳΫϥΠΞϯτϚγϯεϖο Ϋʹґଘ͢ΔͨΊɺແବʹNode͕૿͑ΔՄೳੑ ɻ
• ͦͦͦͷσʔλͦͷDBʹอଘ͢Δඞཁ͋Δͷ͔ʁ • DynamodbΛར༻͢Δ(ΩϟύγςΟʔϢχοτ͕Φʔτε έʔϧରԠ͠ɺίωΫγϣϯΛجຊతʹؾʹ͢Δඞཁ͕ ແ͘ͳͬͨ) • DBίωΫγϣϯϓʔϧ༻ͷαʔόʔΫϥελʔΛ࡞Γɺ lambda͔ΒͦͷΫϥελʔʹଓ͠ɺΫϥελʔͷΠ ϯελϯε͕DBͷ௨৴Λߦ͢Δɻ
• SQSΛͬͨδϣϒΩϡʔ+ϫʔΧʔύλʔϯͰඇಉظʹ DBΠϯαʔτ(SQSͷฒྻ࣮ޮੑೳະݕূ) ΫϥΠΞϯτͷίωΫγϣϯ = DBଓͷղܾҊ
ίʔϧυελʔτ ॳճىಈ࣌ɺ͠Β͘ΞΫηε͕ແ͍߹ɺlambdaίʔ ϧυঢ়ଶʹҠߦ͢Δɻ ࣍ͷϦΫΤετͰίʔϧυঢ়ଶ͔Β෮ؼ͢Δ·ͰͷΞΠυϧ࣌ ͕ؒ͜ͷίʔϧυελʔτͰ͋Δɻ(ίϯςφωοτ ϫʔΫΠϯλʔϑΣʔεͷηοτΞοϓʹ͕͔͔࣌ؒΔ) ࠷େͷɺϦΫΤετ͕λΠϜΞτ͢Δ͔ͱ͍͏ (10ඵ)
ίʔϧυελʔτͷղܾҊ • ͦͦਓʹΑͬͯʹͳΒͳ͍έʔε • τϥϑΟοΫ͕ৗ࣌͋Δ߹΄ͱΜͲൃੜ͠ ͳ͍ͱͷ͜ͱʢAWSެࣜεϥΠυΑΓʣ • lambdaͷεέδϡʔϦϯάػೳ(cronʹ૬)Λ ͬͯɺఆظతʹΤϯυϙΠϯτʹϦΫΤετ Λ͛Δ͜ͱͰɺΥʔϜঢ়ଶΛอͭ
• HexavilleόΠφϦίϯςϯπͷϨεϙϯε͕Մೳɻ= SwiftProtobufͱNSURLSessionͰ؆୯ɺ҆શʹ௨৴ग़དྷΔ • SPMͷϥΠϒϥϦ͕ͦͷ··͑Δ • ΫϥΠΞϯτϥΠϒϥϦͦͷ··͑Δέʔε (SwiftyJSONɺSwiftProtoBuf etc..) •
VPCΧελϜυϝΠϯ͕͑Δ • Session͕͑Δ • Linux͔ΒdeployͰ͖Δ ͦͷଞHexavilleͰग़དྷΔ͜ͱʢൈਮʣ
• HexavilleόΠφϦίϯςϯπͷϨεϙϯε͕Մೳɻ= SwiftProtobufͱNSURLSessionͰ؆୯ɺ҆શʹ௨৴ग़དྷΔ • SPMͷϥΠϒϥϦ͕ͦͷ··͑Δ • ΫϥΠΞϯτϥΠϒϥϦͦͷ··͑Δέʔε (SwiftyJSONɺSwiftProtoBuf etc..) •
VPCΧελϜυϝΠϯ͕͑Δ • Session͕͑Δ • Linux͔ΒdeployͰ͖Δ ͦͷଞϊϋ
ͱ͍͏͜ͱ…!
CIɺσϓϩΠͷࣗಈԽ
ݱࡏCIڥܶతʹ্͠ɺ ແྉαʔϏε͕಄͠·͍ͬͯ͘·͢Ͷɻ
HexavilleϝδϟʔͳCIαʔϏεͰಈ࡞͢Δ
HexavilleLinux͔ΒσϓϩΠՄೳͳͷͰɺ ແྉͰCIڥΛ࡞Δ͜ͱ͕ग़དྷ·͢ɻ
Travis͔ΒࣗಈσϓϩΠ͢Δྫ
HexavilleϩʔΧϧͰαʔόʔΛىಈͰ͖ΔͷͰɺ APIͷςετίʔυ؆୯ʹॻ͚·͢
αʔόʔϨεͰ؆୯ʹCIΛಋೖՄೳʂ
ࠓޙͷϩʔυϚοϓ
• Dynamodbͷ؆қΞΫηεAPI • MysqlɺRedisͷίωΫγϣϯϓʔϦϯάαʔόʔΛECSαʔϏεͱ ͯ͠ఏڙ • ϩάूϓϥάΠϯͷ։ൃ • DockerίϯςφͰςετίʔυ࣮ߦͷαϙʔτ(CIڥʹSwiftࣗ ମͷΠϯετʔϧΛ͠ͳͯ͘ࡁΉΑ͏ʹ)
• grpcͷΑ͏ͳܗͰΫϥΠΞϯτ <-> αʔόʔؒͷαʔϏεͷΠλʔ ϑΣʔεΛఆٛͰ͖ΔΑ͏ʹʢTLS+http1.1ʣ • SwiftެࣜHTTP APIͱͷ౷߹ ࠓޙͷϩʔυϚοϓ
HexavilleΛͬͯɺ Server SideͰΨϯΨϯSwiftॻ͖·͠ΐ͏ʂ
ڵຯͷ͋Δํɺ͓ؾܰʹ։ൃʹ͝ࢀՃԼ͍͞ʂ
͓Βͤ
None
None
builderscon 2017Ͱ͠·͢ʂ 8݄5 PM3:50ʙ
ઌఔͷϩʔυϚοϓΛؚΊ࣮ͨફతͳ Hexaville։ൃ/ӡ༻ͷͷ΄͔ɺHTTP APIͱͷ౷߹ Swiftαʔόʔ։ൃͷ࠷લઢʹ͍ͭͯൃද͠·͢ɻ
None
νέοτͷൢചऴྃͯ͠͠·༷ͬͨͰ͕͢ɺ Ճൢച༧ఆ͍ͯ͠ΔʁΈ͍ͨͳͷͰνέοτ ແ͍͚ͲࢀՃ͍ͨ͠ͱ͍͏ํɺ #buidersconΛ͚ͭͯTweetͯ͠ΈͯԼ͍͞ʂ
͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ɻ