<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/"><generator uri="https://jekyllrb.com/" version="4.4.1">Jekyll</generator><link href="https://mehmandarov.com/tag/jekyll/feed.xml" rel="self" type="application/atom+xml"/><link href="https://mehmandarov.com/tag/jekyll/" rel="alternate" type="text/html"/><updated>2019-01-01T11:01:00+01:00</updated><id>https://mehmandarov.com/tag/jekyll/feed.xml</id><title type="html">Rustam Mehmandarov - tag: jekyll</title><subtitle type="text">Posts tagged &quot;jekyll&quot; on Rustam Mehmandarov.</subtitle><author><name>Rustam Mehmandarov</name></author><entry><title type="html">Disposable Docker Containers</title><link href="https://mehmandarov.com/disposable-docker-containers/" rel="alternate" type="text/html" title="Disposable Docker Containers"/><published>2019-01-01T11:01:00+01:00</published><updated>2019-01-01T11:01:00+01:00</updated><id>https://mehmandarov.com/disposable-docker-containers</id><content type="html" xml:base="https://mehmandarov.com/disposable-docker-containers/"><![CDATA[<p><em>Disposable containers may sound like a tautology. However, here we will be looking into single-use, ephemeral containers &#8211; even in the context of the containers &#8211; that are used for building and testing applications, and disposing of them shortly after.</em></p>

<hr />

<p>Containers are something that we use to run our applications and, normally, we dispose of the whole container when we build a new version of the application or need to upgrade something in the setup. This means that containers are generally having a short lifespan.</p>

<p>However, in this case, I want to show you how to build something that exists for an even shorter period of time and that can be used as an alternative to a local setup for building and testing applications locally before pushing it to test, staging, production, etc.</p>

<p>This is a simplified example of what is being done on a much bigger scale with moving your CI/CD pipelines to such disposable containers, and with libraries like <a href="https://www.testcontainers.org/">Testcontainers</a>.</p>

<p>In this case, I would like to show you how to setup Jekyll applications, but this can be easily applied to any kind of applications written in any of your favorite languages, like Java or Python. Until recently, I have been running a Jekyll installation locally with all dependencies installed on my machine. However, it has been a bit challenging when moving between machines and reinstalling operating systems. To simplify the process, I decided to containerize the local build and test processes.</p>

<p>I wanted the following:</p>

<ul>
  <li>To build my code from and to the local folder on my (host) machine</li>
  <li>Run the application (in this case this blog) from a local folder on my (host) machine</li>
  <li>Avoid setting up the environment, or have a minimal and portable setup</li>
  <li>Avoid environment clean-up &#8211; I didn&#8217;t want to hold on to the unnecessary containers and container images</li>
</ul>

<h2 id="tldr-the-solution"><em><strong>TL;DR</strong></em>: The solution</h2>
<p><em><strong>(see next section for the explanation)</strong></em></p>

<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nv">$ </span><span class="nb">export </span><span class="nv">JEKYLL_VERSION</span><span class="o">=</span>3.8
<span class="nv">$ </span>docker run <span class="nt">--rm</span> <span class="nt">--volume</span><span class="o">=</span><span class="s2">"</span><span class="nv">$PWD</span><span class="s2">:/srv/jekyll"</span> <span class="se">\</span>
       <span class="nt">-it</span> jekyll/jekyll:<span class="nv">$JEKYLL_VERSION</span> jekyll build
<span class="nv">$ </span>docker run <span class="nt">--name</span> newblog <span class="nt">--volume</span><span class="o">=</span><span class="s2">"</span><span class="nv">$PWD</span><span class="s2">:/srv/jekyll"</span> <span class="nt">-p</span> 4000:4000 <span class="se">\</span>
       <span class="nt">-it</span> jekyll/jekyll:<span class="nv">$JEKYLL_VERSION</span> jekyll serve <span class="nt">--watch</span> <span class="nt">--drafts</span></code></pre></figure>

<h2 id="explanation--line-by-line">Explanation &#8211; line by line</h2>

<p>So, let&#8217;s take a closer look at each of the lines:</p>

<figure class="highlight"><pre><code class="language-bash" data-lang="bash">1: <span class="nb">export </span><span class="nv">JEKYLL_VERSION</span><span class="o">=</span>3.8</code></pre></figure>

