<?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[Stories by Eric Torti on Medium]]></title>
        <description><![CDATA[Stories by Eric Torti on Medium]]></description>
        <link>https://medium.com/@erictorti?source=rss-9519d446e334------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*qpAKI3TB9sx84Xkh.jpg</url>
            <title>Stories by Eric Torti on Medium</title>
            <link>https://medium.com/@erictorti?source=rss-9519d446e334------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 16:16:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@erictorti/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Makefile + docker]]></title>
            <link>https://medium.com/@erictorti/makefile-docker-870864350553?source=rss-9519d446e334------2</link>
            <guid isPermaLink="false">https://medium.com/p/870864350553</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[vivareal]]></category>
            <category><![CDATA[makefile]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[english-language]]></category>
            <dc:creator><![CDATA[Eric Torti]]></dc:creator>
            <pubDate>Tue, 09 Aug 2016 14:36:19 GMT</pubDate>
            <atom:updated>2016-08-09T14:36:19.629Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://en.wikipedia.org/wiki/Commensalism">Commensalism</a> building your project :)</p><p>At Vivareal, we have been using docker a lot to make building and deploying apps more homogeneous. Docker is great for that. Mainly because the Dockerfile is a declarative mean of describing your build. And the docker image is a complete enough object to run and deploy the app.</p><p>But … an app’s build assumes some steps previous to running <em>docker build </em>have been performed. For instance, in java, there is the need for an artifact; normally a <em>jar</em> or <em>war</em>, that contains the app’s <em>bytecode</em> and some other assets.</p><p>What is cool here, is that there is a dependency relationship between building the docker image and generating the artifact. Building the docker image depends on the artifact already being in place. <em>Make </em>is an almost omnipresent tool in the Unix world. And it’s purpose is exactly defining and managing this kind of relationship. That is the reason why we have been experimenting with Makefiles that aim at building, running and deploying dockerized apps. Yep; running and deploying from a Makefile may be controversial :D. But it is working nicely for now.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/731/1*3fi8bbVgxspX6peiAWkwgQ.jpeg" /><figcaption>A lift (image author not found)</figcaption></figure><p>In this text, I am going to show an example of building the app. I will leave running and deploying for another post. Disclaimer: some good practices regarding <em>Makefiles </em>are not in place here. Especially regarding .PHONY targets. As almost all of our targets resulted in being .PHONY, marking them as so became really redundant and noisy. But we are learning and any suggestions are welcome.</p><p>The example: a <em>java</em> app that builds its jar using <a href="https://gradle.org/"><em>gradle</em></a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/33caec544669cd85edc16426ce72b6b0/href">https://medium.com/media/33caec544669cd85edc16426ce72b6b0/href</a></iframe><p>Line <em>7</em> states that <em>gradle clean build </em>has to be executed in order to generate the <em>$(ARTIFACT)</em> file. And line <em>10</em> provides kind of an alias to the creation of this file, as it declares <em>build</em> as depending on the existence of <em>$(ARTIFACT)</em>.</p><p>Thus,</p><pre>make build</pre><p>generates the <em>jar</em> file.</p><p>But what if the machine running <em>make build</em> does not have <em>gradle</em> installed? Oh-oh :)</p><p>We could install <em>gradle</em> everywhere. But each engineer would end up having a different version of it. And the continuous integration machines yet some other versions. For this kinds of situations there exists the concept of a <em>gradle wrapper </em>that can be declared in<em> build.gradle. </em>But since we are already commited to using docker, why not use it as the wrapper? So, the project’s Makefile declares <em>gradle</em> as:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c94da1585d62c04f7eac35293a1a1382/href">https://medium.com/media/c94da1585d62c04f7eac35293a1a1382/href</a></iframe><p>This way, we replace the need of installing <em>gradle </em>for a dockerized version of it. The above code is illustrative, but not completely functional. It is necessary to map the project’s directory to <em>/project</em> inside the container, otherwise the built artifact would end up trapped inside the container. The following Makefile solves that. Check out line <em>9</em>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/33fbe29ce9b5f5fbec079cac6e296376/href">https://medium.com/media/33fbe29ce9b5f5fbec079cac6e296376/href</a></iframe><p>Ok. That gives us the java artifact. In this case a <em>jar</em> file. Now, to make a docker image, I want a target that can be invoked as:</p><pre>make image</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/85bb3ea17ae8c3786877229a3fb126ca/href">https://medium.com/media/85bb3ea17ae8c3786877229a3fb126ca/href</a></iframe><p>Line <em>17</em> builds the docker image and calls it <em>vivareal/example:1.0</em>. The point here is that the <em>image</em> target depends on the <em>build</em> target. And this makes for the artifact being built, in case it isn’t already so.</p><p>The following Dockerfile describes building the image.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8a113eb4c34a4f603c7b93155b1cb603/href">https://medium.com/media/8a113eb4c34a4f603c7b93155b1cb603/href</a></iframe><p>In line <em>4</em>, pay attention to the fact that the path to the artifact is relative. Docker assumes the file will be in reach from the build context.</p><p>Having a static artifact name (<em>build/libs/example-1.0.jar</em>) stuck to the Dockerfile is not cool. The artifact’s version should be something quite dynamic. That is why it is best to use a docker build argument.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bef34162f8421bbf706f266074794dab/href">https://medium.com/media/bef34162f8421bbf706f266074794dab/href</a></iframe><p>And fill up the this information at image building time. Check out line <em>20</em> in the following Dockerfile. Cool, right? :)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c3fe3ba43b1889ce702afdd41adc97af/href">https://medium.com/media/c3fe3ba43b1889ce702afdd41adc97af/href</a></iframe><p>In this example,</p><pre>make image</pre><p>does all that is necessary from building the jar to building the docker image. This is nice, as it encloses well all the tools needed to make this happen.</p><p>I take great pleasure in using <em>make</em> in this context. To me the obstacles <em>make</em> imposes to the engineer’s creativity is exactly its greatest value. When using <em>make</em> there is one opinionated way of doing what you want to to. That is: establishing a chain of dependencies. And that makes for more unequivocal design choices than those we tend to make with other build tools.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=870864350553" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Makefile + docker]]></title>
            <link>https://medium.com/tech-grupozap/makefile-docker-93a28cd2aa92?source=rss-9519d446e334------2</link>
            <guid isPermaLink="false">https://medium.com/p/93a28cd2aa92</guid>
            <category><![CDATA[vivareal]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[makefile]]></category>
            <dc:creator><![CDATA[Eric Torti]]></dc:creator>
            <pubDate>Mon, 08 Aug 2016 22:51:11 GMT</pubDate>
            <atom:updated>2016-08-09T03:24:05.233Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://pt.wikipedia.org/wiki/Comensalismo">Comensalismo</a> no build do seu projeto :) | <a href="https://medium.com/@erictorti/870864350553">English version</a></p><p>No VivaReal, a gente tem usado bastante o docker pra uniformizar o processo de build e deploy das aplicações. O docker é ótimo pra isso. Principalmente porque o Dockerfile é uma maneira declarativa de organizar o build. E a imagem de docker gerada é suficientemente completa para o deploy.</p><p>Mas … o build de uma aplicação pressupõe algumas etapas anteriores ao <em>docker build</em>. Por exemplo, para java, precisa-se de gerar um artefato; normalmente, um <em>jar</em> ou <em>war</em>, que contenha o <em>bytecode</em> e outros assets do programa.</p><p>O legal é que aí se mostra uma relação de dependência. O build da imagem docker depende de o artefato já existir. O <em>make</em> é uma ferramenta quase onipresente no mundo Unix que serve exatamente para organizar e definir esse tipo de relação. Por isso, fizemos um experimento usando Makefiles que tem por objetivo o build, a execução local e o deploy de aplicações docker. Sim; executar e fazer deploy a partir do Makefile é algo controverso :D. Mas ficou muito legal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/731/1*3fi8bbVgxspX6peiAWkwgQ.jpeg" /><figcaption>Caroninha (autor da foto não encontrado)</figcaption></figure><p>Nesse post, vou dar um exemplo de build e deixo execução e deploy para um próximo texto. Atenção; algumas boas práticas de <em>make</em> não estão sendo respeitadas aqui. Não marquei os targets que são independentes do sistema de arquivos como <em>.PHONY </em>. Isso porque, usando docker, nossos targets são quase todos <em>.PHONY</em>, e por isso o Makefile ficava super redundante. Talvez exista um jeito maroto de resolver isso. Estamos aprendendo e sugestões são bem-vindas :)</p><p>O exemplo; uma app java que constrói o <em>jar</em> usando <a href="https://gradle.org/"><em>gradle</em></a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/33caec544669cd85edc16426ce72b6b0/href">https://medium.com/media/33caec544669cd85edc16426ce72b6b0/href</a></iframe><p>A linha <em>7</em> diz que para gerar o arquivo <em>$(ARTIFACT)</em> é necessário executar <em>gradle clean build</em>. E a linha <em>10</em> dá um tipo de “apelido” pra a criação desse arquivo. Pois declara <em>build</em> como dependente de existir <em>$(ARTIFACT)</em>. Assim,</p><pre>make build</pre><p>cria o artefato.</p><p>Mas e se a máquina onde estou executando <em>make build</em> não tiver <em>gradle </em>instalado? Oh-oh :)</p><p>Podemos instalar <em>gradle</em> em todas as máquinas. Mas cada engenheiro acaba tendo uma versão diferente. E nas máquinas de integração ainda outras. Pra isso existe o conceito de <em>wrapper</em>, que permite declarar no arquivo <em>build.gradle</em> a versão que se pretende usar. Isso funciona. Mas já que estamos adotando docker, decidimos usá-lo como um wrapper para a ferramenta de build também. Então, o Makefile do projeto declara o executável do <em>gradle</em> como:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c94da1585d62c04f7eac35293a1a1382/href">https://medium.com/media/c94da1585d62c04f7eac35293a1a1382/href</a></iframe><p>E assim, substituimos o <em>gradle</em> instalado na máquina por uma versão dockerizada. O código acima é didático, mas não completamente funcional. É necessário mapear o diretório do projeto no host para o diretório <em>/project</em> do container, caso contrário o artefato ficaria “preso” dentro do container. O Makefile a seguir já contém essa alteração.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/33fbe29ce9b5f5fbec079cac6e296376/href">https://medium.com/media/33fbe29ce9b5f5fbec079cac6e296376/href</a></iframe><p>Ok. Isso nos dá o artefato java. Nesse caso um <em>jar</em>. Agora, pra fazer a imagem docker, quero um target que possa ser invocado com:</p><pre>make image</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/85bb3ea17ae8c3786877229a3fb126ca/href">https://medium.com/media/85bb3ea17ae8c3786877229a3fb126ca/href</a></iframe><p>A linha 17 constrói a imagem de docker da aplicação e a chama de <em>vivareal/example:1.0</em>. A sacada aqui é que o target <em>image</em> depende do target <em>build</em>. Isso faz que o artefato seja construído, caso ele já o não tenha sido.</p><p>O Dockerfile a seguir descreve o build da imagem.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8a113eb4c34a4f603c7b93155b1cb603/href">https://medium.com/media/8a113eb4c34a4f603c7b93155b1cb603/href</a></iframe><p>Na linha <em>4</em>, atenção pra o caminho do artefato: ele é relativo. O docker assume que o arquivo vai estar dentro do contexto de execução do build.</p><p>Esse nome do artefato (<em>build/libs/example-1.0.jar</em>) chumbado no Dockerfile não é uma boa. A versão do artefato deve ser algo dinâmico. Por isso é melhor usar um argumento de build do docker.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bef34162f8421bbf706f266074794dab/href">https://medium.com/media/bef34162f8421bbf706f266074794dab/href</a></iframe><p>E preencher essa informação no momento de construir a imagem. Se liga na linha <em>20</em> do Dockerfile abaixo. Opa! :)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c3fe3ba43b1889ce702afdd41adc97af/href">https://medium.com/media/c3fe3ba43b1889ce702afdd41adc97af/href</a></iframe><p>Nesse exemplo,</p><pre>make image </pre><p>faz todo o necessário desde o build do <em>jar</em> até o build da imagem de docker. Isso é legal, porque esconde bem o ferramental usado pra fazer o build do projeto.</p><p>Me agrada muito em trabalhar com <em>make</em> nesse contexto. Acho que a dificuldade que ele impõe à criatividade do engenheiro é exatamente o valor que ele entrega. No <em>make</em> existe <strong>uma</strong> maneira de fazer o que se quer fazer: estabelecer uma relação de dependência. E isso faz com que as escolhas de desenvolvimento se tornem mais inequívocas do que em outras ferramentas de build.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=93a28cd2aa92" width="1" height="1" alt=""><hr><p><a href="https://medium.com/tech-grupozap/makefile-docker-93a28cd2aa92">Makefile + docker</a> was originally published in <a href="https://medium.com/tech-grupozap">Tech@Grupo ZAP</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>