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
280
Server Side Swift の個人的な利用シーン
noppoman
2
590
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
Formal Development of Operating Systems in Rust
riru
1
420
実践! ソフトウェアエンジニアリングの価値の計測 ── Effort、Output、Outcome、Impact
nomuson
0
2k
Bring Your Own Container: When Containers Turn the Key to EDR Bypass/byoc-avtokyo2024
tkmru
0
840
Oracle Base Database Service:サービス概要のご紹介
oracle4engineer
PRO
1
16k
東京Ruby会議12 Ruby と Rust と私 / Tokyo RubyKaigi 12 Ruby, Rust and me
eagletmt
3
870
KMP with Crashlytics
sansantech
PRO
0
240
AWS re:Invent 2024 recap in 20min / JAWSUG 千葉 2025.1.14
shimy
1
100
Docker Desktop で Docker を始めよう
zembutsu
PRO
0
160
0→1事業こそPMは営業すべし / pmconf #落選お披露目 / PM should do sales in zero to one
roki_n_
PRO
1
1.3k
dbtを中心にして組織のアジリティとガバナンスのトレードオンを考えてみた
gappy50
0
200
Amazon Route 53, 待ちに待った TLSAレコードのサポート開始
kenichinakamura
0
160
[IBM TechXchange Dojo]Watson Discoveryとwatsonx.aiでRAGを実現!座学①
siyuanzh09
0
110
Featured
See All Featured
How STYLIGHT went responsive
nonsquared
96
5.3k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.8k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
GraphQLとの向き合い方2022年版
quramy
44
13k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
860
Build your cross-platform service in a week with App Engine
jlugia
229
18k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
1.2k
Building Flexible Design Systems
yeseniaperezcruz
328
38k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
7
570
A better future with KSS
kneath
238
17k
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ͯ͠ΈͯԼ͍͞ʂ
͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ɻ