<p>Just setting up versions that will be used later &#8211; a bit of housekeeping. Nothing exciting here.</p>

<hr />

<figure class="highlight"><pre><code class="language-bash" data-lang="bash">2: docker run <span class="nt">--rm</span> <span class="nt">--volume</span><span class="o">=</span><span class="s2">"</span><span class="nv">$PWD</span><span class="s2">:/srv/jekyll"</span> <span class="se">\</span>
        <span class="nt">-it</span> jekyll/jekyll:<span class="nv">$JEKYLL_VERSION</span> jekyll build</code></pre></figure>

<p>Here, we build the code and output it to the same disk volume as the source code, i.e. the volume that is shared with my host machine. Now I have the built version on my machine without the hassle of setting up the local build environment. In addition to that, I will be doing some clean-up, by deleting the build container after the build job is finished.</p>

<ul>
  <li><code class="language-plaintext highlighter-rouge">--rm</code> &#8211; just execute the command and clean-up (remove the container, file system, etc.)</li>
  <li><code class="language-plaintext highlighter-rouge">--volume</code> &#8211; mapping the current directory to <code class="language-plaintext highlighter-rouge">/srv/jekyll</code> in the container</li>
  <li><code class="language-plaintext highlighter-rouge">-it</code> instructs Docker to allocate a pseudo-TTY connected to the container&#8217;s stdin; creating an interactive shell in the container
    <ul>
      <li><code class="language-plaintext highlighter-rouge">-i</code> &#8211; attach container&#8217;s STDIN</li>
      <li><code class="language-plaintext highlighter-rouge">-t</code> &#8211; allocate a pseudo-TTY</li>
    </ul>
  </li>
  <li><code class="language-plaintext highlighter-rouge">jekyll/jekyll:$JEKYLL_VERSION</code> &#8211; Docker <a href="https://github.com/envygeeks/jekyll-docker/blob/master/README.md">image</a> to use and the tag</li>
  <li><code class="language-plaintext highlighter-rouge">jekyll build</code> &#8211; command to run</li>
</ul>

<hr />

<figure class="highlight"><pre><code class="language-bash" data-lang="bash">3. docker run <span class="nt">--name</span> newblog <span class="nt">--volume</span><span class="o">=</span><span class="s2">"</span><span class="nv">$PWD</span><span class="s2">:/srv/jekyll"</span> <span class="nt">-p</span> 4000:4000 <span class="se">\</span>
        <span class="nt">-it</span> jekyll/jekyll:<span class="nv">$JEKYLL_VERSION</span> jekyll serve <span class="nt">--watch</span> <span class="nt">--drafts</span></code></pre></figure>

<p>This will create another container that will be running our application. Here we will need to add a few other parameters &#8211; like mapping the container ports to the ports on the local machine and giving the container a name.</p>

<ul>
  <li><code class="language-plaintext highlighter-rouge">--name newblog</code> &#8211; give your container a name</li>
  <li><code class="language-plaintext highlighter-rouge">--volume</code> &#8211; mapping the current directory to <code class="language-plaintext highlighter-rouge">/srv/jekyll</code> in the container</li>
  <li><code class="language-plaintext highlighter-rouge">-p</code> &#8211; bind port 4000 of the container to TCP port 4000 (<code class="language-plaintext highlighter-rouge">-p host_machine:container</code>)</li>
  <li><code class="language-plaintext highlighter-rouge">-it</code> instructs Docker to allocate a pseudo-TTY connected to the container&#8217;s stdin; creating an interactive shell in the container
    <ul>
      <li><code class="language-plaintext highlighter-rouge">-i</code> &#8211; attach container&#8217;s STDIN</li>
      <li><code class="language-plaintext highlighter-rouge">-t</code> &#8211; allocate a pseudo-TTY</li>
    </ul>
  </li>
  <li><code class="language-plaintext highlighter-rouge">jekyll/jekyll:$JEKYLL_VERSION</code> &#8211; Docker <a href="https://github.com/envygeeks/jekyll-docker/blob/master/README.md">image</a> to use and the tag</li>
  <li><code class="language-plaintext highlighter-rouge">jekyll serve --watch --drafts</code> &#8211; command to run</li>
</ul>

