In a project I’ve been working on it came up the want/need to put a Elixir (ErLang) app in the cloud, and me I’d like to manage the infrastructure as much as possible, but as my life continues to get busier and busier, sometimes its nice to have an infrastructure that you can simply deploy to and just worry about making the code work. This is where places like Heroku and Gigalixir (and many many others) come into play. So the dev I’ve been working with created the Elixir app in Windows which did not natively go into either Heroku or Gigalixir so it definitely took some tweaking.

In this overall Apps case it had 3 sub apps, we’ll call these App1, App2, and App3, where App1 one has a dependency on App2 and App3. When the developer coded this app on the Windows machine he put all three apps’ folders at the same level in his dev folder.

\dev\App1

\dev\App2

\dev\App3

This worked fine for what he had working on the temp server I had setup for him in my VMWare cluster, however when trying to upload into a cloud environment, it would want the three apps to be separate (or at least this is what I figured). So in order for it to operate under a single container with either of the cloud providers I was working with I found the dependency section in the mix.exs of App1. So I was able to update the entries to bring them all into a single “App” Folder

\dev\App1

\dev\App1\App2

\dev\App1\App3

Then I updated the mix.exs like this: (Before the path had two periods (eg. “../App2”) so just had to remove one to make it point at local folder)

{:App2, path: “./App2”},

{:App3, path: “./App3”},

This was the first step in getting it working, otherwise I wasn’t even able to get the git push to attempt the Heroku’s or Gigalixir’s pre-hook command. After this I discovered that the dev had not included the elixir_buildpack.config file which tells these cloud providers environment settings such as Erlang version, elixir version, runtime_path, etc. Which with out the config file it will try to use defaults which in our case were not the correct versions of the Erlang and Elixir. My elixir_buildpack.config is below


# Erlang version
erlang_version=21.0

# Elixir version
elixir_version=1.6.6

# Always rebuild from scratch on every deploy?
always_rebuild=true

# A command to run right before fetching dependencies
hook_pre_fetch_dependencies=”pwd”

# A command to run right before compiling the app (after elixir, .etc)
hook_pre_compile=”pwd”

# A command to run right after compiling the app
hook_post_compile=”pwd”

# Set the path the app is run from
runtime_path=/app


Other gotcha’s I noticed, when my developer built the mix.exs file the default for “start_permanent: Mix.env” was set to prod (which is good in my thoughts) however didn’t do any settings in the prod.exs file so in order for the app to run I had to update a number of the prod.exs file entries. Which included an unused reference to the Windows System Environment Variables as well as updating the host URLs to the respective App URL provided by our cloud provider.

No one interesting thing I learned about (at least Heroku) is that when you specific a port in the prod.exs file it ignores it for running on their location, in fact I’m not 100% sure, it may ignore any of the settings in the exs files that pertain to URL, or Port numbers as their platform has a standard of running on specific ports. (At least in the free account) Which brings up another great point about both of these cloud providers (as with most cloud providers) they have a free tier which allows you to get your app up and running at no hosting cost and to ensure its the right platform for what you are wanting to do. I’ve really grown to like the IaaS environment the more I use it and sure makes what I used to do many years ago as my primary living of managing hardware for development teams and their test environments for a large software company kind of obsolete and makes me glad I’ve been migrating into Dev and DevOps, among other things.

I know I didn’t cover everything you need in this post to get up and running on Heroku, feel free to comment (Sorry not the fastest at responding) and I will get back to you. I have included some of the basic commands you will need to get your code base in Heroku or Gigalixir.


Commands:

  • Heroku Specific 
    • heroku login -> This command is pretty obvious, you will need the heroku CLI for this to work, but it authenticates you with the heroku environment
    • heroku git:clone -a app1 -> This command takes the local directory that you are in and sets it for the remote repository on heroku’s side that you will be pushing your code to
    • git add .   -> (Must include the period at the end) This is adding the changes you have made to the local directory to your “local git repository” (More about local git repository versus remote some day later)
    • git commit -am “Some relevant commit text” -> This commits the code to your “local repository” with the comment tag specified in the quotations
    • git push heroku master -> Finally this command will push your code to the heroku “remote repository” which will kick off the hook scripts to run your app code through their verification and build out process specified in your code. After this step your site “should” be live unless there are issues.
    • heroku logs -> This is a great command if you are needing to see the logs of your app which you wouldn’t otherwise be able to see great for troubleshooting apps when they’ve been deployed
  • gigalixir specific 
    • git remote add gigalixir https://<URL Provided by gigalixir> -> This command is used to add the gigalixir remote repository to your local folder so that you can push your code to gigalixir using the following command
    • git push gigalixir master -> This command is used to push your code upto your gigalixir repository and subsequently rebuild your app and deploy it to your replica
    • Gigalixir too has a CLI you can install but requires you to install Python first and subsequently pip so you can install the CLI using pip. Please refer to gigalixir’s command’s page for these commands

As a final comment on the commands above, please keep in mind that these were accurate at the time of writing this article and if any don’t work, its a good possibility something was updated and I would recommend you go to the respective cloud provider for the most up to date commands. Also Heroku and Gigalixir are not affiliated in any way with this site nor this post, they are simply the mediums I used to get my code base on the internet.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.