This tutorial will walk you through deploying your first Vapor app to Vapor Cloud.
vapor cloud deploy inside your Vapor project (in the same folder as
Package.swift) and follow the instructions.
If you haven't already, sign up for a Vapor Cloud account here.
Vapor Cloud applications are deployed through the Vapor Toolbox.
Verify that the toolbox is correctly installed by calling the help command.
vapor cloud --help
Create an Organization¶
If you didn't already create an organization during the signup process, create one now.
You can do this through the toolbox
vapor cloud create org or through the dashboard.
Create a Project¶
You can do this through the toolbox
vapor cloud create proj or through the dashboard.
Projects help organize related applications. You can invite individual users to your projects and assign read, write, or admin permissions. You can even create teams of users and add those to your projects.
You cannot assign different permissions to each application, only to a project. So feel free to create as many projects as you want for your permissioning needs.
Now that we have created an Organization and Project, we can begin our first deployment.
To deploy your app, your code needs to be available through Git. The easiest way to do this is through GitHub.
The toolbox will automatically walk you through this process and the other required steps to deploy your first app.
Let's get started.
vapor cloud deploy
Create Git Remote¶
The easiest way to host code for your deployed project is as a public repo on GitHub.
If you would like to use this method, respond
yes to the first prompt. GitHub will be opened automatically.
Once you have created your new repository (or using an existing) copy the SSH (not HTTP) url into the next prompt.
After the Git remote has been added, you can create your first application. Each application can have multiple services, such as hosting, databases, caches, and more.
Not every Vapor Cloud application needs to have hosting. For instance, you could create a Vapor Cloud application that just consists of a MySQL database for your own use.
However, in this tutorial, we will be creating an application with hosting.
Respond yes to the prompt to create an application. Give it a name, and a slug.
Application slugs will be used to access your app on Vapor Cloud. If you use the slug
foo, then your application would
be accessible at
If you create environments besides
dev, then you can access those separate environments using a
- suffix. For example,
As we mentioned in the previous section, we will be adding the hosting service to our application to host our Vapor app.
yes to the prompt to create hosting, and select the Git URL that we just added previously.
The hosting service can have unlimited environments. This is useful for creating environments like testing, staging, devlopment, and more.
For now, we will create our main
production environment. This environment is special because it is not followed by a suffix in the
To create this special environment, ensure the environment name is exactly
After you have named your environment, choose the branch it will deploy from. This is usually the
master branch for
You can host your project for free with the
Free size replicas. This size has a monthly request limit, but is free forever. Select the
Free size for this environment.
Add Database (Optional)¶
Next you will be asked if you'd like to add a database. If your application will need a database, you can do this now.
Otherwise, ignore the prompt. You can always add a database later using
vapor cloud create db.
If you do add a database, the environment variables to access the database will be exposed to your Vapor application's config.
See the MySQL Guide for more information about accessing these variables.
For high availability and throughput, Vapor Cloud allows you to deploy your application to multiple replicas. However,
for Free size replicas you are limited to
1 replicas. If you set the replica count to
0 your application will be taken offline. If you set it to
1 it will be online.
The replica count will automatically be set to
1 for a new application. You can use the
--replicas= flag to change this in future deployments.
The Swift Package Manger 3.1 allows a few different ways to build your application.
Vapor Cloud simply runs
swift build on your application. Dependencies are not updated. This is the fastest method for subsequent deploys.
Vapor Cloud runs
swift package update before running
swift build. This option is slightly slower than incremental, but required if you have modified your
Vapor Cloud deletes all build metadata (such as the
.build folder) then runs
swift build on your application. This option takes a considerably longer amount of time than update or incremental, but can sometimes fix strange build issues.
Verify that the information is correct and deploy your application! Once your app is deployed, you will get a URL to visit in your browser.
Congratulations on deploying your first app through Vapor Cloud.
Please let us know if you have any ideas or feature requests through https://ideas.vapor.cloud.
Also free free to chat with one of us through the chat feature (blue bubble in lower right corner) in https://dashboard.vapor.cloud.