Phoenix with PostgreSQL
Phoenix is a web development framework written in Elixir, designed for building scalable and maintainable applications. This example demonstrates how to deploy a Phoenix application with a PostgreSQL database on Unikraft Cloud.
This example app has been generated using Phoenix Express, and the Dockerfile used for building the rootfs was generated following the instructions here.
To run this example, follow these steps:
-
Install the CLI. Use the unikraft CLI or the legacy kraft CLI. You need a BuildKit builder. The easiest way to get one is via Docker. Alternatively, you can also directly set up and use BuildKit, see the quick start.
The unikraft CLI is the current standard, while kraft is the legacy version. Choose one of the CLIs below and only run the commands associated with it for the rest of this guide.
-
Clone the
examplesrepository andcdinto theexamples/phoenix-postgresdirectory:
Code
Make sure to log into Unikraft Cloud and pick a metro close to you.
This guide uses fra (Frankfurt, 🇩🇪):
Create a volume for PostgreSQL data persistence:
Build and deploy the PostgreSQL instance.
Update POSTGRES_PASSWORD with a secure password:
Make sure to replace <my-org> with your username / org-name.
The output shows the PostgreSQL instance details:
Build and deploy the Phoenix instance.
Generate a secret key for Phoenix:
Code
Replace <your-secret-key-base> in the commands below with the generated value, and update the password in DATABASE_URL to match the one set for PostgreSQL:
The output shows the instance address and other details:
In this case, the instance names are postgres-ik5at and phoenix-hd29m.
They're different for each run.
Use a browser to access the Phoenix application using the URL from the fqdn field in the output.
You can list information about the instances by running:
When done, you can remove the instances:
Volume
This deployment creates a volume (db-data) for PostgreSQL data persistence.
The volume persists after removing instances, allowing you to redeploy without losing data.
To remove the volume:
Learn more
- Phoenix's Documentation
- PostgreSQL's Documentation
- Unikraft Cloud's Documentation
- Building
DockerfileImages withBuildkit
Use the --help option for detailed information on using Unikraft Cloud:
Or visit the CLI Reference or the legacy CLI Reference.