If you're going to server-side swift... • Look at https://github.com/vsouza/awesome-ios • ~16 OSS options listed • Why not use something that claims it's elegant? Based on the PHP micro-framework Lumen. • https://github.com/qutheory/vapor
Install the right swift version... and build • $ cat .swift-version • $ swiftenv install DEVELOPMENT- SNAPSHOT-2016-03-24-a • $ vapor build • $ .build/debug/App Run the server Verify what version is needed
https://en.wikipedia.org/wiki/LXC "LXC (Linux Containers) is an operating-system- level virtualization method for running multiple isolated Linux systems (containers) on a control host using a single Linux kernel."
Why use a container? • More lightweight than full fledged virtual machines: "better utilization" • Single artifact through the entire development process. Dev equals Prod!?! Easier deployment?!? • Better abstraction. Don't think of where the app runs (the server), think of the service the app provides.
What's Docker? • Open-source tooling (and a private company) to help package apps using containers. • Funky layered filesystem that's hard to grok. • Much improved Mac beta on the way* • Until then: https://docs.docker.com/mac/ *https://medium.com/@nzoschke/docker-for-mac-beta-review-b91692289eb5
Docker app image: best practice Base Image Main Image Runtime environment Ubuntu + Swift + Deps App environment Just the compiled vapor app https://blog.newrelic.com/2015/06/18/zero-to-docker/
App Dockerfile (app) The default Dockerfile that comes with a vapor-CLI generated app, except we're using a custom build of the swift development snapshot (smithclay/swift:v03-23-a) vapor needs.
Build it, run it # Build image of current vapor app, tagged v1 $ docker build -t smithclay/helloswift:v1 . # Run container on port 80 $ docker run -d -p 80:8080 smithclay/helloswift:v1 # Verify. Did it work? # Can also just open Safari :) $ curl -s -D - $(docker-machine ip) -o /dev/null
What's Kubernetes? • Open-source system to manage apps in containers across multiple servers. From Google originally.* • Handles the hard part of building distributed systems: maintenance, deployment, scaling, etc. • Definitely overkill for small and simple stuff. http://queue.acm.org/detail.cfm?id=2898444
Lessons • Containers are great for portability across different clouds, environments, etc. • Containers hide the complexity of building deploying server-side swift. • Kubernetes is definitely overkill for "Hello World" in Swift. • Not mentioned: logging, security, monitoring, health checks... you get the idea.