Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Swift server-side-let swift2016

7,489 views

Published on

www.letswift.kr 2016

Published in: Internet
  • Be the first to comment

Swift server-side-let swift2016

  1. 1. let swift(16) Docker + Swift Server-Side OSXDEV.orgByungwook Ahn OSXDEV.orgWonseok Yang 1
  2. 2. 2 Experienced Device driver(windows, linux) Media streaming CDN Docker Letswift Conf. 2016 Speaker Tensorflow-KR 2016 Speaker PyCon Hongkong 2015 Speaker PyCon Korea 2015 Speaker
  3. 3. 3
  4. 4. Agenda WWDC 2016 - swift session Server-Side? Swift backend framework VirtualBox, Kitura, Docker myFirstProject Demo Summary 4
  5. 5. WWDC 2016 - swift session Swift What’s New in Swift : https://developer.apple.com/videos/play/wwdc2016/402/ Client-Side What’s New in Foundation for Swift : https://developer.apple.com/videos/play/wwdc2016/207/ Getting Started with Swift : https://developer.apple.com/videos/play/wwdc2016/404/ Introducing Swift Playgrounds : https://developer.apple.com/videos/play/wwdc2016/408/ Swift API Design Guidelines : https://developer.apple.com/videos/play/wwdc2016/403/ Understanding Swift Performance : https://developer.apple.com/videos/play/wwdc2016/416/ Concurrent Programming With GCD in Swift 3 : https://developer.apple.com/videos/play/ wwdc2016/720/ Using Store Kit for In-App Purchase wit Swift 3 : https://developer.apple.com/videos/play/ wwdc2016/702/ Server-Side Going Server-side with Swift Open Source : https://developer.apple.com/videos/play/ wwdc2016/415/ Software Engineer @red 5
  6. 6. Server-Side? Backend Web Framework Web Framework? Ajax asynchronous Javascript and XML MVC framework Model/View/Controller i18n Internationalization ( ex:date … ) ORM Object Relational Mapping(RDB) Testing framework Framework JUnit, Cedar… Security Framework Spring Security(OAuth) Template Framework Mustache Caching Framework redis, Ehcache 6
  7. 7. Kitura Perfect Hosted IBM perfect.org latest version v0.20.0 v1.0.0 started date Feb 9, 2016 Oct 3, 2015 License Apache 2.0 Apache 2.0 MySQL O O SQLite O O Redis O O HTTP URL routing O O Parmeter Parsing O O JSON O O OAuth Kitura-Credentials - Package/3rdParty Library Many ? Swift backend framework Most popular Swift backend framework : Zewo,Vapor…
  8. 8. let swift(16) VirtualBox, Kitura, Docker https://github.com/bwahn/letswift2016-conference 8
  9. 9. VirtualBox(vagrantfile) # -*- mode: ruby -*- # vi: set ft=ruby : BOX_URL = 'https://cloud-images.ubuntu.com/vagrant/wily/current/wily-server-cloudimg-amd64-vagrant- disk1.box'.freeze SWIFT_PATH = 'https://swift.org/builds/development/ubuntu1510/swift-DEVELOPMENT- SNAPSHOT-2016-06-06-a'.freeze SWIFT_DIRECTORY = 'swift-DEVELOPMENT-SNAPSHOT-2016-06-06-a-ubuntu15.10'.freeze SWIFT_FILE = "#{SWIFT_DIRECTORY}.tar.gz".freeze SWIFT_HOME = "/home/vagrant/#{SWIFT_DIRECTORY}".freeze LIBDISPATCH_URL = '-b experimental/foundation https://github.com/apple/swift-corelibs-libdispatch'.freeze KITURA_URL = 'https://github.com/IBM-Swift/Kitura.git'.freeze KITURA_BRANCH = 'master'.freeze Vagrant.configure(2) do |config| config.vm.box = BOX_URL config.vm.network 'forwarded_port', guest: 8090, host: 8090 Swift 3.0 For Restful-APIs 9 KITURA master
  10. 10. ### # 1. Install compiler, autotools sudo apt-get --assume-yes install clang sudo apt-get --assume-yes install autoconf libtool pkg-config # 2. Install dtrace (to generate provider.h) sudo apt-get --assume-yes install systemtap-sdt-dev # 3. Install libdispatch pre-reqs sudo apt-get --assume-yes install libblocksruntime-dev libkqueue-dev libpthread- workqueue-dev libbsd-dev # 4. Kitura packages sudo apt-get --assume-yes install libhttp-parser-dev libcurl4-openssl-dev libhiredis-dev Install packages 10
  11. 11. 11 ### Download and install Kitura git clone #{KITURA_URL} -b #{KITURA_BRANCH} cd Kitura swift build -Xcc -fblocks cd .. $ vagrant up
  12. 12. let swift(16) myFirstProject
  13. 13. 13 $ vagrant ssh vagrant@vagrant-ubuntu-wily-64: $ mkdir myFirstProject vagrant@vagrant-ubuntu-wily-64: $ cd myFirstProject vagrant@vagrant-ubuntu-wily-64: $ swift package init
  14. 14. 14 $ vi package.swift import PackageDescription let package = Package( name: "myFirstProject", dependencies: [ .Package(url: "https://github.com/IBM-Swift/Kitura.git", majorVersion: 0, minor: 20) ])
  15. 15. 15 $ vi Sources/main.swift import Kitura let router = Router() router.get("/") { request, response, next in response.send("Hello, World!") next() } Kitura.addHTTPServer(onPort: 8090, with: router) Kitura.run() $ swift build -Xcc -fblocks $ ./build/debug/myFirstProject
  16. 16. let swift(16) For Docker
  17. 17. For Docker build Run a letswift-api server 17
  18. 18. 18 Docker build $ git clone https://github.com/bwahn/ letswift2016-conference.git $ docker build -t swift-api . Docker run $ docker run -d -p 8090:8090 --name api swift-api:latest image(swift-api:latest) $ docker images REPOSITORY TAG IMAGE ID CREATED SIZE swift-api latest 829e110bd520 3 hours ago 1.524 GB ibmcom/kitura-ubuntu latest 20cb1052cd2e 2 weeks ago 1.524 GB ibmcom/swift-ubuntu latest b4daffd2bbaf 2 weeks ago 1.233 GB
  19. 19. Virtual Box VM - Ubuntu $ docker run -d -p 8090 --name api1 swift-api:latest $ docker run -d -p 8090 --name api2 swift-api:latest $ docker run -d -p 8090 --name api3 swift-api:latest … … .. macOS port 8090:8090 ? => scale up $ docker-compose 19
  20. 20. let swift(16) Demo : Introduction
  21. 21. “I Hate Objective-C” Application Client : Swift 2.2 ( Cocoa- touch) Server : Swift 3 ( Kitura) 21
  22. 22. Architecture MySQL Cloud End-Point swift backend swift backend swift backend Google Container cluster Swift App 22
  23. 23. Dev/Prod Environment Virtual Box VM - Ubuntu (Swift - backend) google container registry Swift - Client Google Cloud Platform swift backend swift backend swift backend MySQL
  24. 24. 24 ================================== Description : get a number of vote Request: Verb: GET URL: http://letswift-api:8090/vote Response: HTTP code: 200 Body: { "objective-c": 100, "swift": 100 } ================================== Description : Increase a vote Request: Verb: PUT URL: http://letswift-api:8090/votes/objectivec_voted Request: Verb: PUT URL: http://letswift-api:8090/votes/swift_voted Response: HTTP code: 200
  25. 25. let swift(16) Let’s vote! 25
  26. 26. 26 let swift(16)

×