Swift & BluePic
Oct 25th, 2017 Ricardo Olivieri
1 Agenda
• Swift introduction
• Benefits
• Modern language constructs
• Platforms
• Why Swift on the server?
• Provisioning Swift applications to the IBM Cloud
• The IBM Cloud Buildpack for Swift
• How to use the IBM Cloud Buildpack for Swift?
• What is Kitura?
• What is BluePic?
• Architecture 2 • IBM Cloud Capabilities
• Demo!
• Resources Swift introduction
• Before Swift, Objective-C was the programming language for developing iOS and macOS apps.
• Swift provides a much simpler syntax than Objective-C.
• As soon as Swift was released, developers started sharing their preference of Swift over Objective-C, given its support of many modern programming conventions (e.g. tuples, generics, closures, type inference, and optionals).
3 Swift introduction Objective-C: Person *person = ...; NSMutableString *description = [[NSMutableString alloc] init]; [description appendFormat:@"%@ is %i years old.", person.name, person.age]; if (person.employer) { [description appendFormat:@" They work for %@.", person.employer]; } else { [description appendString:@" They are unemployed."]; }
Swift: var person = … var description = "" description += "\(person.name) is \(person.age) years old." if let employer = person.employer { description += " They work for \(employer)." } else { description += " They are unemployed." }
4 Swift introduction
• Type inference
• Optionals
• Generics
• Tuples
• Extensions
• …
5 The Case for Swift, a Powerful, Intuitive and Uncompromising Programming Language
600% One of the most loved Increase in request for 36K languages Swift Skills Stars in Github (source: Stack Overflow) (source: Toptal)
• Modern programming language constructs • A vibrant developer base • Error detection at compile, not run time • No performance compromises for productivity • Easier code re-engineering 6 It’s more than hype!
http://www.timqian.com/star-history/ #apple/swift&ruby/ruby&scala/scala&aspnet/Home&golang/go&nodejs/node&rust-lang/rust 7 Platforms where you can run Swift today!
8 Why Swift on the Server?
9 Full stack developer & professional growth
NodeJS Attracted Web-based Developers to the Cloud
Hybrid / Web App Development
>13 Million Apple Swift on the Server can attract Developers Swift-based Developers
~100 Apple/IBM Enterprise Solutions and Assets
Swift App Development
10 Application mid-tier layer
Application mid-tier Services Backend Services Logical Extension of App Host Background App Logic, Filter/Stage Data D Standup Web APIs for App ev Frontend Applications el • Web Framework o • D Web Middleware (Sessions, Credentials) e p v e l D • o e D Host Web version of App (static file serving) p v e e v l e > o l > p o Connect to other Services for: > p Big Data and Cognitive
> • > e T > Persistence: Databases T e > s t t T • s e T Integration: MQ, On-prem APIs s e > t s > t • Notifications: Push, SMS, Email > B > > > u > i • l Cognitive: Watson d B u B i u B l i • > d l Caching: Redis > d il u
> D > > e > d p l o D y e D p e > l p > o l y o > y >
> > > 11 D e l p o
y
> Provisioning Swift Applications On The IBM Cloud
12 What is the IBM Cloud Buildpack for Swift?
• Cloud Foundry buildpacks provide the runtime required to execute your applications on the Bluemix cloud.
• There are many Cloud Foundry buildpacks available (e.g. java_buildpack, ruby_buildpack, nodejs_buildpack) on the IBM Cloud.
• The IBM Cloud buildpack for Swift is a new addition to the family of buildpacks on the IBM Cloud.
• Swift applications that follow the structure and conventions required by the Swift Package Manager can now be provisioned on the IBM Cloud.
• Implementing back-end components and micro services in the Swift language that execute on the IBM Cloud is entirely feasible today.
13 What are the main execution phases for a buildpack? • When an application is pushed to the IBM Cloud, buildpacks are responsible for the execution of three main phases:
• Detection – The buildpack lets the Cloud Foundry platform whether it can provision the application.
• Compilation – The buildpack compiles/builds the application; determines what tools should be used for linking and building the app; environment variables are updated as well as needed.
• Release – The buildpack provides metadata on how to execute the application (though this is more useful for containerized environments such as JEE).
• Once the application is provisioned on the IBM Cloud, the buildpack is completely out of the picture!
14 How to use the IBM Cloud Buildpack for Swift
• Swift 4 applications that follow the conventions and structure required by the Swift Package Manager can be pushed to Bluemix.
• Use the IBM Cloud command line to get list of installed buildpacks
• bx cf buildpacks
• Use bx app push to provision your app on Bluemix
• Use the bx app logs command to get a dump of the Cloud Foundry logs:
• bx app logs Kitura-Starter –recent
• Enable debugging to obtain more info during the provisioning phase of the Swift application:
• bx cf set-env
16 Build Fast, Modern Microservices in Swift Introducing Kitura Write Server Applications in Swift • Empower native mobile developers to extend their development skills to the Cloud.
• Deliver micro-services faster with Kitura’s easy-to-learn, lightweight, modular architecture. Integrate Apps with Backend Services
• Leverage a collection of pre-built enterprise connectors including Cloudant, Redis, and Object Storage. A fast, simple to use web • Build with greater confidence through Swift’s technical framework for Server-Side underpinnings, including concurrency, type-safety, and low Swift memory profile.
http://github.com/ibm-swift/kitura 17 BluePic
18 What is BluePic?
• A sample application that allows you to take photos and share them with other BluePic users.
• A cognitive engine enhances images uploaded by users: • Adds weather information (based on the location where the image was uploaded from). • Tags images based on their content. • Push notifications are sent to users once images have been augmented.
• BluePic uses Swift for the implementation of all its components: • iOS application • Web server • Cloud functions 19 Architecture
20 IBM Cloud Capabilities
App ID
Push Watson Visual Notifications Recognition
Cloud Functions
21 BluePic Demo!
22 Resources
• Swift.org – https://swift.org/
• Swift@IBM Development Center – https://developer.ibm.com/swift/
• Buildpack for Swift – https://github.com/IBM-Swift/swift-buildpack/
• Docker images – https://github.com/IBM-Swift/swift-ubuntu-docker
• Kitura Starter – https://github.com/IBM-Bluemix/Kitura-Starter
• Cloud Foundry – https:// docs.cloudfoundry.org/devguide/deploy-apps/manifest.html#minimal-manifest
• Introducing BluePic - https://developer.ibm.com/code/2016/12/15/introducing-bluepic/
• Transition to Server-Side Swift with BluePic - https ://developer.ibm.com/swift/2016/11/15/transition-to-server-side-swift-with-bluepic/
• BluePic journey - https://developer.ibm.com/code/journey/apply-cognitive-to-mobile-images-on- the-go/
• Get answers on our Slack organization: swift-at-ibm.slack.com 23 Questions?
24 25 Backup
26 Using Docker for Development & Testing
• The ibmcom/swift-ubuntu image contains the Swift 3.0.2 RELEASE toolchain as well as the dependencies for running Kitura-based applications.
• Our development team uses the ibmcom/swift-ubuntu image for development and testing of Swift 3 applications on the Linux Ubuntu (v14.04) operating system:
• docker pull ibmcom/swift-ubuntu:latest
• You can mount a folder on your host to your Docker container using the following command:
• docker run -i -t -v
• Exposing your server's port running in a Docker container to the host system (e.g. macOS) is quite easy using the latest version of Docker: 27 • docker run -p