Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Otemachi.swift x Kyobashi.swift #02: Vapor + Pr...
Search
Takeshi Ihara
January 29, 2018
Programming
370
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Otemachi.swift x Kyobashi.swift #02: Vapor + ProtocolBuffers + DockerでServer Side Swift入門
https://kyobashi-swift.connpass.com/event/75379/
Takeshi Ihara
January 29, 2018
More Decks by Takeshi Ihara
See All by Takeshi Ihara
iOSDC20200921: Feature Flagを適切に分類することでA/Bテストの運用コストを下げる
nonchalant
3
1.4k
iOSDC 20190906: 動画アプリの投げ銭機能における 消耗型課金の仕組みと実装
nonchalant
3
6.4k
iOSDC 20190906: 動画アプリの投げ銭機能における 消耗型課金の仕組みと実装 with 発表ノート
nonchalant
2
650
Sign In with Apple
nonchalant
1
2.5k
iOSDC RejectCon 20180915: Factoryの自動生成によりテストを書きやすくする
nonchalant
1
760
iOSDC 20180902: 小さくはじめる端末管理
nonchalant
2
1k
devsap 20180728: コード生成のススメ
nonchalant
0
150
potatotips #50: iOSは自動生成の夢を見るか?
nonchalant
0
2k
try! Swift Tokyo 2018: Best Docker Container in Swift
nonchalant
1
1.4k
Other Decks in Programming
See All in Programming
標準パッケージに uuid が追加された 背景から見る Go らしい意思決定 / go_127_uuid_decision
convto
5
9.2k
Verilogで学ぶCPU自作入門.pdf
uyuki234
7
3.8k
ソニーのクラウド共通基盤の変遷とAI時代の開発スタイルに合わせた進化 / The Journey of Sony’s Common Cloud Platform and Its Evolution for AI-Native Development
kenjiyoneyama
0
200
AI時代のコードレビューは人に向けるな、仕組みに向けろ
texmeijin
5
3k
【高い買い物LT会】初任給で話題の国産フィジカルAIを買った話
akagami
PRO
0
180
技術的負債を組織課題として解く-増えすぎたマイクロサービスとの戦い-
reimaru
1
2.5k
モジュールの視点からSwiftを読み解く #iosdc
s_shimotori
0
270
テストを司るデーモンに会いに行く 〜隔離した仮想マシンでテストを通すまで〜
h1d3mun3
1
600
設計次第でAIコードの読む量は減らせる / designing-for-code-reading
minodriven
30
13k
App Storeの外へ──日本のiOSサイドローディング入門 for iOSDC Japan 2026
yuukiw00w
0
280
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
400
IBM Bob Dojo #1 仕様駆動開発入門
oniak3ibm
PRO
0
320
Featured
See All Featured
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
12k
Building a Scalable Design System with Sketch
lauravandoore
464
34k
The Limits of Empathy - UXLibs8
cassininazir
1
690
Six Lessons from altMBA
skipperchong
29
4.5k
Code Reviewing Like a Champion
maltzj
528
40k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.4k
Code Review Best Practice
trishagee
74
20k
For a Future-Friendly Web
brad_frost
183
10k
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
390
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
710
Producing Creativity
orderedlist
PRO
348
41k
Transcript
Vapor + ProtocolBuffers + DockerͰServer Side Swiftೖ @nonchalant0303 Otemachi.swift x
Kyobashi.swift #2
ࣗݾհ • Takeshi Ihara • Recruit Marketing Partners • iOS
Engineer • Twitter: @nonchalant0303 • GitHub: Nonchalant
Kyobashi.swift
Sample Project • https://github.com/Nonchalant/ VaporProtobufSample • Server, Clientͷαϯϓϧίʔυ (GET, POST)
• Vapor + ProtocolBuffers + Docker
Server Side Swift https://swift.org/download • Swift͕201512݄ʹΦʔϓϯιʔεԽ • LinuxαϙʔτΛ։࢝ • Vapor,
Kitura, PerfectͳͲͷϑϨʔϜϫʔΫ͕ ొ
Vapor https://github.com/vapor/vapor • ࠷ΘΕ͍ͯΔSwiftͷWebϑϨʔϜϫʔ Ϋ • PHPͷLaravelϑϨʔϜϫʔΫʹӨڹΛड͚ͯ ͍Δ • Swift
Package ManagerʹΑΔϥΠϒϥϦཧ • पลπʔϧॆ࣮
Vapor / Toolbox https://github.com/vapor/toolbox • ެ͕ࣜఏڙ͍ͯ͠ΔCLλεΫπʔϧ CSFXJOTUBMMWBQPSUBQUPPMCPY WBQPSOFX\QSPKFDU@OBNF^BQJ WBQPSCVJME
WBQPSSVO
None
Environment WBQPSWFSTJPO 7BQPS5PPMCPY 7BQPS'SBNFXPSL TXJGUWFSTJPO "QQMF4XJGUWFSTJPO TXJGUMBOH DMBOH 5BSHFUY@BQQMFNBDPTY
TXJGUQBDLBHFUPPMTWFSTJPO
Droplet.swift https://github.com/vapor/vapor/blob/master/Sources/Vapor/Droplet/Droplet.swift • VaporͷRoutingΛ࢘ΔΫϥε extension Droplet { func setupRoutes() throws
{ get("hello") { req in var json = JSON() try json.set("hello", "world") return json } } } ฦΓ͕"1*Ϩεϙϯε
ProtocolBuffers (protobuf) https://github.com/google/protobuf • Google͕։ൃͨ͠௨৴ӬଓԽͰͷར༻Λ తͱͨ͠γϦΞϥΠζϑΥʔϚοτ • .protoͰσʔλߏΛఆٛ͢Δ • Apple͕.swiftʹม͢ΔϓϥάΠϯΛެ։
protobufͷϝϦοτ • σʔλྔ͕খ͍͞ • ௨৴ͷߴԽ • σʔλߏΛෳϓϥοτϑΥʔϜͰڞ༗Մೳ
protobuf - ಋೖ https://github.com/apple/swift-protobuf CSFXJOTUBMMQSPUPCVG HJUDMPOFHJU!HJUIVCDPNBQQMFTXJGUQSPUPCVGHJU DETXJGUQSPUPCVGTXJGUCVJME HFOFSBUFCVJMEEFCVHQSPUPDHFOTXJGU
.proto syntax = "proto3"; import "proto/gender.proto"; message User { int64
id = 1; string name = 2; Gender gender = 3; }
generate .swift QSPUPDQMVHJOQSPUPDHFOTXJGUCVJMEEFCVH QSPUPDHFOTXJGUTXJGU@PVU6TFSQSPUP
User.pb.swift import Foundation import SwiftProtobuf … struct User: SwiftProtobuf.Message {
static let protoMessageName: String = "User" var id: Int64 = 0 var name: String = String() var gender: Gender = .other var unknownFields = SwiftProtobuf.UnknownStorage() init() {} … }
Serialize extension Message { … public func serializedData(partial: Bool =
default) throws -> Data public func jsonUTF8Data() throws -> Data … }
Vapor + protobuf extension Droplet { func setupRoutes() throws {
get("user") { req in return UserResponse.with { $0.users = [ User.with { $0.name = "Takeshi Ihara" $0.gender = Gender.male }, User.with { $0.name = "Hanako Yamada" $0.gender = Gender.female } ] }.serializedData() // or .jsonUTF8Data() } } }
Deserialize (Client) var urlRequest = URLRequest(url: URL(string: "http://localhost: 9000/user")!) urlRequest.allHTTPHeaderFields
= [ "Accept": "application/protobuf" ] URLSession.shared.dataTask(with: urlRequest) { data, _, _ in guard let data = data else { return } let response = try! UserResponse(serializedData: data) }.resume() • Serverͱಉ͡ϞσϧΛ͑Δ (User.pb.swift)
Docker https://www.docker.com/ • ίϯςφܕͷԾԽڥΛఏڙ͢ΔΦʔϓϯιʔ ειϑτΣΞ • શԾԽͰͳ͘1ϓϩηε • VMWareͳͲͷશԾԽʹൺͯɺσΟεΫ ༻ྔ͕গͳ͍ɺىಈ͕ૣ͍ɺॲཧ͕ߴ
docker-swift https://github.com/swiftdocker/docker-swift • UbuntuͰಈ࡞ՄೳͳApple͕ఏڙ͍ͯ͠ΔSwift όΠφϦ͕ಈ࡞ՄೳͳDockerΠϝʔδ • ຊ൪ʹ͍ۙLinuxͰͷಈ࡞ΛݕূͰ͖Δ • FoundationͳͲͷίΞϥΠϒϥϦMacOS, Linux
ͷίʔυ͕ҟͳΔ (Linux൛ෆશ)
Dockerfile FROM swift:4.0.3 USER root RUN mkdir -p /server COPY
./Config /server/Config COPY ./Sources /server/Sources COPY ./Makefile /server/Makefile COPY ./Package.resolved /server/Package.resolved COPY ./Package.swift /server/Package.swift ENV PORT 9000 EXPOSE 9000 WORKDIR /server RUN make build CMD ["make", "run"]
docker-compose https://docs.docker.com/compose/ • ෳίϯςφͷఆٛɾىಈͷߏπʔϧ version: "2" services: server: image: nonchalant/server:0.1
ports: - "9000:9000" ϩʔΧϧɺԾڥͷϙʔτͷϚοϐϯά
·ͱΊ • ؆୯ͳπʔϧɾΞϓϦͳͲServer Side SwiftͰ ॻ͍͍͍͔ͯ • Linux - SwiftίΞϥΠϒϥϦ͕ະͳͷ͕πϥ
Π (࣮ߦ࣌Τϥʔ) • Clientͷಈ࡞ݕূʹDocker͑Δ͔ (CircleCI 2.0)