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
cdk deploy JawsSonic #MARATHONしながらAWSリソースをデプロイしてみよう
akihisaikeda
2
130
App Storeの外へ──日本のiOSサイドローディング入門 for iOSDC Japan 2026
yuukiw00w
0
210
From 6 People Classroom Meetup to 100 People Regional Conference / FOSS4G Hiroshima 2026
furukawayasuto
0
200
大喜利で理解するLLM as a Judge / Understanding LLM-as-a-Judge through Ogiri
rockname
0
100
[DroidKaigi 2026] Bring your own phones to Gradle Managed Devices
f2lk
0
120
SREの越境 / SRE Collaboration
y0hgi
0
110
How I Stole PSI from Android Studio - DroidKaigi2026
worker8
0
130
モデルのリファクタリングが難しいと思ったら、そもそも複雑だったのはビジネス仕様だった ? / is-the-business-domain-the-real-complexity
hatsu38
0
260
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
370
20260914 AIエージェント時代のPlatform Engineering LLM基盤とプロダクトの責務境界線
kanfab1
6
1.9k
[GoCon2026] When Goroutines Are Not Enough: Runtime Locality in High-Throughput Go
takehaya
6
2.2k
一人だけ、Kiroが静止する日
hideg
0
110
Featured
See All Featured
My Coaching Mixtape
mlcsv
0
310
Darren the Foodie - Storyboard
khoart
PRO
4
3.9k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
430
How to make the Groovebox
asonas
2
2.4k
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
740
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
4 Signs Your Business is Dying
shpigford
187
23k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
56
3.5k
30 Presentation Tips
portentint
PRO
1
390
Docker and Python
trallard
47
4.2k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
380
Raft: Consensus for Rubyists
vanstee
142
7.7k
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)