- The presentation discussed bringing Swift to the server by enabling modern application design patterns through open source projects like Kitura and OpenWhisk.
- Key points included an overview of the Swift language and tools, how to develop a basic web application using Kitura, and how OpenWhisk allows triggering actions through events.
- Sample applications like BluePic and resources like the Swift Package Catalog and IBM Swift developer center were highlighted as ways to get involved with the Swift community.
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Mobile, Open Source, & the Drive to the Cloud
1. OSCON 2016 – Swift
Mobile, open source, and the drive to the cloud
Patrick Bohrer
IBM Cloud
@pbohrer
2. OSCON 2016 – Swift
Agenda
• Why:
• Enabling Modern App Design Patterns
• What:
• Logic, Data, Events & Integration powered by Open Source
• How:
• Developer Experience & Tools
• Get Involved:
• Sample End-to-end Applications
• Resources & Links
2
3. OSCON 2016 – Swift
Modern Application Design: Tiers
3
Application-specific
Backend
Other Cloud Services
On-prem Services
Experiences being built by this
community are dramatically changing
the way we live and work
New Experiences
User-facing Client Apps
Things / Sensors
End Users
4. OSCON 2016 – Swift
Modern Application Design: Tier Attributes
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. OSCON 2016 – Swift
Modern Application Design: Tier Attributes
5
Application-specific
Backend
Other Cloud Services
On-prem Services
End Users
User-facing Client Apps
Developer Experience
• Tight Coupling/Dependency between Client Apps
and Application Backend
• Need ability to deploy the right functionality to the
proper tier to deliver world class experience
• Successful experience reached through fast
iterations
6. OSCON 2016 – Swift
Modern Application Design: Application Constructs
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
7. OSCON 2016 – Swift
Application Logic: Swift (Client and Server)
• Swift Background
• What is included in Swift.org ?
• Trends
• Bringing Swift to the Server
• Core contributions
• Motivating Server Projects (Kitura & more)
8. OSCON 2016 – Swift
Swift.org: What is included?
• Open Sourced Dec 3, 2015
• Swift Language
• Core libraries:
• XCTest
• Libdispatch (GCD)
• Foundation for non-Apple hosts (New)
• LLVM Compiler & Debugger (swift-lldb, swift-llvm, swift-clang)
• Swift Package Manager (New)
9. OSCON 2016 – Swift
IBM Swift Sandbox
The IBM Swift Sandbox
Experiment with Swift on the server,
share your code and collaborate with
your peers
http://swiftlang.ng.bluemix.net 9
Features
• One click access to Swift on
Linux (multiple versions)
• Mobile UI & Auto Saving
Draft
• Code Snapshots & Sharing,
UI Themes, Social
• Social Sharing
10. OSCON 2016 – Swift
Growth in Swift Popularity
10
2014 2015
11. OSCON 2016 – Swift
Surging Popularity
within 6 months compared to other popular language
11
12. OSCON 2016 – Swift
New Client-side Development Community
12
Hybrid / Web App Development
NodeJS Attracted Web-based
Developers to the Cloud
Swift App Development
Swift on the Server can attract
Swift-based Developers
>11 Million Apple
Developers
~100 Apple/IBM Enterprise
Solutions and Assets
13. OSCON 2016 – Swift
Lessons to be learned from NodeJS Timeline
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: beta1.0
(Web Framework)
(2009-2010)
+ Kitura: alpha1.0
(Web Framework)
(2016-?)
Initial Popularity
(??)
Swift.org Contributions
Sandbox
14. OSCON 2016 – Swift
Swift.org Contributions
Mailing lists (https://swift.org/community/#mailing-lists)
Very active community
IBM’s involvement in bringing Swift to the Cloud
• Core Libraries
• Foundation
• Libdispatch
• Motivating Server Projects
• Kitura Web Framework
• Web Foundation Libraries
• OpenWhisk support of Swift
15. OSCON 2016 – Swift
Status Quo
Still early days
• Language evolution (1.0 2.0 3.0 4.0) currently at 2.2 3.0
New (Very early):
• Swift Package Manager:
• One of the key developers is Max Howell (creator of Homebrew on Mac)
New on Linux (Still in progress)
• Libdispatch (Concurrency)
• Foundation (New for non-Apple platforms)
15
16. OSCON 2016 – Swift
Apple Client Deployment Server/Cloud Deployment
Application-Specific Cloud ServicesClient Facing App
Beyond Swift.org: Bringing Swift to the Server
• Drive towards consistent Swift developer experience across Client & Server
• Building / Investing in Core Swift Libraries (Foundation & Libdispatch)
• Motivated/Prioritized through open source projects (Kitura & OpenWhisk)
• Deployment options across open source technology (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
Driving
Towards
Consistent
Runtime
across
Clients/Servers
OpenWhisk &
Kitura-based
Server-side
Environments
(Built with
Foundation &
Libdispatch)
17. OSCON 2016 – Swift
Kitura Web Framework
What is it?
New, modular, package-based web framework written in
Swift
Why is this cool?
Empower a new generation of native mobile developers to
write and deploy code into the Cloud.
Developer Benefits ?
Delivers core technologies needed to stand up enterprise
apps on the server
Enables developers to create a web application in Swift and
deploy these servers on Linux and the Cloud.
http://github.com/ibm-swift/kitura 17
18. OSCON 2016 – Swift
myFirstProject
├── Package.swift
├── Sources
│ └── main.swift
└── Tests
└── empty
mkdir myFirstProject
2. Next initialize this project as a new Swift package project
Develop a Kitura Web Application in Swift
1. First we create a new project directory
cd myFirstProject
swift build --init
Now your directory structure under myFirstProject should look like this:
19. OSCON 2016 – Swift
import Kitura
import KituraNet
import KituraSys
import SwiftyJSON
import PackageDescription
let package = Package(
name: "myFirstProject",
dependencies: [
.Package(url: "https://github.com/IBM-Swift/Kitura.git", majorVersion: 0, minor: 13) ]
)
4. Import the modules in your code (Sources/main.swift):
Develop a Kitura Web Application in Swift
3. Now we add Kitura as a dependency for your project (Package.swift):
20. OSCON 2016 – Swift
let server = HTTPServer.listen(port: 8090, delegate: router)
Server.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:
Develop a Kitura Web Application in Swift
5. Add a router and a path:
router.get("/hello.json") { request, response, next in
response.status(.OK).send(json: JSON(["Hello": "World!"]))
next()
}
6. Add a JSON data route
21. OSCON 2016 – Swift
import Kitura
import KituraNet
import KituraSys
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()
}
let server = HTTPServer.listen(port: 8090, delegate: router)
Server.run()
Develop a Kitura Web Application in Swift
8. Sources/main.swift file should now look like this:
22. OSCON 2016 – Swift
Linux: swift build -Xcc –fblocks
Mac OS X: swift build -Xcc -fblocks -Xswiftc -I/usr/local/include -Xlinker -L/usr/local/lib
Develop a Kitura Web Application in Swift
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
23. OSCON 2016 – Swift
Application Data: Open Technology
Today, developers chose their cloud data technology based on the
demands of their application. IBM is happy to offer a wide range of open
technologies in managed offerings: Cloudant, Redis, MongoDB, Postgres,
ElasticSearch, RethinkDB, and more
24. OSCON 2016 – Swift 24
Package (P)
Action f(x)
Trigger (T)
Rule (R)
R = T f(x)
Namespace
f(x)
Application Events: OpenWhisk Overview
High-level
Architecture
Triggers: A class of events emitted by
event sources.
Actions: Encapsulate the actual code
to be executed which support multiple
language bindings. Actions invoke any
part of an open ecosystem.
Rules: An association between a
trigger and an action.
Packages: Describe external services
in a uniform manner.
Combined these allow developers to
compose solutions using modern
abstraction and chaining which can be
created, accessed, updated and
deleted via the CLI
25. OSCON 2016 – Swift
OpenWhisk: How does it work?
OpenWhisk
Swift Docker …
Incoming HTTP request
Browser
Mobile App
Web App
Variety of
languages
Event Providers
Cloudant
Git
Weather
…
…
Trigger execution of
associated OpenWhisk
action
JS
27. OSCON 2016 – Swift
Application Integration: Swift Packages
• Swift.org introduced the Swift Package Manager
• Lack of standardization on packages creates a bit of package hell
• Welcome addition but still early days
• Growing content seen in Github
• Catalog to help with sharing and discovery
• Client and Server side packages
• Building upon lessons learned in other package managers
28. OSCON 2016 – Swift
Application Integration: Swift Package Catalog
https://swiftpkgs.ng.bluemix.net/
29. OSCON 2016 – Swift
Xcode Developer
Experience
Swift on the client
Build and
Debug
Applications
IBM Swift Sandbox
Collaborative
Code as
Questions/An
swers
Provision 3rd Party Client-
side Registered Swift
Packages
IBM Cloud Tool
(prototype)
Provision IBM Cloud
Service Packages and
Credentials
Swift
Packages
Swift on the server
Docker
Whisk
CloudFoundry
Sandbox
Developer Experience
29
30. OSCON 2016 – Swift
Sample Applications: BluePic
BluePic is a photo sharing app that allows you to take photos, upload
them and share them with a community. The BluePic community will be
made up of all the users that run an instance of your created app.
https://github.com/IBM-Swift/Kitura-BluePic
31. OSCON 2016 – Swift
Sample Applications: TodoList
A shared example to showcase backend tech stacks
http://todobackend.com/
An example using Kitura to develop a Todo-Backend
https://github.com/IBM-Swift/Kitura-TodoList
33. OSCON 2016 – Swift
Swift@IBM - Developer Resources
https://developer.ibm.com/swift/
The Swift@IBM devCenter
Join IBM Swift Engineering and
leverage the latest resources
33
34. OSCON 2016 – Swift
Technical Blog Threads on Swift@IBM
Swift (General)
• Why I’m Excited about Swift (12/3)
• Running Swift within Docker (12/15)
• Introducing the (beta) IBM Watson iOS SDK! (12/18)
Swift Sandbox
• Introducing Swift Sandbox (12/3)
• Hello Swift! IBM Swift Sandbox Day 1 Wrapup (12/5)
• #HourofCode: Learn Swift in three easy steps today! (12/8)
• Introduction to Swift Tutorial using the IBM Swift Sandbox (12/8)
• What’s new in the IBM Swift Sandbox v0.3 (12/21)
• Exploring Swift on Linux (12/28)
• What’s new in the IBM Swift Sandbox v0.4 (1/20)
https://developer.ibm.com/swift/blogs
Swift (General)
• Swift on POWER Linux (2/1)
• Seven Swift Snares & How to Avoid Them (1/27)
Interconnect 2016
• Build End-to-End Cloud Apps using Swift with Kitura (2/21)
• Introducing the Swift Package Catalog (2/21)
• Talking about Swift Concurrency on Linux (2/21)
• Explore the IBM Swift Sandbox 1-2-3 (2/21)
• Using the Cloud Foundry Buildpack for Swift on Bluemix (2/21)
• 10 Steps To Running a Swift App in an IBM Container (2/21)
• Build End-to-End Cloud Apps using Swift with Kitura (2/21)
Drumbeat of Blogs/Announcements from IBM Swift Engineering Community
34
35. OSCON 2016 – Swift
Summary
Deployment Options
Swift.org Projects Community Packages
Server Projects
Foundation, libdispatch, clang,
llvm, swift-package-manager
MongoDB, Redis, CouchDB,
Postgresql, Elasticsearch, MQ
Open Source OverviewDeveloper Resources
Swift Sandbox
Package Catalog
And many more…
36. OSCON 2016 – Swift 36
Innovators &
Early
Adopters
Wanted
Get involved now at
swift.org
&
developer.ibm.com/swift
Thank you,
@pbohrer
What is it ?
Kitura is a new, modular, package-based web framework written in the Swift language for use in standing up a web server written in Swift on both OSX and Linux.
Why is this cool ?
Now that Swift is open source, a number of included projects are coming together (swift, swift package manager, libdispatch, swift foundation) that makes the development of a Swift-based web server stack both inevitable as well as incredibly valuable means to empower a new generation of native mobile developers to write and deploy code into the Cloud as well.
Developer Benefits ?
Once you have a new language that runs on a server, many developers want to be able to quickly and easily create a web server written in that language. The swift language and runtime does not include a web framework that can be used to easily create a web server. IBM has created this project to enable developers to create a web application in Swift and deploy these servers on Linux and the Cloud.
IBM Message
We are leading the development of this web framework and will work with the community to evolve this framework over time as Swift on Linux evolves.
Other Details
-Discuss why we have multiple imports
Explain why all the additional C language dependencies
-Line up the font on Swift build
-
IBM Confidential
Simplified client/server programming model
Integrated Client/Server Swift Package Management and composition
IBM Cloud deployment and services provisioning
Client/Server Programming Model
IBM Sandbox collaborative coding and sharing