<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Docker Archives - ClickedyClick</title>
	<atom:link href="https://gergely.imreh.net/blog/tag/docker/feed/" rel="self" type="application/rss+xml" />
	<link>https://gergely.imreh.net/blog/tag/docker/</link>
	<description>Life in real, complex and digital.</description>
	<lastBuildDate>Sat, 19 Jul 2025 15:16:35 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>The curious case of binfmt for x86 emulation for ARM Docker</title>
		<link>https://gergely.imreh.net/blog/2025/04/the-curious-case-of-binfmt-for-x86-emulation-for-arm-docker/</link>
					<comments>https://gergely.imreh.net/blog/2025/04/the-curious-case-of-binfmt-for-x86-emulation-for-arm-docker/#respond</comments>
		
		<dc:creator><![CDATA[Gergely Imreh]]></dc:creator>
		<pubDate>Fri, 04 Apr 2025 05:15:48 +0000</pubDate>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[Arch Linux]]></category>
		<category><![CDATA[ArchiveTeam]]></category>
		<category><![CDATA[Docker]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[QEMU]]></category>
		<guid isPermaLink="false">https://gergely.imreh.net/blog/?p=2967</guid>

					<description><![CDATA[<p>Seemingly identical configurations, different results. When two methods for setting up x86 emulation on ARM showed the exact same system configuration but behaved completely differently in Docker, I began questioning my system administration knowledge and my sanity &#8211; and briefly contemplated a new career as a blacksmith. This is a debugging tale for those working [&#8230;]</p>
<p>The post <a href="https://gergely.imreh.net/blog/2025/04/the-curious-case-of-binfmt-for-x86-emulation-for-arm-docker/">The curious case of binfmt for x86 emulation for ARM Docker</a> appeared first on <a href="https://gergely.imreh.net/blog">ClickedyClick</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">Seemingly identical configurations, different results. When two methods for setting up x86 emulation on ARM showed the exact same system configuration but behaved completely differently in Docker, I began questioning my system administration knowledge and my sanity &#8211; and briefly contemplated a new career as a blacksmith.</p>



<p class="wp-block-paragraph">This is a debugging tale for those working with containers, and a reminder that things aren&#8217;t always what they seem in Linux, all with a big pinch reminder to Read the Fine Manual, Always!</p>



<span id="more-2967"></span>



<h2 class="wp-block-heading">ARM with Achiveteam v2</h2>



<p class="wp-block-paragraph">Recently I&#8217;ve got an email from a reader of the <a href="https://gergely.imreh.net/blog/2021/04/arm-images-to-help-the-archive-team/">ARM images to help the Archive Team</a> blogpost from years ago, asking me about refreshing that project to use again. There I was recompiling the ArchiveTeam&#8217;s Docker images to support ARM, and thus I was looking how things changed in the intervening time. I also got more <s>lazy</s> pragmatic since then, I was was wondering if the <a href="https://wiki.archiveteam.org/">Archiveteam</a> just made some ARM or multi-arch images as I believe(d) they should. That lead me to <a href="https://wiki.archiveteam.org/index.php/ArchiveTeam_Warrior#Can_I_run_the_Warrior_on_ARM_or_some_other_unusual_architecture?">their FAQ entry about ARM images</a>:</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph"><strong>Can I run the Warrior on ARM or some other unusual architecture?</strong></p>



<p class="wp-block-paragraph">Not directly. We currently do not allow ARM (used on Raspberry Pi and M1 Macs) or other non-x86 architectures. This is because we have previously discovered questionable practices in the Wget archive-creating components and are not confident that they run correctly under (among other things) different endiannesses. [&#8230;]</p>



<p class="wp-block-paragraph">Set up <a href="https://docs.docker.com/build/building/multi-platform/#qemu">QEMU with your Docker install</a> and add &#8211;platform linux/amd64 to your docker run command.</p>
</blockquote>



<p class="wp-block-paragraph">This actually seems like a sensible thing &#8211; if they dug that deep that they&#8217;ve seen issues in <a href="https://www.gnu.org/software/wget/">wget</a>, I&#8217;ve definitely been doing things naively before.</p>



<p class="wp-block-paragraph">The guidance of installing QEMU seems sensible as well (we were doing a lot of those at <a href="https://www.balena.io/">balena</a>), and it goes roughly like.</p>



<ol class="wp-block-list">
<li>install <code>binfmt</code></li>



<li>install QEMU with statically compiled binaries</li>



<li>load those binaries to emulate the platforms you want with the <code>F</code> / <code>fix_binary</code> flag</li>
</ol>



<p class="wp-block-paragraph">For those unfamiliar, <code>binfmt_misc</code> is a <a href="https://www.kernel.org/doc/html/latest/admin-guide/binfmt-misc.html">Linux kernel feature</a> that allows non-native binary formats to be recognized and passed to user space applications. It&#8217;s what makes it possible to run ARM binaries on x86 systems and vice versa through emulation. The various flags are how the actual behaviour of <code>binfmt</code> is adjusted (F, P, C, O)</p>



<p class="wp-block-paragraph">Docker advised to use a image to set things up, that is, for example for the <code>x86_64</code>/<code>amd64</code> platform like this:</p>



<pre class="wp-block-code"><code class="">docker run --privileged --rm tonistiigi/binfmt --install amd4</code></pre>



<p class="wp-block-paragraph">My Raspberry Pi is running <a href="https://archlinuxarm.org/">ArchLinuxARM</a> which installs <a href="https://www.freedesktop.org/software/systemd/man/latest/systemd-binfmt.service.html">systemd-binfmt</a> to load the relevant emulation settings at boot time, which seemed handy: with the docker method I had to run that every time before I could run an emulated container, with systemd I would have thing ready by every time the time Docker is ready to run (ie. keeping the Archiveteam containers always on and restarting after reboot.) So I have a strong incentive to use the systemd-based approach instead of the <code>docker run</code> based one.</p>



<p class="wp-block-paragraph">Now comes the kicker <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f92f.png" alt="🤯" class="wp-smiley" style="height: 1em; max-height: 1em;" />:</p>



<ul class="wp-block-list">
<li>the <code>docker</code> installed <code>binfmt</code> setup worked and allowed to run <code>linux/amd64</code> containers</li>



<li><code>systemd-binfmt</code> initiated <code>binfmt</code> setup worked for the <code>x86_64</code> binaries in the file system, but not in Docker where the binaries just failed to run</li>



<li>both setups had identical output when looking at the config in <code>/proc/sys/fs/binfmt_misc</code></li>
</ul>



<h2 class="wp-block-heading">When Same&#8217;s Not the Same</h2>



<p class="wp-block-paragraph">To see whether emulation works, the <code>tonistiigi/binfmt</code> container can be invoked without any arguments and it shows the status. For example setting things up with <code>docker</code> would show:</p>



<pre class="wp-block-code"><code class="">$ docker run --privileged --rm tonistiigi/binfmt
{
  "supported": [
    "linux/arm64",
    "linux/amd64",
    "linux/amd64/v2",
    "linux/arm/v7",
    "linux/arm/v6"
  ],
  "emulators": [
    "qemu-x86_64"
  ]
}</code></pre>



<p class="wp-block-paragraph">Here the <code>supported</code> section shows <code>amd64</code> as it should, and their test of running an amd64 image to check if the binaries are run has the expected output:</p>



<pre class="wp-block-code"><code class="">$ docker run --rm --platform linux/amd64 -t alpine uname -m
x86_64</code></pre>



<p class="wp-block-paragraph">Going back to the alternative, after uninstalling that emulatior I start up <code>systemd-binfmt</code>I can test the status again:</p>



<pre class="wp-block-code"><code class="">$ docker run --privileged --rm tonistiigi/binfmt
{
  "supported": [
    "linux/arm64",
    "linux/arm/v7",
    "linux/arm/v6"
  ],
  "emulators": [
[...snip...]
    "qemu-x86_64",
[...snip...]
  ]
}</code></pre>



<p class="wp-block-paragraph">This shows that while the emulator is installed, Docker doesn&#8217;t find that the <code>linux/amd64</code> platform is supported, and this checks out with running the <code>alpine</code> image again as above:</p>



<pre class="wp-block-code"><code class="">$ docker run --rm --platform linux/amd64 -t alpine uname -m
exec /bin/uname: exec format error</code></pre>



<p class="wp-block-paragraph">Well, this doesn&#8217;t work.</p>



<p class="wp-block-paragraph">The <a href="https://docs.kernel.org/admin-guide/binfmt-misc.html">binfmt_misc docs in the Linux Kernel wiki</a> do have plenty of info on the setup and use of the that emulation function. For example to check the configuration of the emulation setup, we can look at the contents of a file in <code>/proc</code> filesystem:</p>



<pre class="wp-block-code"><code class="">$ cat /proc/sys/fs/binfmt_misc/qemu-x86_64
enabled
interpreter /usr/bin/qemu-x86_64
flags: POCF
offset 0
magic 7f454c4602010100000000000000000002003e00
mask fffffffffffefe00fffffffffffffffffeffffff</code></pre>



<p class="wp-block-paragraph">This was the almost the same whether I the <code>docker</code> based setup or used <code>systemd-binfmt</code> with a slight difference: the <code>flags</code> bit is only <code>PF</code> when run with <code>systemd-binfmt</code>, and <code>POCF</code> when set things up with <code>docker run</code>. Even if the Docker docs are asking for the <code>F</code> flag, I wanted to make sure we are on equal footing, so I&#8217;ve tried to modify  the QEMU setup to be the same. This means overriding the <code>qemu-x86_64.conf</code> that is shipped by default:</p>



<ul class="wp-block-list">
<li>Copy the config from <code>/usr/lib/binfmt.d/qemu-x86_64.conf</code> to <code>/etc/binfmt.d/qemu-x86_64.conf</code> (make sure the file has the same name to ensure this new file overrides the one from the lib folder)</li>



<li>Edit the end of the line from <code>:FP</code> to <code>:FPOC</code> </li>



<li>restart <code>systemd-binfmt</code></li>
</ul>



<p class="wp-block-paragraph">After this the output of the the runtime info in <code>/proc/sys/fs/binfmt_misc/qemu-x86_64</code> was completely the same. Why&#8217;s the difference?</p>



<p class="wp-block-paragraph">More debugging steps ensued:</p>



<h3 class="wp-block-heading">More Debugging Ensued</h3>



<p class="wp-block-paragraph">I&#8217;ve <strong>read through the source code</strong> of <code>tonistiigi/binfmt</code> on <a href="https://github.com/tonistiigi/binfmt/tree/master/cmd/binfmt">GitHub</a> and seen that it doesn&#8217;t do anything fancy, it&#8217;s quite clear implementation of the `binfmt_misc` usage docs and the same magic values as QEMU shipped on my system. Good that no surprise, but no hints of any difference</p>



<p class="wp-block-paragraph">I&#8217;ve tried to <strong>replicate that process</strong> of setting up QEMU through translating it into Python and running, still the same</p>



<p class="wp-block-paragraph">I&#8217;ve <strong>recompiled the binary</strong> on my system, and run it outside of docker: it worked the same way as the <code>systemd-binfmt</code> setup: <code>x86_64</code> static binaries<sup data-fn="edde2512-e0d8-4c40-8fc7-32ce3232f660" class="fn"><a id="edde2512-e0d8-4c40-8fc7-32ce3232f660-link" href="#edde2512-e0d8-4c40-8fc7-32ce3232f660">1</a></sup> worked outside of Docker but not inside of it</p>



<p class="wp-block-paragraph">A sort-of <strong>breakthrough</strong> came when I&#8217;ve tried out <a href="https://github.com/dbhi/qus">dbhi/qus</a> Docker images, that promises &#8220;qemu-user-static (qus) and containers, non-invasive minimal working setups&#8221;, and can do the similar emulator &amp; platform support setup with:</p>



<pre class="wp-block-code"><code class="">docker run --rm --privileged aptman/qus -s -- -p x86_64</code></pre>



<p class="wp-block-paragraph">It was a lot slower to run (coming back to this later), but worked like the charm, just like Docker&#8217;s own recommendation. However there was a difference in the outcome when I checked the runtime config info:</p>



<pre class="wp-block-code"><code class="">$ cat /proc/sys/fs/binfmt_misc/qemu-x86_64
enabled
interpreter /qus/bin/qemu-x86_64-static
flags: F
offset 0
magic 7f454c4602010100000000000000000002003e00
mask fffffffffffefe00fffffffffffffffffeffffff</code></pre>



<p class="wp-block-paragraph">It has just the apparently required <code>F</code> flag, but the interpreter points to <code>/qus/bin/qemu-x86_64-static</code> &#8230; which is not in the regular file system. Nevertheless <code>alpine</code> happily runs, just as my local static binaries.</p>



<p class="wp-block-paragraph">How does this actually work, then?</p>



<h2 class="wp-block-heading">Everything&#8217;s Illuminated</h2>



<p class="wp-block-paragraph">With this above, and with a better understanding what the docs say, we have everything in place to understand the all the behaviours above, things we had pointers throughout, but not enough experience to put them together:</p>



<p class="wp-block-paragraph">So, the <code>F</code> flag was required by the Docker docs, what does that <em>actually</em> do?</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph"><code>F</code> &#8211; fix binary</p>



<p class="wp-block-paragraph">The usual behaviour of binfmt_misc is to spawn the binary lazily when the misc format file is invoked. However, this doesn’t work very well in the face of mount namespaces and changeroots, so the <code>F</code> mode opens the binary as soon as the emulation is installed and uses the opened image to spawn the emulator, meaning it is always available once installed, regardless of how the environment changes.</p>
</blockquote>



<p class="wp-block-paragraph">Because of this, if <code>F</code> is set, the <code>interpreter</code> entry in the runtime settings doesn&#8217;t mean the path of the interpreter it <em>will</em> be called, but where it <em>was</em> called at the time &#8211; ie. it&#8217;s irrelevant for the actual runtime.</p>



<p class="wp-block-paragraph">The <code>tonistiigi/binfmt</code> image ships its own static-compiled <code>qemu-*</code> binarlies, as well as  <code>aptman/qus</code> container gets the right ones at runtime (hence the slowness), and the <code>interpreter</code> path is the binary <em>inside the container when the command is run</em>. The binary is then kept in memory, and the container can go away, the <code>interpreter</code> path&#8217;s not refering anything that exists any longer.</p>



<p class="wp-block-paragraph">Why does <code>systemd-binfmt</code> fail then? Well of course because it&#8217;s a <code>dynamically</code> linked binary:</p>



<pre class="wp-block-code"><code class="">$ file /usr/bin/qemu-x86_64
/usr/bin/qemu-x86_64: ELF 64-bit LSB pie executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, BuildID[sha1]=a4b8a93a4361be61dfa34a0eab40083325853839, for GNU/Linux 3.7.0, stripped</code></pre>



<p class="wp-block-paragraph">&#8230; and because it&#8217;s dynamically linked, even if the <code>F</code> flag makes it stay in memory, its lib dependencies aren&#8217;t, so when in run in Docker (which uses namespaces) it doesn&#8217;t have everything to run&#8230;</p>



<p class="wp-block-paragraph">And of course, ArchLinux <a href="https://wiki.archlinux.org/title/QEMU">spells</a> this out:</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph"><strong>Note:</strong> At present, Arch does not offer a full-system mode and statically linked variant (neither officially nor via AUR), as this is usually not needed.</p>
</blockquote>



<p class="wp-block-paragraph">Yes, &#8220;as this is usually not needed&#8221;. :)</p>



<h2 class="wp-block-heading">Updated Setup and Looking Forward</h2>



<p class="wp-block-paragraph">Sort of lobbying ArchLinux to have static QEMU<sup data-fn="f5c8a1a6-6844-4956-adf5-488644168f92" class="fn"><a id="f5c8a1a6-6844-4956-adf5-488644168f92-link" href="#f5c8a1a6-6844-4956-adf5-488644168f92">2</a></sup> what options do I have?</p>



<ul class="wp-block-list">
<li>set up a <code>systemd</code> service to run the <code>tonistiigi/binfmt</code> container on startup (which is <a href="https://blog.container-solutions.com/running-docker-containers-with-systemd">possible</a>)</li>



<li>get some static QEMU binaries and override the settings that <code>systemd-binfmt</code> uses</li>



<li>switch to anothe Linux Distro that supports the Pi, the software I run, but also ships static QEMU builds</li>
</ul>



<p class="wp-block-paragraph">All three are suboptimal, potentially fragile, and the third is way too much work. Still the second one was kinda fine:</p>



<pre class="wp-block-code"><code class="">cd $(mktemp -d)
docker create --name="tmp_$$"  tonistiigi/binfmt
docker export tmp_$$ -o tonistiigi.tar.gz
docker rm tmp_$$
tar -xf tonistiigi.tar.gz --wildcards "*/qemu-x86_64"
# Copy along the binaries folder:
sudo cp usr/bin/qemu-x86_64 /usr/bin/qemu-x86_64-static</code></pre>



<p class="wp-block-paragraph">Then just like we&#8217;ve overridden the upstream <code>qemu-x86_64.conf</code> we do it again:</p>



<ul class="wp-block-list">
<li>Copy the config from <code>/usr/lib/binfmt.d/qemu-x86_64.conf</code> to <code>/etc/binfmt.d/qemu-x86_64.conf</code> (make sure the file has the same name to ensure this new file overrides the one from the lib folder)</li>



<li>Edit the end of the line from <code>:/usr/bin/qemu-x86_64:FP</code> to <code>:/usr/bin/qemu-x86_64-static:FPOC</code> (that is updating the binary it points at and the flags for good measure too</li>



<li>As a bonus, can update the <code>:qemu-x86_64:</code> in the front too, say to <code>:qemu-x86_64-static:</code>, to change the display name of the emulator without affecting any of the functionality, it will just rename the entrin in <code>/proc/sys/fs/binfmt_misc</code> </li>



<li>restart <code>systemd-binfmt</code></li>
</ul>



<p class="wp-block-paragraph">Then the check again:</p>



<pre class="wp-block-code"><code class="">$ cat /proc/sys/fs/binfmt_misc/qemu-x86_64-static
enabled
interpreter /usr/bin/qemu-x86_64-static
flags: POCF
offset 0
magic 7f454c4602010100000000000000000002003e00
mask fffffffffffefe00fffffffffffffffffeffffff</code></pre>



<p class="wp-block-paragraph">And the <code>alpine</code>-based checks work once more.</p>



<h2 class="wp-block-heading">Lessons Learned</h2>



<p class="wp-block-paragraph">The details were all in plain sight, but not enough experience to piece these things together. The Docker-recommended image ships its own QEMU? What does that <code>F</code> flag actually do? Can you run binaries while you don&#8217;t have them anymore? Dynamic and static linking and the signs of their misbehaviours to provide hints&#8230; However this is coupled with confusion when expectations are broken (say the <code>interpreter</code> doesn&#8217;t have to refer to an actual file path that exists <em>now</em>), until I started to question my expectations. Also, just being a heavy user of Docker doesn&#8217;t mean I&#8217;m knowledgeable of the relevant kernel functionality, and probably I should be more…</p>



<p class="wp-block-paragraph">This whole process underlined my previous thoughts on <a href="https://gergely.imreh.net/blog/2025/03/software-engineering-when-ai-seems-everywhere/">Software Engineering when AI seems Everywhere</a>, as I did try to debug things by rubber ducking with <a href="https://claude.ai">Claude</a>: this time the hallucinations were through the roof (a metric tonne of non-existent systemd funcionality, non-existent command line flags), definitely got me on a wild goose chase in a few cases. So even more care&#8217;s needed, maybe a version of <a href="https://en.wikipedia.org/wiki/Hofstadter%27s_law">Hofstadter&#8217;s Law</a>:</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">Imreh&#8217;s Law<sup data-fn="f632dbc3-dd26-4b73-b6cc-0b53e878e3dc" class="fn"><a id="f632dbc3-dd26-4b73-b6cc-0b53e878e3dc-link" href="#f632dbc3-dd26-4b73-b6cc-0b53e878e3dc">3</a></sup>: LLMs are always more wrong than you expect, even when you take into account Imreh&#8217;s Law.</p>
</blockquote>



<p class="wp-block-paragraph">In the end, Don&#8217;t Panic, make theories and try to prove them, and talk with anyone who listens, even when they are wrong, and you are more likely to get there<sup data-fn="692118e9-bc19-43d4-8ac0-1603d91facdf" class="fn"><a id="692118e9-bc19-43d4-8ac0-1603d91facdf-link" href="#692118e9-bc19-43d4-8ac0-1603d91facdf">4</a></sup>.</p>


<ol class="wp-block-footnotes"><li id="edde2512-e0d8-4c40-8fc7-32ce3232f660">I&#8217;ve download static binaries from <a href="https://github.com/andrew-d/static-binaries">andrew-d/static-binaries</a>, recommend <code>strings</code> as something that&#8217;s quick and simple to use <code>./strings /bin/sh | head</code> for example, allowing fast iteration. <a href="#edde2512-e0d8-4c40-8fc7-32ce3232f660-link" aria-label="Jump to footnote reference 1"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/21a9.png" alt="↩" class="wp-smiley" style="height: 1em; max-height: 1em;" />︎</a></li><li id="f5c8a1a6-6844-4956-adf5-488644168f92">ArchLinux is x86 by default, for them it would be to emulate <code>linux/arm64</code>, <code>linux/arm/v7</code>, <code>linux/arm/v6</code> images. For ArchLinux ARM it would be a different work the other direction. If only the main Arch would support ARM, it would be a happier world (even if even more complex). <a href="#f5c8a1a6-6844-4956-adf5-488644168f92-link" aria-label="Jump to footnote reference 2"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/21a9.png" alt="↩" class="wp-smiley" style="height: 1em; max-height: 1em;" />︎</a></li><li id="f632dbc3-dd26-4b73-b6cc-0b53e878e3dc">Tongue-in-cheek, of course. <a href="#f632dbc3-dd26-4b73-b6cc-0b53e878e3dc-link" aria-label="Jump to footnote reference 3"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/21a9.png" alt="↩" class="wp-smiley" style="height: 1em; max-height: 1em;" />︎</a></li><li id="692118e9-bc19-43d4-8ac0-1603d91facdf">And with this we just rediscovered the <a href="https://wiki.c2.com/?FeynmanAlgorithm">Feynman Algorithm</a>, I guess. <a href="#692118e9-bc19-43d4-8ac0-1603d91facdf-link" aria-label="Jump to footnote reference 4"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/21a9.png" alt="↩" class="wp-smiley" style="height: 1em; max-height: 1em;" />︎</a></li></ol><p>The post <a href="https://gergely.imreh.net/blog/2025/04/the-curious-case-of-binfmt-for-x86-emulation-for-arm-docker/">The curious case of binfmt for x86 emulation for ARM Docker</a> appeared first on <a href="https://gergely.imreh.net/blog">ClickedyClick</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://gergely.imreh.net/blog/2025/04/the-curious-case-of-binfmt-for-x86-emulation-for-arm-docker/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>ARM images to help the Archive Team</title>
		<link>https://gergely.imreh.net/blog/2021/04/arm-images-to-help-the-archive-team/</link>
					<comments>https://gergely.imreh.net/blog/2021/04/arm-images-to-help-the-archive-team/#comments</comments>
		
		<dc:creator><![CDATA[Gergely Imreh]]></dc:creator>
		<pubDate>Tue, 20 Apr 2021 21:02:54 +0000</pubDate>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[ArchiveTeam]]></category>
		<category><![CDATA[ARM]]></category>
		<category><![CDATA[Docker]]></category>
		<guid isPermaLink="false">https://gergely.imreh.net/blog/?p=2598</guid>

					<description><![CDATA[<p>Adventures into rebuilding the Archive Team scrapers for the Raspberry Pi and other ARM devices.</p>
<p>The post <a href="https://gergely.imreh.net/blog/2021/04/arm-images-to-help-the-archive-team/">ARM images to help the Archive Team</a> appeared first on <a href="https://gergely.imreh.net/blog">ClickedyClick</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">Two weeks ago I came across <a href="https://news.ycombinator.com/item?id=26701045">a thread on Hacker News</a>, linking to an announcement of the shutdown of Yahoo! Answers by early May. One of the early comments pointed people to the <a href="https://wiki.archiveteam.org/">Archive Team</a> and <a href="https://wiki.archiveteam.org/index.php/Yahoo!_Answers">their project to archive Yahoo Answers</a> before that 4th May deadline. It looked interesting and I gave their recommended tool, the <a href="https://wiki.archiveteam.org/index.php/ArchiveTeam_Warrior">Archive Team Warrior</a> a spin. It runs in VirtualBox, super easy to set up, lightweight, and all around good. Nevertheless after one night keeping my laptop running and archiving things I was wondering if there was a less wasteful way of doing the archiving. In short order I came across the team&#8217;s notes on <a href="https://wiki.archiveteam.org/index.php/Running_Archive_Team_Projects_with_Docker">how to run the archiver as Docker containers</a>. That&#8217;s more like it: I have some Raspberry Pi devices running at home anyways, if those could be the archiving clients it would make a lot more sense!</p>



<p class="wp-block-paragraph">While trying out the instructions, it was quickly clear that the Archive Team provided images out of the box were not working on the Pi. Could they be made to work, though? (Spoiler: it did, and you can <a href="https://github.com/imrehg/archiveteam-arm">check the results on GitHub.</a>)</p>



<h2 class="wp-block-heading">Container ARM-ification</h2>



<p class="wp-block-paragraph">The issue was that the Archive Team-provided project container, <code>atdr.meo.ws/archiveteam/yahooanswers-grab</code> is only available for <code>amd64</code> (x64-64) machines. Fortunately the source code is <a href="https://github.com/ArchiveTeam/yahooanswers-grab">available on GitHub</a> and thus could check out the <a href="https://github.com/ArchiveTeam/yahooanswers-grab/blob/a06166bb9b20635acc9b5959dfc09325772e6820/Dockerfile">relevant Dockerfile</a>. It uses a specific base image, <code>atdr.meo.ws/archiveteam/grab-base</code>, <a href="https://github.com/ArchiveTeam/grab-base-df">whose repo</a> reveals that internally it pulls in <code>atdr.meo.ws/archiveteam/wget-lua</code> containing a modified version of wget from <a href="https://github.com/ArchiveTeam/wget-lua">yet another repo</a> (adding Lua scripting support, plus a bunch of other stuff added by Archive Team). But fortunately this is the bottom of the stack. And this bottom of the stack is based on <a href="https://hub.docker.com/layers/debian/library/debian/buster-slim/images/sha256-ed2569b9207276b983a5ef1a9905ffa50e6a25a1605bd34d64e103c3d8636a07?context=explore">debian:buster-slim</a> which does come built as multiarchitecture images, providing arm64, armv7, armv6 versions, the architectures that are relevant for us if building for the Raspberry Pi (and other ARM boards, since why not).</p>



<span id="more-2598"></span>



<p class="wp-block-paragraph">Thus the challenge is now to rebuild the whole stack of wget-lua → grab-base → yahooanswers-grab images with these extra architectures. This would allow our humble Pi to work, since the main Archive Team payload seems to be Python, only the (forked) wget in there is architecture dependent.</p>



<p class="wp-block-paragraph">There was <a href="https://www.docker.com/blog/multi-arch-build-and-images-the-simple-way/">a very handy blogpost</a> on the Docker site on how to actually do that using <a href="https://docs.docker.com/buildx/working-with-buildx/">buildx</a>: it&#8217;s beautifully straightforward:</p>



<ul class="wp-block-list"><li>create a &#8220;builder&#8221; for a set of compatible architectures</li><li>run the build command through buildx with extra flags defining the architectures you need</li></ul>



<p class="wp-block-paragraph">This simple setup hides a few gotchas, though.</p>



<p class="wp-block-paragraph">Firstly, when building for multiple architectures, you most likely need the relevant target docker repository set up, as buildx will need to push the images somewhere. They are normally in the &#8220;builder&#8221; container, and they won&#8217;t show up locally in &#8220;docker images&#8221;.</p>



<p class="wp-block-paragraph">Secondly, for simplicity all the builds are happening in parallel and for &#8220;n&#8221; architectures I&#8217;ve kinda seen more-than-n-times slowdown (anecdotal, I haven&#8217;t measured it:). This slowdown had some unexpected effects, that while my Raspberry Pi 3 running <a href="https://archlinuxarm.org/">Arch Linux ARM</a> (armv8 or also called arm64) and it could build all 3 relevant architectures listed above, 2 of them together worked fine while 3 of them resulted in various timeouts that prevented the successful finish of the build &#8211; after the 2 hours or so it took to build the &#8220;wget-lua&#8221; image&#8230; Not fun.</p>



<p class="wp-block-paragraph">This needed a change of approach, and started to go down the emulated build path instead, using Docker with QEMU and thus enabling x86 machines to build ARM images. Here I enlisted GitHub actions to have a build architecture remotely, and the <a href="https://github.com/marketplace/actions/docker-setup-qemu">Docker Setup QEMU</a> and the <a href="https://github.com/marketplace/actions/docker-setup-buildx">Docker Setup Buildx</a> actions. They allowed me to potentially build any of these platforms: linux/amd64,linux/arm64,linux/riscv64,linux/ppc64le,linux/s390x,linux/386,linux/mips64le,linux/mips64,linux/arm/v7,linux/arm/v6</p>



<p class="wp-block-paragraph">Then the whole thing came down to:</p>



<ul class="wp-block-list"><li>If the stage uses a base image (in the FROM statement) that has a build by me, replace the archive team image name with my images</li><li>Since some images install Python packages, they might not exists in prebuilt wheel format, thus the Dockerfile need to be patched to install the build requirements for that &#8220;pip install&#8221; to succeed.</li></ul>



<p class="wp-block-paragraph">These steps were packaged up in <a href="https://github.com/imrehg/archiveteam-arm/blob/b053ec60b963fa91b2e7ed81dab6243cd32955e5/build.sh">a build script</a> (the link is to the current snapshot, just FYI), and used that to successfully build all images one by one and push to Docker Hub. From here I could set up the archiving task on the Pi finally and start contributing to the scrape again! <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f389.png" alt="🎉" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>



<figure class="wp-block-image size-large"><img fetchpriority="high" decoding="async" width="1024" height="189" src="https://gergely.imreh.net/blog/wp-content/uploads/2021/04/archiveteam_yahooanswers-1024x189.png" alt="" class="wp-image-2604" srcset="https://gergely.imreh.net/blog/wp-content/uploads/2021/04/archiveteam_yahooanswers-1024x189.png 1024w, https://gergely.imreh.net/blog/wp-content/uploads/2021/04/archiveteam_yahooanswers-500x92.png 500w, https://gergely.imreh.net/blog/wp-content/uploads/2021/04/archiveteam_yahooanswers-768x142.png 768w, https://gergely.imreh.net/blog/wp-content/uploads/2021/04/archiveteam_yahooanswers-1200x222.png 1200w, https://gergely.imreh.net/blog/wp-content/uploads/2021/04/archiveteam_yahooanswers.png 1262w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>Rasberry Pi 3 running Raspbian and scraping Yahoo! Answers (eventually)</figcaption></figure>



<p class="wp-block-paragraph">Are we done yet, though? I&#8217;ve noticed that once the upstream code for the task changes, my running task just stops doing anything until it was restated with the latest version. The Archive Team uses an extra <a href="https://containrrr.dev/watchtower/">Watchtower</a> container that checks running containers for newer versions for images, and if found, it will update &amp; restart things. Fortunately Watchtower containers are provided in multi-architecture fashion, so I didn&#8217;t need to fork/compile that, I only needed to rebuild the images if the upstream projects have changed&#8230;</p>



<h2 class="wp-block-heading">Keeping things up to date</h2>



<p class="wp-block-paragraph">So let&#8217;s rebuild the images, automatically for good measure, so we won&#8217;t have to keep an eye on when it is due. But how to best do that?</p>



<p class="wp-block-paragraph">The current idea I settled on uses Docker image tags to communicate which versions are available and which aren&#8217;t (yet).</p>



<ul class="wp-block-list"><li>when building an image, also push a tag that is the upstream source repo&#8217;s commit hash</li><li>when preparing to build next time, check the upstream latest commit hash, and check if a corresponding image exists on Docker Hub? Only build if no such image exists.</li></ul>



<p class="wp-block-paragraph">This is complicated however by the fact, that we also want to rebuild stuff automatically if not just the last image in the stack has a new commit, but the upstream projects as well! I&#8217;ve tried to put together some logic in a Makefile that would handle all this rebuilding in a dependency-aware way, but it stated to become very hairy very quick. So instead settled on <a href="https://www.pyinvoke.org/">Invoke</a> to have some resemblance to make-like tasks, but more flexibly due to Python. With a bit of trial and error I&#8217;ve ended up with a crude dependency management and external script calls (git rev-parse for remote repo status, docker manifest for image status, and the build script).</p>



<p class="wp-block-paragraph">The first build was roughly 1:45h, afterwards with caching it takes 30-60s for the GitHub action to run when it has nothing to build. That&#8217;s fast enough to set it on a schedule, and try to rebuild every half an hour or so. </p>



<p class="wp-block-paragraph">And with this, we are pretty much done, <a href="https://github.com/imrehg/archiveteam-arm">here&#8217;s the relevant GitHub repo</a> all packaged up. So far it works pretty decently, and already had one automatic rebuild &amp; update of images this week that I didn&#8217;t have to know about.</p>



<h2 class="wp-block-heading">Future improvements</h2>



<p class="wp-block-paragraph">No programming project is ever really finished, and this one has a lot of room for improvements.</p>



<p class="wp-block-paragraph">Could <strong>add images for more Archive Team projects</strong> (ideally all of them). This is complicated by that some of the images have multiple forms (e.g. wget-lua build with openssl or gnutls), and my current build system doesn&#8217;t take that into account. I would need to replicate support for those build args and expand on the &#8220;have this image been built?&#8221; checks to take those into account as well for robustness.</p>



<p class="wp-block-paragraph">But the more ambitious and likely trickier and better bang for buck task would be <strong>folding this work into the official images</strong> by the Archive Team. This is likely challenging for a few reasons. The first, easier aspect is that they use another Docker registry (not Docker Hub) and I don&#8217;t know whether that supports multiarch images (though it should). The trickier part is that they use <a href="https://cloud.drone.io/welcome">Drone</a> as CI/CD tool, and <a href="http://plugins.drone.io/drone-plugins/drone-docker/">their Docker plugin</a> is not based on buildx (naturally, I guess) nor have they any other plugin that we could use here (unlike GitHub actions). So besides code change also some convincing needed to encourage tool changes. Much higher bar.</p>



<p class="wp-block-paragraph">Finally, it would be interesting to <strong>dig in to the reasons of the slow builds</strong>. It seems like the wget-lua image is dead slow in buildx (about 1:20h), and not sure why, when regular build finishes at a fraction of that time. So far some steps that seem to take very long are git submodule init/update, and some of the config steps, I believe, but didn&#8217;t look too deep so far. Cutting this build time would help a lot with experimentation, though since the relevant image doesn&#8217;t need to be rebuilt often it might be low return on investment.</p>



<p class="wp-block-paragraph">And this is all&#8230; I&#8217;d love to hear how did it work for you if you try the <a href="https://github.com/imrehg/archiveteam-arm">these</a> ARM images!</p>
<p>The post <a href="https://gergely.imreh.net/blog/2021/04/arm-images-to-help-the-archive-team/">ARM images to help the Archive Team</a> appeared first on <a href="https://gergely.imreh.net/blog">ClickedyClick</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://gergely.imreh.net/blog/2021/04/arm-images-to-help-the-archive-team/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>Continuous integration testing of Arch User Repository packages</title>
		<link>https://gergely.imreh.net/blog/2018/04/circleci-aur/</link>
					<comments>https://gergely.imreh.net/blog/2018/04/circleci-aur/#comments</comments>
		
		<dc:creator><![CDATA[Gergely Imreh]]></dc:creator>
		<pubDate>Thu, 12 Apr 2018 11:56:40 +0000</pubDate>
				<category><![CDATA[Admin]]></category>
		<category><![CDATA[Arch Linux]]></category>
		<category><![CDATA[CircleCI]]></category>
		<category><![CDATA[Docker]]></category>
		<category><![CDATA[YAML]]></category>
		<guid isPermaLink="false">https://gergely.imreh.net/blog/?p=2425</guid>

					<description><![CDATA[<p>Using git submodules and CircleCI workflows to build and test the AUR packages I maintain.</p>
<p>The post <a href="https://gergely.imreh.net/blog/2018/04/circleci-aur/">Continuous integration testing of Arch User Repository packages</a> appeared first on <a href="https://gergely.imreh.net/blog">ClickedyClick</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>I maintain <a href="https://aur.archlinux.org/packages/?K=imrehg&amp;SeB=m">a couple of ArchLinux user-contributed packages</a> on the <a href="https://wiki.archlinux.org/index.php/Arch_User_Repository">Arch User Repository (AUR)</a>, and over time I&#8217;ve built out a bit of infrastructure around that to make that maintenance easier (and hopefully the results better). The core of it is automated building of packages in Continuous Integration, which catches a number of issues which otherwise would be more difficult.</p>
<p>This write-up will go through the entire packaging process to make it easily reproducible.<span id="more-2425"></span></p>
<h2>Contributing a package</h2>
<p>AUR is a great resource for Arch Linux users, and  it is pretty easy to <a href="https://wiki.archlinux.org/index.php/Arch_User_Repository#Sharing_and_maintaining_packages">create and contribute new packages</a>.</p>
<p>Packages are created by cloning an empty <a href="https://git-scm.com/">git</a> repository with the desired package name. I do it in a slightly different setup compared to the wiki that&#8217;s linked just above, as:</p>
<pre class="lang:sh decode:true" title="Clone an empty repo to create a new AUR package">git clone ssh+git://aur@aur.archlinux.org/&lt;PACKAGENAME&gt;.git</pre>
<p>Add your PKGBUILD and any other required files, run mksrcinfo, and git commit, and push&#8230; If everything went well, your package is now visible in the <a href="https://aur.archlinux.org/packages/?O=0&amp;K=">AUR search</a>.</p>
<p>Next time that repository is cloned, it will contain the code, and changes (i.e. package updates) can be pushed just as well too.</p>
<h2>Keeping track of packages</h2>
<p>As more packages are contributed, it is increasingly hard to keep track of them as separate repositories. One way to improve on this, is creating a &#8220;meta&#8221; repository (or repo), where all the contributed packages are linked as <a href="https://git-scm.com/book/en/v2/Git-Tools-Submodules">git submodules</a>.</p>
<p>This organization is achieved by creating your meta-repo, and add your package as a submodule:</p>
<pre class="lang:sh decode:true " title="Adding AUR package as a submodule to a git repo">git submodule add ssh+git://aur@aur.archlinux.org/&lt;PACKAGENAME&gt;.git</pre>
<p>Then you&#8217;d make package updates in that submodule, and the meta repo would contain all your packages as a collection.</p>
<p>My packages&#8217; meta repo that show this arrangement is on Github at <a href="https://github.com/imrehg/aur">imrehg/aur</a>.</p>
<h2>Continuous integration testing</h2>
<p>What we can do with this setup now, is to automatically check out, build, analyze, and test (including installation) of the all the packages.  I&#8217;ve set that up as <a href="https://circleci.com/">CircleCI</a> build jobs for each of the packages: each of them built and installed in a clean Arch Linux environment.</p>
<p>The clean Arch Linux environment is provided by a <a href="https://www.docker.com/">Docker</a> image, that I&#8217;ve created for this purpose, <a href="https://github.com/imrehg/archlinux-makepkg-docker">archlinux-makepkg-docker</a>. That image builds on an upstream Arch Linux image, and sets a few things up:</p>
<ul>
<li>updates the image with the latest base build system</li>
<li>creates a &#8220;builder&#8221; user that can run sudo</li>
<li>installs two packages from scratch that are sometimes needed for working with AUR packages: &#8220;package-query&#8221; and &#8220;yaourt&#8221;</li>
<li>installs &#8220;<a href="https://wiki.archlinux.org/index.php/Namcap">namcap</a>&#8221; to analyze the package</li>
</ul>
<p>Each AUR package is set up with its own CircleCI build job as part of a <a href="https://circleci.com/docs/2.0/workflows/">workflow</a>.</p>
<p>Since most of the work for each package is pretty much the same, we can simplify things with templates, such as this:</p>
<pre class="lang:yaml decode:true" title="A CircleCI config to build my-package"># Common sections
defaults: &amp;defaults
  working_directory: ~/aur
  docker:
    - image: imrehg/archlinux-makepkg

updatepackage: &amp;updatepackage
  name: Update packages
  command: sudo pacman -Syu --noconfirm

gitupdate: &amp;gitupdate
  name: Git repo updates
  command: |
    sed -i "s#ssh+git://aur@aur.archlinux.org#https://aur.archlinux.org#" .gitmodules
    git submodule update --init
pkgbuildtest: &amp;pkgbuildtest
  name: Testing PKGBUILD
  command: |
    cd ~/aur/${CIRCLE_JOB}
    namcap PKGBUILD
buildtest: &amp;buildtest
  name: Building package
  command: |
    cd ~/aur/${CIRCLE_JOB}
    makepkg -sci --noconfirm

# Main
version: 2
jobs:
  my-package:
    &lt;&lt;: *defaults
    steps:
      - run:
          &lt;&lt;: *updatepackage
      - checkout
      - run:
          &lt;&lt;: *gitupdate
      - run:
          &lt;&lt;: *pkgbuildtest
      - run:
          &lt;&lt;: *buildtest

workflows:
  version: 2
  build:
    jobs:
      - my-package
</pre>
<p>The sample CircleCI &#8220;config.yml&#8221; here is set up to build an AUR package called &#8220;my-package&#8221;:</p>
<ul>
<li>it pulls the Arch Linux Docker image mentioned earlier</li>
<li>updates any outdated OS package</li>
<li>checks out meta repo that we are working from</li>
<li>updates the submodule configuration to be able to pull the required submodule without authentication. the &#8220;ssh+git://&#8221; setup requires the maintainer&#8217;s SSH credentials, while switching to &#8220;https://&#8221; the CI environment is allowed to check the package&#8217;s code out (and won&#8217;t be able to push back upstream, which is safer)</li>
<li>runs &#8220;namcap&#8221; on the PKGBUILD to catch any obvious issues</li>
<li>builds and installs the package (including dependencies)</li>
</ul>
<p>As &#8220;my-package&#8221; is set up above, it does not have any line specific in to that package in the build steps. The specifics are set up using CircleCI variables (CIRCLE_JOB) and <a href="http://yaml.org/spec/1.2/spec.html">YAML</a> <a href="http://yaml.org/type/merge.html">Merge Key Language-Independent Types</a> (the &#8220;foo: &amp;foo&#8221; and &#8220;&lt;&lt; : *foo&#8221; section). Thus if there&#8217;s &#8220;another-package&#8221;, it&#8217;s easy to clone the &#8220;my-package&#8221; section as it is, naming that &#8220;another-package&#8221;, and adding a new build job to the end of the file called &#8220;another-package&#8221;. With this &#8220;templating&#8221; when the build steps need to be modified, they can be updated in the header, and all the packages will pick that up.</p>
<p>Workflows are also useful, as  jobs can be made dependent on each other, if they are related, such as my &#8220;gnushogi&#8221; and &#8220;xshogi&#8221; packages, or likely any AUR package that requires other AUR packages that need to be built.</p>
<pre class="lang:yaml decode:true" title="Workflow with dependency">...
workflows:
  version: 2
  build:
    jobs:
      &lt;other jobs&gt;
      - gnushogi
      - xshogi:
          requires:
            - gnushogi
</pre>
<p>This would result in a dependency in the jobs as:</p>
<p><figure id="attachment_2443" aria-describedby="caption-attachment-2443" style="width: 724px" class="wp-caption aligncenter"><a href="https://gergely.imreh.net/blog/wp-content/uploads/2018/04/circleci_aur_jobs.png"><img decoding="async" class="size-full wp-image-2443" src="https://gergely.imreh.net/blog/wp-content/uploads/2018/04/circleci_aur_jobs.png" alt="" width="724" height="973" srcset="https://gergely.imreh.net/blog/wp-content/uploads/2018/04/circleci_aur_jobs.png 724w, https://gergely.imreh.net/blog/wp-content/uploads/2018/04/circleci_aur_jobs-372x500.png 372w" sizes="(max-width: 724px) 100vw, 724px" /></a><figcaption id="caption-attachment-2443" class="wp-caption-text">Jobs in the CircleCI workflow</figcaption></figure></p>
<p>The workflows also allow for jobs to give files to each other. E.g. as above &#8220;xshogi&#8221; depends on &#8220;gnushogi&#8221; to be installed, I could build all the required dependencies again in &#8220;xshogi&#8221;, but it was already built, I could just pass on the created package from the earlier job to the next, using <a href="https://circleci.com/blog/deep-diving-into-circleci-workspaces/">CircleCI workspaces</a>.</p>
<pre class="lang:yaml decode:true" title="Sample file passing between jobs with workspaces">  gnushogi:
    &lt;&lt;: *defaults
    steps:
      - run:
          &lt;&lt;: *updatepackage
      - checkout
      - run:
          &lt;&lt;: *gitupdate
      - run:
          &lt;&lt;: *pkgbuildtest
      - run:
          &lt;&lt;: *buildtest
      - persist_to_workspace:
          root: gnushogi
          paths: gnushogi-*.pkg.tar.xz

  xshogi:
    &lt;&lt;: *defaults
    steps:
    &lt;&lt;: *defaults
    steps:
      - run:
          &lt;&lt;: *updatepackage
      - checkout
      - run:
          &lt;&lt;: *gitupdate
      - run:
          &lt;&lt;: *pkgbuildtest
      - attach_workspace:
          at: /tmp/workspace
      - run:
          name: Installing gnushogi
          command: sudo pacman -U --noconfirm /tmp/workspace/gnushogi*.pkg.*
      - run:
          &lt;&lt;: *buildtest
</pre>
<p>The meta repo is now ready to go with such &#8220;.circleci/config.yml&#8221;, and on each push, it will build all the packages defined in the job list. You can check how the results look for my AUR packages in CircleCI&#8217;s <a href="https://circleci.com/gh/imrehg/aur">build job view</a> (one entry by build job, ie. package-per-push) or <a href="https://circleci.com/gh/imrehg/workflows/aur">workflow view</a> (one entry per push, aggregating all jobs).</p>
<p><figure id="attachment_2453" aria-describedby="caption-attachment-2453" style="width: 1020px" class="wp-caption aligncenter"><a href="https://gergely.imreh.net/blog/wp-content/uploads/2018/04/circleci_aur_workflow_small.png"><img decoding="async" class="size-full wp-image-2453" src="https://gergely.imreh.net/blog/wp-content/uploads/2018/04/circleci_aur_workflow_small.png" alt="" width="1020" height="845" srcset="https://gergely.imreh.net/blog/wp-content/uploads/2018/04/circleci_aur_workflow_small.png 1020w, https://gergely.imreh.net/blog/wp-content/uploads/2018/04/circleci_aur_workflow_small-500x414.png 500w, https://gergely.imreh.net/blog/wp-content/uploads/2018/04/circleci_aur_workflow_small-768x636.png 768w" sizes="(max-width: 1020px) 100vw, 1020px" /></a><figcaption id="caption-attachment-2453" class="wp-caption-text">Last build workflows</figcaption></figure></p>
<p>One of the advantages of this setup, is that if a build fails on any of the package (e.g. a source file is no longer available) it&#8217;s easy to see, and I can catch a number of out-of-date packages sooner than someone reports it on AUR.</p>
<h2>Keeping the build image up to data</h2>
<p>The  Arch Linux Docker image is <a href="https://docs.docker.com/docker-hub/builds/">automatically built</a> on Docker Hub (and can be found at <a href="https://hub.docker.com/r/imrehg/archlinux-makepkg/">imrehg/archlinux-makepkg</a>. It is kept fresh by an <a href="https://ifttt.com/">If This Than That</a> applet, which triggers the build every morning.</p>
<p><figure id="attachment_2441" aria-describedby="caption-attachment-2441" style="width: 691px" class="wp-caption aligncenter"><a href="https://gergely.imreh.net/blog/wp-content/uploads/2018/04/aur_build_image_ifttt.png"><img loading="lazy" decoding="async" class="wp-image-2441 size-full" src="https://gergely.imreh.net/blog/wp-content/uploads/2018/04/aur_build_image_ifttt.png" alt="" width="691" height="549" srcset="https://gergely.imreh.net/blog/wp-content/uploads/2018/04/aur_build_image_ifttt.png 691w, https://gergely.imreh.net/blog/wp-content/uploads/2018/04/aur_build_image_ifttt-500x397.png 500w" sizes="auto, (max-width: 691px) 100vw, 691px" /></a><figcaption id="caption-attachment-2441" class="wp-caption-text">IFTTT Applet to trigger Docker Hub automated builds</figcaption></figure></p>
<p>That applet just uses the <a href="https://ifttt.com/date_and_time">Date &amp; Time</a> and <a href="https://ifttt.com/maker_webhooks">Webhooks</a> recipes. The webhook points to the Trigger URL provided by the &#8220;Build Settings / Build Triggers&#8221; section on Docker Hub for the image, and it&#8217;s a POST request with payload of:</p>
<pre class="lang:js decode:true" title="Docker Hub build trigger payload">{"docker_tag": "latest"}</pre>
<p><figure id="attachment_2442" aria-describedby="caption-attachment-2442" style="width: 525px" class="wp-caption aligncenter"><a href="https://gergely.imreh.net/blog/wp-content/uploads/2018/04/docker_hub_triggers.png"><img loading="lazy" decoding="async" class="wp-image-2442 size-large" src="https://gergely.imreh.net/blog/wp-content/uploads/2018/04/docker_hub_triggers-1024x563.png" alt="" width="525" height="289" srcset="https://gergely.imreh.net/blog/wp-content/uploads/2018/04/docker_hub_triggers-1024x563.png 1024w, https://gergely.imreh.net/blog/wp-content/uploads/2018/04/docker_hub_triggers-500x275.png 500w, https://gergely.imreh.net/blog/wp-content/uploads/2018/04/docker_hub_triggers-768x422.png 768w, https://gergely.imreh.net/blog/wp-content/uploads/2018/04/docker_hub_triggers.png 1909w" sizes="auto, (max-width: 525px) 100vw, 525px" /></a><figcaption id="caption-attachment-2442" class="wp-caption-text">Docker HUB Build Settings / Build Triggers settings</figcaption></figure></p>
<p>Keeping the image fresh like this shortens the build time when running the jobs on CircleCI (fewer packages need to be updated), which especially important as free users have limited CPU time available each month.</p>
<p>Not many packages which use other AUR packages, which likely need more setup here.</p>
<h2>Update workflow</h2>
<p>As an aside, the process to update any given package with this setup as follows:</p>
<ul>
<li>Update the &#8220;PKGBUILD&#8221; for the package, quite often it&#8217;s just the version number</li>
<li>Update the checksums easily with &#8220;updpkgsums&#8221; (part of &#8220;pacman&#8221; so it should be always available)</li>
<li>Build the package</li>
<li>If everything goes well, update the required &#8220;.SRCINFO&#8221; with &#8220;mksrcinfo&#8221; (part of &#8220;pkgbuild-introspection&#8221;)</li>
<li>git add, commit (signed if you can:), and push to AUR</li>
<li>Clean up the package directory (&#8220;git clean -d -f &amp;&amp; rm -rf src&#8221;)</li>
<li>Going back up in the folder hierarchy to the meta repo git add and commit the changes to the submodules</li>
<li>Push to github, and enjoy the build!</li>
</ul>
<h2>Future</h2>
<p>Many things can be improved on this setup (one day), here are some ideas</p>
<p>It should be possible to <strong>publish the build artifacts</strong> to somewhere (say S3) and set it up as a custom Arch Linux package repository, thus can be reused without everyone needing to build from scratch every time.</p>
<p>If that publishing would happen, I&#8217;m guessing it would be good to also <strong>sign the built packages</strong>, which might be a bit trickier to set up safely, but would make package distribution nicer and more robust.</p>
<p>In my list of packages there are not that many that depend on other AUR packages. Other <strong>packages with more AUR dependencies</strong> might need even more custom setup than shown above, besides the templated sections, to make them speedy and logical.</p>
<p>In the package testing steps, probably should <strong>run &#8220;namcap&#8221; on the finished package</strong> too, to catch other issues (e.g. dependencies required but not included).</p>
<hr />
<p>What&#8217;s your experience with maintaining AUR packages, or with CircleCI? Have any feedback on how to make this above even more useful?</p>
<p>The post <a href="https://gergely.imreh.net/blog/2018/04/circleci-aur/">Continuous integration testing of Arch User Repository packages</a> appeared first on <a href="https://gergely.imreh.net/blog">ClickedyClick</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://gergely.imreh.net/blog/2018/04/circleci-aur/feed/</wfw:commentRss>
			<slash:comments>7</slash:comments>
		
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Object Caching 18/25 objects using APC
Page Caching using Disk: Enhanced 
Lazy Loading (feed)

Served from: gergely.imreh.net @ 2026-10-04 20:37:52 by W3 Total Cache
-->