<p>Now you can stop the container with <code class="language-plaintext highlighter-rouge">CTRL+c</code>, and restart it again with:</p>

<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nv">$ </span>docker start newblog <span class="nt">-i</span></code></pre></figure>

<p>If you don&#8217;t want the container being persistent on your system, you can simply add <code class="language-plaintext highlighter-rouge">--rm</code> as in the previous command:</p>

<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nv">$ </span>docker run <span class="nt">--rm</span> <span class="nt">--name</span> newblog <span class="nt">--volume</span><span class="o">=</span><span class="s2">"</span><span class="nv">$PWD</span><span class="s2">:/srv/jekyll"</span> <span class="nt">-p</span> 4000:4000 <span class="se">\</span>
       <span class="nt">-it</span> jekyll/jekyll:<span class="nv">$JEKYLL_VERSION</span> jekyll serve <span class="nt">--watch</span> <span class="nt">--drafts</span></code></pre></figure>

<hr />]]></content><author><name>Rustam Mehmandarov</name></author><summary type="html">Using single-use, ephemeral Docker containers for building and testing applications locally.</summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://mehmandarov.com/assets/images/posts-images/containers.jpg"/><category term="blog"/><category term="containers"/><category term="docker"/><category term="jekyll"/><category term="field notes"/><category term="english"/></entry><entry><title type="html">Posting Jekyll Content on Time</title><link href="https://mehmandarov.com/jekyll-content-on-time/" rel="alternate" type="text/html" title="Posting Jekyll Content on Time"/><published>2016-06-12T11:04:00+02:00</published><updated>2016-06-12T11:04:00+02:00</updated><id>https://mehmandarov.com/jekyll-content-on-time</id><content type="html" xml:base="https://mehmandarov.com/jekyll-content-on-time/"><![CDATA[<p><em>Posting of content in Jekyll relies on the date assigned to the post, and the time is relative to the time zone on the server. While this works fine for local installations of Jekyll, it can sometimes be confusing when running Jekyll on the remote servers without being able to control the time zone on that server, like hosting the content on GitHub Pages.</em></p>

<ul>
  <li><a href="#whats-going-on">What&#8217;s going on?</a></li>
  <li><a href="#setting-the-date-in-the-front-matter">Setting the date in the front matter</a></li>
  <li><a href="#setting-the-time-zone-in-the-jekyll-configuration-file">Setting the time zone in the Jekyll configuration file</a></li>
</ul>

<hr />

<h2 id="whats-going-on">What&#8217;s going on?</h2>

<p>So, you have written a brand new post. You have run tests on a local <a href="https://jekyllrb.com/">Jekyll</a> server, and everything looks great. You finally commit the changes to your GitHub site repository and push the changes to the server. You are excited and full of anticipation to see your new blog post online, you hit refresh in your browser, and&#8230; nothing. Another refresh &#8211; still nothing.</p>

<p>One of the reasons for this is that you have specified a date/time for your post in the <a href="https://jekyllrb.com/docs/frontmatter/">YAML front matter</a> in the header.</p>

<p>By setting a date in the front matter, you can override the date/time assigned to the post in the format <code class="language-plaintext highlighter-rouge">YYYY-MM-DD HH:MM:SS</code>. However, this notation will use the local time zone, set by your operating system. This works fine when running a local installation of Jekyll. However, if your Jekyll installation is running on a remote server (e.g., on the GitHub Pages server) the time on that server is likely not to be the same as the time on your local machine. Jekyll will then wait before processing the contents of the post until the specified time hits the clock on the server.</p>

<p>For your post to be processed according to your time zone, you can either add a UTC offset for your time zone for the post in question or specify a time zone in the Jekyll configuration file.</p>

<h2 id="setting-the-date-in-the-front-matter">Setting the date in the front matter</h2>

<p>To specify the UTC offset for each post use the following format: <code class="language-plaintext highlighter-rouge">YYYY-MM-DD HH:MM:SS +/-TTTT</code>, e.g. <code class="language-plaintext highlighter-rouge">2016-06-12 11:04:00 +0200</code>. This might be useful if you want to specify the offset for some specific posts.</p>

