Elixir and Phoenix are now officially supportedBy Laurent Doguin,
Today we officialize our support for Elixir and Phoenix!
We have been testing this with some of our customers for quite a while now. So there it is, you can now deploy any Elixir code, like a Phoenix based website for instance. But first, if you are not familiar with both Elixir and Phoenix, let's see what it is.
Straight from Wikipedia:
Elixir is a functional, concurrent, general-purpose programming language that runs on the Erlang virtual machine. Elixir builds on top of Erlang and shares the same abstractions for building distributed, fault-tolerant applications. Elixir also provides productive tooling and extensible design.
Yes, it's using Erlang. The language and VM that powers, among others RabbitMQ, CouchDB, Facebook/Whatsapp messaging backend, and many Telcos backend. We are talking massive scale, concurrent usage here. To go back to elixir, here's what some simple code looks like:
defmodule KVTest do use ExUnit.Case def hello do :world end test "greets the world" do assert hello() == :world end end
It feels like a functional Ruby.
Elixir applications use the Mix build tool as a task runner. With that, you can scaffold projects and code, compile, test, run, manage dependencies, run database migrations, and more. Everything runs on top of OTP (Open Telecom Platform), a set of Erlang libraries and tools. And inside OTP you will find BEAM, the virtual machine that compiles Erlang and Elixir source code into bytecode and run it. So this is what you have access to when you run and Elixir application on Clever Cloud.
The most wide-used Elixir Framework is Phoenix. It feels like Ruby on Rails. And this is what we'll see how to deploy today. If you want to follow, make sure you have installed clever-tools and Mix
mix phx.new hello # generate a project, say Yes to Fetch and install dependencies. clever addon create postgresql-addon hello-phoenix-pg # create a postgres database clever create --type elixir hello-phoenix # create an erlang application on Clever Cloud clever service link-addon hello-phoenix-pg # link the database clever env set CC_PHOENIX_ASSETS_DIR assets # Tell Clever Cloud where to run the js build
This will generate all the code you need to start a Phoenix application. Just like Rails, there are other tasks you can use to generate code. Take a look at the list of available tasks.
Next, we should configure the database access. By default the DATABASE_URL variable is defined in
./config/prod.secret.exs. In this file you will define all the secrets, which is to say anything that should not be hardcoded in your configuration files. The DATABASE_URL should be changed to POSTGRESQL_ADDON_URI, which is what will be available in your app. There are three other variables we can use in this file. The PORT is already configured, we just have do set a secret and a pool size limit:
clever env set SECRET_KEY_BASE Th3S3Cr3t clever env set POOL_SIZE 5
And now all there is to do is run these:
git init # initialize a git repository git add . # add all the files git commit -m"init" first commit clever deploy # push your code to Clever Cloud clever open # open the site in your default browser
And you should see the Phoenix default app running :) As with most applications running on Clever Cloud, you can configure your build and deployment through environment variables. Here's the current list of options:
|CC_ELIXIR_VERSIONChoose the Elixir version between '1.8' or||
|CC_PHOENIX_ASSETS_DIRFolder in which your Phoenix assets are located.|
|CC_PHOENIX_DIGEST_GOAL||Phoenix digest goal.||phx.digest|
|CC_PHOENIX_SERVER_GOAL||Phoenix server goal.||phx.server|
|CC_PHOENIX_RUN_ECTO_MIGRATE||Whether to run 'mix ecto.migrate' or not.||true|
Now you know all the basics to start an Elixir or Phoenix project. Have a look at some other Elixir frameworks like the Bot Framework Hedwig or the simpler web one like Raxx, trot or Maru. Please let us know what you think about this :) Happy hacking!
By clicking "Get started" I agree to Clever Cloud's Terms and Conditions
Head of Developer Relation @clever_cloud. Devoxx Champion. I am also a nerdy metal head living in Paris.