Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
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
470
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
LINEヤフーにおけるPrerender技術の導入とその効果
narirou
3
3.5k
静的解析で実現した効率的なi18n対応の仕組みづくり
minako__ph
2
2.2k
Nutanixにいらっしゃいませ。Moveと仮想マシン移行のポイント紹介
shadowhat
0
120
累計2500万着電を支える大規模 電話自動応答サービスのアーキテクチャ / Architecture of a Large-Scale Automated Phone Response Service Supporting 25 Million Cumulative Calls
ymachida
8
3.8k
LLMの気持ちになってRAGのことを考えてみよう
john_smith
0
180
AWS re:Invent 2024 予選落ちのBedrockアプデをまとめて解説!
minorun365
PRO
2
210
専門領域に特化したチームの挑戦
leveragestech
0
180
SREが投資するAIOps ~ペアーズにおけるLLM for Developerへの取り組み~
takumiogawa
5
1.3k
GAS × Discord bot × Gemini で作ったさいきょーの情報収集ツール
ysknsid25
1
200
今はまだ小さい東京ガス内製開発チームが、これからもKubernetesと共に歩み続けるために
yussugi
3
420
"とにかくやってみる"で始めるAWS Security Hub
maimyyym
2
210
クルマのサブスクを Next.jsで内製化した経験とその1年後
kintotechdev
2
360
Featured
See All Featured
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
The Cost Of JavaScript in 2023
addyosmani
45
6.8k
5 minutes of I Can Smell Your CMS
philhawksworth
202
19k
A better future with KSS
kneath
238
17k
What's in a price? How to price your products and services
michaelherold
243
12k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Visualization
eitanlees
145
15k
Optimising Largest Contentful Paint
csswizardry
33
2.9k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Designing on Purpose - Digital PM Summit 2013
jponch
115
7k
YesSQL, Process and Tooling at Scale
rocio
169
14k
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ͯ͠ΈͯԼ͍͞ʂ
͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ɻ