Deploy your server-side swift project to Vapor cloud

Testing Vapor cloud for hosting a server-side Swift application. Last week I watched Tanner Nelsons try!Swift NY talk about Vapor. Tanner is the person behind the Vapor framework, so I was pretty excited when someone tweeted the talk. I’ve been keeping my eye on server-side Swift development for about a year now and especially on Vapor. I haven’t used it for any commercial app yet, but I’ve had a project running on Heroku for almost a year. Incase you want to know more checkout: Friend service . It works as a backend for an example Friend application. It’s designed with MVVM and I created it for an example project of the architecture.

Today Friend service also runs on Vapor cloud! Or atleast it was running for a little while, and then I discovered the free beta period was already over…

What is Vapor cloud?

Vapor cloud is a hosting service built by Vapor team. The service uses AWS S3 for data storage. It also has Swift installed as default to make deployment of your project as smooth as possible. Another great thing is that it configures your database for you. This means that your service is up and running after answering a few command line questions. All you need to have is a git repository that holds your code and you are ready go.
I was so excited when I spotted the service that I had to give it a try as soon as possible. So let’s dive in and see how to deploy an application.

Getting started with Vapor cloud

I assume that you have your project up and running in localhost so I am not going explain how to do that in this article. (check how to set up backend with swift if you want to know more about setting up a project)

There are few steps you need to make to get service up and running:

  1. Sign-up to Vapor cloud
  2. Set up a git repository
  3. Update Vapor
  4. Deploy using the command line

Sign up for Vapor cloud

First thing you need to do is to create your profile on vapor cloud: Click sing-up and follow the instructions. After completing the sign up process, you’ll see the dashboard of Vapor cloud.

Vapor could dashboard

Vapor cloud dashboard

On the menu on the left side you can see the dashboard icon, organisations and your profile. I created and organisation named “SwiftyJimmy”. I also a project called “Swifty Jimmy Applications”. Inside a project you can have many applications, but let’s not create the app yet. It is actually very easy to do on the command line, so let’s do it from there.

Git repository

There are plenty of tutorials about git, so I am not going to explain it here. I have mine in GitHub: FriendService. Incase you want to deploy your own project, make sure you have a git repository.

Update Vapor

Now, make sure to update Vapor to have all the tools up to date. You can do that by typing in terminal:

Incase you don’t have homebrew installed, you can install it from their homepage.

Deploy your project to Vapor cloud

Last step we need to make is to deploy the project. This is actually so easy that it took me less than 30 minutes from the opening of the documentation, to have the service up and running. Open your terminal on your project folder and start deployment by typing:

Incase you are not logged in to the cloud, Vapor asks for your emailaddress and password. Type those and you are good to go.
Next, command line tools will ask you few questions about the setup. Answer yes to the features that you want and provide all the other information that Vapor needs. Let’s go through some of the questions with more detail.
Vapor cloud deploy to production

Choosing production environment

If you need a staging service for development, type in “staging” or “development” or other name that you like. The image shows how naming affects the service. I don’t need a development build at the moment so I chose production.
When you configure the replica size and database, it also shows you the monthly fees:
vapor cloud replica fees

vapor cloud replica fees

Free replica can only have 1 tear at max and it also has a monthly request limit, but it is free forever. Since the service is not going to be used in any real application, let’s go with the free plan.

vapor cloud database monthly fees

vapor cloud database monthly fees

As you see, databases cost 7$/month. This actually was a bit confusing for me since I didn’t have to give any credit card info. Still I was able to use the service. After the service had been running for a while Vapor shut it down. I was a bit confused why this happened. At this point I thought the service was still in beta. The explanation came the day after when I received an email that I had “negative account balance”. I didn’t add any credits to the service, and since database is not free, the service
was shut down.

Last thing to do is to select which type of deployment you want: incremental, update or clean. Incremental builds the code. Update also updates depencies. Clean also cleans the project before building. I selected the clean build, but you can go with the one you want.
vapor cloud deployment complete

vapor cloud deployment complete

And after 5-6 minutes the deployment is done! You can check the service up and running in here:


The deployment process is super easy! It was quick and easy and fast and, did mention it was easy? It also lacked the usual “What now?!” -moments, which I had plenty with Heroku. Deployment to server and running web apps is not my comfort zone. I think that was the biggest reason I had to spend some time with Heroku. If you want to know more about vapor cloud, check the documentation. There is plenty of good information there and this post was only a scratch on the surface.

The web page wasn’t the most intuitive that I’ve seen. I had to spend some time to find how to stop and delete the service when I decided to write this post. I wanted to record and document the steps so I wanted to start over. The menu on the left side has different items depending on where you are on the service. This led to a situation like “where is that item now?” when I opened another page. I also had to delete the database manually, and set the replica count to zero before I was able to delete the service. I couldn’t find where to set the replica to zero from the page, but you can do it from the terminal with a command:

I need to play around a bit more with the page to be familiar with it. In the mean time, the right hand side message center is very helpful. Vapor team answered to my questions the next day, when I asked why I was being charged from beta service. They also told me that they are launching “first beta of a completely new and more flexible database setup, that includes a free plan”. It will be available for sign-up with the next Vapor tools update.
That was all that I wanted to cover with this post! Incase you liked the post, make sure to check also my other posts about server-side Swift. Thank you for reading and have a great day my friend!

Leave a Comment

Your email address will not be published. Required fields are marked *