<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Vladimir Zhukov - Medium]]></title>
        <description><![CDATA[Mixing Technology And Startups - Medium]]></description>
        <link>https://medium.com/vladimir-zhukov?source=rss----5da972500aeb---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Vladimir Zhukov - Medium</title>
            <link>https://medium.com/vladimir-zhukov?source=rss----5da972500aeb---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 22:11:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/vladimir-zhukov" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Insights into Deploying Elixir App with Amazon Elastic Beanstalk and Docker]]></title>
            <link>https://medium.com/vladimir-zhukov/insights-into-deploying-elixir-app-with-amazon-elastic-beanstalk-and-docker-846b31feca7f?source=rss----5da972500aeb---4</link>
            <guid isPermaLink="false">https://medium.com/p/846b31feca7f</guid>
            <category><![CDATA[elastic-beanstalk]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[phoenix-framework]]></category>
            <dc:creator><![CDATA[Vladimir Zhukov]]></dc:creator>
            <pubDate>Mon, 20 Jun 2016 18:28:13 GMT</pubDate>
            <atom:updated>2016-07-06T11:13:19.921Z</atom:updated>
            <content:encoded><![CDATA[<p>Last weeks we were rewriting our backend from Clojure to Elixir with Phoenix Framework. It was a second step on our way from Ruby — &gt; Clojure |&gt; Elixir which we went to get rid of a legacy code and an old API.</p><p>We manage all our infrastructure at Amazon with <a href="http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html">CloudFormation</a>. To make our life a bit more pleasant we have written a small Ruby util which leverages AWS SDK and helps us to generate CloudFormation templates avoiding configuration duplication and create, update and delete stacks from the command line. We separate our databases, applications, DNS, CDN and other configurations by different CloudFormation stacks. We have a separate Virtual Private Cloud (VPC) for every stack where it’s applicable without any public access. All instances in a VPC lives in specified subnets. In our case we use subnets which looks like 172.17.x.x, 172.18.x.x etc. I will show later why it’s important for Docker deployment, please stay with me and remember that <strong>172.17.x.x </strong>subnet. In a case an instance from one VPC needs to access an instance from another VPC we configure <a href="http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/vpc-peering.html">peering connections</a>.</p><p>Our initial app in Ruby was deployed to AWS with the help of <a href="http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/Welcome.html">Elastic Beanstalk</a>. Thanks to a vast variety of <a href="http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/concepts.platforms.html">supported platforms</a> when we migrated our backend to Clojure it was almost as easy to keep the same approach in deployment and configuration as changing a solution stack from <a href="http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/concepts.platforms.html#concepts.platforms.ruby">Ruby</a> to <a href="http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/concepts.platforms.html#concepts.platforms.javase">Java SE</a>. We were able to conform to our main deployment requirements:</p><ul><li>application config should be kept in environment variables which are configured when we create or update a stack and should not live in the application repo. Yes, we try to follow <a href="http://12factor.net/">The Twelve Factors</a>.</li><li>database migrations should be run automatically during deployment.</li><li>we should have console access to the deployed app.</li></ul><p>Everything else like zero downtime, autoscaling, nice CLI, logs, downgrades and etc. already handled by Elastic Beanstalk.</p><p>Unfortunately Elastic Beanstalk does not support either Elixir nor Erlang out of the box. Luckily it supports Docker. We have chosen a <a href="http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/docker-singlecontainer-deploy.html">Single Container Docker</a> because it better fits our needs at the moment. The limitation is that only one port can be exposed from a Docker container which might not be suitable when more open ports are required, for e.g. in case <a href="http://stackoverflow.com/questions/29339866/elasticsearch-on-elastic-beanstalk">Elasticsearch cluster</a>.</p><p>I faced two main approaches in deploying Elixir apps in a wild:</p><ul><li>Build a release locally (<a href="https://github.com/bitwalker/exrm">exrm</a>) or remotely (<a href="https://github.com/boldpoker/edeliver">edeliver</a>) and then deploy it to the deployment target.</li><li>Upload the code on the deployment target and compile it there.</li></ul><blockquote>To be-uild or not to be-uild? <strong>That is the question!</strong></blockquote><p>The first approach is definitely better at least because it’s possible to do hot upgrades, build once and deploy on multiple. On the other side there are also pitfalls which are rarely covered in blog posts and which should also be considered before taking on it. For example, if a release is built locally by Exrm then it takes local environment variables and mix also can’t be used for Ecto migrations. There are workarounds for those problems which can be googled.</p><p>The pragmatic approach in the beginning for us was to avoid additional problems/costs so we have chosen the second one and here is the Dockerfile:</p><pre>FROM ubuntu:14.04<br><br><strong>ENV HOST_VARS inject_here</strong><br>ENV PORT 8000</pre><pre>RUN apt-get update<br>RUN apt-get install -y wget git build-essential<br><br># Install Erlang and Elixir<br>RUN wget https://packages.erlang-solutions.com/erlang-solutions_1.0_all.deb<br>RUN dpkg -i erlang-solutions_1.0_all.deb<br>RUN apt-get update<br>RUN apt-get install -y esl-erlang<br>RUN apt-get install -y elixir<br><br><strong>COPY . /current</strong><br><br>WORKDIR /current<br><br>RUN mix do local.rebar, local.hex --force<br>RUN mix deps.get --only-prod<br>RUN mix do compile, phoenix.digest<br><strong>RUN mix ecto.migrate</strong><br><br>CMD [&quot;mix&quot;, &quot;phoenix.server&quot;]<br><br>EXPOSE 8000</pre><p>A number of things to notice here. First we need to pass environment variables which we configured with CloudFormation from the host machine to a Docker container. For that reason we set a marker</p><pre>ENV HOST_VARS inject_here</pre><p>Now we need to tell Elastic Beanstalk to actually inject those variables before creating container. It’s possible to do with a <strong>deploy hook</strong>. In app root we create a file ./.ebextensions/host_env_vars.config:</p><pre>files:  <br>  &quot;/opt/elasticbeanstalk/hooks/appdeploy/pre/02export_host_env_vars.sh&quot;:<br>    mode: &quot;000755&quot;<br>    owner: root<br>    group: root<br>    content: |<br>      #!/usr/bin/env bash<br>      echo Defaults:root \!requiretty &gt;&gt; /etc/sudoers<br>      for envvar in `jq &#39;.optionsettings | {&quot;aws:elasticbeanstalk:application:environment&quot;}[] | .[]&#39; /opt/elasticbeanstalk/deploy/configuration/containerconfiguration`<br>      do<br>        host_vars=&quot;${envvar//\&quot;/}&quot;;<br>        host_vars=&quot;${host_vars/=/ }&quot;;<br>        sed -i &quot;/ENV HOST_VARS inject_here/a ENV $host_vars&quot; /var/app/current/Dockerfile<br>      done</pre><p>When we do <strong>eb deploy </strong>Elastic Beanstalk uploads an app directory to the target machine. With that hook in place before a container will be created all configured environment variables will be injected in the Dockerfile. When a container is being created those injected env vars are implicitly applied for all commands which are below the point of an injection. It means that we can, for e.g., omit MIX_ENV=prod when we compile source or migrate database or start server. To finish with variables this is an example how we use them in our app:</p><pre># Configure your database<br>config :api, App.Repo,<br>  adapter: Ecto.Adapters.Postgres,<br>  username: System.get_env(&quot;DB_USER&quot;),<br>  password: System.get_env(&quot;DB_PASSWORD&quot;),<br>  hostname: System.get_env(&quot;DB_HOST&quot;),<br>  database: System.get_env(&quot;DB_NAME&quot;),<br>  pool_size: 20</pre><p>Next we need to tell docker to copy an application source files into container. Probably the most common approach would be to get an app source from a remote repo. In that case we have somehow to pass a private key of a deploy user to the container if we want to access a private repo. With Elastic Beanstalk this is much simpler. We already have our application at the host machine so we are telling Docker to copy it into the container:</p><pre>COPY . /current</pre><p>The last point I wanted to notice about Dockerfile are migrations. Since we already have a mix command available in the container we can simply run migrations:</p><pre>RUN mix ecto.migrate</pre><p>And then it brakes with the probability of 0.01%! Yep, it’s our case. Even though we have configured db access correctly our database server was not accessible neither from the container nor from the host machine. The biggest confusion for us was that we still have our old Clojure app stack configured the same way and it works. The only difference is that we don’t use Docker there. It is worth to elaborate what just has happened. Remember that <strong>172.17.x.x </strong>subnet? We used that subnet for our database VPC and Docker uses it as subnet of a <a href="https://docs.docker.com/engine/userguide/networking/dockernetworks/#the-default-bridge-network-in-detail">default bridge network</a>. All requests to a database server either from the host machine or from the container were routed to the container itself where we for sure had no db server. At this point we have two options. We can try to re-configure Docker with Elastic Beanstalk extensions or to change a subnet for database VPC and forget about the problem. We were lucky to be able to choose the second option.</p><p>The last thing I wanted to cover in that already long blog post is how to run Elixir console of an app in the Docker container. Once we are on the instance we list our running containers:</p><pre>sudo docker ps</pre><p>Run bash in that container:</p><pre>sudo docker exec -it 28afb2c2c542 /bin/bash</pre><p>Run a console on a different port than we have a running app:</p><pre>PORT=8888 iex -S mix</pre><p>Remember we have a mix command in the container and MIX_ENV is also configured.</p><p>That’s it for that post. Thanks for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=846b31feca7f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/vladimir-zhukov/insights-into-deploying-elixir-app-with-amazon-elastic-beanstalk-and-docker-846b31feca7f">Insights into Deploying Elixir App with Amazon Elastic Beanstalk and Docker</a> was originally published in <a href="https://medium.com/vladimir-zhukov">Vladimir Zhukov</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>