Deployment of a Vapor Application

Deployment of a server side swift app, really a different game, not like creating a release build for an iOS.
At least no issues with provisioning profiles, codesign and the other niceties Xcode throws at you when creating a release build. There are other issues, though…

Today I set up the Ubuntu server to host the server side Vapor build app.  So after kicking off the VPS, I first opted to start with Ubuntu 1804 LTS. Let’s see where it takes me. Well, after the normal hardening of the any server:

  • Disable SSH root login
  • Setup UFW
  • Setup SSH Key Based Authentication
  • Nginx setup as reverse-proxy to the application.
  • Hardened TLS setup for Nginx.

I installed Swift, checked out the code, and tried to build the project. Sadly no luck, a quick search revealed that Ubuntu 1804 LTS will hold support for Swift 4.2. Since that one is in Beta, better not go there just yet.. So re-start the VPS installation and this time with Ubuntu 1604 LTS. Probably better luck there…

So after the same steps, this time the compilation works, and when I run the application, it works!. Cool let’s test the API calls, using Paw, and yeah it really works. Now we need to make sure are able to run the app unattended.  Thanks to this post, I figured out that I needed to add Supervisor to the equation.  Installed supervisor as advised.  Trying to start the supervisor application. Now the problem started… The Vapor does want start. I keep on getting the same error: “FATAL Exited too quickly (process log may have details)”. Sadly the log files do not really help..  After some digging I realised that the Vapor app by default is running under localhost, could this be the culprit? How can we start the Vapor app so it is not bound to localhost but to instead.

So I created this config for Vapor:

services.register(Server.self) { container -> NIOServer in 
   var serverConfig = try container.make() as NIOServerConfig 
   serverConfig.port = 8080 
   serverConfig.hostname = "" 
   let server = NIOServer( config: serverConfig, container: container ) 
   return server 

Now it starts and runs properly.  Bonus of this config is that you also easily change the port of the App.


All in all a nice exercise in getting the Vapor 3 based app deployed.