First time at Zeet?

17 Oct
2020
-
4
min read

Deploying a Phoenix app

Johnny Dallas

CEO & Co-Founder, Zeet
How To
Content
heading2
heading3
heading4
heading5
heading6
heading7

Share this article

This guide will walk you through deploying a Phoenix project (with a database!) to production on Zeet.

Finished code from this demo is available here!

Setup

If you already have a Phoenix app, feel free to skip this section!

Pre-requisites

First things first, you're gonna need to install some tooling. If you haven't already, install Elixir and NodeJS.

We'll also need to grab the Hex package manager, and install the Phoenix application generator:

mix local.hex
mix archive.install hex phx_new 1.5.6 # version is optional

Install hex and Phoenix

Creating our app

Now that we have everything installed, let's setup a Github repo for it, and psuh some code!

Make a new Github repository

Now all we have to do is generate our app and push it to Github!

mix phx.new zeet_hello # When prompted, press Y to fetch and install dependencies
cd zeet_hello
git init
git remote add origin git@github.com:username/repo.git # NOTE: change username to your github username, and repo to your newly created repo name!
git checkout -b main
git commit -m "Initial commit"
git push -u origin main

Generate and push your code

Getting Production Ready

Now that we have our project generated, let's deploy it to Zeet and setup a database alongside it!

Setup a private database

Phoenix projects usually come with a database, so you can store information about your users / app. Zeet makes it super easy to deploy a PostgreSQL database alongside your Phoenix application!

Click here for instructions on deploying a private database alongside your Phoenix application – it's only 1 click!

Deploying the app!

Last but not least, let's deploy this app 😤

Let's link our new Github repo to Zeet. Click New Project -> Github on zeet.co and look for your new Github repository.

If you don't see your repo, click Manage Repositories and make sure Zeet has access to your Github repository. We recommend checking the "All Repositories" option to make this easy in the future!

Click that beautiful "Deploy Now" button and we're off to the races! Right away, Zeet will start building and deploying our project.

If you click on the Settings tab, you'll see Zeet configured almost everything for our project!

So configured, so little work 🤩

Connecting to the database

There's one more step before we're all done: we need to connect this new project to our database!

Scroll down to the Environment Variables section – the DATABASE_URL is empty 😢

Database-senpai... where are you? 🥺

Phoenix uses Ecto as a database driver. Ecto needs a special URL in the form of

ecto://USER:PASS@HOST/DATABASE

We're going to need 4 things from our database project:

  1. Private Endpoint
  2. Username
  3. Password
  4. Database name

Luckily, Zeet makes this super easy! Go back to your database project, and the Private Endpoint is right there! This tells your app how to communicate with the database.

On your postgres Overview tab, look for Private Endpoint

The Username, Password, and Database name are in the Settings tab

The values are hidden by default for security, hover to reveal

Great, we have everything we need. Let's put it all together into a DATABASE_URL. Remember, the format is

ecto://USER:PASS@HOST/DATABASE

For this example, my DATABASE_URL is

ecto://postgres:u2D2dp6XwQ@zeet-hello-postgres-production/postgres

Paste your URL into your Phoenix project's Settings tab and click Save

Don't worry! Since this database is private, even with the password being published I'm secure

All done!

Click the Visit button in the top right corner, and see your app in action!

Subscribe to Changelog newsletter

Jack from the Zeet team shares DevOps & SRE learnings, top articles, and new Zeet features in a twice-a-month newsletter.

Thank you!

Your submission has been processed
Oops! Something went wrong while submitting the form.