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
【Startup CTO of the Year 2024 / Audience Award】アセンド取締役CTO 丹羽健
niwatakeru
0
1.3k
オープンソースAIとは何か? --「オープンソースAIの定義 v1.0」詳細解説
shujisado
10
1.1k
Platform Engineering for Software Developers and Architects
syntasso
1
520
心が動くエンジニアリング ── 私が夢中になる理由
16bitidol
0
100
B2B SaaSから見た最近のC#/.NETの進化
sansantech
PRO
0
890
初心者向けAWS Securityの勉強会mini Security-JAWSを9ヶ月ぐらい実施してきての近況
cmusudakeisuke
0
130
OCI Vault 概要
oracle4engineer
PRO
0
9.7k
複雑なState管理からの脱却
sansantech
PRO
1
150
OCI Network Firewall 概要
oracle4engineer
PRO
0
4.2k
ExaDB-D dbaascli で出来ること
oracle4engineer
PRO
0
3.9k
SRE×AIOpsを始めよう!GuardDutyによるお手軽脅威検出
amixedcolor
0
170
New Relicを活用したSREの最初のステップ / NRUG OKINAWA VOL.3
isaoshimizu
3
630
Featured
See All Featured
Art, The Web, and Tiny UX
lynnandtonic
297
20k
We Have a Design System, Now What?
morganepeng
50
7.2k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
430
It's Worth the Effort
3n
183
27k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
GraphQLとの向き合い方2022年版
quramy
43
13k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
Into the Great Unknown - MozCon
thekraken
32
1.5k
BBQ
matthewcrist
85
9.3k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.3k
Scaling GitHub
holman
458
140k
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ͯ͠ΈͯԼ͍͞ʂ
͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ɻ