<figure class="highlight"><pre><code class="language-yaml" data-lang="yaml"><span class="nn">---</span>
<span class="na">title</span><span class="pi">:</span> <span class="s2">"</span><span class="s">Your</span><span class="nv"> </span><span class="s">title"</span>
<span class="na">layout</span><span class="pi">:</span> <span class="s">post</span>
<span class="na">date</span><span class="pi">:</span> <span class="s">2016-06-12 11:04 +0200</span>
<span class="nn">---</span>
<span class="s">Your content.</span></code></pre></figure>

<h2 id="setting-the-time-zone-in-the-jekyll-configuration-file">Setting the time zone in the Jekyll configuration file</h2>

<p>If you want an offset to be applied to all of the dates on your site, you should configure Jekyll by setting the time zone for site generation in <code class="language-plaintext highlighter-rouge">_config.yml</code>.</p>

<p>Any entry from the <a href="https://en.wikipedia.org/wiki/Tz_database">IANA Time Zone Database</a> is a valid value, e.g., <code class="language-plaintext highlighter-rouge">Europe/Oslo</code>. Wikipedia also has a list of <a href="https://en.wikipedia.org/wiki/List_of_tz_database_time_zones">all available values</a>.</p>

<figure class="highlight"><pre><code class="language-yaml" data-lang="yaml"><span class="c1"># set timezone</span>
<span class="na">timezone</span><span class="pi">:</span> <span class="s">Europe/Oslo</span></code></pre></figure>

<p>If not specified, Jekyll will use the local time zone, as set by your operating system.</p>

<hr />]]></content><author><name>Rustam Mehmandarov</name></author><summary type="html">Posting of content in Jekyll relies on the date assigned to the post, and the time is relative to the time zone on the server. It can sometimes be confusing when running Jekyll on the remote servers in different time zones, like hosting the content on GitHub Pages.</summary><category term="blog"/><category term="field notes"/><category term="jekyll"/><category term="english"/></entry><entry><title type="html">It Is Alive!</title><link href="https://mehmandarov.com/it-is-alive/" rel="alternate" type="text/html" title="It Is Alive!"/><published>2016-05-15T17:45:00+02:00</published><updated>2016-05-15T17:45:00+02:00</updated><id>https://mehmandarov.com/it-is-alive</id><content type="html" xml:base="https://mehmandarov.com/it-is-alive/"><![CDATA[<p><em>Getting the site up and running, introducing it to you, and plans for the future.</em></p>

<ul>
  <li><a href="#welcome">Welcome</a></li>
  <li><a href="#what-is-this-thing">What is this thing?</a></li>
  <li><a href="#now-what">Now what?</a></li>
</ul>

<hr />

<h2 id="welcome">Welcome!</h2>

<p>Finally, the site is up and running! The plan is to use it for mostly two things - geeky stuff and family history. <em>Labs</em> is where you will find posts about programming, software development, tech and all other geeky awesomeness. <em>Family</em> is where you will find the promised dash of family history and posts from other family members.</p>

<hr />

<h2 id="what-is-this-thing">What is this thing?</h2>

<p>Now, over to geeky stuff. I wanted the site itself to be a part of the technology playground I will be writing about here. I wanted it to be simple, extensible, responsive, and open-source. I also wanted to experiment with a site without a database, logins and all those (hackable) bells and whistles. The concerns were not as much about the security, but more about the simplicity of operation - things like upgrades, back-ups, deployment, and versioning.</p>

<p>After spending some time searching, doing the research and comparing different alternatives, I ended up choosing <a href="https://jekyllrb.com/">Jekyll</a> - the engine behind, amongst others, <a href="https://github.com">GitHub</a>. Static files, markdown, version control, GitHub integration, open-source, great themes and templates. Check, check and check! What else can you wish for?</p>

<hr />

<h2 id="now-what">Now what?</h2>

<p>The site was up and running in no time, it was simple to customize, and here is the first post. Now I will just have to automate the deployment. Right now I am looking at several options, and more information about this will be posted here soon.</p>

<p>Looking forward to seeing how the site will develop and to the future posts. Stay tuned!</p>

<hr />]]></content><author><name>Rustam Mehmandarov</name></author><summary type="html">Getting the site up and running, introducing it to you, and plans for the future.</summary><category term="blog"/><category term="first"/><category term="helloworld"/><category term="jekyll"/><category term="english"/></entry></feed>
