<?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 Le Moment It on Medium]]></title>
        <description><![CDATA[Stories by Le Moment It on Medium]]></description>
        <link>https://medium.com/@le_moment_it?source=rss-abfdaec6dc48------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dmbNkD5D-u45r44go_cf0g.png</url>
            <title>Stories by Le Moment It on Medium</title>
            <link>https://medium.com/@le_moment_it?source=rss-abfdaec6dc48------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 15:39:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@le_moment_it/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[Nginx UNIT discover and benchmark (part 3)]]></title>
            <link>https://medium.com/@le_moment_it/nginx-unit-discover-and-benchmark-part-3-c38661194cd0?source=rss-abfdaec6dc48------2</link>
            <guid isPermaLink="false">https://medium.com/p/c38661194cd0</guid>
            <category><![CDATA[nginx]]></category>
            <category><![CDATA[servers]]></category>
            <category><![CDATA[web]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[hosting]]></category>
            <dc:creator><![CDATA[Le Moment It]]></dc:creator>
            <pubDate>Mon, 26 Jun 2023 00:26:57 GMT</pubDate>
            <atom:updated>2023-06-26T00:26:57.153Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*SYXutUc4_uWq6-56.png" /></figure><p>The latest article about Nginx Unit! If you haven’t read the previous one, you can find them listed here:</p><ul><li><a href="https://medium.com/@le_moment_it/nginx-unit-discover-and-benchmark-part-1-341cd85896bf">Nginx UNIT discover and benchmark (part 1)</a></li><li><a href="https://medium.com/@le_moment_it/nginx-unit-discover-and-benchmark-part-2-b9c81744b1">Nginx UNIT discover and benchmark (part 2)</a></li></ul><p>In this article, we will solely focus on the performance aspect of Nginx Unit. I will begin by describing the context and tools utilized during this benchmark. Afterwards, I will present the results of my tests.</p><h3>Context</h3><p>When I began testing Nginx Unit and chose to perform live benchmarks, I encountered an issue. How could I assess its performance without incurring excessive costs? Since my content is free and doesn’t generate any income, I cannot afford to spend a significant amount of money on these tests.</p><p>Therefore, I made the decision to work with a limited budget and evaluate how well Nginx Unit could handle the load on a small server.</p><p>That&#39;s why I have decided to perform my benchmark on this type of instance:</p><ul><li>AWS EC2 <strong>t2.micro</strong> instance (1 Vcpu &amp; 1GB RAM).</li><li>Operating system : <strong>Debian 11</strong></li></ul><p>Now that we have our server, we need an application to test ! I have decided to benchmark Nginx UNIT on two different programming languages :</p><ul><li>PHP Wordpress : A simple <a href="https://wordpress.com/">wordpress</a> application using a default theme.</li><li>Python3.9 Datasette : Datasette is simple python application exposed by uvicorn that allows users to exploring and publishing data.</li></ul><p>I have selected these applications because they can emulate the basic requirements of a small company with a limited budget.</p><h3>Benchmark tool</h3><p>After selecting the applications for testing, I needed to find a method to simulate the load for my tests. Through extensive research, I opted to utilize the benchmark tool <a href="https://loader.io/">Loader.io</a>.</p><p>Loader.io is a straightforward yet powerful SAAS application that allows us to configure various loading scenarios.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DiEl8KfBRWB1qtffRopkAA.png" /></figure><p>In its free version, you can only configure a single loading test and target host. Fortunately, this will be sufficient for our testing purposes.</p><p>💡To configure our AWS EC2 instance as the target for our tests, we need to add a file provided by Loader.io that is accessible on the internet. Subsequently, Loader.io servers will verify the existence of the provided file on the target server configured within the platform. This process closely resembles the verification system used by Certbot before issuing an SSL Let’s Encrypt certificate.</p><p>Loader.io provide three types of benchmark :</p><ul><li><strong>Clients per test</strong> : Number of client connection during a defined amount of time. This test answers the question <strong>&quot;<em>How does my server perform when &lt;NUMBER OF USERS&gt; connect over the course of &lt;TIME&gt;</em></strong>&quot;</li><li><strong>Clients per second</strong> : Clients requests made each seconds. This test answers the question <strong>&quot;How does my server perform when &lt;NUMBER OF USERS&gt; connect every second over a &lt;TIME&gt; period&quot;</strong></li><li><strong>Maintain client load</strong> : A constant client count will be maintained throughout the test duration. This test answers the question : <strong>&quot;How does my server perform over a &lt;TIME&gt; period when there is a constant load of &lt;MINIMUM NUMBER OF USERS&gt; to &lt;MAXIMUM NUMBER OF USERS&gt; connected?&quot;</strong></li></ul><p>For each scenarios we will perform the following tests :</p><ul><li>Client per Test : 200 clients/min during 1 minute</li><li>Client per Test : 500 clients/min during 1 minute</li><li>Client per Test : 1000 clients/min during 1 minute</li><li>Client per Test : 1500 clients/min during 1 minute</li><li>Client per Test : 2000 clients/min during 1 minute</li><li>Maintain client load : 0 -&gt; 20 clients during 1 minute</li><li>Maintain client load : 0 -&gt; 50 clients during 1 minute</li><li>Maintain client load : 0 -&gt; 100 clients during 1 minute</li><li>Clients per second : 20 clients/seconds during 1 minute</li><li>Clients per second : 50 clients/seconds during 1 minute</li><li>Clients per second : 100 clients/seconds during 1 minute</li></ul><p>Now everything is ready for our tests !</p><h3>PHP : Wordpress</h3><p>For this these tests, I&#39;ve decided to compare Nginx UNIT (with unit-php unit) to :</p><ul><li>Nginx with php-fpm</li><li>Apache with libapache2-mod-php</li></ul><p>I will use the same configuration for all PHP tests :</p><p>PHP-FPM :</p><pre># php.ini<br>memory_limit=512M<br><br># PHP-FPM pool :<br>pm = dynamic<br>pm.max_children = 5<br>pm.start_servers = 2<br>pm.min_spare_servers = 1</pre><p>Apache :</p><pre>memory_limit=512M</pre><p>Nginx Unit (The rest of the configuration has been based on <a href="https://unit.nginx.org/howto/wordpress/">Nginx Unit Wordpress configuration</a> :</p><pre>    &quot;applications&quot;: {<br>        &quot;wordpress&quot;: {<br>            &quot;type&quot;: &quot;php&quot;,<br>            &quot;processes&quot;: {<br>                &quot;max&quot;: 5,<br>                &quot;spare&quot;: 1,<br>                &quot;idle_timeout&quot;: 20<br>            },<br>            &quot;options&quot;: {<br>                &quot;admin&quot;: {<br>                    &quot;memory_limit&quot;: &quot;512M&quot;,<br>                    &quot;log_errors&quot;: &quot;1&quot;<br>                }<br>            }<br>          ...<br>        }<br>    },</pre><p>To have a full tests, HTTPS will be configured using Let&#39;s encrypt certificates.</p><p>These are the results of the tests :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*62vy1XC3bh6T_huI5UPAiQ.png" /></figure><p>During these tests, it became evident that Nginx Unit outperformed other solutions in all scenarios. It was the only one capable of successfully handling the load of 2000 clients per minute, although it did experience a maximum response time of around 6 seconds.</p><h3>Python 3.9 : Datasette</h3><p>For these tests I&#39;ve decided to compare Nginx Unit (with unit-python39 ) to an architecture with Nginx (as a reverse proxy) and Uvicorn. Moreover, each request will perform a sql query to the sqlite database :</p><pre>https://unit.stream.vasseurlaurent.com/_memory?sql=select+sqlite_version%28%29</pre><p>These are the configuration :</p><p>Nginx Unit application :</p><pre>    &quot;applications&quot;: {<br>        &quot;python&quot;: {<br>            &quot;type&quot;: &quot;python&quot;,<br>            &quot;module&quot;: &quot;asgi&quot;,<br>            &quot;callable&quot;: &quot;app&quot;,<br>            &quot;path&quot;: &quot;/www/data/prod&quot;<br>        }<br>    },</pre><p>Nginx proxy pass for Uvicorn :</p><pre>daemon off;<br><br>events {<br>  worker_connections  1024;<br>}<br>http {<br>  server {<br>    ...<br>    location /{<br>      proxy_pass http://127.0.0.1:8009;<br>      proxy_set_header Host $host;<br>    }<br>  }<br>}</pre><p>To be able to deploy Datasette with Nginx Unit, you need to create a wrapper application (more detail <a href="https://unit.nginx.org/howto/datasette/#">here</a>) :</p><pre>import glob<br>from datasette.app import Datasette<br><br>application = Datasette(glob.glob(&#39;*.db&#39;)).app()</pre><p>These are the results of the benchmark :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6x-2wRi6w9mQXNMQJ_Nc6Q.png" /></figure><p>Based on the results of these tests, it can be concluded that Nginx Unit outperforms Nginx as a proxy pass and Uvicorn in terms of performance. However, it is worth noting that the results of the last two tests (50 and 100 clients per second) appear to be unusual. It is difficult to determine whether these response times were influenced by previous tests, but in my opinion, they seem longer than expected.</p><h3>Conclusion</h3><p>Based on our tests, it is evident that Nginx Unit outperforms the other web servers we tested in terms of performance. However, it is important to note that these benchmarks were conducted on a very limited set of resources. If you are interested in a Nginx Unit benchmark with more substantial resources, I highly recommend reading the article titled “<a href="https://habr.com/en/articles/646397/">Comparing PHP-FPM, NGINX Unit, and Laravel Octane.</a>”</p><p>Throughout my career, I have encountered numerous instances where I had to conduct load testing to demonstrate a system’s capability to handle a specific workload. However, I discovered that benchmarking different solutions with their unique configurations was neither straightforward nor highly informative. I gained valuable insights from this benchmark, and I am confident that I will be able to conduct even more effective tests in the future.</p><p>With this article, we conclude our exploration of Nginx Unit and its configuration. I hope you enjoyed following along as we tested and benchmarked Nginx Unit!</p><h3>One more thing …</h3><p>These researches and this article is the result of researches done on my Twitch channel : <a href="https://www.twitch.tv/le_moment_it">@le_moment_it</a> . If you want to support me for free, you can follow the channel and join us for more IT research !</p><p>We live <strong>every Tuesday and Thursday at 15h PM</strong> (UTC+1).<br>To finish, we also have a discord where we share IT news and articles. You can join us here : <a href="https://discord.gg/Bn66XZsWfn">le_moment_it</a></p><p>See you soon !</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c38661194cd0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Nginx UNIT discover and benchmark (part 2)]]></title>
            <link>https://medium.com/@le_moment_it/nginx-unit-discover-and-benchmark-part-2-b9c81744b1?source=rss-abfdaec6dc48------2</link>
            <guid isPermaLink="false">https://medium.com/p/b9c81744b1</guid>
            <category><![CDATA[nginx]]></category>
            <category><![CDATA[computers]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[web]]></category>
            <category><![CDATA[ansible]]></category>
            <dc:creator><![CDATA[Le Moment It]]></dc:creator>
            <pubDate>Mon, 19 Jun 2023 13:43:54 GMT</pubDate>
            <atom:updated>2023-06-19T13:43:54.828Z</atom:updated>
            <content:encoded><![CDATA[<p>Here we are ! Welcome to the second part of our comprehensive Nginx UNIT test !</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XzMZ5t_3eFmR4DKcWq-jmA.png" /></figure><p>As mentioned in the previous article, this section will focus on providing an overview of advanced configuration and automation using an Nginx Ansible role.</p><p>If you haven’t read the first part of this test, I highly recommend taking a look at it : <a href="https://medium.com/@le_moment_it/nginx-unit-discover-and-benchmark-part-1-341cd85896bf?source=your_stories_page-------------------------------------">Nginx UNIT discover and benchmark (part 1)</a></p><p>Let&#39;s start !</p><h3>Application configuration</h3><p>The main distinction between Nginx and Nginx Unit lies in the ability of Nginx Unit to handle application management.</p><p>After conducting extensive testing on Nginx Unit, it became evident that this solution is more suited for application management rather than serving as a traditional web server.</p><p>According to the language of your application, you will be able to customize your runtime.</p><p>Let’s consider an example: deploying a WordPress website.</p><p>The configuration may resemble the following:</p><pre>{<br>    &quot;listeners&quot;: {<br>        &quot;*:80&quot;: {<br>            &quot;pass&quot;: &quot;routes&quot;<br>        }<br><br>    },<br><br>    &quot;routes&quot;: [<br>        {<br>            &quot;match&quot;: {<br>                &quot;uri&quot;: [<br>                    &quot;*.php&quot;,<br>                    &quot;*.php/*&quot;,<br>                    &quot;/wp-admin/&quot;<br>                ]<br>            },<br><br>            &quot;action&quot;: {<br>                &quot;pass&quot;: &quot;applications/wordpress/direct&quot;<br>            }<br>        },<br>        {<br>            &quot;action&quot;: {<br>                &quot;share&quot;: &quot;/path/to/app$uri&quot;,<br>                &quot;fallback&quot;: {<br>                    &quot;pass&quot;: &quot;applications/wordpress/index&quot;<br>                }<br>            }<br>        }<br>    ],<br><br>    &quot;applications&quot;: {<br>        &quot;wordpress&quot;: {<br>            &quot;type&quot;: &quot;php&quot;,<br>            &quot;targets&quot;: {<br>                &quot;direct&quot;: {<br>                    &quot;root&quot;: &quot;/path/to/app/&quot;<br>                },<br><br>                &quot;index&quot;: {<br>                    &quot;root&quot;: &quot;/path/to/app/&quot;,<br>                    &quot;script&quot;: &quot;index.php&quot;<br>                }<br>            }<br>        }<br>    }<br>}</pre><p>In this configuration, we can find multiple things interesting :</p><ul><li><strong>Routes</strong> : According to the url called, we will call<strong> two different application</strong> scripts (defined through <strong>targets</strong>)</li><li><strong>Target</strong> : Define which script is called.</li></ul><p>This is only a simple example of application customization available with Nginx Unit.</p><p>On top of these applications configuration, we can also configure Nginx Unit parameters such as :</p><ul><li><strong>user/group</strong> : User and group used to run the Unit. Each unit can be ran with a different user</li><li><strong>processes</strong> : Number of processes to run the unit</li><li><strong>limits</strong> : Maximum number of requests and timeouts</li><li>…</li></ul><p>You can find the full documentation here : <a href="https://unit.nginx.org/configuration/#applications">https://unit.nginx.org/configuration/#applications</a></p><h3>Under the hood of Units</h3><p>When I initially tried Nginx Unit (using the unit-php), I was surprised to find that the environment was fully set up as soon as I installed unit-php. Furthermore, when I checked the PHP version being utilized by my unit, I observed that it was version 7.4.33, as mentioned in the first article.</p><p>Where does this environment come from? How can I configure Nginx Unit to use PHP 8.2 instead of 7.4? Let’s address these questions here!</p><h4>Environment setup</h4><p>Something I didn&#39;t notice when I first installed the nginx unit unit-php is that it also installed all php packages dependencies.</p><pre>Package: unit-php<br>Version: 1.30.0-1~bullseye<br>Priority: extra<br>Section: admin<br>Maintainer: NGINX Packaging &lt;nginx-packaging@f5.com&gt;<br>Installed-Size: 196 kB<br># Here the libphp-embded packages depends on php7.4-cli, php7.4-common etc ...<br>Depends: lsb-base, libc6 (&gt;= 2.17), unit-r1.30.0, libphp-embed</pre><p>It means that, by itself, the unit does <strong>NOT</strong> embed the environment.</p><p>You will still need to manage and update environment packages installed by nginx unit.</p><p>Because I was testing Nginx UNIT on Debian 11, the default PHP version was 7.4. That&#39;s explain the result given when I checked the PHP version during my first tests.</p><p>But how is I want to use a later version PHP such as PHP 8.2 ?</p><h4><strong>Define our environment</strong></h4><p>At the time I write this article, the latest version of PHP available in official Debian packages is 7.4.33. So to be able to install PHP 8.2, I have decided to install packages from sury .</p><p>Sury packages gathers all old and new version of PHP. You can install it on your server with the following commands :</p><pre>wget https://packages.sury.org/php/apt.gpg -O /usr/share/keyrings/deb.sury.org-php.gpg<br>echo &quot;deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main&quot; &gt; /etc/apt/sources.list.d/php-sury.list<br>apt update</pre><p>However, even if you have installed the php8.2 package on your machine, it will not be utilized by Nginx Unit’s unit-php. <strong>This limitation exists because these packages can only function with official packages that are directly associated with your Linux distribution</strong>.</p><p>The sole method to execute a PHP unit with a specific PHP version is to <strong>generate our own PHP unit</strong>. Since each unit is treated as a Debian package, we will need to create a Debian package for this purpose.</p><p>Let&#39;s do it :</p><pre># Install your php package is not already done<br>apt install php8.2<br><br># Install dev packages needed<br>apt install php-dev libphp-embed<br><br># Create folder for apt<br>export UNITTMP=$(mktemp -d -p /tmp -t unit.XXXXXX)<br>mkdir -p $UNITTMP/unit-php8.2/DEBIAN<br>cd $UNITTMP<br><br># Prepare the build<br>curl -O https://unit.nginx.org/download/unit-1.30.0.tar.gz<br>tar xzf unit-1.30.0.tar.gz<br>cd unit-1.30.0<br><br>./configure --prefix=/usr --statedir=/var/lib/unit --control=unix:/var/run/control.unit.sock --pid=/var/run/unit.pid --log=/var/log/unit.log --tmpdir=/var/tmp --user=unit --group=unit --tests --openssl --modulesdir=/usr/lib/unit/modules --libdir=/usr/lib/x86_64-linux-gnu --cc-opt=&#39;-g -O2 -ffile-prefix-map=/data/builder/debuild/unit-1.30.0/pkg/deb/debuild/unit-1.30.0=. -specs=/usr/share/dpkg/no-pie-compile.specs -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC&#39;<br>./configure php --module=php8.2 --config=php-config<br>make php8.2<br>mv ./build/lib/unit/modules/php8.2.unit.so $UNITTMP/unit-php8.2/MODULESPATH<br>nano $UNITTMP/unit-php8.2/DEBIAN/control<br><br></pre><pre># Create a file to define package name &amp; dependencies<br><br>nano $UNITTMP/unit-php8.2/DEBIAN/control<br><br>Package: unit-php8.2<br>Version: 1.30.0<br>Comment0: Use Unit&#39;s package version for consistency: &#39;apt show unit | grep Version&#39;<br>Architecture: amd64<br>Comment1: To get current architecture, run &#39;dpkg --print-architecture&#39;<br>Comment2: For a list of other options, run &#39;dpkg-architecture -L&#39;<br>Depends: unit (= 1.30.0-1~bullseye), php8.2, libphp-embed<br>Comment3: Specify Unit&#39;s package version to avoid issues when Unit updates<br>Comment4: Again, run &#39;apt show unit | grep Version&#39; to get this value<br>Maintainer: Jane Doe &lt;j.doe@example.com&gt;<br>Description: Custom PHP 8.2 language module for NGINX Unit 1.30.0</pre><pre># Just need to build and install our brand new package : unit-php8.2<br><br>dpkg-deb -b $UNITTMP/unit-php8.2<br>dpkg -i $UNITTMP/unit-php8.2.deb<br><br># You can check that the package is installed <br><br>apt list --installed | grep unit-php<br><br>unit-php8.2/now 1.30.0 amd64 [installed,local]</pre><p>Now you can use it into your Nginx Unit configuration :</p><pre>&quot;applications&quot;: {<br>        &quot;wordpress&quot;: {<br>            &quot;type&quot;: &quot;php8.2&quot;,<br>...<br>        }<br>    }</pre><p>That&#39;s it !</p><p>💡Even if it is possible to create a customized unit with a defined environment, it can be really hard to manage and maintain. This complexity may slow the nginx unit adoption in Production environment. However, if you are still interesting by Nginx Unit, you can deploy Docker with the environment version that you want, for example in our case : <a href="https://hub.docker.com/layers/nginx/unit/1.29.1-php8.1/images/sha256-3d9f40cae27cfd15c0adf99b9ff6d28a416ebbfc1ab3e73e9d16027dc94337ba?context=explore">1.29.1-php8.1</a> (the PHP 8.2 version is not available at the time I write this article).</p><h3>Nginx Unit Ansible role !</h3><p>I am an automation lover, so naturally, I wanted to create a Nginx Unit Ansible role that could be used in production.</p><p>You can find the final result here : <a href="https://github.com/le-moment-it/nginx-unit">https://github.com/le-moment-it/nginx-unit</a></p><p>This Ansible role will :</p><ul><li>Install Nginx Unit and its dependencies</li><li>Install certbot and generate a certificate</li><li>Configure Nginx UNIT</li></ul><p>This Ansible role has been specifically designed for deployment on immutable servers. This means that it will create all the necessary components during its initial deployment. If you wish to update your configurations, you can either reuse this Ansible role or deploy a new server while still utilizing this role.</p><p>Developing this role has been a challenging task. Let’s highlight the reasons behind this difficulty.</p><h4>Let&#39;s encrypt certificate renewal</h4><p>One of the most difficult part of this Ansible role development have been the integration of an automated system to renew Let&#39;s encrypt certificates.</p><p>If you have previously used Certbot with Nginx or Apache, you are likely familiar with the automatic certificate renewal feature. The certificates generated can be renewed without requiring any additional configuration. This functionality is made possible by the available <strong>Certbot plugins</strong> that are automatically configured when using commands such as:</p><pre>certbot --nginx</pre><p>Unfortunately, Nginx Unit does <strong>NOT</strong> have any certbot plugins which means that the certificate renewal process needs to be automated by ourselves.</p><p>This renewal process looks like :</p><ul><li>Generation of a new Let&#39;s encrypt certificates</li><li>Upload of the new generated certificate in the Nginx Unit API</li><li>Replacement of the certificate used in the listener</li><li>Deletion of the previous certificate</li></ul><p>To automate this process, I&#39;ve decided to use certbot post hook script. Each time a new certificate is generated (through a cronjob defined), it will launch a bash script that looks like :</p><pre>#!/bin/bash<br><br># ./renew.sh &lt;name_of_nginx_unit_listener&gt;<br><br># curl --request PUT --data-binary \&quot;unit.stream.vasseurlaurent.com\&quot; --unix-socket /var/run/control.unit.sock http://localhost/config/listeners/*:443/tls/certificate<br>for certificate in $(ls -d /etc/letsencrypt/live/*/ | xargs -n 1 basename); do<br>    cat /etc/letsencrypt/live/$certificate/fullchain.pem /etc/letsencrypt/live/$certificate/privkey.pem &gt; /tmp/$certificate.pem<br>    <br>    # Upload temporary certificate on name tmp-&lt;certificate&gt;<br>    curl -X PUT --data-binary @/tmp/$certificate.pem --unix-socket /var/run/control.unit.sock http://localhost/config &quot;http://localhost/certificates/tmp-$certificate&quot; 2&gt; /dev/null<br>    curl -X PUT --data-binary \&quot;tmp-$certificate\&quot; --unix-socket /var/run/control.unit.sock &quot;http://localhost/config/listeners/$1/tls/certificate&quot;<br><br>    # Delete previous certificate<br>    curl -X DELETE --unix-socket /var/run/control.unit.sock &quot;http://localhost/certificates/$certificate&quot;  2&gt; /dev/null<br>    <br>    # Upload new certificate on name &lt;certificate&gt;<br>    curl -X PUT --data-binary @/tmp/$certificate.pem --unix-socket /var/run/control.unit.sock http://localhost/config &quot;http://localhost/certificates/$certificate&quot; 2&gt; /dev/null<br>    curl -X PUT --data-binary \&quot;$certificate\&quot; --unix-socket /var/run/control.unit.sock &quot;http://localhost/config/listeners/$1/tls/certificate&quot;<br>    <br>    # Remove temporary certificate<br>    curl -X DELETE --unix-socket /var/run/control.unit.sock &quot;http://localhost/certificates/tmp-$certificate&quot;  2&gt; /dev/null<br><br>done</pre><p>Thanks to this system, your certificates will be renewed without any disruption !</p><h4>Configuration management and idempotency</h4><p>Nginx Unit management is inherently designed to be friendly towards infrastructure as code practices. You have the capability to define your entire configuration within a JSON document and import it through the Nginx Unit API. Therefore, I have made the decision to allow users to import their configurations using the variable nginx_unit_configuration.</p><p>To import this configuration, I&#39;ve decided to use the ansible plugin ansible.builtin.uri . This plugin will push our Nginx Unit configuration by creating a HTTP request.</p><pre>- name: Configure Nginx unit<br>  ansible.builtin.uri:<br>    url: http://localhost/config<br>    unix_socket: /var/run/control.unit.sock<br>    method: PUT<br>    body_format: json<br>    status_code:<br>      - 200<br>    body: &quot;{{ nginx_unit_configuration | to_json }}&quot;<br>  become: true</pre><p>However, it is worth noting that the default output of the Ansible plugin is always “ok” (I am unable to explain why this is the case). Although my Ansible role has been designed for deployment on immutable servers, I want to ensure that if the role is deployed multiple times on the same server, we can track whether a configuration modification has been applied. This aligns with the principle of idempotency.</p><p>To achieve this, I have implemented a straightforward JSON comparison (using JQ) between the current configuration (located in the nginx state folder at /var/lib/unit/conf.json) and the new configuration. If there are any differences, we apply the new configuration; otherwise, we skip the configuration task.</p><p>The comparison is performed like this :</p><pre>- name: Compare current and new configuration<br>  ansible.builtin.shell:<br>    cmd: |<br>      set -o pipefail<br>      jq --argfile a /tmp/unit.json --argfile b {{ nginx_state_directory }}/conf.json -n &#39;($a | (.. | arrays) |= sort) as $a | ($b | (.. | arrays) |= sort) as $b | $a == $b&#39;<br>  args:<br>    executable: /bin/bash<br>  register: comparison<br>  changed_when: false<br>  become: true</pre><h3>Conclusion</h3><p>In this second article, we have discussed how to optimize and configure our application using native Nginx Unit parameters or by utilizing a custom Nginx Unit unit.</p><p>If you are interested in deploying Nginx Unit in your environment, you can also make use of the Nginx Ansible role that I have created.</p><p>In the next article, we will address the crucial question: Is Nginx Unit performant? Together, we will explore this by benchmarking Nginx Unit and comparing its performance to other web servers.</p><h3>One more thing …</h3><p>These researches and this article is the result of researches done on my Twitch channel : <a href="https://www.twitch.tv/le_moment_it">@le_moment_it</a> . If you want to support me for free, you can follow the channel and join us for more IT research !</p><p>We live <strong>every Tuesday and Thursday at 15h PM</strong> (UTC+1).<br>To finish, we also have a discord where we share IT news and articles. You can join us here : <a href="https://discord.gg/Bn66XZsWfn">le_moment_it</a></p><p>See you soon !</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b9c81744b1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Nginx UNIT discover and benchmark (part 1)]]></title>
            <link>https://medium.com/@le_moment_it/nginx-unit-discover-and-benchmark-part-1-341cd85896bf?source=rss-abfdaec6dc48------2</link>
            <guid isPermaLink="false">https://medium.com/p/341cd85896bf</guid>
            <category><![CDATA[nginx]]></category>
            <category><![CDATA[hosting]]></category>
            <category><![CDATA[nginx-unit]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[application]]></category>
            <dc:creator><![CDATA[Le Moment It]]></dc:creator>
            <pubDate>Tue, 25 Apr 2023 06:05:29 GMT</pubDate>
            <atom:updated>2023-04-25T06:05:29.868Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0OsjdBxCov8-A6Vl.jpg" /></figure><p>According to statistics from W3techs.com, Nginx is the most widely used web server solution, with a utilization rate of 34.4%. This puts it ahead of its closest competitor, Apache2, which has a utilization rate of 32.1%.</p><p>In 2017, Nginx company announced a new open-source project called Nginx UNIT. During the conference, Nginx UNIT was introduced as a new dynamic web and application server. Six months later, the product became globally available and ready for production.</p><p>As of April 2023, Nginx UNIT is compatible with the following programming languages:</p><ul><li>Go</li><li>Javascript (Node js)</li><li>Java</li><li>Perl</li><li>PHP</li><li>Python</li><li>Ruby</li></ul><p>In this article, you will follow me as I discover Nginx UNIT and its features. This discovery will be divided into three separate articles:</p><ol><li>Installation and First Configuration (the article you are currently reading)</li><li>Advanced Configuration and Automation (part 2)</li><li>Benchmarking (part 3)</li></ol><p>Are you ready? Let’s get started!</p><h3>Installation</h3><p>The first step to perform is the installation of NGINX Unit. To do so, we will follow the <a href="https://unit.nginx.org/installation/#debian">documentation</a>. I will be performing my tests on a Debian 11 machine.</p><p>Note that installation on other Linux distributions may differ.</p><p>Download and Save Nginx&#39;s GPG signing key :</p><pre>sudo curl --output /usr/share/keyrings/nginx-keyring.gpg  \<br>      https://unit.nginx.org/keys/nginx-keyring.gpg</pre><p>Configure apt packages by creating the file /etc/apt/sources.list.d/unit.list :</p><pre>deb [signed-by=/usr/share/keyrings/nginx-keyring.gpg] https://packages.nginx.org/unit/debian/ bullseye unit<br>deb-src [signed-by=/usr/share/keyrings/nginx-keyring.gpg] https://packages.nginx.org/unit/debian/ bullseye unit</pre><p>Now we are ready to install Nginx Unit :</p><pre>apt update<br>apt install unit</pre><p>⚠️ The runtime details depends on your installation. For an installation on Debian with official packages, we will have the following configuration :</p><ul><li>Control socket : /var/run/control.unit.sock</li><li>Log file : /var/log/unit.log</li><li>Non-privileged user and group : unit</li></ul><p>Now, you also need to install the Nginx Unit package that corresponds to the application you want to host. I have decided to perform my first tests with a PHP application, so I will install the PHP Unit package :</p><pre>apt install unit-php</pre><p>The last installation step is to restart the unit service (it will allow Nginx UNIT to use the new unit you installed).</p><pre>systemctl restart unit</pre><p>We&#39;re good to go ! Now we can start to configure our Nginx Unit.</p><h3>Configuration</h3><p>If you are familiar with Nginx, you may be accustomed to configuring your vhosts by adding their configuration in the /etc/nginx/sites-available folder .</p><p>But it is <strong>NOT </strong>how Nginx UNIT configuration works. Instead, the entire configuration is managed dynamically <strong>over HTTP via a friendly RESTful JSON API</strong>.</p><p>This is one of the key features of Nginx Unit, as configuration changes can be made <strong>locally</strong> or <strong>remotely</strong> without restarting processes.</p><p>For my first tests, I have decided to write a JSON file where I will include all my configuration. Each time I want to update my configuration, I will use the following command: :</p><pre>curl -X PUT --data-binary @snippet.json --unix-socket /var/run/control.unit.sock http://localhost/config</pre><p>💡Having the full configuration within a single JSON file is quite convenient. It can be easily read and backed up.</p><h4>Application configuration</h4><p>Now, it’s time to configure our first application! As I mentioned before, I will be hosting a simple PHP application (a single page that shows the phpinfo() information).</p><p>The first configuration that we need to do is for the listener. The listener defines on which ports the web server will listen to. Additionally, you can configure SSL encryption and protocol forwarding.</p><p>For this first example, we will add a very simple configuration that listens on port 80 and sends requests to an application named blog :</p><pre>{<br>    &quot;listeners&quot;: {<br>        &quot;*:80&quot;: {<br>            &quot;pass&quot;: &quot;applications/blog&quot;<br>        }<br>    },<br>    &quot;applications&quot;: {<br>        &quot;blog&quot;: {<br>            &quot;type&quot;: &quot;php&quot;,<br>            &quot;root&quot;: &quot;/www/data/prod&quot;,<br>            &quot;index&quot;: &quot;index.html&quot;<br>        }<br>    }<br>}</pre><p>Let&#39;s describe the above configuration :</p><ul><li><strong>Listener</strong> : We listen on the port 80 and we pass the request to the application blog .</li><li><strong>Applications</strong> : This API is where we define applications that we host. First you need to define the type of application. <strong>The type of the application is the name of the package without </strong><strong>unit-</strong> (for example php for a package unit-php ).<br>Then define the root folder (where the application source code is) and the index</li></ul><p>We apply the configuration with the curl command defined above then we create a file /www/data/prod/index.html with the following content :</p><pre>&lt;?php<br>phpinfo();<br>phpinfo(INFO_MODULES);<br>?&gt;</pre><p>And that&#39;s it , our application is live :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/968/1*ZtcT8Du6dTs7zUWIrpwAiw.png" /></figure><p>🚀 More application configuration will be tested and explained in the second part of this discover.</p><h3>Let&#39;s encrypt integration</h3><p>The next step is to implement SSL encryption to use HTTPS.</p><p>As it is free, I have decided to use a Let’s Encrypt certificate (with certbot) to implement SSL encryption in our Nginx Unit configuration. If you already have certificates, you can skip the following commands.</p><p>💡In order to better manage the Let’s Encrypt HTTP challenge, I have decided to centralize the creation of certbot temporary files into a single directory named /certbot_challenge .</p><p>⚠️ There is currently no certbot plugin available for Nginx Unit, so we will need to implement our own matching rules. This will allow us to introduce a new concept: routes</p><p>A route configuration entity defines internal request routing. It receives requests from listeners and, according to conditions, will perform different actions (e.g., filter, redirect, load balance, etc.).</p><p>In our case we will create a route named http . This route will have the following condition :</p><p><strong>IF</strong> uri is equal to /.well-known/acme-challenge/* (which is the uri used by certbot), <strong>THEN</strong> share (way to expose static content) to the folder /certbot_challenge .</p><p>Let&#39;s update our configuration :</p><pre>{<br>    &quot;listeners&quot;: {<br>        &quot;*:80&quot;: {<br>            &quot;pass&quot;: &quot;routes/http&quot;<br>        }<br>    },<br>    &quot;applications&quot;: {<br>        &quot;blog&quot;: {<br>            &quot;type&quot;: &quot;php&quot;,<br>            &quot;root&quot;: &quot;/www/data/prod&quot;,<br>            &quot;index&quot;: &quot;index.html&quot;<br>        }<br>    },<br>    &quot;routes&quot;: {<br>        &quot;http&quot;: [<br>            {<br>                &quot;match&quot;: {<br>                    &quot;uri&quot;: &quot;/.well-known/acme-challenge/*&quot;<br>                },<br>                &quot;action&quot;: {<br>                    &quot;share&quot;: &quot;/certbot_challenge/$uri&quot;<br>                }<br>            }<br>        ]<br>    }<br>}</pre><p>Few things to note here :</p><ul><li>The listeners pass the request to routes/http</li><li>The action share to the path /certbot_challenge/$uri . In the <a href="https://unit.nginx.org/howto/certbot/#generating-certificates">official documentation</a> , it is missing the $uri . It is because the share action changed its behavior since the version 1.26.0 (cf <a href="https://unit.nginx.org/howto/certbot/#generating-certificates">static files documentation</a>).</li></ul><p>⚠️ After applying this configuration, the php application will NOT be available. It is normal, no worry.</p><p>Now it is time generate our certificate ! We point out the DNS unit.stream.vasseurlaurent.com on our server public IP.</p><p>To generate the certificate, we use the following command :</p><pre>certbot certonly --webroot -w /certbot_challenge/ -d unit.stream.vasseurlaurent.com --non-interactive --agree-tos -m le_moment_it@proton.me</pre><p>The certificate is generated :</p><pre>oot@ip-172-31-15-108:/configuration# certbot certonly --webroot -w /certbot_challenge/ -d unit.stream.vasseurlaurent.com --non-interactive --agree-tos -m le_moment_it@proton.me<br>Saving debug log to /var/log/letsencrypt/letsencrypt.log<br>Plugins selected: Authenticator webroot, Installer None<br>Requesting a certificate for unit.stream.vasseurlaurent.com<br><br>IMPORTANT NOTES:<br> - Congratulations! Your certificate and chain have been saved at:<br>   /etc/letsencrypt/live/unit.stream.vasseurlaurent.com/fullchain.pem<br>   Your key file has been saved at:<br>   /etc/letsencrypt/live/unit.stream.vasseurlaurent.com/privkey.pem<br>   Your certificate will expire on 2023-07-21. To obtain a new or<br>   tweaked version of this certificate in the future, simply run<br>   certbot again. To non-interactively renew *all* of your<br>   certificates, run &quot;certbot renew&quot;<br> - If you like Certbot, please consider supporting our work by:<br><br>   Donating to ISRG / Let&#39;s Encrypt:   https://letsencrypt.org/donate<br>   Donating to EFF:                    https://eff.org/donate-le</pre><p>Now, we need to concatenate the fullchain.pem certificate and the privkey.pem file into one file that we will name bundle.pem :</p><pre>cat /etc/letsencrypt/live/unit.stream.vasseurlaurent.com/fullchain.pem  \<br>      /etc/letsencrypt/live/unit.stream.vasseurlaurent.com/privkey.pem &gt; bundle.pem</pre><p>The next step is to upload our bundle.pem to the Nginx UNIT API :</p><pre>curl -X PUT --data-binary @bundle.pem --unix-socket /var/run/control.unit.sock  http://localhost/certificates/unit.stream.vasseurlaurent.com</pre><p>⚠️ Note that the Nginx UNIT endpoint I have used is http://localhost/certificates/unit.stream.vasseurlaurent.com . The end of the URL represents the name of certificate inside Nginx UNIT (here the name will be unit.stream.vasseurlaurent.com ).</p><p>Now we configure our listener to be able to use our newly created certificate :</p><pre>{<br>    &quot;listeners&quot;: {<br>        &quot;*:80&quot;: {<br>            &quot;pass&quot;: &quot;routes/http&quot;<br>        },<br>        &quot;*:443&quot;: {<br>            &quot;pass&quot;: &quot;routes/main&quot;,<br>            &quot;tls&quot;: {<br>                &quot;certificate&quot;: &quot;unit.stream.vasseurlaurent.com&quot;<br>            }<br>        }<br>    },<br>    &quot;applications&quot;: {<br>        &quot;blog&quot;: {<br>            &quot;type&quot;: &quot;php&quot;,<br>            &quot;root&quot;: &quot;/www/data/prod&quot;,<br>            &quot;index&quot;: &quot;index.html&quot;<br>        }<br>    },<br>    &quot;routes&quot;: {<br>        &quot;main&quot;: [<br>            {<br>                &quot;action&quot;: {<br>                    &quot;pass&quot;: &quot;applications/blog&quot;<br>                }<br>            }<br>        ],<br>        &quot;http&quot;: [<br>            {<br>                &quot;match&quot;: {<br>                    &quot;uri&quot;: &quot;/.well-known/acme-challenge/*&quot;<br>                },<br>                &quot;action&quot;: {<br>                    &quot;share&quot;: &quot;/certbot_challenge/$uri&quot;<br>                }<br>            },<br>            {<br>                &quot;match&quot;: {<br>                    &quot;scheme&quot;: &quot;http&quot;<br>                },<br>                &quot;action&quot;: {<br>                    &quot;location&quot;: &quot;https://unit.stream.vasseurlaurent.com/&quot;,<br>                    &quot;return&quot;: 301<br>                }<br>            }<br>        ]<br>    }<br>}</pre><p>We need to point out several things in this configuration:</p><ul><li><strong>Listeners</strong> : We have now two listeners , one for the port 80 and another for port 443. On the second listener, we configure the certificate using the <strong>name</strong> of the certificate we uploaded (in my case, I called the certificate unit.stream.vasseurlaurent.com )<br>Each listener passes the request to a different route.</li><li><strong>Routes</strong> : We configured two routes. The first one, named http, handles all workflows when someone tries to access my server using the HTTP protocol. I defined two cases :<br>- <strong>Cerbot</strong> challenge : As explained above, I need to redirect requests containing the path /.well-known/acme-challenge to the folder /certbot_challenge <br>- <strong>HTTPS redirection</strong> : Someone can try to access my application using the HTTP protocol; in that case, I redirect the traffic to my HTTPS endpoint<br><br>My second route, named main simply send the request to my PHP application.</li></ul><p>💡 It is important to note that when multiple conditions are created within a route, they are processed in order (from top to bottom). For example, in the http , the condition if uri = /well-known/acme-challenge is processed before the condition if scheme = http . As soon as a condition is validated (and the associated action performed), the next ones won’t be processed.</p><p>You can now apply the configuration :</p><pre>certbot certonly --webroot -w /certbot_challenge/ -d unit.stream.vasseurlaurent.com --non-interactive --agree-tos -m le_moment_it@proton.me</pre><p>And that&#39;s it ! The PHP application is available with HTTPS protocol !</p><h3>Conclusion</h3><p>In this first article, we have discovered how to install Nginx UNIT and host a simple PHP application on Debian.</p><p>We also generated and integrated a Let’s Encrypt certificate.</p><p>This is only the beginning! In the next article, we will discover more about how to configure the units themselves and how we can create units with a non-default version environment.</p><h3>One more thing …</h3><p>These researches and this article is the result of researches done on my Twitch channel : <a href="https://www.twitch.tv/le_moment_it">@le_moment_it</a> . If you want to support me for free, you can follow the channel and join us for more IT research !</p><p>We live <strong>every Tuesday and Thursday at 15h PM</strong> (UTC+1).<br>To finish, we also have a discord where we share IT news and articles. You can join us here : <a href="https://discord.gg/Bn66XZsWfn">le_moment_it</a></p><p>See you soon !</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=341cd85896bf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Scaffolding a repository]]></title>
            <link>https://medium.com/@le_moment_it/scaffolding-a-repository-74482b7d5774?source=rss-abfdaec6dc48------2</link>
            <guid isPermaLink="false">https://medium.com/p/74482b7d5774</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[github]]></category>
            <dc:creator><![CDATA[Le Moment It]]></dc:creator>
            <pubDate>Tue, 11 Apr 2023 01:25:51 GMT</pubDate>
            <atom:updated>2023-04-11T01:25:51.279Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_YuhK_8kOZMFeUFbOzzUAw.jpeg" /></figure><p>Starting a new IT project is exciting. You have tons of ideas, and you are motivated and ready to code! But wait a minute! You need to create and initialize your Git repository!</p><p>To init your repository you imagine two choices :</p><ul><li><strong>Starting from scratch</strong>: You may consider using framework commands like “npm init” or others to initialize your repository. However, if you want to implement the tools you used to use for this type of project, you will need to add them manually. This can be a tedious task, and you may end up forgetting some of the necessary tools.</li><li><strong>Copying from another project</strong>: Another solution you may consider is to copy/paste your last successful project, which was based on the same technology, and change the values that need to be updated. However, even in this case, you may end up forgetting about half of the values that need to be changed.</li></ul><p>So, what should you do? What if there was a third solution? Let me introduce you to <strong>scaffolding</strong>.</p><p>In this article, we will explain what scaffolding is, how to create a repository template, and share some examples.</p><h4>What is the scaffolding ?</h4><p>The repository scaffolding is based on two components :</p><ul><li>A <strong>template</strong> : A set of one or multiple files that includes variables to be replaced when the template is copied.</li><li><strong>Values</strong> : A set of defined values that will replace the variables when the template is copied.</li></ul><p>For example, a simple template would be :</p><pre># &lt;%= name %&gt;<br><br>## Overview<br><br>&lt;%= description %&gt;</pre><p>When we generate a file with this template using the following values :</p><ul><li>name = terraform-aws-generated</li><li>description = This is a generated module</li></ul><p>We obtain this result :</p><pre># terraform-aws-generated<br><br>## Overview<br><br>This is a generated terraform module</pre><p>Moreover, we can add conditions, loops, and more. Isn’t that great?</p><h4>Scaffolding technologies</h4><p>When I started to look for scaffolding technologies, I was surprised to find that there weren’t many free tools available that allow for this kind of feature. During my research, I came across three solutions:</p><ul><li><a href="https://github.com/tmrts/boilr"><strong>Boilr</strong></a> : A scaffolding tool that has not been updated since 2017. I did not look any further.</li><li><a href="https://github.com/galElmalah/scaffolder"><strong>Scaffolder</strong></a> : The first tool I found. More precisely, last year during the introduction of <a href="https://www.cncf.io/blog/2022/03/15/backstage-project-joins-the-cncf-incubator/">Backstage in the CNCF</a> (incubator level), I spent hours testing Scaffolder through its Backstage integration (which seemed really great). However, the last update to Scaffolder’s code was done more than a year ago. That’s why I decided not to use it.</li><li><a href="https://yeoman.io/"><strong>Yeoman</strong></a> : Then comes Yeoman. I was surprised to see that this tool was created more than 10 years ago, but it is still actively maintained. Moreover, it seems to integrate by default the functionalities that I was looking for. So, <strong>I decided to go with this solution</strong>.</li></ul><h4>Yeoman : Get started</h4><p>To get started with Yeoman, we simply need to install the CLI :</p><pre>npm install -g yo</pre><p>Then we need to create our generator. A generator will be an npm package that stores all our templates. You can initialize it with the following command :</p><pre>npm init</pre><p>⚠️ It is really important to name your npm module starting with <strong>“generator-”</strong> (such as generator-example). Otherwise, the Yeoman CLI won’t recognize that this npm package is a Yeoman generator.</p><p>A typical Yeoman generator project directory tree looks like this:</p><pre>├───package.json<br>└───generators/<br>    ├───generator1/<br>    │   └───index.js<br>    └───generator2/<br>        └───index.js</pre><p>Let&#39;s explain the role of each file :</p><ul><li><strong>package.json</strong> : Needed in all npm packages, it defines the metadata of your package and its dependencies</li><li><strong>generator folder</strong> : Folder that gathers all your generators. Each subfolders represents a separated generator that can be called following this command :</li></ul><pre>yo &lt;npm package name&gt;:&lt;subfolder&gt;</pre><ul><li><strong>index.js</strong> : This file is the most important part of the Yeoman generator. It represents every action that will be taken during the generation of your code. In this file, you will be able to override multiple functions. Each function is performed in order. <br>- initializing - Your initialization methods (checking current project state, getting configs, etc)<br>- prompting - Where you prompt users for options (where you’d call this.prompt())<br>- configuring - Saving configurations and configure the project (creating .editorconfig files and other metadata files)<br>- default - If the method name doesn’t match a priority, it will be pushed to this group.<br>- writing - Where you write the generator specific files (routes, controllers, etc)<br>- conflicts - Where conflicts are handled (used internally)<br>- install - Where installations are run (npm, bower)<br>- end - Called last, cleanup, say <em>good bye</em>, etc</li></ul><p>Now that we know the theory , let&#39;s practice !</p><h4>Yeoman : Generator creation</h4><p>To illustrate how Yeoman works, I will create an npm package named generator-moment-it.</p><p>Let&#39;s create this npm package :</p><pre>npm init</pre><p>This is the result of the package.json file :</p><pre>{<br>  &quot;name&quot;: &quot;generator-moment-it&quot;,<br>  &quot;version&quot;: &quot;1.0.0&quot;,<br>  &quot;description&quot;: &quot;This is an example repository for Yeoman&quot;,<br>  &quot;main&quot;: &quot;index.js&quot;,<br>  &quot;scripts&quot;: {<br>    &quot;test&quot;: &quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot;<br>  },<br>  &quot;keywords&quot;: [<br>    &quot;yeoman-generator&quot;<br>  ],<br>  &quot;author&quot;: &quot;Le Moment IT&quot;,<br>  &quot;license&quot;: &quot;Apache-2.0&quot;,<br>  &quot;files&quot;: [<br>    &quot;generators&quot;<br>  ],<br>  &quot;dependencies&quot;: {<br>    &quot;@octokit/rest&quot;: &quot;^19.0.7&quot;, // =&gt; Will come back to this later<br>    &quot;yeoman-generator&quot;: &quot;^5.8.0&quot;,<br>    &quot;yosay&quot;: &quot;^2.0.2&quot;<br>  }<br>}</pre><p>We are ready to go ! Let&#39;s create the ./generators/ansible-role folder and the ./generators/ansible-role/index.js .</p><h4>Yeoman : Our first variable</h4><p>In the index.js , we will define how to create our content. The first step is to define our variable values. We can use a prompting system where each time the generator is used, a prompt will appear to request variable values.</p><p>Let&#39;s define a simple variable name :</p><pre>// ./generators/ansible-role/index.js    <br>    async prompting() {<br>        this.log(<br>            yosay(&#39;Welcome to the moment-it generator v1.0.0!&#39;)<br>        );<br><br>        this.answers = await this.prompt([{<br>            type: &#39;input&#39;,<br>            name: &#39;name&#39;,<br>            message: &#39;Enter name for the new ansible role : &#39;,<br>        }<br>        ]);</pre><p>This is the result :</p><pre>~ took 18s yo moment-it:ansible-role<br><br>     _-----_     <br>    |       |    ╭──────────────────────────╮<br>    |--(o)--|    │ Welcome to the moment-it │<br>   `---------´   │     generator v1.0.0!    │<br>    ( _´U`_ )    ╰──────────────────────────╯<br>    /___A___\   /<br>     |  ~  |     <br>   __&#39;.___.&#39;__   <br> ´   `  |° ´ Y ` <br><br>? Enter name for the new ansible role :</pre><p>Seems to work perfectly ! We can now use this variable into a template file.</p><p>Let&#39;s create a folder templates , and add a file README.md where we add our name variable :</p><pre>&lt;%= name %&gt;<br>=========</pre><h4>Yeoman : Writing actions</h4><p>Now that we have defined a variable and a template, we need to tell Yeoman how to generate the content, including where to put the file and how to replace the variables</p><p>To do that, we will rewrite the writing() function :</p><pre>    writing() {<br>        // Define the folder where templates will be copied<br>        this.destinationRoot(this.name);<br>        // Copy all template files and replace variables<br>        this.fs.copyTpl(<br>            `${this.templatePath()}/*/*`,<br>            this.destinationRoot(), {<br>            name: this.name,<br>        }<br><br>    }</pre><p>That&#39;s it ! We have created our first scaffold repository ! Now we can add other needed files and variables !</p><h4>Yeoman : Let&#39;s go further !</h4><p>During my research on Yeoman, I felt a bit frustrated about one thing: generating the content of a Git repository is great, but what about generating the repository itself?</p><p>In my case, I am using Github. So, is it possible to perform the following actions with a single yo command?</p><ul><li>Create a Github repository and configure it according to my needs</li><li>Create the git repository content locally from my templates</li><li>Push my initialized repository to the Github remote repository</li></ul><p>Before starting, we have two prerequisites :</p><ul><li>Create a Github PAT (Personal Access Token) and set it up in the GITHUB_TOKEN environment variable.</li><li>Setup my SSH agent to be able to push using a SSH key</li></ul><p>To create the repository, we will use the @octokit/rest npm package.</p><p>To create the repository, I rewrite the configuring() function (which comes before the writing() function) :</p><pre>    async configuring() {<br>        if (this.create) {<br>            const octokit = new Octokit({<br>                auth: process.env.GITHUB_TOKEN, // Use the GITHUB_TOKEN env variable<br>            });<br><br>            try {<br>                await octokit.rest.repos.createForAuthenticatedUser({<br>                    name: this.name,<br>                    description: this.description,<br>                    private: this.private,<br>                    allow_squash_merge: false, // Github repository configuration<br>                    allow_merge_commit: false,<br>                    allow_rebase_merge: true,<br>                    auto_init: false<br>                });<br>            }<br>            catch {<br>                this.log(&quot;Creation of the git repository failed, skipping ...&quot;)<br>                this.failed_github_repository_creation = true<br>            }<br><br><br><br>        }<br><br>    }</pre><p>Perfect ! Now the repository will be created (if I decide to through the prompt).</p><p>Now I need to push my local content after that I copied my templates. To do that, I decide to rewrite the install() which is the functions that comes after the writing() one.</p><p>I couldn’t find a convenient way to push my local content except by executing local git commands :</p><pre> install() {<br>        if (this.push_init) {<br>            if (this.failed_github_repository_creation) {<br>                this.log(&quot;Push to origin skipped because the Github repository has not been created succesfully&quot;)<br>            }<br>            else {<br>                this.spawnCommandSync(&#39;git&#39;, [&#39;init&#39;]);<br>                this.spawnCommandSync(&#39;git&#39;, [&#39;remote&#39;, &#39;add&#39;, &#39;origin&#39;, &quot;git@github.com:&quot; + this.github_user + &quot;/&quot; + this.name + &quot;.git&quot;]);<br>                this.spawnCommandSync(&#39;git&#39;, [&#39;checkout&#39;, &#39;-b&#39;, &#39;main&#39;])<br>                this.spawnCommandSync(&#39;git&#39;, [&#39;commit&#39;, &#39;--allow-empty&#39;, &#39;-m&#39;, &#39;&quot;empty commit for init&quot;&#39;]);<br>                this.spawnCommandSync(&#39;git&#39;, [&#39;push&#39;, &#39;--set-upstream&#39;, &#39;origin&#39;, &#39;main&#39;]);<br>                this.spawnCommandSync(&#39;git&#39;, [&#39;checkout&#39;, &#39;-b&#39;, &#39;develop&#39;])<br>                this.spawnCommandSync(&#39;git&#39;, [&#39;add&#39;, &#39;--all&#39;]);<br>                this.spawnCommandSync(&#39;git&#39;, [&#39;commit&#39;, &#39;-m&#39;, &#39;&quot;initial commit from generator [skip ci]&quot;&#39;]);<br>                this.spawnCommandSync(&#39;git&#39;, [&#39;push&#39;, &#39;--set-upstream&#39;, &#39;origin&#39;, &#39;develop&#39;]);<br>            }<br><br>        }<br><br>    }</pre><p>With these commands, I create :</p><ul><li>A remote <strong>main</strong> branch : The main branch with an empty commit (for initialization)</li><li>A remote <strong>develop </strong>branch : The develop branch with the initialized content.</li></ul><p>That&#39;s it ! We succesfully created a Github repository and initialized it !</p><h4>Moment-IT generator example</h4><p>To properly illustrate all the research I did during our livestream, I have created a Yeoman generator : <a href="https://github.com/le-moment-it/generator-moment-it">generator-moment-it</a></p><p>This generator stores two templates (to use in personal Github account) :</p><ul><li><a href="http://ansible-role/">ansible-role</a> : Simple directory tree to create an Ansible role. Moreover we add some lint good practices and <a href="https://molecule.readthedocs.io/en/latest/">molecule</a> unit test.</li><li><a href="https://github.com/le-moment-it/generator-moment-it/tree/main/generators/terraform-module">terraform-module</a> : Directory tree to create a Terraform module with <a href="https://terratest.gruntwork.io/">Terratest</a> unit tests.</li></ul><p>These both templates integrate a Github CI/CD pour create automatically tags and releases following the semantic versioning. To understand how does it work, you can read my previous article : <a href="https://medium.com/@le_moment_it/tags-releases-automation-77678047c79e">Tags &amp; Releases automation</a></p><p>⚠️ Before using these templates (and if you want to use the Github repository creation feature), please remember to :</p><ul><li><strong>Set your Github PAT in the env variable </strong><strong>GITHUB_TOKEN</strong></li><li><strong>Configure your SSH agent to push code over SSH to the Github remote</strong></li></ul><p>Let&#39;s go, first, we need to install the generator :</p><pre>npm install -g https://github.com/le-moment-it/generator-tf-module.git</pre><p>That&#39;s it ! You are ready to go ! Let&#39;s generate an ansible-role !</p><pre>yo moment-it:ansible-role<br><br><br>     _-----_     <br>    |       |    ╭──────────────────────────╮<br>    |--(o)--|    │ Welcome to the moment-it │<br>   `---------´   │     generator v1.0.0!    │<br>    ( _´U`_ )    ╰──────────────────────────╯<br>    /___A___\   /<br>     |  ~  |     <br>   __&#39;.___.&#39;__   <br> ´   `  |° ´ Y ` <br><br>? Enter name for the new ansible role :  linux-generated<br>? Enter description for the new ansible role :  This is an ansible role generated<br>? Create the Github CI/CD workflow ? : Yes<br>? Do you want to generate the Github repository ? :  Yes<br>? Enter your github user  le-moment-it<br>? Enter the description of the project :  This is a Github repository generated<br>? Is your project private ?  No<br>? Do you want to push the generated code to the remote ? : (Y/n) n</pre><p>TADAAAAM! Your repository has been initialized. Check the remote develop branch to see your files.</p><p>If you want to see one example for each template you can check :</p><ul><li>ansible-role : <a href="https://github.com/le-moment-it/linux-generated/tree/develop">linux-generated</a></li><li>terraform-module : <a href="https://github.com/le-moment-it/terraform-aws-generated/tree/develop">terraform-aws-generated</a></li></ul><h3>Conclusion</h3><p>Yeoman is a fantastic tool that provides an easy way to create and share templates within your organization. It offers great flexibility and can be customized to fit any need as long as it can be coded in JavaScript.</p><p>The examples shared during this livestream are just simple templates for initializing repositories, but they can be enhanced and tailored to your specific requirements.</p><h3>One more thing …</h3><p>These researches and this article is the result of researches done on my Twitch channel : <a href="https://www.twitch.tv/le_moment_it">@le_moment_it</a> . If you want to support me for free, you can follow the channel and join us for more IT research !</p><p>We live <strong>every Tuesday and Thursday at 15h PM</strong> (UTC+1).<br>To finish, we also have a discord where we share IT news and articles. You can join us here : <a href="https://discord.gg/Bn66XZsWfn">le_moment_it</a></p><p>See you soon !</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=74482b7d5774" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tags & Releases automation]]></title>
            <link>https://medium.com/@le_moment_it/tags-releases-automation-77678047c79e?source=rss-abfdaec6dc48------2</link>
            <guid isPermaLink="false">https://medium.com/p/77678047c79e</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <category><![CDATA[releases]]></category>
            <category><![CDATA[it]]></category>
            <category><![CDATA[github-actions]]></category>
            <dc:creator><![CDATA[Le Moment It]]></dc:creator>
            <pubDate>Sun, 02 Apr 2023 13:58:24 GMT</pubDate>
            <atom:updated>2023-04-03T10:57:01.767Z</atom:updated>
            <content:encoded><![CDATA[<p>As a professional DevOps , one of my key responsibilities is to manage git repositories, which include Terraform modules and Ansible roles.</p><p>Whenever I need to update a repository, I start by creating a branch and making the necessary changes. Then, I open a pull request and wait for it to be reviewed. If the changes are approved, I merge the pull request and manually tag my repository. However, this <strong>manual tagging process can be tedious and prone to errors</strong>.</p><p>To address this issue, I decided to implement a process that <strong>generates a calculated tag version</strong> (following semantic versioning), <strong>creates the tag</strong> <strong>and</strong> <strong>release</strong>, and <strong>generates a CHANGELOG.md</strong> file that tracks all the changes made between the previous and current versions. In this article, I will walk you through the steps I took to implement this workflow using Github Actions.</p><p><strong>So this is where my journey begins !</strong></p><p>By the end of this article, you will have a clear understanding of how to implement this workflow in your own projects. Additionally, I have provided a <strong>link to a Github repository template that demonstrates everything</strong> I have explained in this article.</p><h3>Step 1 — The semantic versioning automation</h3><p>To begin implementing the workflow, the first step is to automate the “calculation” of the version. I&#39;ve decided to use the great Github Actions : <a href="https://github.com/PaulHatch/semantic-version">paulhatch/semantic-version@v5.0.3</a></p><p>Because, when I was in live, I had some struggle understanding how this Github Actions was calculating the new version, let&#39;s explain it here.</p><h4>Semantic versioning explained</h4><p>The semantic versioning is a simple set of rules that normalize the version update of a software. To explain it easily, we could say that the version of a software is define by 3 numbers (you can add more if you need) :</p><p><strong>&lt;MAJOR&gt;.&lt;MINOR&gt;.&lt;PATCH&gt;</strong></p><p>According to your changes in the application, you will need to update :</p><ul><li><strong>MAJOR</strong> : Need to be updated if there is a breaking change between the previous and the current version</li><li><strong>MINOR : </strong>Need to be updated if there is no breaking changes</li><li><strong>PATCH</strong> : Need to be updated when you perform a fix</li></ul><p>💡 To keep it simple, and because for infrastructure as code development we don&#39;t need more than these 3 numbers, I won&#39;t explained more. However, if you want more details you can check the <a href="https://semver.org/">semantic versioning documentation</a></p><h4>Implementation : Github Action</h4><p>Like said previously, I will use the Github Action : <a href="https://github.com/PaulHatch/semantic-version">paulhatch/semantic-version@v5.0.3</a> .</p><p>With this Github Action, you can define whether your changes are major, minor, or patch updates by setting a pattern in your commit titles or messages. :</p><pre>      - name: Perform semantic version<br>        uses: paulhatch/semantic-version@v5.0.3<br>        id: semantic_version<br>        with:<br>          tag_prefix: &quot;v&quot;<br>          major_pattern: &quot;(MAJOR)&quot;<br>          minor_pattern: &quot;(MINOR)&quot;<br>          version_format: &quot;${major}.${minor}.${patch}-rc${increment}&quot;<br>          user_format_type: &quot;csv&quot;<br>          bump_each_commit: false<br>          search_commit_body: true</pre><p>As you can read above, the patterns will be :</p><ul><li>(MAJOR) : Major change</li><li>(MINOR) : Minor change</li><li>&lt;empty&gt; : Patch</li></ul><p>If we need to illustrate a life-cycle of a repository that uses these patterns, it would looks like this :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/841/1*euQbbzzjta_6uA1yXzAuWA.png" /></figure><p>⛔ When I started working on this project, I made the assumption that if I created two commits with “MINOR” changes, the new version would be updated by two instead of one (X.X+2.X). However, this assumption is incorrect. Let me explain why:</p><p>When you create a new version, the Github Action compares the current version to the <strong>last production version</strong>. <strong>Regardless of the number of changes you have made</strong> (major, minor, or patch), the new version number is calculated based on the change that is <strong>defined as the most important</strong>. For example, if you make two patches and one minor change, then the next version number will only increment the minor number.</p><p>Ok ! So now we know how to calculate automatically the next version tag. The next step is the creation of the tag and the release !</p><h3>Step 2— Tags &amp; Releases automation</h3><p>To create my tags and releases automatically, I will also use Github Actions found on the marketplace.</p><p>To create the tags :</p><pre>      - name: Bump version and push tag<br>        id: tag_version<br>        uses: mathieudutour/github-tag-action@v6.1<br>        with:<br>          custom_tag: ${{ steps.semantic_version.outputs.version_tag }}<br>          tag_prefix: &quot;&quot;<br>          github_token: ${{ secrets.GITHUB_TOKEN }}</pre><p>And to create the release :</p><pre>      - name: Create production release<br>        uses: ncipollo/release-action@v1<br>        id: release<br>        with:<br>          tag: ${{ steps.tag_version.outputs.new_tag }}<br>          name: ${{ steps.semantic_version.outputs.version_tag }}<br>          body: ${{ steps.build_changelog.outputs.changelog }}<br>          draft: false<br>          prerelease: false<br>          commit: ${{ steps.semantic_version.outputs.current_commit }}</pre><p>As you can see, I am using outputs from previous Github actions to fill in inputs from these ones.</p><p>There is nothing much to add about these Github actions.</p><p>⚠️ On the Github platform, by default, when you create a Pull Request, you have 3 options to merge your branch :</p><ul><li>Allow merge commits</li><li>Allow squash merging</li><li>Allow rebase merging</li></ul><p>To use the workflow that I am presenting here correctly, it is recommended that you only use the “Allow rebase merging” option (to avoid issues with versioning and unwanted commit merges).</p><p>You can enforce your merge policy from the Github repository settings :</p><p><em>Settings -&gt; General -&gt; Pull Request -&gt; Choose only &quot;Allow rebase merging&quot;</em></p><h3>Step 3 — CHANGELOG.md automation</h3><p>When I began working on this small project, I assumed that updating the changelog of an application would be the easiest part. However, it turned out to be the most challenging part for me. Let me explain why.</p><p>First of all, when we work with releases, there are 2 &quot;type&quot; of changelogs to update :</p><ul><li>CHANGELOG.md file : Simple file where we write every modification done on the application to track changes</li><li>Release changelog : The release changelog is a &quot;text&quot; that we write to explain the change that has been done with the release. For example, on Github it looks like :</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/829/1*c-8a7kztwvFqaAZmtS8_Mw.png" /></figure><p>To maintain coherence between the two different types of changelogs, it is necessary to ensure that the content inside the CHANGELOG.md and inside the release are identical.</p><h4>Changelog content creation</h4><p>To generate the content of my both changelogs, I have used this github action :</p><pre>      - name: &quot;Build Changelog&quot;<br>        id: build_changelog<br>        uses: mikepenz/release-changelog-builder-action@v3.7.0<br>        with:<br>          fromTag: v${{ steps.semantic_version.outputs.previous_version }}<br>          toTag: ${{ steps.tag_version.outputs.new_tag }}</pre><p>This Github Action connects to the Github API to get all Pull Requests that had been merged from the previous version (defined thanks to the semantic version output) to the new version.</p><p>It formats its outputs depending on <strong>Pull Request labels.</strong> For example if we add the label <strong>feature </strong>to a Pull Request, it will create the following content :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/173/1*gShEdqWQIi426CJurn7ozQ.png" /></figure><p>All default label mapping can be found in the <a href="http://mikepenz/release-changelog-builder-action@v3.7.0">documentation</a>. You can fully customize this mapping according to your business need.</p><p>Now that we know how to create the content of our changelogs, we need to use it to fill in our changelogs.</p><h4>Release changelog</h4><p>Writting the content of the changelog is really easy thanks to the release creation github action. We already need to take the output of the Changelog build and add it as an input to the release Github action :</p><pre>      - name: Create production release<br>        uses: ncipollo/release-action@v1<br>        id: release<br>        with:<br>          tag: ${{ steps.tag_version.outputs.new_tag }}<br>          name: ${{ steps.semantic_version.outputs.version_tag }}<br>          body: ${{ steps.build_changelog.outputs.changelog }} # The magic is here<br>          draft: false<br>          prerelease: false<br>          commit: ${{ steps.semantic_version.outputs.current_commit }}</pre><h4>CHANGELOG.md update</h4><p>Updating the CHANGELOG.md file turned out to be the most challenging part for me.</p><p>Surprisingly, I didn’t find any Github Actions that could efficiently update the file without any bugs. Therefore, I decided to use bash commands to successfully write my updates inside the CHANGELOG.md file :</p><pre>      - name: Automatic rebase main onto develop<br>        run: |<br>          # Prepare the git configuration to commit &amp; push<br>          git config --global user.name &quot;${{ env.CI_COMMIT_AUTHOR }}&quot;<br>          git config --global user.email &quot;${{ env.CI_COMMIT_AUTHOR }}&quot;<br>          # Set the output of the build changelog github action<br>          # into a bash variable<br>          changelog=&#39;${{ steps.build_changelog.outputs.changelog }}&#39;<br>          # Modify the content of the changelog to escape some characters<br>          escaped_changelog=$(printf &#39;%s\n&#39; &quot;$changelog&quot; | sed &#39;s/\\/&amp;&amp;/g;s/^[[:blank:]]/\\&amp;/;s/$/\\/&#39;)<br>          # Write on the second line of the file the content of the<br>          # changelog<br>          sed -i &quot;2i ${escaped_changelog%?}&quot; CHANGELOG.md<br>          # Write on the second line the date + version<br>          # (so the content of the changelog will be from line 3)<br>          sed -i &quot;2i ## ${{ steps.semantic_version.outputs.version_tag }} - $(date +&#39;%d-%m-%Y&#39;)&quot; CHANGELOG.md<br>          git add -A &amp;&amp; git commit -m &quot;chore(docs): update CHANGELOG.MD&quot;<br>          # Push to main<br>          git push origin main<br>          # Update develop branch<br>          git push --force origin main:develop</pre><p>As commented in the script above, we write on the second line to be sure that the latest version of the app is at the top of your file (the first line of the CHANGELOG.md is the title).</p><p>I cannot say that it is the cleanest approach, but it gets the job done as expected!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/376/1*UzElCg4HIGLXEb2OZjDY0Q.png" /></figure><p>That&#39;s it ! We can now fully automate our tags &amp; releases !</p><h3>[OPTIONAL] Step 4 — Pull request comment</h3><p>During my live session, I though it would be great to add an automated system that write the future new version of the app directly in the Pull Request like shown below :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/949/1*pmLciXbgOJJ-BLmwc4TohQ.png" /></figure><p>The implementation is really easy :</p><pre>on:<br>  pull_request_target:<br>    types:<br>      - &quot;opened&quot;<br>    branches:<br>      - main<br><br>env:<br>  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}<br><br>jobs:<br>  comment_pull_request:<br>    runs-on: ubuntu-latest<br>    permissions:<br>      # Needed to write comments in the pull request<br>      pull-requests: write<br>    steps:<br>      - name: Checkout<br>        uses: actions/checkout@v3<br>        with:<br>          # Really important to get the good commit<br>          ref: &quot;refs/pull/${{ github.event.number }}/merge&quot; <br>          fetch-depth: 0<br><br>      - name: Perform semantic version<br>        uses: paulhatch/semantic-version@v5.0.3<br>        id: semantic_version<br>        with:<br>          tag_prefix: &quot;v&quot;<br>          major_pattern: &quot;(MAJOR)&quot;<br>          minor_pattern: &quot;(MINOR)&quot;<br>          version_format: &quot;${major}.${minor}.${patch}-rc${increment}&quot;<br>          user_format_type: &quot;csv&quot;<br>          bump_each_commit: false<br>          search_commit_body: true<br><br>      - name: Comment PR<br>        # Github action used to write pull request comments<br>        uses: thollander/actions-comment-pull-request@v2<br>        with:<br>          message: |<br>            :rocket: The next version will be **${{ steps.semantic_version.outputs.version_tag }}** ! :rocket:</pre><h3>Futher thoughts</h3><p>Before showing you a proper example of repository with all the workflow implemented, I want to share with you the advantages and the drawbacks about this implementation :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xKz8w7CMhH4Ry9x3d-mLSg.png" /></figure><h3>A full example : Terraform module</h3><p>It is time for an example !</p><p>You can find the link of the repository here : <a href="https://github.com/le-moment-it/terraform-aws-example">terraform-aws-example</a></p><p>In this repository you will find :</p><ul><li><a href="https://github.com/le-moment-it/terraform-aws-example/blob/main/README.md">README.md</a></li><li><a href="https://github.com/le-moment-it/terraform-aws-example/blob/main/.github/workflows/on-push-main-semantic-version.yml">Tags and release creation workflow</a></li><li><a href="https://github.com/le-moment-it/terraform-aws-example/blob/main/.github/workflows/on-pr-main-future-version.yml">Pull Request automation</a></li><li><a href="https://github.com/le-moment-it/terraform-aws-example/blob/main/CHANGELOG.md">CHANGELOG.md result</a></li><li><a href="https://github.com/le-moment-it/terraform-aws-example/releases/tag/v2.0.0">Release result</a></li><li><a href="https://github.com/le-moment-it/terraform-aws-example#repository-lifecycle">Example of a lifecycle</a></li></ul><h3>Conclusion</h3><p>These are my initial results on how to automatically create tags and releases following semantic versioning. I understand that this workflow can be further improved or customized to fit your daily workflow, but I hope it has been helpful to you and your team in getting started with this topic.</p><p>Please feel free to share your thoughts and comments on how you manage your new version releases!</p><h3>One more thing …</h3><p>This workflow and this article is the result of researches done on my Twitch channel : <a href="https://www.twitch.tv/le_moment_it">@le_moment_it</a> . If you want to support me for free, you can follow the channel and join us for more IT research !</p><p>We live <strong>every Tuesday and Thursday at 14h PM</strong> (UTC+1).<br>To finish, we also have a discord where we share IT news and articles. You can join us here : <a href="https://discord.gg/Bn66XZsWfn">le_moment_it</a></p><p>See you soon !</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=77678047c79e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is the best GIT client ?]]></title>
            <link>https://medium.com/@le_moment_it/what-is-the-best-git-client-3e394c6c1b4d?source=rss-abfdaec6dc48------2</link>
            <guid isPermaLink="false">https://medium.com/p/3e394c6c1b4d</guid>
            <category><![CDATA[tools]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[benchmark]]></category>
            <category><![CDATA[it]]></category>
            <category><![CDATA[git]]></category>
            <dc:creator><![CDATA[Le Moment It]]></dc:creator>
            <pubDate>Mon, 06 Mar 2023 01:27:43 GMT</pubDate>
            <atom:updated>2023-03-06T11:33:46.895Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is the best GIT client ?</h3><h3>Introduction</h3><p>As a DevOps professional, I need to manage various Git repositories, including those shared with developers to configure their CI/CD pipelines, Terraform/Ansible code repositories, etc …</p><p>As I felt the need to improve my Git practices, write better commits, squash my commits before a Pull Request review, and be able to rebase faster branches, I decided to benchmark <strong>FREE</strong> Git clients to find a tool that can help me save time in my Git workflows.</p><h3>A benchmark ? Let&#39;s first define our needs !</h3><p>That&#39;s right ! To perform a good benchmark, we need first to define what are our needs and put them into a Google sheet ! (I know you are as excited as me about it !). So these are my needs :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/783/1*3H2VjchlHa-C8X07g-K47w.png" /><figcaption>Needs definition</figcaption></figure><p>💡 To perform a good benchmark, we first need to define our needs and list them in a Google sheet. Each need is assigned a ponderation based on its importance, where the number 5 indicates a “must-have” and the number 1 indicates a “nice-to-have” feature. We then verify whether the tool we are benchmarking has these features (add 1 to the cell) or not (add 0 to the cell). Finally, we sum all points and compare them with the other tools. Easy right ?</p><p>To summarize my needs, I am looking for a tool that I can use <strong>from my terminal</strong> to perform Git commands easily and quickly. I also need to be able to use <strong>multiple git config</strong> (you can find an excellent example : <a href="https://deepsource.io/blog/managing-different-git-profiles/">here</a>).</p><p>To finish summarizing my needs, the nature of my job does not include a lot of conflict resolution, that&#39;s why it is acceptable for me to use a second tool to resolve my conflicts such as VScode.</p><p>Now that I have defined my needs, it is benchmarking time ! For each tool I will show its interface and give you my overall experience. For more details about the tool possibility please refer to the <strong>benchmark results</strong> part</p><h3>Github Desktop</h3><p>The first tool we are benchmarking is <a href="https://desktop.github.com/">Github Desktop</a>. The bad news is that Github Desktop is not natively available on Linux, and I am using an Ubuntu laptop. However, a Linux fork is available that can be found at <a href="https://github.com/shiftkey/desktop">shiftkey/desktop</a>, and this is the version that I will benchmark.</p><p>Good news, the package is installable through packages managers, so let&#39;s do that (you can changes GPG key location to avoid <a href="https://askubuntu.com/questions/1286545/what-commands-exactly-should-replace-the-deprecated-apt-key">apt-key deprecation</a>):</p><pre>wget -qO - https://apt.packages.shiftkey.dev/gpg.key | gpg --dearmor | sudo tee /usr/share/keyrings/shiftkey-packages.gpg &gt; /dev/null<br>sudo sh -c &#39;echo &quot;deb [arch=amd64 signed-by=/usr/share/keyrings/shiftkey-packages.gpg] https://apt.packages.shiftkey.dev/ubuntu/ any main&quot; &gt; /etc/apt/sources.list.d/shiftkey-packages.list&#39;</pre><p>When you launch the application, you will see something like :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9FXYutU8bkJMyhsQATBNiA.gif" /></figure><p>Github Desktop panels are easy to use and you can perform basic git commands with them. Something that I personally feel inconvenient, is that you can create only one stash per branch. If you create a new stash it will override the previous one (that&#39;s why I consider that the feature is missing in the final benchmark result)</p><p>Github Desktop is a handy tool to perform Git actions on a repository, and its integration with Github can help companies that host their repositories on Github. However, if you already have Git profiles set up, Github Desktop profiles can mess them up, potentially affecting your GPG signature, which is not originally managed by Github Desktop.</p><p>Additionally, some interesting features like the history schema as a tree are not yet available on the Linux fork compared to the Windows version. Lastly, this tool is more mouse-centric, and some actions cannot be performed with keyboards.</p><h3>GitUI</h3><p>The next tool that I benchmarked is <a href="https://github.com/extrawurst/gitui">GitUI</a>, a terminal application written in Rust that promises a fast and stable experience for Git commands</p><p>Let&#39;s install it (version 0.22.1 at the moment) :</p><pre>wget https://github.com/extrawurst/gitui/releases/download/v0.22.1/gitui-linux-musl.tar.gz<br>tar -xvf gitui-linux-musl.tar.gz<br>mv gitui /usr/bin/gitui</pre><p>That&#39;s it ! Let&#39;s start it. Switch repository to a git repository, and launch it gitui :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4o8L9kjwWwGfpduERIH3Bg.gif" /><figcaption>GitUI</figcaption></figure><p>When we open gitUI, we can see 5 tabs :</p><ul><li>Status : You can see all changes to your tab , add them, commit etc ..</li><li>Log : You can see the git history</li><li>Files : See your files, navigate inside and modify them with a navigator</li><li>Stashing : See files that you can stash</li><li>Stashes : Your saved stash</li></ul><p>The panels are nicely designed and easy to navigate, and you can perform Git actions quickly. However, this solution lacks some necessary features for me :</p><ul><li><strong>GPG signature</strong> : Because GitUI is using a specific library implementation (and not the Git cli like some others solutions), they need to wait the implementation inside the library. A pull request is already opened (at the moment where I write this article) <a href="https://github.com/extrawurst/gitui/pull/1544">here</a>, so let&#39;s hope this feature will be released soon.</li><li><strong>Interactive rebase</strong> (used for squash) : We cannot perform interactive rebase needed for rebasing branchs</li></ul><p>GitUI seems really promising, but is a bit too &quot;young&quot; to answer all my needs. However, it is definitely a tools to keep an eye on, and follow its future evolution !</p><h3>LazyGit</h3><p>As a good IT professional , I am lazy ! The fewer tasks I need to perform, the better my life and performance will be ! So let&#39;s try Lazy…GIT (ok, it was an easy one) !</p><p>According to its documentation, <a href="https://github.com/jesseduffield/lazygit">LazyGIT</a> is a simple terminal UI for git commands, written in Go. Its repository has 33,1k ⭐ at the moment, so it seems to be tool with the biggest community and users.</p><p>So let&#39;s install it :</p><pre>wget https://github.com/jesseduffield/lazygit/releases/download/v0.37.0/lazygit_0.37.0_Linux_x86_64.tar.gz<br>tar -xvf lazygit_0.37.0_Linux_x86_64.tar.gz<br># Here I change the name of the binary to launch faster by just writing &quot;lg&quot; (lazyness when you get me...)<br>mv mv lazygit /usr/bin/lg</pre><p>Switch repository to a git repository, and launch it lg :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*liLLbpYa9WMuQF4Yg6EwAA.gif" /><figcaption>Lazygit</figcaption></figure><p>When you launch lazygit, you can see really friendly panels:</p><ul><li>Files/Submodules: Lists your changes and allows you to add files before committing.</li><li>Local branches/Remotes/Tags: Self-explanatory tabs.</li><li>Commits-Reflog: Git history.</li></ul><p>Lazygit includes really good embedded documentation with the letter x. Each panel has its own shortcut, and the documentation helps you understand it.</p><p>To summarize, I would say that Lazygit answers almost all my needs. The tool is really handy and can perform many actions. LazyGit is a tool that I can recommend to any Git beginners (even to experienced Git users).</p><p>If I want to be meticulous, I can say that this tool is missing a few features:</p><ul><li>Creating application Git profiles (at the moment, we can use only the ones that we can configure outside of the tool).</li><li>Removing remote branches.</li></ul><p>I also noticed that sometimes the tool can “crash,” which freezes the terminal completely. It does not happen often, but it is worth mentioning.</p><h3>Git-brunch</h3><p>According to its documentation, <a href="https://github.com/andys8/git-brunch">git-brunch</a> is git command-line tool to work with branches.</p><p>So let&#39;s install it :</p><pre>wget https://github.com/andys8/git-brunch/releases/download/v1.6.0/git-brunch-Linux<br>chmod +x git-brunch-Linux<br>mv git-brunch-Linux /usr/bin/git-brunch</pre><p>We can now start it with the command git-brunch :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QgMz9hpm6OFnR11llARMKA.gif" /><figcaption>git-brunch</figcaption></figure><p>Git-brunch panel are simple and easy to use. They allow you see and manage branches of your git repository.</p><p>To summarize my experience with git-brunch, I can say that the tool does its job. However, I am looking for a tool that can achieve much more than “just” managing branches. Git-brunch can be used alongside another tool, but it cannot fulfill all the needs that I have by itself.</p><h3>Tig</h3><p>Let’s reverse Git and we get Tig! There is a tool with that name that exists! According to its documentation, Tig functions mainly as a Git repository browser but can also assist in staging changes for commit at the chunk level and act as a pager for output from various Git commands.</p><p>Let&#39;s install it :</p><pre>wget https://github.com/jonas/tig/releases/download/tig-2.5.4/tig-2.5.4.tar.gz<br>tar -xvf tig-2.5.4.tar.gz<br>cd tig-2.5.4<br># Needed this package to be able to compile the code<br>apt install libncursesw5-dev<br>make<br>make install<br># Prefer to move the binary to /usr/bin<br>mv /home/&lt;YOUR_USER&gt;/bin/tig /usr/bin/tig</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RytN2mBd7VYTAjshnp_Hrg.gif" /><figcaption>Tig</figcaption></figure><p>Tig has a lot of different panels according to the command provided (show in the gif above)</p><p>Giving an opinion about Tig is really difficult. It seems to be an interesting tool but not easy to start to work with. You can customize it as much as you want thanks to its config file (you can find the documentation <a href="https://jonas.github.io/tig/doc/tigrc.5.html">here</a>).</p><p>I would recommend a tool such as Tig only for experienced git users.</p><p>For this benchmark I will consider features only available &quot;out of the box&quot;. No special settings will be done.</p><h3>Glint</h3><p>Glint is a non-open-source Git client that offers a simple graphical interface to perform Git actions.</p><p>Glint is available through snap packages, so let’s install it:</p><pre>snap install glint</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/998/1*LOsrImI2LSmcjDAOcEgtYQ.gif" /></figure><p>My overall experience with Glint was pleasant. It offers an easy way to perform Git actions such as merge, squash, checkout, etc. Moreover, Glint allows you to create application Git profiles and associate them with credentials (SSH or password at the moment).</p><p>However, this solution still lacks key features for me:</p><ul><li>GPG signature (we cannot configure GPG credentials in the application at the moment)</li><li>Rebase feature</li></ul><h3>VScode</h3><p>Everyone knows VS Code. This famous IDE has its own Git client integrated. In this article, we will only benchmark VS Code’s Git feature without any extensions.</p><p>If you have never installed VS Code before, you can do it with the following command:</p><pre>snap install code</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1018/1*hu9RI0VWItHVTH4R0BqvSg.gif" /></figure><p>Even though VS Code’s “vanilla” Git implementation has many features, I personally don’t think that they are convenient to use. Typing each command is long (with the format Git: command ) and there is no Git history by default.</p><p>To optimize your experience and performance, I would recommend installing VS Code plugins, such as :</p><ul><li>Git history : <a href="https://marketplace.visualstudio.com/items?itemName=donjayamanne.githistory">donjayamanne.githistory</a></li><li>Git Graph : <a href="https://marketplace.visualstudio.com/items?itemName=mhutchie.git-graph">mhutchie.git-graph</a></li></ul><h3>Benchmark results</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_lfpttnjwB212_2idTt1BA.png" /></figure><p>Without surprise, with a total point of <strong>127</strong>, <strong>Lazygit</strong> is the winner 🎉🎉! As said earlier, Lazygit <strong>answers almost all my needs</strong>. It is a tool that can help beginners perform Git actions or can help advanced users perform their tasks. I definitely recommend it, and I will use it to perform my personal and professional daily Git tasks.</p><p>With a total point of <strong>86</strong>, I would also keep an eye on <strong>GitUI</strong>. This young project is promising. I cannot wait to see how it will evolve.</p><p>That’s it for the benchmark! I repeat a second time, but this benchmark has been done following my needs. If you plan to do the same, I highly advise you to ask yourself, “What are my needs?”</p><h3>One more thing …</h3><p>This benchmark and this article is the result of researches done on my Twitch channel : <a href="https://www.twitch.tv/le_moment_it">@le_moment_it</a> . If you want to support me for free, you can follow the channel and join us for more IT research !</p><p>We live <strong>every Tuesday and Thursday at 14h PM</strong> (UTC+1). <br>To finish, we also have a discord where we share IT news and articles. You can join us here : <a href="https://discord.gg/Bn66XZsWfn">le_moment_it</a></p><p>See you soon !</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3e394c6c1b4d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>