Notes on Releases

Releases allow developers to precompile and package all of their code and the runtime into a single unit.

Elixir and Erlang VM are packaged within a release and don't need to be installed on the target machine. Releases have very much simplified how Elixir applications are deployed and managed in production.

Release Commands

In the build script, you may have noticed we have the line that runs a migrate function in the Render.Release module. Here's the purpose:

Another common need in production systems is to execute custom commands required to set up the production environment. One of such commands is precisely migrating the database. Since we don't have Mix, a build tool, inside releases, which are a production artifact, we need to bring said commands directly into the release.

To add the custom module, create LIB_PATH/release.ex with this content:

Render.com Setup

With our github repo ready, you can register on render.com using your Github account.

Create a DB Service:

Dashes aren't accepted, use underscores

Create Web Service:

And while that's creating, create the web service under Services -> New Web Service and select the repo created earlier. If you didn't connect your Github account, you can still do it now.

Name: `<something-unique>`

Environment: Elixir

Branch: master

Build Command: ./bin/render-build

Start Command: _build/prod/rel/render/bin/render start

Hit create the service and it will fire off an initial attempt to deploy the app.

You'll likely see an error in the log:

Which means our app can't connect the database. This is expected because we haven't configured it yet.

Environment Variables

We're going to configure a few environment variables necessary to run the app.

Navigate to the "Databases" section of the render.com dashboard, and select the DB you just created.

Then copy the "Internal Connection String":

render.com database dashboard

Then navigate to the services section and select your newly created service.

Hit the "Environment" tab:

Where we can enter DATABASE_URL and the "Internal Connection String"

Next we can generate a new secret key using:

$ mix phx.gen.secret

And set SECRET_KEY_BASE to the output value.

Test it out

If you monitor the deployment log, there shouldn't be any issues at this point and we have our first release in production.

You can test it out by visited the service url in the browser.

Auto Deploy

In the settings section for your app you can toggle auto-deploys on commits. Any changes made to the environment variables will also trigger a deployment.

Conclusion

We really enjoy working with render.com and though there are many other options for deployment, we're finding that $14/mth is a small price to pay for a solid, production ready deployment pipeline.

There are many other features that we didn't get to in the guide such as PR deploys/review apps, background services and the infrastructure as code using yaml files, but maybe we'll dive deeper into these features if there's enough interest.

I hope you enjoyed this guide and let us know if you have any questions for feedback on how to improve it.