-
Notifications
You must be signed in to change notification settings - Fork 172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
recap elixir deployment #61
Changes from all commits
7ff0854
9726d29
1dae3fb
7c9cf6b
1d9f7f5
c435b2e
9c86ef4
a5faf40
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
# Deploy an Elixir or Phoenix application | ||
|
||
This markdown summarises the research done | ||
on how to deploy a Phoenix application. | ||
|
||
|
||
## PaaS vs VPS | ||
|
||
In the past we have mostly used Platform as a Service (PaaS) providers | ||
to deploy Elixir applications. The main advantage of PaaS | ||
is it is quick to setup and have your application running | ||
for your users. | ||
However in the longer term using a PaaS can become costly (per unit of compute e.g. RAM/CPU). | ||
Virtual Private Server are in contrast normally cheaper to run | ||
but require more setup time and DevOps knowledge to maintain. | ||
|
||
### PaaS | ||
|
||
#### Heroku | ||
|
||
We are used to deploy Elixir/Phoenix on Heroku | ||
and we have already a ["how to"](https://github.com/dwyl/learn-phoenix-framework/blob/master/heroku-deployment.md) guide of this process. | ||
|
||
However there are some limitations when using Heroku with Phoenix (see https://hexdocs.pm/phoenix/heroku.html): | ||
![image](https://user-images.githubusercontent.com/6057298/83642784-2e1d1200-a5a7-11ea-8c97-9c7dd920469c.png) | ||
|
||
pricing: | ||
![image](https://user-images.githubusercontent.com/6057298/83641712-cc0fdd00-a5a5-11ea-8cbf-49981ae3747e.png) | ||
|
||
The pricing above doesn't include the database which needs to be added to the total cost, see https://elements.heroku.com/addons/heroku-postgresql | ||
|
||
|
||
### Gigalixir | ||
|
||
Similar to Heroku [Gigalixir](https://www.gigalixir.com/) provides | ||
a platform which focuses _exclusively_ on deploying Elixir/Phoenix application. | ||
Having an exclusive focus on deploying Elixir Apps gives Gigalixir several key advantages: | ||
1. Zero-downtime blue-green continuous deployment. | ||
see: https://martinfowler.com/bliki/BlueGreenDeployment.html | ||
2. No limit to concurrent connections. | ||
3. All clustering handled transparently. | ||
(so if you need to scale your app beyond 10k concurrent users, | ||
you don't have to pay exponentially more for bigger "dynos" | ||
the way you are forced to scale vertically on Heroku) | ||
|
||
Deploying: https://elixircasts.io/deploying-with-gigalixir-%28revised%29 | ||
|
||
Pricing: | ||
|
||
![image](https://user-images.githubusercontent.com/6057298/83643629-290c9280-a5a8-11ea-89da-648daec204f3.png) | ||
|
||
Gigalixir vs Heroku: | ||
|
||
![image](https://user-images.githubusercontent.com/6057298/83644108-d1225b80-a5a8-11ea-869a-c8c0e4a28012.png) | ||
|
||
Like Heroku you need to add the cost for using the database: | ||
|
||
![image](https://user-images.githubusercontent.com/6057298/83644296-09c23500-a5a9-11ea-9fdd-c50532195c95.png) | ||
|
||
see also tiers pricing page: https://gigalixir.readthedocs.io/en/latest/tiers-pricing.html | ||
|
||
|
||
### Render | ||
|
||
[Render](https://render.com/) is another Paas similar to Heroku | ||
|
||
pricing: | ||
|
||
![image](https://user-images.githubusercontent.com/6057298/83645052-e9df4100-a5a9-11ea-8d3e-f1b18bb4cc02.png) | ||
|
||
|
||
|
||
## Virtual Private Server | ||
|
||
VPS allow us to manage ourself the deployement | ||
setup. This allow us to customise the server and | ||
the costs linked to it. | ||
|
||
|
||
### Linode | ||
|
||
#### Ubuntu | ||
|
||
Linode provides and support Ubuntu: | ||
![linode-distribution-options-screen](https://user-images.githubusercontent.com/6057298/83647811-3bd59600-a5ad-11ea-893c-b99e3df7f605.png) | ||
|
||
|
||
From there the idea is install Erlang and Elixir on the server | ||
and then to run the application. | ||
|
||
- Install Erlang/Elixir with asdf: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @SimonLab as previously noted dwyl/phoenix-liveview-counter-tutorial#17 (comment) please don't introduce a completely new way of managing dependencies without giving some context. This is the first mention of If you want to propose using |
||
- `git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.7.8` | ||
- Edit `~/.bashrc file` and add `. $HOME/.asdf/asdf.sh` and run `source ~/.barhrc` to access the `asdf` command | ||
- Install required pacakges for Erlang `sudo apt install libssl-dev make automake autoconf libncurses5-dev gcc` | ||
- Add erlang plugin to asdf: `asdf plugin-add erlang` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we are using Linux as our Host OS then we 100% do not need to install Erlang/Elixir on the VM.
The whole point is that our Continuous Integration server (Travis-CI) does the testing and build phase and then just ships an We already demonstrated how to build and deploy a Phoenix App to a VM using The only reason I did not specify using P.S. sorry to be a pain about this in the in the PR review, I should have made it clearer in the issue. |
||
- Install Erlang: `asdf install erlang latest` | ||
- Install Elixir: `asdf install elixir latest` | ||
- Define which Elixir version to use `asdf global elxir <version>` | ||
|
||
- Instsall Nodejs using nvm | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We definitely don't want to install I tolerate running Node.js on my |
||
- `wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash` (from https://github.com/nvm-sh/nvm#installing-and-updating) | ||
- run `nvm install node` | ||
|
||
- Clone and run the Phoenix application | ||
- Clone the application, e.g. `git clone https://github.com/dwyl/hits.git` | ||
- Make sure to have all the environemt variables for the application defined | ||
- e.g. for the secret key: `mix phx.gen.secret` then `export SECRET_KEY_BASE=<secret>` | ||
- Compile assets (see https://hexdocs.pm/phoenix/deployment.html#compiling-your-application-assets) | ||
- `npm run deploy --prefix ./assets` | ||
- `mix phx.digest` | ||
- Start the server with `Mix`: `MIX_ENV=prod mix phx.server` | ||
|
||
- Another way to run the server is to use `mix release`: https://hexdocs.pm/phoenix/releases.html | ||
|
||
#### FreeBSD/OpenBSD | ||
|
||
I've also been investigating how to run | ||
an Elixir/Phoenix applicaiton on FreeBSD (and OpenBSD) | ||
|
||
Linode provides a way to create server from image, | ||
however the backup system won't support server running FreeBSD: | ||
![image](https://user-images.githubusercontent.com/6057298/83650091-d931c980-a5af-11ea-8ed1-ffc693d79e41.png) | ||
|
||
The following guide explain how to install FreeBSD on Linode: | ||
https://www.linode.com/docs/tools-reference/custom-kernels-distros/install-freebsd-on-linode/ | ||
|
||
I've also tested the installation on one of my machine: https://github.com/SimonLab/FreeBSD-installation | ||
|
||
The idea is then to use the FreeBSD package manager to install Elixir and Erlang: | ||
- `pkg install erlang` | ||
- `pkg install elixir` | ||
|
||
|
||
### DigitalOcean | ||
|
||
DigitalOcean provides a FreeBSD droplet: | ||
![image](https://user-images.githubusercontent.com/6057298/83651322-472ac080-a5b1-11ea-8ce3-764cb9fe7927.png) | ||
|
||
see https://www.digitalocean.com/products/linux-distribution/freebsd/ | ||
|
||
However OpenBSD can't be installed directly. | ||
There are some way we could install it and investigate | ||
if it can be used safely and without any blockers with DigitalOcean: | ||
https://dev.to/nabbisen/custom-openbsd-droplet-on-digitalocean-4a9o | ||
|
||
see also: https://www.digitalocean.com/community/tutorials/how-to-get-started-with-freebsd | ||
|
||
|
||
## Current Conclusion | ||
|
||
After reading and testing some Elixir/Phoenix/Linux/BSD installations | ||
I can see that Linode (or similar) can be on a longer term a better tool | ||
to manage the applications. | ||
|
||
The simple deployement used above with Ubuntu works well, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be clear, the instructions given above are not a "Deployment" they are a "build and run on the server". That is exactly what we don't want to do and we definitely don't want to advise other people to do it that way. |
||
however I still have some research and testing to do especially | ||
linked to continuous deployment without downtime. | ||
From reading the chapter 11 "Deploy Your Application to Production" of | ||
nelsonic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Real Time Phoenix, the solutions to deploy witout downtime are based on running | ||
applications on Elixir clusters. I'd like to learn more about this aspect | ||
but from a MVP perspective this point might take too much time to assimilate | ||
and I think a PaaS might be best to use at the moment. | ||
nelsonic marked this conversation as resolved.
Show resolved
Hide resolved
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