<?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 Daniel Ortiz on Medium]]></title>
        <description><![CDATA[Stories by Daniel Ortiz on Medium]]></description>
        <link>https://medium.com/@taik0?source=rss-9ffda40f4590------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*WQLsA9fOr41XMkVx-y0Ysw.jpeg</url>
            <title>Stories by Daniel Ortiz on Medium</title>
            <link>https://medium.com/@taik0?source=rss-9ffda40f4590------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 02:43:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@taik0/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[KrakenD framework becomes a Linux Foundation project]]></title>
            <link>https://medium.com/krakend/krakend-framework-becomes-a-linux-foundation-project-b48af0a05df?source=rss-9ffda40f4590------2</link>
            <guid isPermaLink="false">https://medium.com/p/b48af0a05df</guid>
            <dc:creator><![CDATA[Daniel Ortiz]]></dc:creator>
            <pubDate>Tue, 11 May 2021 00:00:00 GMT</pubDate>
            <atom:updated>2021-05-14T11:43:46.368Z</atom:updated>
            <content:encoded><![CDATA[<p>Today, <a href="https://linuxfoundation.org/en/press-release/open-source-api-gateway-krakend-becomes-linux-foundation-project/">together with the Linux Foundation</a>, we are announcing that the KrakenD framework, our core engine, has been <strong>donated to the Linux Foundation and is now the “</strong><a href="https://luraproject.org/"><strong>Lura Project</strong></a><strong>.”</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ThTPvKDsqUkIZwNB.png" /></figure><p>The Lura Project’s mission is to offer an extendable, simple, and stateless high-performance API Gateway framework designed for cloud-native and on-prem setups. Rather than solving a specific use case, Lura provides a library of components, a framework for assembling them into custom API gateway systems like a Lego set.</p><p>Two very well-known API gateway implementations of the Lura engine are the KrakenD Community and Enterprise editions. <strong>We will incorporate Lura as the new engine on KrakenD 2.0</strong> (coming soon, stay tuned!).</p><p>KrakenD API Gateway will continue with no changes needed for its Community (FOSS) and Enterprise editions, and <strong>no action is necessary to take if you are using our assembled products</strong>.</p><p>So, what is different now? The way we are running the project from now on. The KrakenD team is the initial <strong>Technical Steering Committee</strong>, responsible for all the open-source project’s technical oversight, but with an open governance model bringing engineers to improve the framework.</p><p>KrakenD framework becomes the Lura Project and gets home at Linux Foundation, where it will be <strong>the only enterprise-grade API Gateway hosted in a neutral, open forum</strong>.</p><p>Visit the <a href="https://luraproject.org/">Lura Project</a>.</p><p>One more thing! Last week, we were celebrating that we had reached 1 million online KrakenD servers in a month, but today the numer rises to 1.8M!! A milestone we set that arrived quicker than expected. Joining the Linux Foundation provides us the necessary open governance structure to support Lura Project’s massive growth.</p><p><em>Originally published at </em><a href="https://www.krakend.io/blog/krakend-framework-joins-the-linux-foundation/"><em>https://www.krakend.io</em></a><em> on May 11, 2021.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b48af0a05df" width="1" height="1" alt=""><hr><p><a href="https://medium.com/krakend/krakend-framework-becomes-a-linux-foundation-project-b48af0a05df">KrakenD framework becomes a Linux Foundation project</a> was originally published in <a href="https://medium.com/krakend">KrakenD</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reloading the Krakend configuration with Reflex and Docker]]></title>
            <link>https://medium.com/krakend/reloading-the-krakend-configuration-with-reflex-and-docker-7a66f7e73fa8?source=rss-9ffda40f4590------2</link>
            <guid isPermaLink="false">https://medium.com/p/7a66f7e73fa8</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[api-gateway]]></category>
            <category><![CDATA[reflex]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Daniel Ortiz]]></dc:creator>
            <pubDate>Fri, 22 Jun 2018 10:24:26 GMT</pubDate>
            <atom:updated>2018-06-22T10:24:26.460Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nc0OPAH_TLr3Llto9aFqDQ.jpeg" /></figure><p>A recurrent question when we go around is if KrakenD configuration can be hot-reloaded, this is changing endpoints, backends, or any other configuration of the gateway while it’s running. The short answer is: No, you can’t. You must restart the server. And although we might have something to alleviate this, let us explain first why we don’t support such a feature:</p><ul><li><strong>Performance</strong>: This is the #1 reason, and strong enough. <strong>KrakenD is focused on performance</strong>, we never take choices lightly. All decision process from beginning to end, the pipes, are built at start up time and when it finishes starts serving the traffic. This means KrakenD will do this job only once and there is no need to calculate routes or what to do when serving. This makes a huge difference.</li><li><strong>Simplicity</strong>: Because we believe an API contract must go under the version control system and after that be released (and through CI/CD if possible), but never altered at runtime by throwing curls or whatever. Are you familiar with <a href="https://en.wikipedia.org/wiki/Principle_of_least_astonishment">POLA</a>?</li><li><strong>Consistency</strong>: Imagine yourself distributing configuration updates in an ecosystem like the one KrakenD is offering: <strong>independent, non-coordinated and state-less</strong>. It would require you to develop consistency strategies that are far out of the scope of an API Gateway. And not to mention that this would come with some restrictions making the hot-reload feature less attractive and the system very error-prone.</li><li><strong>Why us?</strong>: You never demanded such a feature in Varnish, Apache, Nginx or any other major service. All of them are reloaded when configuration changes, and the Internet is still running.</li></ul><p>We could keep going, but with just this in mind, it’s clear that KrakenD won’t support a feature were you can push the new configuration at runtime. But we heard you! So we have built a small solution to automate the KrakenD reloading task, at least in development.</p><p>Check <a href="https://github.com/devopsfaith/krakend-config-watcher/">the Github repository for the code used</a> in this post.</p><h3>Enters krakend:config-watcher mode</h3><p>We have published a new Docker tag :config-watcher in the existing <a href="https://hub.docker.com/r/devopsfaith/krakend/">KrakenD Docker</a>, you can get it with:</p><pre>docker pull devopsfaith/krakend:config-watcher</pre><p>This image starts the service from the reflex watcher.</p><p><strong>What is reflex?</strong></p><p><a href="https://github.com/cespare/reflex">Reflex</a> is a small tool that watches a directory and reruns a command when certain files change (e.g using a regexp). Since it’s written in golang it has no dependencies. Take the opportunity to look to this amazing tool!</p><p>By having reflex as the entrypoint when the configuration changes KrakenD is reloaded. This is very convenient while you are developing as it allows you to test new changes without having to restart manually and making the process less tedious.</p><h3>Pull it or build it yourself</h3><p>This is the <a href="https://github.com/devopsfaith/krakend-config-watcher/blob/master/Dockerfile">Dockerfile</a> that generates our config-watcher image today:</p><pre>FROM devopsfaith/krakend:latest</pre><pre>LABEL maintainer=&quot;dortiz@devops.faith&quot;</pre><pre>ENV KRAKEND_CONFIG krakend.json</pre><pre>ADD reflex /usr/bin/reflex<br>ADD entrypoint.sh /</pre><pre>WORKDIR /etc/krakend</pre><pre>ENTRYPOINT [ &quot;/entrypoint.sh&quot; ]</pre><p>As you can see it uses the latest KrakenD version available (at the moment of writing <a href="https://hub.docker.com/r/devopsfaith/krakend/tags/">0.5.1</a>), adds the reflex binary, defines the KRAKEND_CONFIG environment variable and adds the entrypoint script to launch everything.</p><p><strong>Note</strong>: Reflex binary needs to be the alpine version, since KrakenD container uses it as base.</p><p>And the <a href="https://github.com/devopsfaith/krakend-config-watcher/blob/master/entrypoint.sh">entrypoint script</a> is as follows:</p><pre>#!/bin/sh</pre><pre>KRAKEND_CFG=${KRAKEND_CONFIG:-krakend.json}</pre><pre>cd /etc/krakend<br>/usr/bin/reflex -g &quot;$KRAKEND_CFG&quot; -s \<br> -- /usr/bin/krakend run -c /etc/krakend/${KRAKEND_CFG} -d</pre><p>It executes reflex with the file pattern to look for (in the same directory) and launches the command as a service. If you don’t want to use Docker, you can just use the entrypoint.sh as start script.</p><h3>Let’s develop! Running the Docker image</h3><p>To run the container you need to mount a volume with your configuration file mapped to the /etc/krakend directory. Optionally you can pass the environment variable KRAKEND_CONFIG if the configuration file you are using is not named krakend.json.</p><p>Example:</p><pre>docker run -it --rm -v $PWD:/etc/krakend -e \ KRAKEND_CONFIG=krakend.json devopsfaith/krakend:config-watcher</pre><p><strong>IMPORTANT</strong>: The volume needs to be shared as a directory, and not as a file because the changes wouldn’t be notified inside the container (<em>it’s a Docker thing</em>)</p><p>Now play with your configuration file as much as you want, KrakenD will be restarted every time!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PdQjpUE69lW9jfyQ.png" /></figure><h3>Conclusion</h3><p>We don’t support hot reloading in production, but we have shared this blog post to help you test your KrakenD configurations while you are developing. We also hope you discovered an amazing tools like Reflex or have given you ideas of the kind of stuff you can do with Docker.</p><p>Just try to keep it simple! Thanks for reading! If you like our product don’t forget to <a href="https://github.com/devopsfaith/krakend/stargazers">star our project</a>!</p><p><em>Originally published at </em><a href="http://www.krakend.io/blog/reloading-the-krakend-configuration/"><em>www.krakend.io</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7a66f7e73fa8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/krakend/reloading-the-krakend-configuration-with-reflex-and-docker-7a66f7e73fa8">Reloading the Krakend configuration with Reflex and Docker</a> was originally published in <a href="https://medium.com/krakend">KrakenD</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Website development as a sysadmin]]></title>
            <link>https://medium.com/krakend/website-development-as-a-sysadmin-848e7ec4b019?source=rss-9ffda40f4590------2</link>
            <guid isPermaLink="false">https://medium.com/p/848e7ec4b019</guid>
            <category><![CDATA[sysadmin]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[api-gateway]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Daniel Ortiz]]></dc:creator>
            <pubDate>Sat, 12 May 2018 14:56:06 GMT</pubDate>
            <atom:updated>2018-05-12T15:07:54.260Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*RWQK4EFHXz5SDcfC.jpg" /></figure><p>As a systems administrator for the past 15 years, I’m not very used to web development as this kind of work has been usually done by other colleagues in every company I’ve worked for. I wanted to create a web application myself using an external API, as an exercise to go out my comfort zone.</p><p>Some time ago I found that Marvel Comics has a REST API where you can get a lot of information about comics, characters, authors and other interesting information. This API is used in this exercise, <a href="https://developer.marvel.com/">get your own key</a>.</p><p>My first reaction when I initially though about this problem was to start the project in python, writing the code to do the requests, authenticating to the API, parsing the responses and generating the HTML output. Everything in the same service. This is the “classical” way of developing and the code became dirty very fast as I am an inexperienced programmer. Doing the API authentication was also painful and I wanted a more generic and reusable code.</p><p>Being part of KrakenD, I decided to revisit this exercise using KrakenD to do the requests, authentication, parsing, filtering and merging the responses for me.</p><p>Check <a href="https://github.com/taik0/krakend-marvel-example">my Github repository for the code used</a> in this post.</p><h3>The backend: Adding automatic API authentication</h3><p>The <a href="http://www.krakend.io/">KrakenD API Gateway</a> can filter the fields of all your requests’ responses using a declarative configuration in json but I also needed KrakenD to do the authentication against the Marvel API for me before doing these requests.</p><p>KrakenD supports a <a href="https://github.com/devopsfaith/krakend-contrib/">lot of middleware</a> one of them being <a href="https://github.com/devopsfaith/krakend-martian/">krakend-martian</a> and, since one of the reasons for this project was to do some programming, I created a martian request modifier so each request would automatically add any data needed to authenticate against Marvel API, decoupling this custom authentication from the application.</p><p>In this case, Marvel requests need to include in every query string the following parameters:</p><ul><li>ts: timestamp</li><li>apikey: the public API key</li><li>hash: an md5 of timestamp + private key + public key.</li></ul><p>You can also see this modifier source code in <a href="https://github.com/taik0/marvelapi-martian_querystring">github</a>.</p><p>At the time I created this query string modifier <strong>we didn’t had </strong><a href="http://www.krakend.io/blog/krakend-golang-plugins/"><strong>plugins</strong></a> so I needed to recomplile KrakenD to add a custom modifier like this one.</p><h3>Setting up KrakenD</h3><p>To add the custom modifier to KrakenD it’s only needed to create a file like this one in the root of the <a href="https://github.com/devopsfaith/krakend-ce">KrakenD-CE</a> repository:</p><p><em>marvel.go:</em></p><pre>package main </pre><pre>import _ &quot;github.com/taik0/marvelapi-martian_querystring&quot;</pre><p>and just follow the regular build steps (make prepare and make).</p><p>To configure KrakenD I needed to add an extra_config using the krakend-martian Namespace and the custom configuration for the modifier. Check also the whitelist and mapping sections where I set a filter of some fields.</p><h4>KrakenD configuration example</h4><pre>{&quot;endpoints&quot;: [<br>    {<br>        &quot;backend&quot;: [<br>            {<br>                &quot;extra_config&quot;: {<br>                    &quot;<a href="http://github.com/devopsfaith/krakend-martian">github.com/devopsfaith/krakend-martian</a>&quot;: {<br>                        &quot;fifo.Group&quot;: {<br>                            &quot;aggregateErrors&quot;: true,<br>                            &quot;modifiers&quot;: [<br>                                {<br>                                    &quot;querystring.MarvelModifier&quot;: {<br>                                        &quot;private&quot;: &quot;private_api_key&quot;,<br>                                        &quot;public&quot;: &quot;public_api_key&quot;,<br>                                        &quot;scope&quot;: [<br>                                            &quot;request&quot;<br>                                        ]<br>                                    }<br>                                }<br>                            ],<br>                            &quot;scope&quot;: [<br>                                &quot;request&quot;,<br>                                &quot;response&quot;<br>                            ]<br>                        }<br>                    }<br>                },<br>                &quot;host&quot;: [<br>                    &quot;<a href="http://gateway.marvel.com/">http://gateway.marvel.com</a>&quot;<br>                ],<br>                &quot;url_pattern&quot;: &quot;/v1/public/characters?name={name}&quot;,<br>                &quot;whitelist&quot;: [<br>                  &quot;data.results&quot;,<br>                  &quot;attributionHTML&quot;<br>                ],<br>                &quot;mapping&quot;: { &quot;data&quot;: &quot;characters&quot;}<br>            }<br>        ],<br>        &quot;endpoint&quot;: &quot;/character/{name}&quot;,<br>        &quot;method&quot;: &quot;GET&quot;<br>    }<br>  ],<br>  &quot;extra_config&quot;: {<br>      &quot;github_com/devopsfaith/krakend-gologging&quot;: {<br>          &quot;level&quot;: &quot;INFO&quot;,<br>          &quot;prefix&quot;: &quot;[KRAKEND]&quot;,<br>          &quot;stdout&quot;: true,<br>          &quot;syslog&quot;: false<br>      }<br>  },<br>  &quot;name&quot;: &quot;My lovely gateway&quot;,<br>  &quot;port&quot;: 8080,<br>  &quot;timeout&quot;: &quot;3s&quot;,<br>  &quot;version&quot;: 2}</pre><h3>The frontend: API2HTML</h3><p>To generate the frontend of the application I created some simple logic-less <a href="https://mustache.github.io/">mustache</a> templates and configured <a href="http://api2html.com/">api2html</a> to query the KrakenD endpoints and generate the HTML output without even the need of a web server.</p><p>In a nutshell, Api2html takes data from an API and injects it in the mustache templates so you can build websites without coding controllers, models or setting web servers. Besides being simple, the service uses the Go standard libraries and will offer a lot of throughput.</p><h3>Mustache Template</h3><p>The HTML template needs to live inside api2html and is used to display the frontend. It looks like this:</p><pre>&lt;html&gt;<br>&lt;head&gt;<br>  &lt;link rel=&quot;stylesheet&quot; href=&quot;<a href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css">https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css</a>&quot; integrity=&quot;sha384-Zug+QiDoJOrZ5t4lssLdxGhVrurbmBWopoEl+M6BdEfwnCJZtKxi1KgxUyJq13dy&quot; crossorigin=&quot;anonymous&quot;&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>{{#Data.characters.results}}<br>  &lt;div class=&quot;container&quot;&gt;<br>    &lt;a href=&quot;/character/{{id}}&quot;<br>    &lt;div class=&quot;row&quot;&gt;<br>      &lt;div class=&quot;col-4&quot;&gt;<br>        &lt;img class=&quot;rounded-right&quot; src=&quot;{{thumbnail.path}}/landscape_xlarge.{{thumbnail.extension}}&quot; alt=&quot;{{name}}&quot;&gt;<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br>    &lt;div class=&quot;row&quot;&gt;<br>        &lt;div class=&quot;col-4&quot;&gt;<br>          &lt;h5 class=&quot;mt-0&quot;&gt;{{name}}&lt;/h5&gt;<br>          {{description}}<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br>{{/Data.characters.results}}<br>&lt;div class=&quot;row&quot;&gt;<br>  &lt;div class=&quot;col-4&quot;&gt;<br>    {{{Data.attributionHTML}}}<br>  &lt;/div&gt;<br>&lt;/div&gt;<br>&lt;/a&gt;<br>&lt;/div&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><h3>api2html configuration</h3><p>Notice that the backend URL it’s KrakenD service, not Marvel API.</p><pre>{<br>	&quot;templates&quot;:{<br>		&quot;character&quot;: &quot;character.mustache&quot;<br>	},<br>	&quot;pages&quot;:[<br>    {<br>      &quot;name&quot;: &quot;character&quot;,<br>      &quot;URLPattern&quot;: &quot;/character/:character&quot;,<br>      &quot;BackendURLPattern&quot;: &quot;<a href="http://localhost:8080/character/:character">http://localhost:8080/character/:character</a>&quot;,<br>      &quot;CacheTTL&quot;: &quot;3600s&quot;,<br>      &quot;Template&quot;: &quot;character&quot;<br>    }<br>  ]<br>}</pre><h3>Running the service</h3><p>The docker-compose will spin up both services, api2html for the frontend, and KrakenD for the backend:</p><pre>$ docker-compose up<br>Starting krakendmarvelexample_krakend_1 ... done<br>Starting krakendmarvelexample_api2html_1 ... done<br>Attaching to krakendmarvelexample_krakend_1, krakendmarvelexample_api2html_1<br>krakend_1   | Parsing configuration file: /etc/krakend/krakend.json<br>krakend_1   | [KRAKEND] 2018/05/11 - 11:28:42.180 ▶ WARNIN building the etcd client: unable to create the etcd client: no config<br>krakend_1   | [GIN-debug] [WARNING] Running in &quot;debug&quot; mode. Switch to &quot;release&quot; mode in production.<br>krakend_1   |  - using env:	export GIN_MODE=release<br>krakend_1   |  - using code:	gin.SetMode(gin.ReleaseMode)<br>krakend_1   |<br>krakend_1   | [GIN-debug] GET    /__stats/                 --&gt; <a href="http://github.com/devopsfaith/krakend-ce/vendor/github.com/gin-gonic/gin.WrapH.func1">github.com/devopsfaith/krakend-ce/vendor/github.com/gin-gonic/gin.WrapH.func1</a> (4 handlers)<br>api2html_1  | [GIN-debug] [WARNING] Running in &quot;debug&quot; mode. Switch to &quot;release&quot; mode in production.<br>api2html_1  |  - using env:	export GIN_MODE=release<br>api2html_1  |  - using code:	gin.SetMode(gin.ReleaseMode)<br>api2html_1  |<br>api2html_1  | reading ./static/500 : open ./static/500: no such file or directory<br>api2html_1  | using the default 500 template<br>api2html_1  | [GIN-debug] GET    /character/:character     --&gt; <a href="http://github.com/devopsfaith/api2html/engine.(*Handler).HandlerFunc-fm">github.com/devopsfaith/api2html/engine.(*Handler).HandlerFunc-fm</a> (4 handlers)<br>api2html_1  | handler without layout character<br>api2html_1  | reading ./static/404 : open ./static/404: no such file or directory<br>api2html_1  | using the default 404 template<br>api2html_1  | [GIN-debug] PUT    /template/:templateName   --&gt; <a href="http://github.com/devopsfaith/api2html/engine.Factory.New.func1">github.com/devopsfaith/api2html/engine.Factory.New.func1</a> (4 handlers)<br>api2html_1  | [GIN-debug] Listening and serving HTTP on :8080</pre><p>The docker-compose exposes the service on the 8081 port:</p><pre>curl -i <a href="http://localhost:8081/character/Wolverine">http://localhost:8081/character/Wolverine</a><br>...<br>[GIN] 2018/05/11 - 11:29:15 | 200 |  849.266342ms |             ::1 |  GET     /character/Wolverine</pre><p>Or in your browser:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/356/0*tLvpfQkMNjS4OONu.png" /></figure><p>Check the <a href="https://github.com/devopsfaith/api2html">documentation</a> to see a lot more of api2html (like generating templates with templates!)</p><p>Now if you want to create your own site run this command:</p><pre>docker run -it --rm -v $PWD:/tmp -w /tmp devopsfaith/api2html skel create blog</pre><p>and a more complete example will be generated in example/blog.</p><h3>Conclusion</h3><p>One of the most important lessons I learned building this, apart from golang coding and some application building, is that you need to know the tools you are using as much as possible since we tend to over-complicate things and rebuild pieces that someone already did (exclude from this exercises/katas to understand better a technology) and knowing what a tool can and can’t do helps a lot!</p><p>So read documentation, test, play, build something, read a bit more and try again!</p><p><em>Originally published at </em><a href="http://www.krakend.io/blog/website-development-as-a-sysadmin/"><em>www.krakend.io</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=848e7ec4b019" width="1" height="1" alt=""><hr><p><a href="https://medium.com/krakend/website-development-as-a-sysadmin-848e7ec4b019">Website development as a sysadmin</a> was originally published in <a href="https://medium.com/krakend">KrakenD</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How we automated our RPM and DEB packaging with Docker]]></title>
            <link>https://medium.com/krakend/how-we-automated-our-rpm-and-deb-packaging-with-docker-krakend-api-gateway-and-manager-26b0cc5cd211?source=rss-9ffda40f4590------2</link>
            <guid isPermaLink="false">https://medium.com/p/26b0cc5cd211</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[krakend]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[makefile]]></category>
            <category><![CDATA[package-management]]></category>
            <dc:creator><![CDATA[Daniel Ortiz]]></dc:creator>
            <pubDate>Sun, 21 Jan 2018 20:31:28 GMT</pubDate>
            <atom:updated>2018-01-21T20:35:45.664Z</atom:updated>
            <content:encoded><![CDATA[<p>Everyone loves reaching the maximum number of available platforms for their software but this usually comes at a cost. In this article we will explain how we generated our packaging for Linux in an automated fashion, being faithful to our DevOps dogma.</p><h3>Dockerize all the things!</h3><p>Our team uses both Ubuntu and MacOS X in desktop machines and KrakenD has been running and behaving in the same way in all the platforms because from day one we decided to run everything on Docker. We use containers for all the software we produce and this is still true for the rest of our tooling (as what we are going to show today).</p><p>When it comes to generating RPM or DEB packages, choosing Docker ensures that anyone building or compiling a package will generate a consistent output.</p><p>Having Docker as the platform to work on, let’s see how to build the packages.</p><h3>Building packages the easy way using FPM</h3><p>For those who don’t know fpm, this is the key piece for the package generation. According to <a href="https://github.com/jordansissel/fpm">their own intro</a>:</p><blockquote><em>The goal of fpm is to make it easy and quick to build packages</em></blockquote><p>fpm is a tool written in Ruby that allows you to create packages for multiple platforms in a very easy way. Examples of the packages you can create are deb, rpm, tar and even Mac OS X .pkg, solaris, freebsd or pacman (ArchLinux).</p><p>Let’s get started by creating the fpm builder with a Dockerfile to generate the versions deb and rpm, the ones we were most interested in.</p><p><strong>The </strong><strong>Dockerfile for Debian/Ubuntu</strong>:</p><pre>FROM ubuntu:16.04<br>LABEL maintainer=&quot;dortiz@devops.faith&quot;<br><br>RUN apt-get update &amp;&amp; apt-get install -y \<br>	ruby-dev \<br>	gcc \<br>	make \<br>	ruby \<br>	&amp;&amp; rm -rf /var/lib/apt/lists/*<br><br>RUN gem install fpm -v 1.9.3 --no-ri --no-rdoc<br><br>VOLUME [ &quot;/tmp/fpm&quot; ]<br>WORKDIR /tmp/fpm<br><br>ENTRYPOINT [ &quot;/usr/local/bin/fpm&quot; ]<br>CMD [ &quot;--help&quot; ]</pre><p><strong>The </strong><strong>Dockerfile for CentOS/Rhel</strong>:</p><pre>FROM centos:7<br>LABEL maintainer=&quot;dortiz@devops.faith&quot;<br><br>RUN yum install -y \<br>	ruby-devel \<br>	gcc \<br>	make \<br>	ruby \<br>	rpm-build \<br>	rpm-sign &amp;&amp; yum clean all<br><br>RUN gem install fpm -v 1.9.3 --no-ri --no-rdoc<br><br>VOLUME [ &quot;/tmp/fpm&quot; ]<br>WORKDIR /tmp/fpm<br><br>ENTRYPOINT [ &quot;/usr/local/bin/fpm&quot; ]<br>CMD [ &quot;--help&quot; ]</pre><p>Then build it and run it:</p><pre>$ docker run --rm -it fpm:deb<br>Intro:<br><br>  This is fpm version 1.9.3</pre><p>Notice that the FROM in each one uses a different OS (because fpm still needs rpmbuild, dpkg-deb and other tools).</p><p>Now the container is ready to package anything.</p><p><strong>Source code:</strong></p><h3>Sign packages using PGP</h3><p>If you want to distribute packages you’ll need to sign them using your PGP key. To do so you need to mount your .pgp directory in the container as a volume, as well as the rpmmacros configuration so the process has everything it needs.</p><pre>docker run --rm -it -v &quot;${PWD}/rpmmacros:/root/.rpmmacros&quot; -v $HOME/.gnupg:/root/.gnupg \<br>		-v &quot;${PWD}:${DOCKER_WDIR}&quot; -w ${DOCKER_WDIR} ${DOCKER_FPM}:rpm -t rpm ${RPM_OPTS} \<br>		--iteration ${RELEASE}.el7 \<br>		-C skel/el7 \<br>		${FPM_OPTS}</pre><p>The example uses some vars that we haven’t seen so far. Keep reading…</p><h3>Write a Makefile</h3><p>Unless your are OK with having an environment that suffers the <a href="https://en.wikipedia.org/wiki/Diogenes_syndrome">diogenes syndrome</a>, the next problem you want to face is managing what files go in which package version and leaving the house clean after compiling. How convenient is a Makefile to get that!</p><p>Makefile variables, example:</p><pre>VERSION := 0.3.9<br>PKGNAME := krakend<br>LICENSE := Apache 2.0<br>VENDOR=<br>URL := <a href="http://krakend.io/">http://krakend.io</a><br>RELEASE := 0<br>USER := krakend<br>ARCH := amd64<br>DESC := High performance API gateway. Aggregate, filter, manipulate and add middlewares<br>MAINTAINER := Daniel Ortiz &lt;dortiz@devops.faith&gt;<br>DOCKER_WDIR := /tmp/fpm<br>DOCKER_FPM := fpm</pre><p>Then every specific option for fpm is also added to the Makefile:</p><pre>FPM_OPTS=-s dir -v $(VERSION) -n $(PKGNAME) \<br>  --license &quot;$(LICENSE)&quot; \<br>  --vendor &quot;$(VENDOR)&quot; \<br>  --maintainer &quot;$(MAINTAINER)&quot; \<br>  --architecture $(ARCH) \<br>  --url &quot;$(URL)&quot; \<br>  --description  &quot;$(DESC)&quot; \<br>	--config-files etc/ \<br>  --verbose<br><br>DEB_OPTS= -t deb --deb-user $(USER) \<br>	--before-remove scripts/prerm.deb \<br>  --after-remove scripts/postrm.deb \<br>	--before-install scripts/preinst.deb<br><br>DEB_INIT=--deb-init krakend.init<br><br>RPM_OPTS =--rpm-user $(USER) \<br>	--before-install scripts/preinst.rpm \<br>	--before-remove scripts/prerm.rpm \<br>  --after-remove scripts/postrm.rpm \<br>  --rpm-sign</pre><p>Now all the options and variables are controlled inside the Makefile.</p><h3>Pattern-specific variables</h3><p>A key of success are the pattern-specific variables present in the Makefile. They are used to define a kind of template that can be reused many times (as a function) but with different declarations.</p><p>A single platform would be easy to manage: one config file, a couple of scripts (pre and post install) and the systemd configuration. That’s it.</p><p>For us the problem came when we wanted to generate packages for old versions of Ubuntu/Debian and CentOS/RHEL. Some distributions were using upstart while others created scripts in init.d or needed custom scripts for pre and post installations. Differences never ended.</p><p>The use of the pattern-specific variables fixes in a simple way the problem (and using something it’s been there for years), this is how we completed the Makefile.</p><p>We defined all the files that might be needed during the package creation:</p><pre>skel/%/etc/init/krakend.conf: krakend.conf<br>	mkdir -p &quot;$(dir $@)&quot;<br>	cp krakend.conf &quot;$@&quot;<br><br>skel/%/etc/init.d/krakend: krakend.init<br>	mkdir -p &quot;$(dir $@)&quot;<br>	cp krakend.init &quot;$@&quot;</pre><p>When declaring the file using the full path, the directory will be created and the file will be copied inside, generating this way the skeleton for that specific version. In addition, it will save you from having to manually maintain that skel, because it is generated every time is needed, copying the “latest” available versions of them.</p><pre>.PHONY: ubuntu-trusty<br>ubuntu-trusty: skel/ubuntu-trusty/usr/bin/krakend<br>ubuntu-trusty: skel/ubuntu-trusty/etc/krakend/krakend.json<br>ubuntu-trusty: skel/ubuntu-trusty/etc/krakend/service.yml<br>ubuntu-trusty: skel/ubuntu-trusty/etc/init.d/krakend<br>ubuntu-trusty: skel/ubuntu-trusty/etc/init/krakend.conf<br>	docker run --rm -it -v &quot;${PWD}:${DOCKER_WDIR}&quot; -w ${DOCKER_WDIR} ${DOCKER_FPM}:deb -t deb ${DEB_OPTS} \<br>		--iteration ${RELEASE}.ubuntu-trusty \<br>		-C skel/ubuntu-trusty \<br>		${DEB_INIT} \<br>		${FPM_OPTS}</pre><pre>.PHONY: ubuntu-xenial<br>ubuntu-xenial: skel/ubuntu-xenial/usr/bin/krakend<br>ubuntu-xenial: skel/ubuntu-xenial/etc/krakend/krakend.json<br>ubuntu-xenial: skel/ubuntu-xenial/etc/krakend/service.yml<br>	docker run --rm -it -v &quot;${PWD}:${DOCKER_WDIR}&quot; -w ${DOCKER_WDIR} ${DOCKER_FPM}:deb -t deb ${DEB_OPTS} \<br>		--iteration ${RELEASE}.ubuntu-xenial \<br>		--deb-systemd krakend.service \<br>		-C skel/ubuntu-xenial \<br>		${FPM_OPTS}</pre><h3>Testing your packages</h3><p>The last step before releasing to the world the packages just created is to test they work properly. There are many ways and strategies to do that and we are not going to show you how, but for us it worked to run a docker container with the OS version we wanted to try and install inside the generated package.</p><p>With this done, it is very easy to check that the pre and post installation scripts worked correctly as well as the installation and the service operation.</p><p>We did a simple shell script (not being able to invest more time in something elegant and reusable) and a Dockerfile template where the package gets copied and a new container is generated tagged with the version of the package. By specifying the package version as a tag in the docker image, executing docker images will list all the generated packages ready to test!</p><p>Dockerfile testing:</p><pre>FROM ubuntu:16.04<br>maintainer dortiz@devops.faith<br><br>ARG debfile<br>ADD $debfile /<br>RUN dpkg -i /$debfile<br><br>EXPOSE 8080<br><br>CMD [ &quot;krakend&quot;, &quot;run&quot;, &quot;-d&quot; ]</pre><p>Testing script:</p><pre>#!/bin/sh<br><br>DEB=$1<br>TARGET=$2<br>VERSION=$3<br>cp $DEB tests/ubuntu-xenial/<br>docker build --build-arg debfile=$DEB -t test_${TARGET}_${VERSION} tests/ubuntu-xenial<br>rm -f tests/ubuntu-xenial/$DEB</pre><p>Makefile:</p><pre>.PHONY: ubuntu-xenial<br>ubuntu-xenial: skel/ubuntu-xenial/usr/bin/krakend<br>ubuntu-xenial: skel/ubuntu-xenial/etc/krakend/krakend.json<br>ubuntu-xenial: skel/ubuntu-xenial/etc/krakend/service.yml<br>	docker run --rm -it -v &quot;${PWD}:${DOCKER_WDIR}&quot; -w ${DOCKER_WDIR} ${DOCKER_FPM}:deb -t deb ${DEB_OPTS} \<br>		--iteration ${RELEASE}.ubuntu-xenial \<br>		--deb-systemd krakend.service \<br>		-C skel/ubuntu-xenial \<br>		${FPM_OPTS}<br>	tests/ubuntu-xenial/test.sh ${PKGNAME}_${VERSION}-${RELEASE}.ubuntu-xenial_${ARCH}.deb ubuntu-xenial ${VERSION}</pre><h3>Conclusion</h3><p>We have seen through several examples how we automated the generation of package files for KrakenD. You can quickly adapt this scripts and containers to your own application and start producing packages in a more automated way. With the combination of the provided Makefile and fpm you will be able to distribute your application to several distributions.</p><p>Enjoy!</p><p><em>Originally published at </em><a href="http://www.krakend.io/blog/automating-linux-packaging/"><em>www.krakend.io</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=26b0cc5cd211" width="1" height="1" alt=""><hr><p><a href="https://medium.com/krakend/how-we-automated-our-rpm-and-deb-packaging-with-docker-krakend-api-gateway-and-manager-26b0cc5cd211">How we automated our RPM and DEB packaging with Docker</a> was originally published in <a href="https://medium.com/krakend">KrakenD</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>