Deployment
How to get your app running in production
Was this helpful?
How to get your app running in production
Was this helpful?
Before deployment, we've found an issue in production with the new content security policy headers. Basically, you need to add wss://...
and your domain to the :content_security_policy
default_src
array, like below.
Read more:
If you don't care about content security policies, you can remove this config and then in router.exs
change:
We have found Fly.io to be the best combination of cheap and easy. Petal Pro has been set up for users to quickly deploy on Fly.io's servers.
Once signed in, you can create a new project with:
fly launch
Give your app a name (this can't be changed in future).
Under Database, choose "Fly Postgres", as we'll need that.
Pick a server size - we usually go with the cheapest configuration.
You can leave Redis as none.
Hit Confirm.
At this point, it may try to generate and deploy the app, but will fail, as we haven't told Fly to add our "petal" repo. See the section below on what to do next.
In the generated Dockerfile you may need to add a small change to properly compile the assets.
Change:
to:
To be able to register/sign in, we'll need to ensure email is set up and we'll need a service to send our emails out. We've found that the simplest and cheapest solution is Amazon SES, and so Petal defaults to using this. Look in runtime.exs
to see the setup:
We don't really use Amazon for much else, but its email service is cheap and the emails don't get sent to spam as easily as other services we've tried (cough cough Sendgrid).
Since Petal Framework is not coming from hex.pm, we need Fly to know to add our Petal registry.
After running the fly launch
command above, Fly has generated a dockerfile in the root of our project.
Open Dockerfile
and search for this bit:
Before those commands are run, we need to add the Petal repo. So, above this block of code you want to add the Petal repo:
You may also need to add RUN mix assets.setup
to the compile assets block of code.
Finally, we can run fly deploy --build-secret PETAL_LICENSE_KEY=<your key>
After deploying you can run fly open
to see it in your browser.
If you haven't already, download the . Then you will need to .
Setting up Amazon SES is beyond the scope of this tutorial. You can read their docs to set it up. The end result should be you are able to provide the following secrets that we'll provide to our production server:
If you don't want to use SES you can switch to a .
Petal Framework is a hex package like any other. The only difference is the repo that you fetch it from. Normally your hex packages are fetched from . But Petal Framework is fetched from our private registry. We need to let Fly know about this.
You can see your key in the on Petal (see Step 1 and copy the key written after "--auth-key").