KITURAとサーバーサイドSwift
24th April 2017
BlueHub
Developer Ecosystem Group
IBM Japan Ltd.1
⾃⼰紹介
2
森住 祐介
もりずみ ゆうすけ
@ymorizumi
会社:⽇本IBM株式会社
部署:Developer Ecosystem Group, BlueHub
役職:Developer Advocate
主な活動
・デベロッパー⽀援
・スタートアップ・ベンチャー⽀援
・IBM developerWorks ⽇本版 編集⻑
・オープン・イノベーションを推進する活動
モダンアプリケーション・デザイン:階層
3
Application-specific
Backend
Other Cloud Services
On-prem Services
それぞれの階層におけるコミュニティーで作られた
エクスペリエンスは⽣活や仕事を⼤きく変えた
新しいエクスペリエンス
User-facing Client Apps
Things / Sensors
End Users
モダンアプリケーション・デザイン:階層属性
4
Application-specific
Backend
Other Cloud Services
On-prem Services
End Users
User-facing Client Apps
Role: User Interactions &
Remote Sensing
Application State: User
& View Specific State,
Caching of eventually
consistent state
Usage: Sometimes on,
Driven by Users and
Events
Resources: Constrained
CPU, Mem, Network BW
Role: Integration
Service Composition,
Background Monitoring/Activity,
Event/Traffic Routing,
State synchronization across
clients and things
Application State: Global
Application State
Usage: Always-on, Always
Connected
Resources: Unlimited CPU,
Mem, Network BW
モダンアプリケーション・デザイン:階層属性
5
Application-specific
Backend
Other Cloud Services
On-prem Services
End Users
User-facing Client Apps
デベロッパーエクスペリエンス
• クライアントアプリとバックエンドアプリとの依
存関係を連結
• 適切な機能を適切な階層に適⽤し世界レベルのエ
クスペリエンスを提供する能⼒が必要
• ⾼速なイテレーションにて成功した経験
モダンアプリケーション・デザイン:アプリケーション構造
6
Application-specific
Backend
Other Cloud Services
On-prem Services
Logic: Client and Server-side Swift
Data: Cloudant, MongoDB, Redis, ElasticSearch,
PostgresQL, etc
Events: OpenWhisk
Integration: Open Github Packages
User-facing Client Apps
Developer Experience
End Users
Swift.orgが設⽴しコミュニティーで⾼速開発されている
7
IBM Swift Sandbox
8
The IBM Swift Sandbox
Swiftをサーバーで書いて
仲間とシェア
特徴
• Swift on Linux に⼀撃
アクセス
• モバイル利⽤・オートセ
ーブ機能
• コードスナップショット
• ソーシャルシェアリング
https://swift.sandbox.bluemix.net
Swift⾔語の⼈⼝は急激に拡⼤
9
2014 2015
新しいクライアント・サイド開発コミュニティー
10
Hybrid	/	Web	App	Development
NodeJSはWebベースのデベロッパー
をクラウドに惹きつけた
Swift	App	Development
サーバーサイドSwiftはSwiftベースの
デベロパーをクラウドへ惹きつける
>11 Million Apple
Developers
NodeJSから得られる教訓
11
V8 Release
(2008)
+ libuv (concurency)
+ foundation
= NodeJS
(2009)
+ npm
(2009-2011)
Initial Popularity
(2012-2013)
Mainstream
Usage
(2014-2015)
Swift Release
(Late 2015)
+ libdispatch (concurrency)
+ Foundation
+ Web Foundation (Kitura)
= ??
(2016)
+ swift pkg mgr
+ catalog
(? 2016)
Package Growth
(2012)
Package Growth
(2016-2017)
Mainstream
Usage
(??)
+ Express: betaà1.0
(Web Framework)
(2009-2010)
+ Kitura: alphaà1.0
(Web Framework)
(2016-?)
Initial Popularity
(??)
Swift.org Contributions
Sandbox Package	Catalog
Swiftをサーバーへ
12
Apple Client Deployment Server/Cloud Deployment
Application-Specific Cloud ServicesClient Facing App
• クライアントとサーバー間のSwiftデベロッパーのエクスペリエンスを⼀貫させたものに
• Core Swift Librariesの構築と投資(Foundation & Libdispatch)
• オープンソースプロジェクトの啓蒙と優先(Kitura & OpenWhisk)
• オープンソースプロジェクトへの開発オプション (Docker, Cloud Foundry, Vagrant)
Foundation
Swift
Swift Standard Library
Core Foundation
DispatchPWQ
Clibs
GLibc
Foundation
Swift
Swift Standard Library
Core Foundation
Dispatch
Darwin
Clibs
Client-specific Libraries App Libraries Server-specific LibrariesApp Libraries
クライアントと、
サーバー間を⼀
貫したものに
OpenWhisk & Kitura
ベースのサーバー
サイド
(Foundation &
Libdispatchで構築)
Kitura Webフレームワーク
13
Kituraとは?
• Swiftで書かれたWebフレームワーク
なぜKitura?
• 次世代のネイティブモバイルデベロッパーにクラウドでの開発を
容易にするため
デベロッパーのメリットは?
エンタープライズ向けのアプリに必要なコア・テクノロジーを実装
• デベロッパーはSwiftでLinux上やクラウド環境上にSwiftで書い
たWebアプリを構築することが可能
http://github.com/ibm-swift/kitura
開発の流れ
14
myFirstProject
├── Package.swift
├── Sources
│ └── main.swift
└── Tests
└── empty
mkdir myFirstProject
2. Swift package projectのイニシャライズ
1. 新規プロジェクトのディレクトリの作成
cd myFirstProject
swift build --init
myFirstProject 配下で以下の通りにSwiftのライブラリが構成される:
開発の流れ
15
import Kitura
import SwiftyJSON
import PackageDescription
let package = Package(
name: "myFirstProject",
dependencies: [
.Package(url: "https://github.com/IBM-Swift/Kitura.git", majorVersion: 0, minor: 13) ]
)
4. Kituraのmodulesをインポートする(Sources/main.swift)
3. Package.swiftからKituraのパッケージを指定する
開発の流れ
16
Kitura.addHTTPServer(port: 8090, with: router)
Kitura.run()
let router = Router()
router.get("/hello") { request, response, next in
response.status(.OK).send("<h1>Hello, World!</h1>")
next()
}
7. Create and start a HTTPServer:
5. router と pathを記述
router.get("/hello.json") { request, response, next in
response.status(.OK).send(json: JSON(["Hello": "World!"]))
next()
}
6. JSON data routeを記述
開発の流れ
17
import Kitura
import SwiftyJSON
let router = Router()
router.get("/hello") { request, response, next in
response.status(.OK).send("<h1>Hello, World!</h1>")
next()
}
router.get("/hello.json") { request, response, next in
response.status(.OK).send(json: JSON(["Hello": "World!"]))
next()
}
Kitura.addHTTPServer(port: 8090, with: router)
Kitura.run()
8. Sources/main.swiftは以下の通り
開発の流れ
18
Mac OS X: swift build
Linux: swift build -Xcc –fblocks
9. Compile your application:
.build/debug/myFirstProject
10. Run your web application:
11. Open your browser:
http://localhost:8090/hellohttp://localhost:8090/ http://localhost:8090/hello.json
アプリケーションデータ:とにかくオープン・テクノロジー
19
デベロッパーはクラウドデータテクノロジーをアプリケーションの要件により選択可能
IBMは様々なオープンテクノロジーのテクノロジーをご提供
Cloudan, Redis, MongoDB, Postgres, ElasticSearch, and more
アプリケーションイベント: OpenWhisk概要
20
Function
as a Service
トリガー:
プロセスを実⾏させるためのイ
ベント
ルール:トリガーとアクション
の関係を記述
アクション:実⾏するコード
パッケージ:外部のサービスに
よるイベント
Trigger
Package
Feed
Package
Feed
Package
Feed
Package
Feed
REST
CLI iOS SDK
CRUD triggers, actions, and rules
Invoke actions
UI
Action
NodeJS
Action
Swift
Action
Docker
Rule
Rule
Rule
Action
NodeJS
Action
Docker
Service	ecosytem
Bluemix services
3rd party services
Self-enabled services
Chain Chain Invoke
Docker (and potentially other abstractions going forward)
API Gateway
イベント駆動型とは
21
Swift
Application
Container VMCF
2
Polling
1b
Request
1a
Trigger
1
Running
action
Running
action
Running
action
3
Deploy action within millisecs,
run it,
free up resources
OpenWhisk
Engine
2 Pool of actions
Swift DockerJS Python Java*
• 最適に処理し、稼働した分だけ課⾦
• リクエストごとにスケールさせて処理
• 耐障害性の考慮によるコストがかからない
• アイドリング時も課⾦
• 拡張性を考慮する必要がある
• 耐障害性を考慮した運⽤コスト
OpenWhiskの詳細はこちらで
22
https://github.com/openwhisk https://console.ng.bluemix.net/openwhisk/
Swift Package Catalog
23
https://swiftpkgs.ng.bluemix.net/
デベロッパーエクスペリエンス
24
Xcode Developer
Experience
Swift on the client
Build and
Debug
Applications
IBM Swift Sandbox
Collaborative Code as
Questions/Answers
Provision 3rd Party Client-side
Registered Swift Packages
IBM Cloud Services
Provision IBM Cloud
Service Packages and
Credentials
Swift
Packages
Swift on the server
Docker
Whisk
CloudFoundry
Sandbox
参考情報 – Swift@IBM -
25 https://developer.ibm.com/swift/
The Swift@IBM devCenter
IBMのエンジニアと交流
26
Qiitaでの投稿お待ちしております
Qiitaにてフォローください
27
http://qiita.com/tags/Bluemix
http://qiita.com/tags/Kitura
http://qiita.com/tags/OpenWhisk
Hints & Tipsはユーザー会から⼊⼿
28
• 2015年5⽉に正式発⾜
• 世界初のBluemixユーザー会
• Bluemixって何? という⽅でも⼤歓迎!
• ゆる〜くカジュアルに情報交換・meetup
facebookで「グループに参加」をクリック!
http://ibm.biz/bmxug-facebook
connpassで「グループに参加」をクリック!
https://bmxug.connpass.com/
BMXUG Meetup Vol.1 (XCITE) BMXUG Meetup Vol.4 SoftLayer Bluemix Summit Bluemix⼥⼦会 Vol.3
▼▼参加⽅法▼▼
ビーザグ と
読みます
現在の会員数 – 4,000名以上
質疑応答
29
30
Get Started Today!
developer.ibm.com/swift
Thank you, @ymorizumi
For more information
IBM BlueHub official website
www.ibm.com/ibm/jp/bluehub/
IBM BlueHub official Facebook
www.facebook.com/IBMBlueHub
31

KituraとサーバーサイドSwift