Server Side Swift with Vapor: Deploying to Heroku | Ray Wenderlich

In this screencast you'll learn how to deploy a Vapor app using PosgreSQL to a production environment using Heroku.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/5005-server-side-swift-with-vapor-deploying-to-heroku-with-postgresql

Awesome, as usual. Thanks

ā€“ Pourpre

Thanks for another great tut :slight_smile:

Thought Iā€™d add the commands used, for reference, I donā€™t use git/heroku enough to remember :stuck_out_tongue:

git init
git add .
git commit

Add in your message

"Commit Message"
<Esc>
:wq

Now setup the project for Heroku

vapor heroku init

Answer the questions

n | n | n | n

Add postgres to the app

heroku addons:create heroku-postgresql:hobby-dev

Update the Config file to use the DatabaseURL

heroku config

Update the Procfile

vi Procfile
--config:postgresql.url=$DATABASE_URL
<Esc>
:wq

Commit your changes

git status
git add .
git commit

Add your message

"Modified procfile"
<Esc>
:wq

Now push and wait

git push heroku master

Nice thanks for doing that Alex! That looks like it might be handy for folks who come across this in the future.

1 Like

Do you have a screencast: ā€œServer Side Swift with Vapor: Deploying with Dockerā€?

Hi. Sorry for asking this question here but I didnā€™t find the correct place to ask the question. Have any of you tried out Perfect server and what do you think about it? Am trying to Start Swift server side development but I really need to choose the best tool for this. Any input will be highly appreciated.

@tof Not yet but I agree that would be awesome to make!

@gutenberg Havenā€™t tried out Perfect myself yet. But in case it helps, hereā€™s a quote from @sebastian on the Vapor Slack about his 2c on the various frameworks:

Perfect - Perfect is older and it was first but it was pre-Swift 3 so it does not count I guess. IBM Kitura was started with a big hype and generally puts a lot of attention of server-side Swift which is awesome. But: and yes, there is a big BUT: Vapor is from all 3 the best choice because it is developing faster, more open and with a much stronger community than Perfect or IBM. Additionally, the internals also look much more healthy and powerful and Logan and Tanner are great as project owners.

How I can do the same for MongoDB (mLab) just for Procfile settings?

Hi,

I followed the tutorial but ran into the following issue with my app.

git push heroku master
remote: ! No such app as salty-crag-95408.
fatal: repository ā€˜Deploying with Git | Heroku Dev Centerā€™ not found

I had deleted the ā€˜salty-cragā€™ app. Is there any way to change the Heroku app that Vapor deploys to?

@rafael_yami I havenā€™t looked into MongoDB so am not sure, but maybe someone else can answer.

@agaba This may help: git push heroku master error: Repository not found - Stack Overflow

I worked through the Vapor screencasts, and my app runs fine locally, using a local postgresql database.

However, when I deployed it to heroku, the logs on Heroku are showing this:

2017-01-11T17:36:13.336738+00:00 heroku[web.1]: Process exited with status 132
2017-01-11T17:36:16.486617+00:00 heroku[web.1]: Starting process with command App --env=production --workdir=./ --config:servers.default.port=5614 ā€”-config:postgresql.url=postgres://yxbtoxwlxquvyw:4810659c75b2608b64754ee6de7015ef07bd8768f34aad89a7ec687aeedb7326@ec2-23-21-46-94.compute-1.amazonaws.com:5432/d51nbt8v8s68c4
2017-01-11T17:36:18.996590+00:00 app[web.1]: fatal error: Error raised at top level: VaporPostgreSQL.Provider.Error.noPostgreSQLConfig: file /home/buildnode/disk2/workspace/oss-swift-3.0-package-linux-ubuntu-14_04/swift/stdlib/public/core/ErrorType.swift, line 184

To me, this means Iā€™ve screwed up the configuration for the app on Heroku somewhere. Anyone have any ideas what Iā€™ve done wrong?

Thanks in advance,

Iā€™m interested in trying this out as I want to start doing server side development in swift. However, I am having an issue even building the project. I get an error when the PostgreSQL target builds as it canā€™t locate the CPostgreSQLMac module. Iā€™m having trouble finding a framework for this module anywhere. Any advice? Thanks!

hi ray my local postgreqsql workes just fine but after depoloying to heroku i try to save some data i get this error back
{
ā€œcodeā€: 500,
ā€œerrorā€: true,
ā€œmessageā€: ā€œThe operation could not be completedā€,
ā€œmetadataā€: null
}
any clue why is that?

Thanks for take the time to make this tutorial. I just wanted to comment for those watching that I had an issue with trying to run ā€œvapor heroku initā€ :- it was giving me an error ā€œUnable to connect to Heroku API, please check internet connectivity and try again.ā€

After digging for a couple of days, I finally discovered that the default path in the terminal was the problem and that it didnā€™t point to the version of the heroku command I had intended. This was because a few years back I did a tutorial on Ruby On Rails that changed the path and inserted a different version at the beginning of the path. So finding where the .bash_profile had been changed and reverting that fixed the issue.

I am having a similar issue. Works fine locally, then when deployed it fails.

2017-02-07T22:46:47.133573+00:00 heroku[web.1]: Starting process with command App --env=production --workdir=./ --config:servers.default.port=22759 --config:portgresql.url=postgres://fpqiljwmplazex:8a2b730cbfb62f65678aac5054ff263d420ae521e283cc572cae3ab762b45151@ec2-23-21-76-49.compute-1.amazonaws.com:5432/denrli797vo73s
2017-02-07T22:46:49.241878+00:00 app[web.1]: Production mode enabled, disabling informational logs.
2017-02-07T22:46:49.253625+00:00 app[web.1]: Could not initialize provider Provider: noPostgreSQLConfig
2017-02-07T22:46:49.255083+00:00 app[web.1]: No command supplied, defaulting to serveā€¦
2017-02-07T22:46:49.255254+00:00 app[web.1]: Can not run preparations, droplet has no database
2017-02-07T22:46:49.347605+00:00 heroku[web.1]: State changed from starting to crashed
2017-02-07T22:46:49.337843+00:00 heroku[web.1]: Process exited with status 1
2017-02-07T22:47:16.809194+00:00 heroku[router]: at=error code=H10 desc=ā€œApp crashedā€ method=GET path=ā€œ/allā€ host=vast-cliffs-48348.herokuapp.com request_id=5e84716b-fcc8-4c1a-a1db-e7da56b58cb3 fwd=ā€œ88.3.87.40ā€ dyno= connect= service= status=503 bytes=

anyone have an idea how to investigate this?

It turned out there must have been a typo of some kind in my Procfile, even though there were no differences that I could see.

I ended up copying the contents from the Procfile in this link, and everything deployed and worked fine.

Postgresql works fine locally. But after deploying it on heroku im getting error

Production mode enabled, disabling informational logs.
2017-02-20T05:48:24.663363+00:00 app[web.1]: fatal error: Error raised at top level: VaporPostgreSQL.Provider.Error.noPostgreSQLConfig: file /home/buildnode/disk2/workspace/oss-swift-3.0-package-linux-ubuntu-14_04/swift/stdlib/public/core/ErrorType.swift, line 184