Deploy your Server-side Swift App to Heroku
You finished implementing your Server-side Swift App.
Everything works well in localhost
. Now you want to sent it off to Heroku so that you can share your app with the world.
Here is the guideline to deploy your Swift App to Heroku.
Prerequisites
- Register a free Heroku Account here.
- Install Heroku CLI
Check if you have Heroku CLI installed in your machine, try to login
heroku login
If now, follow steps in this link to install it.
In macOS, easily install via Homebrew:
brew install heroku/brew/heroku
Remember run a login command after you installed it.
Create Procfile
Heroku uses Procfile to specify the commands that will be executed.
Create a new file, named it Procfile
, in the root of your project. Add the following to it.
web: myProjectName
Replace myProjectName
with your Package Name (defined in Package.swift).
Learn more about Procfile here.
Create App in Heroku
In your project folder, run the following command to create an app in Heroku.
heroku create --buildpack https://github.com/kylef/heroku-buildpack-swift.git
Buildpacks is a set of scripts that help deploying your app.
Currently Heroku doesn’t have official Buildpacks for Swift. So we use an open source one.
Learn more about Buildpacks here.
Push your code to Heroku
Remember to commit all your code to master
branch, and push it to Heroku.
git push heroku master
This command does not only push your code, but also start your app. It will take some minutes to finish.
Open your app in browser
heroku open