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
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
270
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
420
Server Side Framework Slimaneの紹介
noppoman
1
1.1k
Other Decks in Technology
See All in Technology
株式会社ログラス − エンジニア向け会社説明資料 / Loglass Comapany Deck for Engineer
loglass2019
3
32k
小学3年生夏休みの自由研究「夏休みに Copilot で遊んでみた」
taichinakamura
0
170
TSKaigi 2024 の登壇から広がったコミュニティ活動について
tsukuha
0
160
Oracle Cloudの生成AIサービスって実際どこまで使えるの? エンジニア目線で試してみた
minorun365
PRO
4
290
Storage Browser for Amazon S3
miu_crescent
1
240
バクラクのドキュメント解析技術と実データにおける課題 / layerx-ccc-winter-2024
shimacos
2
1.1k
継続的にアウトカムを生み出し ビジネスにつなげる、 戦略と運営に対するタイミーのQUEST(探求)
zigorou
0
600
社内イベント管理システムを1週間でAKSからACAに移行した話し
shingo_kawahara
0
190
LINE Developersプロダクト(LIFF/LINE Login)におけるフロントエンド開発
lycorptech_jp
PRO
0
120
ゼロから創る横断SREチーム 挑戦と進化の軌跡
rvirus0817
2
270
1等無人航空機操縦士一発試験 合格までの道のり ドローンミートアップ@大阪 2024/12/18
excdinc
0
170
How to be an AWS Community Builder | 君もAWS Community Builderになろう!〜2024 冬 CB募集直前対策編?!〜
coosuke
PRO
2
2.8k
Featured
See All Featured
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
132
33k
Reflections from 52 weeks, 52 projects
jeffersonlam
347
20k
Optimising Largest Contentful Paint
csswizardry
33
3k
Visualization
eitanlees
146
15k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
66k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
The Invisible Side of Design
smashingmag
298
50k
Code Reviewing Like a Champion
maltzj
520
39k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
5
450
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
17
2.3k
Adopting Sorbet at Scale
ufuk
73
9.1k
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ͯ͠ΈͯԼ͍͞ʂ
͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ɻ