<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="https://jacobkiers.net/feed.xsl" type="text/xsl"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
    <title>Jacob Kiers</title>
    <link rel="self" type="application/atom+xml" href="https://jacobkiers.net/atom.xml"/>
    <link rel="alternate" type="text/html" href="https://jacobkiers.net"/>
    <generator uri="https://www.getzola.org/">Zola</generator>
    <updated>2026-06-06T00:00:00+00:00</updated>
    <id>https://jacobkiers.net/atom.xml</id>
    <entry xml:lang="en">
        <title>Don&#x27;t accept router advertisements on IX links</title>
        <published>2026-06-06T00:00:00+00:00</published>
        <updated>2026-06-06T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Jacob Kiers
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://jacobkiers.net/post/do-not-accept-router-advertisements-on-ix-links/"/>
        <id>https://jacobkiers.net/post/do-not-accept-router-advertisements-on-ix-links/</id>
        
        <content type="html" xml:base="https://jacobkiers.net/post/do-not-accept-router-advertisements-on-ix-links/">&lt;p&gt;To explore global networking, I run an &lt;a href=&quot;https:&#x2F;&#x2F;jacobkiers.net&#x2F;post&#x2F;ipv6-only-home-network&#x2F;&quot;&gt;IPv6-only&lt;&#x2F;a&gt; &lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Autonomous_system_(Internet)&quot;&gt;Autonomous System&lt;&#x2F;a&gt;. Like any network operator, I need routers.&lt;&#x2F;p&gt;
&lt;p&gt;One of the routers is connected to an &lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Internet_exchange_point&quot;&gt;Internet Exchange&lt;&#x2F;a&gt; LAN network. A while ago, I noticed that router was installing an extra IPv6 default route, which caused routing errors. I didn&#x27;t give it much attention at that point.&lt;&#x2F;p&gt;
&lt;p&gt;Earlier this week, I decided to find out what was happening. I noticed that it only happened if the BGP LAN link was up. I also noticed that when I removed that route, it would come back after a while. So then I removed it, and it came back again. Rinse and repeat...&lt;&#x2F;p&gt;
&lt;p&gt;That led me to formulate a theory: somebody is running a router on that link which sends out &lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Neighbor_Discovery_Protocol&quot;&gt;Router Advertisements&lt;&#x2F;a&gt;. On an IX LAN that should not happen: it should strictly serve peer to peer BGP traffic and nothing else.&lt;&#x2F;p&gt;
&lt;p&gt;So I fired up the trusty old &lt;code&gt;tcpdump&lt;&#x2F;code&gt;, let it run for a while with an RA filter, and sure enough: every fifteen minutes or so I saw an RA come in.&lt;&#x2F;p&gt;
&lt;p&gt;That led me to another question: &lt;em&gt;why would my router even honour these&lt;&#x2F;em&gt;, and install that router as a default router. Router Advertisements work by advertising a specific router so clients know where to send their traffic. But I already &lt;em&gt;have&lt;&#x2F;em&gt; a router, and it already has a correctly configured routing table.&lt;&#x2F;p&gt;
&lt;p&gt;Since I use &lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https:&#x2F;&#x2F;www.freedesktop.org&#x2F;software&#x2F;systemd&#x2F;man&#x2F;systemd-networkd.html&quot;&gt;systemd-networkd&lt;&#x2F;a&gt;, it was time to dig into its manuals. And there it was: &lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https:&#x2F;&#x2F;www.freedesktop.org&#x2F;software&#x2F;systemd&#x2F;man&#x2F;systemd.network.html#IPv6AcceptRA=&quot;&gt;&lt;code&gt;IPv6AcceptRA&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;, enabled by default.&lt;&#x2F;p&gt;
&lt;p&gt;Now the picture was clear: a combination of two misconfigured routers. Mine, accepting RAs. Theirs, sending RAs.&lt;&#x2F;p&gt;
&lt;p&gt;The fix is simple and obvious. Disable IPv6 RAs on any router link, and instead manually configure addresses and routes.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;systemd&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;[Network]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;Address&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; fe80::dead:beef&#x2F;64&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;IPv6AcceptRA&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; no&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Alternating current and its relation to voltage</title>
        <published>2023-01-05T00:00:00+00:00</published>
        <updated>2023-01-10T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Jacob Kiers
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://jacobkiers.net/post/alternating-current-and-relation-to-voltage/"/>
        <id>https://jacobkiers.net/post/alternating-current-and-relation-to-voltage/</id>
        
        <content type="html" xml:base="https://jacobkiers.net/post/alternating-current-and-relation-to-voltage/">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;For a while now I am interested in electronics. So after some false starts,
I started following a long course on it: &lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https:&#x2F;&#x2F;www.udemy.com&#x2F;course&#x2F;crash-course-electronics-and-pcb-design&#x2F;&quot;&gt;Crash Course Electronics and PCB Design&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Lecture 9 was about alternating current (AC), the kind of current that
flows from a wall socket. I struggled to understand how it&#x27;s voltage is
determined, so I took a lot of notes. This is the result.&lt;&#x2F;p&gt;
&lt;p&gt;Warning: algebra ahead. Also: everything here may be wildly inaccurate.
Did I mention that I am just learning this stuff?&lt;&#x2F;p&gt;
&lt;h2 id=&quot;what-is-alternating-current&quot;&gt;What is alternating current&lt;&#x2F;h2&gt;
&lt;p&gt;Alternating current measn that the supply source voltage changes as a
function of time. In general, this is a sine wave, with positive high
peak voltages and negative low peak voltages.&lt;&#x2F;p&gt;
&lt;p&gt;A negative voltage means that the current flows in the opposite direction,
from minus (-) to plus (+). In the span of a full sine wave, the current
changes direction twice. So with a standard 60Hz alternating current, the
current changes direction 120 times per second.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;properties-of-alternating-current&quot;&gt;Properties of alternating current&lt;&#x2F;h2&gt;
&lt;p&gt;Alternating current has a few commonly-used properties:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Peak voltage: the peak voltages on both the upper peak ($V_{pmax}$) and lower peak ($V_{pmin}$).&lt;&#x2F;li&gt;
&lt;li&gt;Peak to peak voltage: the voltage difference between the two peaks: $V_{pp} = V_{pmax} - V_{pmin}$.&lt;&#x2F;li&gt;
&lt;li&gt;Frequency: the number of complete cycles (of $V_{pmax}$ and $V_{pmin}$) per second.&lt;&#x2F;li&gt;
&lt;li&gt;Root-mean-square voltage: the voltage calculation usually associated with alternating current, e.g. 230V or 120V.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;In the rest of this note, we will work with an AC voltage with the following properties:&lt;&#x2F;p&gt;
&lt;h2 id=&quot;root-mean-square-voltage&quot;&gt;Root Mean Square Voltage&lt;&#x2F;h2&gt;
&lt;p&gt;Root Mean Square (RMS, &lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Root_mean_square&quot;&gt;wikipedia&lt;&#x2F;a&gt;) is a formula that is often used
whencalculating the voltage over time for an alternating current circuit.&lt;&#x2F;p&gt;
&lt;p&gt;Its definition is as follows:&lt;&#x2F;p&gt;
&lt;p&gt;$$
f(rms) = \lim_{T \to \infty} \sqrt{\frac{1}{T} \int_0^T [f(t)]^2 dt}
$$&lt;&#x2F;p&gt;
&lt;p&gt;For a pure sine wave, which is common, the formula for the peak-to-peak
amplitude can be simplified as:&lt;&#x2F;p&gt;
&lt;p&gt;$$ V_{pp} = 2\sqrt{2} \cdot RMS \approx 2.828 \cdot RMS$$&lt;&#x2F;p&gt;
&lt;h3 id=&quot;alternate-ways-of-writing&quot;&gt;Alternate ways of writing&lt;&#x2F;h3&gt;
&lt;p&gt;That also means that&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;$V_{rms} = V_{pp} \div 2\sqrt{2} = \frac{V_{pp}}{2\sqrt{2}}$&lt;&#x2F;li&gt;
&lt;li&gt;Written differently: $V_{rms} = V_{pp} \cdot \frac{1}{2\sqrt{2}} = V_{pp} \cdot \frac{1}{2} \cdot \frac{1}{\sqrt{2}}$&lt;&#x2F;li&gt;
&lt;li&gt;This works, because we can pull out the $\frac{1}{2}$ out of $\frac{1}{2\sqrt{2}}$,
as long as we then &lt;em&gt;multiply&lt;&#x2F;em&gt; by the remainder ($\frac{1}{\sqrt{2}}$), which, again,
then gives in full: $V_{rms} = V_{pp} \cdot \frac{1}{2} \cdot \frac{1}{\sqrt{2}}$.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;I know, this is high school level algebra, but it&#x27;s been a long time and I
struggled to get there. So I wrote it out in full.&lt;&#x2F;p&gt;
&lt;p&gt;So, when calculating, one then gets:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;$V_{rms} = V_{pp} \cdot \frac{1}{2} \cdot \frac{1}{\sqrt{2}}$&lt;&#x2F;li&gt;
&lt;li&gt;$V_{rms} \approx V_{pp} \cdot 0.5 \cdot \frac{1}{1.414}$&lt;&#x2F;li&gt;
&lt;li&gt;$V_{rms} \approx V_{pp} \cdot 0.5 \cdot 0.707$&lt;&#x2F;li&gt;
&lt;li&gt;$V_{rms} \approx V_{pp} \cdot 0.354$&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;example-calculations&quot;&gt;Example calculations&lt;&#x2F;h3&gt;
&lt;p&gt;With wo common voltages 120V RMS and 230V RMS, we get:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;For 120V RMS: $V_{pp} \approx 2.828 \cdot 120 \approx 339V$&lt;&#x2F;li&gt;
&lt;li&gt;For 230V RMS: $V_{pp} \approx 2.828 \cdot 230 \approx 650V$&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;And when we go back:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;For 120V RMS: $V_{rms} \approx V_{pp} \cdot .354 \approx 339 \cdot .354 \approx 120V$&lt;&#x2F;li&gt;
&lt;li&gt;For 230V RMS: $V_{rms} \approx V_{pp} \cdot .354 \approx 650 \cdot .354 \approx 230V$&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Given a symmetrical sine wave with the reference point as 0V, that gives also:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;For 120V RMS: $V_{pp} = V_{phigh} - V_{plow} \approx 169V - (-169V) $&lt;&#x2F;li&gt;
&lt;li&gt;For 230V RMS: $V_{pp} = V_{phigh} - V_{plow} \approx 325V - (-325V) $&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;fin&quot;&gt;Fin&lt;&#x2F;h2&gt;
&lt;p&gt;That was it for today. If you found this useful, I highly recommend
following &lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https:&#x2F;&#x2F;www.udemy.com&#x2F;course&#x2F;crash-course-electronics-and-pcb-design&#x2F;&quot;&gt;the course&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Cross compiling Rust with Drone</title>
        <published>2022-12-30T00:00:00+00:00</published>
        <updated>2022-12-30T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Jacob Kiers
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://jacobkiers.net/post/rust-cross-compilation-on-drone/"/>
        <id>https://jacobkiers.net/post/rust-cross-compilation-on-drone/</id>
        
        <content type="html" xml:base="https://jacobkiers.net/post/rust-cross-compilation-on-drone/">&lt;h2 id=&quot;why&quot;&gt;Why&lt;&#x2F;h2&gt;
&lt;p&gt;For a while now, I have been working on a personal project called
&lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https:&#x2F;&#x2F;code.kiers.eu&#x2F;newsletter-to-web&#x2F;newsletter-to-web&quot;&gt;newsletter2web&lt;&#x2F;a&gt;, which I run on a Raspberry PI. As the title
already indicates, it is written in &lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https:&#x2F;&#x2F;www.rust-lang.org&#x2F;&quot;&gt;Rust&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Since compiling the project takes a while, especially on a Raspberry PI,
I decided to investigate how to make it build automatically.&lt;&#x2F;p&gt;
&lt;p&gt;That sounds like a job for continuous integration solution. But these tend
to use quite a bit of resources, even when not in use. That is wasteful
and I didn&#x27;t want that.&lt;&#x2F;p&gt;
&lt;p&gt;So put together, I got the following requirements:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;A continuous integration solution, that&lt;&#x2F;li&gt;
&lt;li&gt;Would use little resources when not in use,&lt;&#x2F;li&gt;
&lt;li&gt;Integrates with Gitea, and&lt;&#x2F;li&gt;
&lt;li&gt;Is capable of cross-compiling Rust&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;After a bit of digging, I found &lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https:&#x2F;&#x2F;www.drone.io&#x2F;&quot;&gt;Drone CI&lt;&#x2F;a&gt; to be a nice fit: it is fairly
lightweight, and easy to get running. Making it work well enough to cross
compile Rust took a while though.&lt;&#x2F;p&gt;
&lt;p&gt;This post describes the cross compilation, the &lt;a href=&quot;https:&#x2F;&#x2F;jacobkiers.net&#x2F;post&#x2F;setting-up-drone-ci-with-autoscaler&#x2F;&quot;&gt;Drone and Gitea setup&lt;&#x2F;a&gt; is
described in the previous post.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;definitions&quot;&gt;Definitions&lt;&#x2F;h2&gt;
&lt;p&gt;Since not everyone may be familiar with cross compilation, it is useful to
know some definitions.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Host: the machine in which cross compilation is performed.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;Target: the operating system and CPU architecture for which a project is
compiled.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;Toolchain: the set of software required for compilation. This is at least a linker, but usually also a C compiler and target-specific source code are required.&lt;&#x2F;p&gt;
&lt;p&gt;When cross compiling, this is usually a different set of software than is required to compile for the host itself.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;how-does-it-work&quot;&gt;How does it work&lt;&#x2F;h2&gt;
&lt;p&gt;Rust has good support for cross compilation already out of the box.
However, in order to use it, the compilation toolchains need to be installed on the host. Also, the Rust project sometimes needs custom configuration as well, in order to be able to use this.&lt;&#x2F;p&gt;
&lt;p&gt;It can be tedious to do this manually. Therefore, we use &lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;cross-rs&#x2F;cross&quot;&gt;cross&lt;&#x2F;a&gt;, which
is a project that uses pre-built Docker images for each target. Cross still
needs to have the &lt;em&gt;Rust&lt;&#x2F;em&gt; toolchain for each target installed though.&lt;&#x2F;p&gt;
&lt;p&gt;Since cross uses Docker, and compiling source code has the possibility of
executing arbitrary code on the host, a security boundary is required as
well. For that, a Docker in Docker setup is used.&lt;&#x2F;p&gt;
&lt;p&gt;Docker in docker means running the Docker service itself inside a Docker
container running on the host.&lt;&#x2F;p&gt;
&lt;p&gt;Since cross needs the Rust toolchain for each target, we will use a custom
Docker image to run it.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;the-docker-image&quot;&gt;The Docker image&lt;&#x2F;h2&gt;
&lt;p&gt;This Docker image will have everything installed that is required to run
cross. So it contains the Rust toolchain for each target and the Docker
service for Docker in Docker.&lt;&#x2F;p&gt;
&lt;p&gt;This is the corresponding &lt;code&gt;Dockerfile&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;docker&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# Base image. Change this to use another Rust version.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;FROM&lt;&#x2F;span&gt;&lt;span&gt; rust:1.66-slim&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# Install Docker (for docker-in-docker)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;RUN&lt;&#x2F;span&gt;&lt;span&gt; apt-get update \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; &amp;amp;&amp;amp; apt-get install -y ca-certificates curl gnupg \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; &amp;amp;&amp;amp; mkdir -p &#x2F;etc&#x2F;apt&#x2F;keyrings \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; &amp;amp;&amp;amp; curl -fsSL https:&#x2F;&#x2F;download.docker.com&#x2F;linux&#x2F;debian&#x2F;gpg | gpg --dearmor -o &#x2F;etc&#x2F;apt&#x2F;keyrings&#x2F;docker.gpg \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; &amp;amp;&amp;amp; echo &lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;&amp;quot;deb [arch=$(dpkg --print-architecture) signed-by=&#x2F;etc&#x2F;apt&#x2F;keyrings&#x2F;docker.gpg] https:&#x2F;&#x2F;download.docker.com&#x2F;linux&#x2F;debian bullseye stable&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt; &amp;gt;&amp;gt; &#x2F;etc&#x2F;apt&#x2F;sources.list.d&#x2F;docker.list \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; &amp;amp;&amp;amp; apt-get update \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; &amp;amp;&amp;amp; apt-get install -y docker-ce-cli \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; &amp;amp;&amp;amp; apt-get clean&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# Install cross v0.2.4&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;RUN&lt;&#x2F;span&gt;&lt;span&gt; mkdir -p &#x2F;usr&#x2F;local&#x2F;cargo&#x2F;bin &amp;amp;&amp;amp; curl -L https:&#x2F;&#x2F;github.com&#x2F;cross-rs&#x2F;cross&#x2F;releases&#x2F;download&#x2F;v0.2.4&#x2F;cross-x86_64-unknown-linux-gnu.tar.gz | tar -xz -C &#x2F;usr&#x2F;local&#x2F;cargo&#x2F;bin&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# (Optional) Pre-install rust targets&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# This significantly reduces build time, at the cost of an increased image size&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;RUN&lt;&#x2F;span&gt;&lt;span&gt; rustup target add \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        aarch64-unknown-linux-gnu \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        aarch64-unknown-linux-musl \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        x86_64-pc-windows-gnu \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        x86_64-unknown-linux-gnu \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        x86_64-unknown-linux-musl \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &amp;amp;&amp;amp; rustup component add --target aarch64-unknown-linux-gnu rust-src \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &amp;amp;&amp;amp; rustup component add --target aarch64-unknown-linux-musl rust-src \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &amp;amp;&amp;amp; rustup component add --target x86_64-pc-windows-gnu rust-src \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &amp;amp;&amp;amp; rustup component add --target x86_64-unknown-linux-gnu rust-src \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &amp;amp;&amp;amp; rustup component add --target x86_64-unknown-linux-musl rust-src&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Don&#x27;t forget to push it to a registry, so it can be used by Drone later.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;the-drone-build-pipeline&quot;&gt;The Drone build pipeline&lt;&#x2F;h2&gt;
&lt;p&gt;The build pipeline is where the real magic happens. I will use a
&lt;code&gt;.drone.yml&lt;&#x2F;code&gt; file here. In production I use a &lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https:&#x2F;&#x2F;jsonnet.org&quot;&gt;Jsonnet&lt;&#x2F;a&gt; file to generate
this. You can find that &lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https:&#x2F;&#x2F;code.kiers.eu&#x2F;newsletter-to-web&#x2F;newsletter-to-web&#x2F;src&#x2F;tag&#x2F;v0.2.3&#x2F;.drone.jsonnet&quot;&gt;in the newsletter-to-web repository&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;The pipeline is long, so it can be found at the
&lt;a href=&quot;https:&#x2F;&#x2F;jacobkiers.net&#x2F;post&#x2F;rust-cross-compilation-on-drone&#x2F;#full-build-pipeline&quot;&gt;end of this post&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;docker-in-docker-service&quot;&gt;Docker in Docker service&lt;&#x2F;h3&gt;
&lt;p&gt;Before starting the builds, a running Docker agent is required. This is
handled by starting Docker in Docker as a service, and then waiting until
it is ready by a separate build step. All the cross compilation build steps
then wait for that to happen.&lt;&#x2F;p&gt;
&lt;p&gt;First, a shared volume is created for the Docker socket. That way, the agent
and all build steps can find each other.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;yaml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# Shared volume for the Docker in Docker service and build steps.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# Without this, cross won&amp;#39;t be able to find a running Docker agent.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;volumes&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #22863A;&quot;&gt; name&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; dockersock&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  temp&lt;&#x2F;span&gt;&lt;span&gt;: {}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Then, the Docker in Docker service is defined. It uses the volume as
described. It will pull the Docker in Docker image and run it.&lt;&#x2F;p&gt;
&lt;p&gt;This requires &lt;code&gt;privileged&lt;&#x2F;code&gt; mode, because otherwise pulling images and
creating volumes fails.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;yaml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;services&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #22863A;&quot;&gt; image&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; docker:dind&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  name&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; docker&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  privileged&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; true&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;   # Docker in Docker requires this, sadly.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  pull&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; true&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  volumes&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #22863A;&quot;&gt; name&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; dockersock&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;    path&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; &#x2F;var&#x2F;run&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Then, in the &lt;code&gt;steps&lt;&#x2F;code&gt;, the &lt;code&gt;Wait for Docker&lt;&#x2F;code&gt; step is defined. This will
try to run &lt;code&gt;docker image ls&lt;&#x2F;code&gt; until it succeeds. Once it is, it will print
information about the current Docker installation, and pull an image.
This is essentially a healt check.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;yaml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# Ensure Docker agent has started before continuing.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;steps&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #22863A;&quot;&gt; name&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; Wait for Docker&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  image&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; rust-dind-cross:1.66-full&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  pull&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; true&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  commands&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; mkdir artifacts&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; while ! docker image ls; do sleep 1; done&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; docker info&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; docker pull hello-world:latest&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  volumes&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #22863A;&quot;&gt; name&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; dockersock&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;    path&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; &#x2F;var&#x2F;run&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;All other build steps can then wait until it is ready by depending on this
build step. Like so:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;yaml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;steps&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #22863A;&quot;&gt; name&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; Build for amd64&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  depends_on&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; Wait for Docker&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h3 id=&quot;cross-compilation&quot;&gt;Cross compilation&lt;&#x2F;h3&gt;
&lt;p&gt;A cross compilation step is defined like so (under the &lt;code&gt;steps&lt;&#x2F;code&gt; definition):&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;yaml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;name&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; Build for windows-amd64&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;image&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; rust-dind-cross:1.66-full&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;pull&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; true&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;environment&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  CROSS_REMOTE&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; true&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;depends_on&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; Wait for Docker&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;volumes&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #22863A;&quot;&gt; name&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; dockersock&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  path&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; &#x2F;var&#x2F;run&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;commands&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; cross build --release --target x86_64-pc-windows-gnu&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; cp target&#x2F;x86_64-pc-windows-gnu&#x2F;release&#x2F;drone-test.exe artifacts&#x2F;drone-test-windows-amd64.exe&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; rm -rf target&#x2F;x86_64-pc-windows-gnu&#x2F;release&#x2F;*&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;It starts with defining the docker image to use &lt;code&gt;image: rust-dind-cross:1.66-full&lt;&#x2F;code&gt;. This is the images that was created before the section
&lt;a href=&quot;https:&#x2F;&#x2F;jacobkiers.net&#x2F;post&#x2F;rust-cross-compilation-on-drone&#x2F;#the-docker-image&quot;&gt;&lt;em&gt;The Docker image&lt;&#x2F;em&gt;&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Then, it sets the environment:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;yaml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;environment&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  CROSS_REMOTE&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; true&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This tells cross that it is running in a remote docker, so it will copy
everything necessary for the build into the build image that it creates.&lt;&#x2F;p&gt;
&lt;p&gt;As described before, it depends on the Docker in Docker agent, so that
is defined as well, together with the shared volume:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;yaml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;depends_on&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; Wait for Docker&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;volumes&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #22863A;&quot;&gt; name&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; dockersock&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  path&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; &#x2F;var&#x2F;run&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Finally, the commands to run are listed:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;yaml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;commands&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; cross build --release --target x86_64-pc-windows-gnu&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; cp target&#x2F;x86_64-pc-windows-gnu&#x2F;release&#x2F;drone-test.exe artifacts&#x2F;drone-test-windows-amd64.exe&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; rm -rf target&#x2F;x86_64-pc-windows-gnu&#x2F;release&#x2F;*&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This will tell cross to build a release binary for the given target.
In order to do so, it will start its own Docker container, copies all
the source files into it, and then runs a normal Rust build.&lt;&#x2F;p&gt;
&lt;p&gt;The container started by cross is the container that contains the
required build toolchain for the specific target, as described in
the &lt;a href=&quot;https:&#x2F;&#x2F;jacobkiers.net&#x2F;post&#x2F;rust-cross-compilation-on-drone&#x2F;#definitions&quot;&gt;definitions&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;When it is finished compiling, the binary is copied to an &lt;code&gt;artifacts&#x2F;&lt;&#x2F;code&gt;
directory for later reference. It will now also gain a postfix with the
target it was build for. Otherwise, all binaries would be named the same
and would be overwritten.&lt;&#x2F;p&gt;
&lt;p&gt;Finally, the release directory is cleaned up in order to save disk space.&lt;&#x2F;p&gt;
&lt;p&gt;When all cross compilations have succeeded, the built artifacts are shown.
This step is not necessary, and you could do anything else with it.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;yaml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;name&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; Show built artifacts&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;image&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; rust-dind-cross:1.66-full&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;commands&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; ls -lah artifacts&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;depends_on&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; Build for arm64-gnu&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; Build for arm64-musl&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; Build for windows-amd64&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; Build for amd64-gnu&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; Build for amd64-musl&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The interesting part here, is that it depends on all the cross compilation
build steps.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;when-tagged-create-a-gitea-release&quot;&gt;When tagged, create a Gitea release&lt;&#x2F;h3&gt;
&lt;p&gt;When the pipeline is run for a tag, than as the very last step a new draft
release is created in Gitea. This can then be edited and published.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;yaml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;name&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; Create release on gitea&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;image&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; plugins&#x2F;gitea-release&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;settings&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  api_key&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;    from_secret&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; gitea_token&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  base_url&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; https:&#x2F;&#x2F;gitea.example.com&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  checksum&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; sha256&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  files&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; artifacts&#x2F;*&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  draft&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; true&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;depends_on&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; Build for arm64-gnu&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; Build for arm64-musl&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; Build for windows-amd64&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; Build for amd64-gnu&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; Build for amd64-musl&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;when&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  event&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; tag&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This steps depends on a successful build of all cross compilation steps.
It uses a drone plugin called &lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https:&#x2F;&#x2F;plugins.drone.io&#x2F;plugins&#x2F;gitea-release&quot;&gt;Gitea Release&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;It will:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Upload all files in the &lt;code&gt;artifacts&#x2F;&lt;&#x2F;code&gt; directory as assets.&lt;&#x2F;li&gt;
&lt;li&gt;Calculate the SHA256 sum of all artifacts, and add that as
a &lt;code&gt;sha256sum.txt&lt;&#x2F;code&gt; file to the assets.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;This only happens when the pipeline runs for a git tag, which is described
like this:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;yaml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;when&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  event&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; tag&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h3 id=&quot;full-build-pipeline&quot;&gt;Full build pipeline&lt;&#x2F;h3&gt;
&lt;details&gt;
&lt;summary&gt;Contents of .drone.yml&lt;&#x2F;summary&gt;
&lt;span&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;yaml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;kind&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; pipeline&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;type&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; docker&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;name&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; &amp;#39;Rust cross compilation&amp;#39;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;platform&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  arch&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; amd64&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;image_pull_secrets&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; docker_private_repo&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# Shared volume for the Docker in Docker service and build steps.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# Without this, cross won&amp;#39;t be able to find a running Docker agent.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;volumes&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #22863A;&quot;&gt; name&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; dockersock&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  temp&lt;&#x2F;span&gt;&lt;span&gt;: {}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;services&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #22863A;&quot;&gt; image&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; docker:dind&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  name&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; docker&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  privileged&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; true&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;   # Docker in Docker requires this, sadly.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  pull&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; true&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  volumes&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #22863A;&quot;&gt; name&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; dockersock&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;    path&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; &#x2F;var&#x2F;run&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# Ensure Docker agent has started before continuing.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;steps&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #22863A;&quot;&gt; name&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; Wait for Docker&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  image&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; rust-dind-cross:1.66-full&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  pull&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; true&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  commands&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; mkdir artifacts&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; while ! docker image ls; do sleep 1; done&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; docker info&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; docker pull hello-world:latest&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  volumes&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #22863A;&quot;&gt; name&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; dockersock&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;    path&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; &#x2F;var&#x2F;run&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# Build for aarch64-unknown-linux-gnu (arm64)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #22863A;&quot;&gt; name&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; Build for arm64-gnu&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  image&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; rust-dind-cross:1.66-full&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  pull&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; true&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  environment&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;    CROSS_REMOTE&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; true&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  commands&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; cross build --release --target aarch64-unknown-linux-gnu&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; cp target&#x2F;aarch64-unknown-linux-gnu&#x2F;release&#x2F;drone-test artifacts&#x2F;drone-test-arm64-gnu&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; rm -rf target&#x2F;aarch64-unknown-linux-gnu&#x2F;release&#x2F;*&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  depends_on&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; Wait for Docker&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  volumes&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #22863A;&quot;&gt; name&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; dockersock&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;    path&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; &#x2F;var&#x2F;run&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# Build for aarch64-unknown-linux-musl (arm64 with Alpine linux)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #22863A;&quot;&gt; name&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; Build for arm64-musl&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  image&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; rust-dind-cross:1.66-full&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  pull&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; true&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  environment&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;    CROSS_REMOTE&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; true&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  commands&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; cross build --release --target aarch64-unknown-linux-musl&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; cp target&#x2F;aarch64-unknown-linux-musl&#x2F;release&#x2F;drone-test artifacts&#x2F;drone-test-arm64-musl&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; rm -rf target&#x2F;aarch64-unknown-linux-musl&#x2F;release&#x2F;*&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  depends_on&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; Wait for Docker&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  volumes&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #22863A;&quot;&gt; name&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; dockersock&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;    path&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; &#x2F;var&#x2F;run&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# Build for x86_64-pc-windows-gnu&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# This generates a binary that can run on Windows.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;-name&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; Build for windows-amd64&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  image&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; rust-dind-cross:1.66-full&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  pull&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; true&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  environment&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;    CROSS_REMOTE&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; true&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  commands&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; cross build --release --target x86_64-pc-windows-gnu&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; cp target&#x2F;x86_64-pc-windows-gnu&#x2F;release&#x2F;drone-test.exe artifacts&#x2F;drone-test-windows-amd64.exe&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; rm -rf target&#x2F;x86_64-pc-windows-gnu&#x2F;release&#x2F;*&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  depends_on&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; Wait for Docker&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  volumes&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #22863A;&quot;&gt; name&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; dockersock&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;    path&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; &#x2F;var&#x2F;run&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# Build for x86_64-unknown-linux-gnu (amd64)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #22863A;&quot;&gt; name&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; Build for amd64-gnu&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  image&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; rust-dind-cross:1.66-full&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  pull&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; true&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  environment&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;    CROSS_REMOTE&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; true&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  commands&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; cross build --release --target x86_64-unknown-linux-gnu&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; cp target&#x2F;x86_64-unknown-linux-gnu&#x2F;release&#x2F;drone-test artifacts&#x2F;drone-test-amd64-gnu&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; rm -rf target&#x2F;x86_64-unknown-linux-gnu&#x2F;release&#x2F;*&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  depends_on&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; Wait for Docker&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  volumes&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #22863A;&quot;&gt; name&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; dockersock&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;    path&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; &#x2F;var&#x2F;run&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# Build for x86_64-unknown-linux-musl (amd64 with Alpine linux)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #22863A;&quot;&gt; name&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; Build for amd64-musl&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  image&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; rust-dind-cross:1.66-full&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  pull&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; true&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  environment&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;    CROSS_REMOTE&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; true&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  commands&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; cross build --release --target x86_64-unknown-linux-musl&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; cp target&#x2F;x86_64-unknown-linux-musl&#x2F;release&#x2F;drone-test artifacts&#x2F;drone-test-amd64-musl&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; rm -rf target&#x2F;x86_64-unknown-linux-musl&#x2F;release&#x2F;*&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  depends_on&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; Wait for Docker&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  volumes&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #22863A;&quot;&gt; name&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; dockersock&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;    path&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; &#x2F;var&#x2F;run&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# Show all built artifacts&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #22863A;&quot;&gt; name&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; Show built artifacts&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  image&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; rust-dind-cross:1.66-full&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  commands&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; ls -lah artifacts&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  depends_on&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; Build for arm64-gnu&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; Build for arm64-musl&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; Build for windows-amd64&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; Build for amd64-gnu&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; Build for amd64-musl&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# When a tag is created, this step gets added.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #22863A;&quot;&gt; name&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; Create release on gitea&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  image&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; plugins&#x2F;gitea-release&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  settings&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;    api_key&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;      from_secret&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; gitea_token&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;    base_url&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; https:&#x2F;&#x2F;code.kiers.eu&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;    checksum&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; sha256&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;    files&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; artifacts&#x2F;*&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  depends_on&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; Show built artifacts&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;  when&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;    event&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; tag&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;&#x2F;span&gt;
&lt;&#x2F;details&gt;
&lt;h2 id=&quot;fin&quot;&gt;Fin&lt;&#x2F;h2&gt;
&lt;p&gt;You&#x27;ve made it! This is the end of the pipeline!&lt;&#x2F;p&gt;
&lt;p&gt;If this was useful for you, or you have comments, feel free to &lt;a href=&quot;mailto:hi@jacobkiers.net&quot;&gt;send me an email&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Automatically scaling Drone CI with Gitea</title>
        <published>2022-12-17T00:00:00+00:00</published>
        <updated>2022-12-30T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Jacob Kiers
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://jacobkiers.net/post/setting-up-drone-ci-with-autoscaler/"/>
        <id>https://jacobkiers.net/post/setting-up-drone-ci-with-autoscaler/</id>
        
        <content type="html" xml:base="https://jacobkiers.net/post/setting-up-drone-ci-with-autoscaler/">&lt;h2 id=&quot;why&quot;&gt;Why&lt;&#x2F;h2&gt;
&lt;p&gt;For a while now, I have been working on a personal project called
&lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https:&#x2F;&#x2F;code.kiers.eu&#x2F;newsletter-to-web&#x2F;newsletter-to-web&quot;&gt;newsletter2web&lt;&#x2F;a&gt;, which I run on a Raspberry PI. As the title
already indicates, it is written in &lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https:&#x2F;&#x2F;www.rust-lang.org&#x2F;&quot;&gt;Rust&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Since compiling the project takes a while, especially on a Raspberry PI,
I decided to investigate how to make it build automatically.&lt;&#x2F;p&gt;
&lt;p&gt;That sounds like a job for continuous integration solution. But these tend
to use quite a bit of resources, even when not in use. That is wasteful
and I didn&#x27;t want that.&lt;&#x2F;p&gt;
&lt;p&gt;So put together, I got the following requirements:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;A continuous integration solution, that&lt;&#x2F;li&gt;
&lt;li&gt;Would use little resources when not in use,&lt;&#x2F;li&gt;
&lt;li&gt;Integrates with Gitea, and&lt;&#x2F;li&gt;
&lt;li&gt;Is capable of cross-compiling Rust&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;After a bit of digging, I found &lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https:&#x2F;&#x2F;www.drone.io&#x2F;&quot;&gt;Drone CI&lt;&#x2F;a&gt; to be a nice fit: it is fairly
lightweight, and easy to get running. Making it work well enough to cross
compile Rust took a while though.&lt;&#x2F;p&gt;
&lt;p&gt;This post describes the Drone and Gitea parts, &lt;a href=&quot;https:&#x2F;&#x2F;jacobkiers.net&#x2F;post&#x2F;rust-cross-compilation-on-drone&#x2F;&quot;&gt;the Rust part is in a followup post&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;the-components&quot;&gt;The components&lt;&#x2F;h2&gt;
&lt;p&gt;In order to build everything, we need a few moving parts:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https:&#x2F;&#x2F;gitea.io&#x2F;en-us&#x2F;&quot;&gt;Gitea&lt;&#x2F;a&gt; for hosting the code.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https:&#x2F;&#x2F;www.drone.io&#x2F;&quot;&gt;Drone CI&lt;&#x2F;a&gt; for running the builds.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https:&#x2F;&#x2F;autoscale.drone.io&#x2F;&quot;&gt;Drone autoscaler&lt;&#x2F;a&gt; to ensure it only uses resources when necessary.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;cross-rs&#x2F;cross&quot;&gt;&lt;code&gt;cross&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;: a cross compilation solution for Rust.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;setting-up-drone-with-gitea&quot;&gt;Setting up Drone with Gitea&lt;&#x2F;h2&gt;
&lt;p&gt;Setting up Drone is not that hard, and the &lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https:&#x2F;&#x2F;docs.drone.io&#x2F;server&#x2F;provider&#x2F;gitea&#x2F;&quot;&gt;installation instructions&lt;&#x2F;a&gt; are clear.&lt;&#x2F;p&gt;
&lt;p&gt;Then, run it with docker using the &lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https:&#x2F;&#x2F;hub.docker.com&#x2F;r&#x2F;drone&#x2F;drone&quot;&gt;drone&#x2F;drone:2&lt;&#x2F;a&gt; image, and ensure that
all these environment variables are passed through. Take care that the Drone
API is reachable from Gitea as well.&lt;&#x2F;p&gt;
&lt;p&gt;For me, the configuration came down to this:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# Drone host configuration&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;DRONE_SERVER_HOST&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;drone-ci.kiers.eu&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;DRONE_LOGS_DEBUG&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;true&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;DRONE_LOGS_PRETTY&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;true&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# RPC secret for build agents&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;DRONE_RPC_SECRET&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;redacted&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# DB configuration&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;DRONE_DATABASE_DATASOURCE&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;postgres:&#x2F;&#x2F;drone:drone-password@db:5432&#x2F;drone-db&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;DRONE_DATABASE_SECRET&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;redacted&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# Gitea integration&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;DRONE_GITEA_SERVER&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;https:&#x2F;&#x2F;code.kiers.eu&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;DRONE_GITEA_CLIENT_ID&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;redacted&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;DRONE_GITEA_CLIENT_SECRET&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;redacted&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# Enable initial admin user&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# This needs to be the same username as in Gitea&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;DRONE_USER_CREATE&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;username:my-username,admin:true&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# Enable Jsonnet support&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;DRONE_JSONNET_ENABLED&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;true&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h2 id=&quot;setting-up-drone-autoscaler&quot;&gt;Setting up Drone autoscaler&lt;&#x2F;h2&gt;
&lt;p&gt;During my research, I tried multiple approaches: first I used a simple Docker
runner on a static build server. But I wasn&#x27;t happy to incur the costs of
something that is only used sporadically. Then I tried multiple different
solutions, such as the VM runner, the (deprecated) Digitalocean runner and
the &lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https:&#x2F;&#x2F;autoscale.drone.io&#x2F;&quot;&gt;autoscaler&lt;&#x2F;a&gt;. In the end, the last one was what I settled on.&lt;&#x2F;p&gt;
&lt;p&gt;It works by polling the Drone server api to see whether there are builds
pending and whether there is build capacity available. Then, it will scale
up or down the numer of servers that are required to handle these builds.
Crucially for me, it is possible to set minimum number of build servers to
zero, to ensure that they will all be destroyed when there is no need for
them anymore.&lt;&#x2F;p&gt;
&lt;p&gt;This does mean that one needs a place to host these build servers. Luckily,
the autoscaler has support for a number of different cloud providers. I
ended up using Digital Ocean.&lt;&#x2F;p&gt;
&lt;p&gt;First, a &lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https:&#x2F;&#x2F;docs.drone.io&#x2F;manage&#x2F;user&#x2F;machine&#x2F;&quot;&gt;machine user&lt;&#x2F;a&gt; with administrative credentials needs to be created.
This needs to be done with the Drone CLI. Check the documentation for how
to do so.&lt;&#x2F;p&gt;
&lt;p&gt;The setup is fairly easy again, and also builds on environment variables:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;#!&#x2F;usr&#x2F;bin&#x2F;bash&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# Communication with the drone server&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;DRONE_RPC_HOST&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;drone-ci.kiers.eu&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;DRONE_RPC_PROTO&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;https&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;DRONE_AUTOSCALER_USER_TOKEN&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;redacted&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt; # Machine user token&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# RPC Secret for the build agents that are installed on the build servers&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;DRONE_RPC_SECRET&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;redacted&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# Digitalocean settings&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# Get these from the DO Droplet Launch UI, in the URL bar&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;DRONE_DIGITALOCEAN_SIZE&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;&amp;#39;s-4vcpu-8gb-amd&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt; &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;DRONE_DIGITALOCEAN_IMAGE&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;&amp;#39;docker-20-04&amp;#39;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;DRONE_DIGITALOCEAN_REGION&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;&amp;#39;fra1&amp;#39;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;DRONE_DIGITALOCEAN_TOKEN&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;redacted&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;DRONE_DIGITALOCEAN_SSHKEY&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;redacted&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt; # To log in to the build servers&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# How often should the autoscaler check whether to scale up or down&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# This then also is the time that it takes before a build server will&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# be started when none is available, and therefore has a big influence&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# on total build time. &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;DRONE_INTERVAL&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;30s&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# Pool settings&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;DRONE_POOL_MIN&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt; # This allows the pool to turn off everything&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;DRONE_POOL_MAX&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;4&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt; # The maximum number of build servers to launch&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;docker&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; run&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; -d \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;  --volume=$(pwd)&#x2F;data:&#x2F;data \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;  --env=DRONE_SERVER_PROTO=${&lt;&#x2F;span&gt;&lt;span&gt;DRONE_RPC_PROTO&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;} \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;  --env=DRONE_SERVER_HOST=${&lt;&#x2F;span&gt;&lt;span&gt;DRONE_RPC_HOST&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;} \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;  --env=DRONE_SERVER_TOKEN=${&lt;&#x2F;span&gt;&lt;span&gt;DRONE_AUTOSCALER_USER_TOKEN&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;} \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;  --env=DRONE_AGENT_TOKEN=${&lt;&#x2F;span&gt;&lt;span&gt;DRONE_RPC_SECRET&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;} \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;  --env=DRONE_POOL_MIN=${&lt;&#x2F;span&gt;&lt;span&gt;DRONE_POOL_MIN&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;} \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;  --env=DRONE_POOL_MAX=${&lt;&#x2F;span&gt;&lt;span&gt;DRONE_POOL_MAX&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;} \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;  --env=DRONE_DIGITALOCEAN_REGION=${&lt;&#x2F;span&gt;&lt;span&gt;DRONE_DIGITALOCEAN_REGION&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;} \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;  --env=DRONE_DIGITALOCEAN_TOKEN=${&lt;&#x2F;span&gt;&lt;span&gt;DRONE_DIGITALOCEAN_TOKEN&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;} \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;  --env=DRONE_DIGITALOCEAN_SIZE=${&lt;&#x2F;span&gt;&lt;span&gt;DRONE_DIGITALOCEAN_SIZE&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;} \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;  --env=DRONE_DIGITALOCEAN_SSHKEY=${&lt;&#x2F;span&gt;&lt;span&gt;DRONE_DIGITALOCEAN_SSHKEY&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;} \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;  --env=DRONE_DIGITALOCEAN_IMAGE=${&lt;&#x2F;span&gt;&lt;span&gt;DRONE_DIGITALOCEAN_IMAGE&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;} \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;  --env=DRONE_LOGS_TRACE=true \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;  --env=DRONE_LOGS_DEBUG=true \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;  --env=DRONE_LOGS_PRETTY=true \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;  --env=DRONE_LOGS_COLOR=true \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;  --env=DRONE_INTERVAL=${&lt;&#x2F;span&gt;&lt;span&gt;DRONE_INTERVAL&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;} \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;  --publish=8080:8080 \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;  --restart&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; always&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;  --name&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; drone-autoscaler&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;  drone&#x2F;autoscaler:latest&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;And that&#x27;s it. Now it will scale up and down the build servers, as new
builds come in.&lt;&#x2F;p&gt;
&lt;p&gt;Also, take a look at all the &lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https:&#x2F;&#x2F;autoscale.drone.io&#x2F;reference&#x2F;&quot;&gt;possible settings&lt;&#x2F;a&gt; for the autoscaler, as
there may be some options that are beneficial as well.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>HTML over DNS: Serving Blog Content Over DNS</title>
        <published>2021-08-17T00:00:00+00:00</published>
        <updated>2021-08-17T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Jacob Kiers
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://jacobkiers.net/post/html-over-dns/"/>
        <id>https://jacobkiers.net/post/html-over-dns/</id>
        
        <content type="html" xml:base="https://jacobkiers.net/post/html-over-dns/">&lt;h2 id=&quot;what-s-up&quot;&gt;What&#x27;s up?&lt;&#x2F;h2&gt;
&lt;p&gt;The past few days, I did an experiment to &lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https:&#x2F;&#x2F;jacobkiers.net&#x2F;hod&#x2F;&quot;&gt;serve blog content over DNS (see here)&lt;&#x2F;a&gt;.
That page contains mostly the same content ast this post, but it is served in a
completely different manner.&lt;&#x2F;p&gt;
&lt;p&gt;This works because of &lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;DNS_over_HTTPS&quot;&gt;DNS over HTTPS&lt;&#x2F;a&gt; for which there is an &lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https:&#x2F;&#x2F;developers.cloudflare.com&#x2F;1.1.1.1&#x2F;dns-over-https&#x2F;json-format&quot;&gt;API from
Cloudflare&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Comments at &lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=28218406&quot;&gt;Hacker News&lt;&#x2F;a&gt;, apparently.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;how-it-works&quot;&gt;How it works&lt;&#x2F;h2&gt;
&lt;p&gt;The DNS over HTTP API from Cloudflare is used to load the contents of that
page, essentially like this:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;fetch&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;&amp;quot;https:&#x2F;&#x2F;cloudflare-dns.com&#x2F;dns-query?ct=application&#x2F;dns-json&amp;amp;type=TXT&amp;amp;name=post.hod.experiments.jacobkiers.net&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The content itself is served over DNS, using CoreDNS, with these contents:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;hod.experiments.jacobkiers.net.:53 {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    log&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    auto hod.experiments.jacobkiers.net. {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    directory &#x2F;etc&#x2F;coredns&#x2F;zones&#x2F;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        reload 10s&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This feeds into a zone file, which looks like this:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$TTL 5m    ; Default TTL&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;@    IN    SOA    experiments.jacobkiers.net.    postmaster.jacobkiers.net. (&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    2021081612    ; serial&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    1h        ; slave refresh interval&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    15m        ; slave retry interval&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    1w        ; slave copy expire time&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    1h        ; NXDOMAIN cache time&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    )&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$ORIGIN hod.experiments.jacobkiers.net.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;; domain name servers&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;@    IN    NS  experiments.jacobkiers.net.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;;; START BLOG RECORDS&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;; posts-2021-08-17-serving-blog-content-over-dns-md&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;posts-2021-08-17-serving-blog-content-over-dns-md    60    IN    TXT    &amp;quot;t=text&#x2F;markdown;c=3;h=2fd63f0f408ad1336283999d0487ced9;m=eyJ0aXRsZSI6IlNlcnZpbmcgYmxvZyBjb250ZW50IG92ZXIgRE5TIiwiZGF0ZSI6IjIwMjEtMDgtMTUiLCJhdXRob3IiOiJKYWNvYiBLaWVycyJ9&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;0.2fd63f0f408ad1336283999d0487ced9    60    IN    TXT    &amp;quot;WW91IG1pZ2h0IG5vdCBiZSBhYmxlIHRvIHNlZSBpdCBpbW1lZGlhdGVseSwgYnV0IHRoZSBjb250ZW50IG9mIHRoaXMgcGFnZSBpcyB2ZXJ2ZWQgb3ZlciBETlMuCgpUaGlzIHdvcmtzIGJlY2F1c2Ugb2YgdGhlIG5ldyBETlMtb3Zlci1IVFRQIHN1cHBvcnQsIHdoaWNoLCBhdCBsZWFzdCBhdCBDbG91ZGZsYXJlLCBhbHNvIGhhcy&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;1.2fd63f0f408ad1336283999d0487ced9    60    IN    TXT    &amp;quot;BhbiBBUEkuCgpUaGF0IEFQSSBpcyB1c2VkIHRvIGxvYWQgdGhlIGNvbnRlbnRzIG9mIHRoaXMgcGFnZSwgZXNzZW50aWFsbHkgbGlrZSB0aGlzOgoKYGBganMKZmV0Y2goImh0dHBzOi8vY2xvdWRmbGFyZS1kbnMuY29tL2Rucy1xdWVyeT9jdD1hcHBsaWNhdGlvbi9kbnMtanNvbiZ0eXBlPVRYVCZuYW1lPXBvc3QuaG9kLmV4cGVy&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;2.2fd63f0f408ad1336283999d0487ced9    60    IN    TXT    &amp;quot;aW1lbnRzLmphY29ia2llcnMubmV0Iik7CmBgYAoKUGxlYXNlIHNlZSB0aGUgW3NvdXJjZSBjb2RlXSBmb3IgdGhlIGRldGFpbHMgb2YgaG93IGl0IHdvcmtzLgoKW3NvdXJjZSBjb2RlXTogaHR0cHM6Ly9naXRodWIuY29tL2phY29ia2llcnMvaHRtbC1vdmVyLWRucwo=&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;These records are base64 encoded content, so when concatenated and decoded,
they give the content of the posts.&lt;&#x2F;p&gt;
&lt;p&gt;Please see the &lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;jacobkiers&#x2F;html-over-dns&quot;&gt;source code&lt;&#x2F;a&gt; for the details.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;faq&quot;&gt;FAQ&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;why-though&quot;&gt;Why, though?&lt;&#x2F;h3&gt;
&lt;p&gt;In short: just because I could. It was one of those ideas I was wondering
idly about, and I decided to just try it.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;has-it-any-practical-use&quot;&gt;Has it any practical use?&lt;&#x2F;h3&gt;
&lt;p&gt;It is not intended to have any. Since DNS records are fairly small, serving
images or something would quickly start consuming 100s of requests per second.
I wouldn&#x27;t want to do that to Cloudflare 😄&lt;&#x2F;p&gt;
&lt;p&gt;It would be an interesting experiment to see how feasible that is though.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>A (mostly) IPv6-only home network</title>
        <published>2021-04-23T00:00:00+00:00</published>
        <updated>2021-04-23T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Jacob Kiers
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://jacobkiers.net/post/ipv6-only-home-network/"/>
        <id>https://jacobkiers.net/post/ipv6-only-home-network/</id>
        
        <content type="html" xml:base="https://jacobkiers.net/post/ipv6-only-home-network/">&lt;p&gt;For a while now I wanted to make my home network IPv6-only. That is a challenge, because my ISP does not enable IPv6. Therefore, I used a &lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https:&#x2F;&#x2F;www.tunnelbroker.net&quot;&gt;Hurricane Electric tunnel&lt;&#x2F;a&gt; to give my home network IPv6. Here I will describe my setup.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;requirements&quot;&gt;Requirements&lt;&#x2F;h2&gt;
&lt;p&gt;To ensure that my whole network is able to use IPv6 I deployed a &lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https:&#x2F;&#x2F;www.raspberrypi.org&#x2F;products&#x2F;raspberry-pi-4-model-b&#x2F;&quot;&gt;Raspberry Pi 4&lt;&#x2F;a&gt; as a router. It is plugged into the router that I received from the ISP.&lt;&#x2F;p&gt;
&lt;p&gt;This router needs access to both IPv4 and IPv6, and is the only machine that requires this&lt;sup class=&quot;footnote-reference&quot; id=&quot;fr-win-1&quot;&gt;&lt;a href=&quot;#fn-win&quot;&gt;1&lt;&#x2F;a&gt;&lt;&#x2F;sup&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Also, of course, this requires a DNS zone from the provider. In my case, I received a &#x2F;48 from Hurricane Electric. Here, we will call it &lt;code&gt;2001:db8:fa12::&#x2F;48&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;setup&quot;&gt;Setup&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;packages&quot;&gt;Packages&lt;&#x2F;h3&gt;
&lt;p&gt;To install the required packages, run:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;apt&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; install ufw dnsmasq dnsutils tayga&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;!--
### Firewall

First of all, I use `ufw` to set up the firewall.

On Raspbian the `ufw` service is run by default as `Before=network.target`. This starts `ufw` too early though, so it does not load the rules correctly. To fix that, run `systemctl edit ufw.service` and add the following contents to the file:

```systemd
[Unit]
After=network-pre.target
```

Also, by default ufw enables incoming pings. But with a default-deny output, then outgoing ping is not allowed. So that needs to be fixed too. Add the following lines in `&#x2F;etc&#x2F;ufw&#x2F;before.rules`:

```
# ok icmp codes for OUTPUT
-A ufw-before-output -p icmp --icmp-type echo-reply -j ACCEPT
```

To enable connectivity, I configured ufw as follows:

```bash
# TBD
```

--&gt;
&lt;h3 id=&quot;tunnel-configuration&quot;&gt;Tunnel configuration&lt;&#x2F;h3&gt;
&lt;p&gt;In order to set up the tunnel, the ISP router needs to be configured to consider the Raspberry Pi as a DMZ, so that it will forward all unknown packets to it by default.&lt;&#x2F;p&gt;
&lt;p&gt;After that, the configuration starts with creating a network device in &lt;code&gt;&#x2F;etc&#x2F;systemd&#x2F;network&#x2F;50-he-ipv6.network&lt;&#x2F;code&gt;. This will create the actual tunnel.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;systemd&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;[Match]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;[NetDev]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;Name&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt;he-ipv6&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;Kind&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt;sit&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;MTUBytes&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;1480&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;[Tunnel]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;Local&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt;192.168.0.101 # RPi IPv4&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;Remote&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt;216.66.84.46 # HE Tunnel server&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;TTL&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;255&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;Independent&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;true&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Then, we need to set up IPv6 connectivity on this device, in &lt;code&gt;&#x2F;etc&#x2F;systemd&#x2F;network&#x2F;50-he-ipv6.network&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;systemd&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;[Match]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;Name&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt;he-ipv6&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;[Network]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# HE client address&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;Address&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;2001&lt;&#x2F;span&gt;&lt;span&gt;:db8:1234:fedc::2&#x2F;64&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# HE server address&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;Gateway&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;2001&lt;&#x2F;span&gt;&lt;span&gt;:db8:1234:fedc::1&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# HE DNS resolver&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;DNS&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;2001&lt;&#x2F;span&gt;&lt;span&gt;:470:20::2&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Finally, it is time to set up the &lt;code&gt;eth0&lt;&#x2F;code&gt; interface with IPv6 as well, in &lt;code&gt;&#x2F;etc&#x2F;system&#x2F;network&#x2F;10-eth0.network&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;systemd&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;[Match]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;Name&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt;eth0&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;[Network]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;Address&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt;192.168.0.101&#x2F;24 # My IPv4 address&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;Gateway&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt;192.168.0.1  # Router IPv4 address&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# Global address from HE &#x2F;48&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;Address&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;2001&lt;&#x2F;span&gt;&lt;span&gt;:db8:fa12:100::1&#x2F;56&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;Gateway&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;2001&lt;&#x2F;span&gt;&lt;span&gt;:db8:1234:fedc::1 # Same as in 50-he-ipv6.network&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# HE DNS resolver&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;DNS&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;2001&lt;&#x2F;span&gt;&lt;span&gt;:470:20::2&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Now, bring the links up:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;ip&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; -6&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; link set he-ipv6 up&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;ip&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; -6&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; link set eth0 down&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;ip&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; -6&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; link set eth0 up&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Now there should be IPv6 connectivity. Try it out by pinging an IPv6 service: &lt;code&gt;ping -6 one.one.one.one&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;coredns&quot;&gt;CoreDNS&lt;&#x2F;h3&gt;
&lt;p&gt;&lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https:&#x2F;&#x2F;coredns.io&quot;&gt;CoreDNS&lt;&#x2F;a&gt; is lightweight and versatile DNS server. It is used here to provide  &lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;IPv6_transition_mechanism#DNS64&quot;&gt;DNS64 resolving&lt;&#x2F;a&gt;. This is used in combination with Tayga (see next section) to ensure that the IPv4 world can still be reached.&lt;&#x2F;p&gt;
&lt;p&gt;So download CoreDNS and ensure that it is installed in &lt;code&gt;&#x2F;usr&#x2F;local&#x2F;bin&#x2F;coredns&lt;&#x2F;code&gt;. Then add the unit file &lt;code&gt;&#x2F;etc&#x2F;systemd&#x2F;system&#x2F;coredns.service&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;systemd&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;[Unit]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;Description&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt;CoreDNS DNS server&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;Documentation&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt;https:&#x2F;&#x2F;coredns.io&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;After&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt;network.target&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;[Service]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;LimitNOFILE&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;1048576&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;LimitNPROC&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;512&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;CapabilityBoundingSet&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;CAP_NET_BIND_SERVICE&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;AmbientCapabilities&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;CAP_NET_BIND_SERVICE&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;NoNewPrivileges&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;true&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;DynamicUser&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;yes&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;StateDirectory&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt;coredns&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;ExecStart&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt;&#x2F;usr&#x2F;local&#x2F;bin&#x2F;coredns -conf=&#x2F;etc&#x2F;coredns&#x2F;Corefile&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;ExecReload&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt;&#x2F;bin&#x2F;kill -SIGUSR1 $MAINPID&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;Restart&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;on-failure&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;[Install]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;WantedBy&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt;multi-user.target&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;And add the configuration file at &lt;code&gt;&#x2F;etc&#x2F;coredns&#x2F;Corefile&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;hcl&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;.:&lt;&#x2F;span&gt;&lt;span&gt;53535 {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;    acl&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        allow net &lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;192.168&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;62&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;24&lt;&#x2F;span&gt;&lt;span&gt; fe80&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;::&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;10 2001&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt;db8&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt;fa12&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;::&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;48&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; ::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;128 2001&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;470&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt;1f0a&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;910&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;2&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;64 127.0&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;8&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        block&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    forward &lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; 1.1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;1&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    dns64 fec0&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;64&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;::&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;96&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;    log&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        class error denial&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    cancel 1s&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Explanation of this configuration:&lt;&#x2F;p&gt;
&lt;p&gt;First, and &lt;em&gt;very important&lt;&#x2F;em&gt;, an access control list is configured. The &lt;em&gt;acl&lt;&#x2F;em&gt; block defines which clients may use this DNS server.  This is important because without it, the DNS server is an &lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https:&#x2F;&#x2F;serverfault.com&#x2F;a&#x2F;573471&quot;&gt;open resolver&lt;&#x2F;a&gt;: anyone can use it, and also attack others with it using a &lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Denial-of-service_attack#Amplification&quot;&gt;DNS amplification attack&lt;&#x2F;a&gt;. This configuration is parsed in order. So here it shows that only RFC1918 (local IPv4) addresses and my delegated IPv6 addresses can use this server, all the rest is blocked.&lt;&#x2F;p&gt;
&lt;p&gt;The &lt;code&gt;forward&lt;&#x2F;code&gt; line forwards all queries (&lt;code&gt;.&lt;&#x2F;code&gt;) to the DNS server at &lt;code&gt;1.1.1.1&lt;&#x2F;code&gt;. On the next line, &lt;code&gt;dns64  fec0:64::&#x2F;96&lt;&#x2F;code&gt; does DNS64 translation, and returns IPv6 addresses for IPv4-only services from the &lt;code&gt;fec6:64::&#x2F;96&lt;&#x2F;code&gt; range. See the &lt;em&gt;Tayga&lt;&#x2F;em&gt; section next for an explanation.&lt;&#x2F;p&gt;
&lt;p&gt;Then, we instruct CoreDNS to log error messages and access denied errors. This is very useful for debugging.&lt;&#x2F;p&gt;
&lt;p&gt;Finally, CoreDNS is instructed to fail all DNS requests that take more than one second to resolve.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;tayga&quot;&gt;Tayga&lt;&#x2F;h3&gt;
&lt;p&gt;&lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;http:&#x2F;&#x2F;www.litech.org&#x2F;tayga&#x2F;&quot;&gt;Tayga&lt;&#x2F;a&gt; is a &lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;NAT64&quot;&gt;NAT64&lt;&#x2F;a&gt; service. That means that it provides connectivity to IPv4 addresses through IPv6. It does so by routing IPv6 addresses in a specific &lt;code&gt;&#x2F;96&lt;&#x2F;code&gt; range to the IPv4 internet.&lt;&#x2F;p&gt;
&lt;p&gt;A &lt;code&gt;&#x2F;96&lt;&#x2F;code&gt; range is used, because the full IPv4 address range fits in that. IPv6 has 128 bits of address space, and IPv4 has 32 bits of address space. Therefore, all of IPv4 fits in a &lt;code&gt;128 - 32 = 96&lt;&#x2F;code&gt; bit range, hence the &lt;code&gt;&#x2F;96&lt;&#x2F;code&gt; address range for NAT64.&lt;&#x2F;p&gt;
&lt;p&gt;Combined with CoreDNS which does the translation of IPv4 addresses into IPv6 addresses, this provides a solution to connect to IPv4 addresses from an IPv6-only network. Of course, the gateway, where Tayga is installed, must have access to both networks in order for this to work.&lt;&#x2F;p&gt;
&lt;p&gt;To set this up, configure tayga in &lt;code&gt;&#x2F;etc&#x2F;tayga.conf&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;hcl&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# Route packets through the na64 deice&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;tun&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;-&lt;&#x2F;span&gt;&lt;span&gt;device nat64&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# Translate packets in the fec0:64::&#x2F;96 address range.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# Use the first address in that range for myself.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;prefix fec0&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;64&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;::&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;96&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;ipv6&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;-&lt;&#x2F;span&gt;&lt;span&gt;addr fec0&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;64&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;1&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# This address pool is used as source addresses for IPv4&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# traffic. Make sure it does not collide with an actual&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# network.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# Again, use the first address for myself.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;dynamic&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;-&lt;&#x2F;span&gt;&lt;span&gt;pool &lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;192.168&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;254&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;24&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;ipv4&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;-&lt;&#x2F;span&gt;&lt;span&gt;addr &lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;192.168&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;254&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;1&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# Keep some translation state in this directory&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;-&lt;&#x2F;span&gt;&lt;span&gt;dir &lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span&gt;var&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span&gt;spool&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span&gt;tayga&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Also ensure that a tunnel is created in &lt;code&gt;&#x2F;etc&#x2F;systemd&#x2F;network&#x2F;90-nat66.netdev&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;systemd&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;[NetDev]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;Name&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt;nat64&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #22863A;&quot;&gt;Kind&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt;tap&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;And start tayga with &lt;code&gt;systemctl enable --now tayga.service&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;dnsmasq&quot;&gt;dnsmasq&lt;&#x2F;h3&gt;
&lt;p&gt;With these changes, the router now has IPv6 connectivity and is ready to serve it to the rest of the network as well. So now it is time to make sure that IPv6 is enabled on the rest of the network as well.&lt;&#x2F;p&gt;
&lt;p&gt;For that, I use &lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https:&#x2F;&#x2F;thekelleys.org.uk&#x2F;dnsmasq&#x2F;doc.html&quot;&gt;dnsmasq&lt;&#x2F;a&gt;, a great and versatile tool for setting up DHCP and DNS in a home network.&lt;&#x2F;p&gt;
&lt;p&gt;So in order for it to give out IPv6 addresses, I configured it as follows:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;ini&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;interface&lt;&#x2F;span&gt;&lt;span&gt;=eth0&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;port&lt;&#x2F;span&gt;&lt;span&gt;=53535&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# Don&amp;#39;t check &#x2F;etc&#x2F;hosts, &#x2F;etc&#x2F;resolv.conf, etc&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;no-hosts&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;no-resolv&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;no-poll&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# Never forward addresses in non-routed address spage&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;bogus-priv&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# Forward queries to the local CoreDNS.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;server&lt;&#x2F;span&gt;&lt;span&gt;=::1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;#53&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;strict-order&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# My local-only domain is .int. Serve that also from here.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;local&lt;&#x2F;span&gt;&lt;span&gt;=&#x2F;int&#x2F;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;domain&lt;&#x2F;span&gt;&lt;span&gt;=int&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;address&lt;&#x2F;span&gt;&lt;span&gt;=&#x2F;router.int&#x2F;2001:db8:fa12:::1&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# Automatically add local domain to simple host names&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;expand-hosts&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# IPv6 DHCP&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;dhcp-range&lt;&#x2F;span&gt;&lt;span&gt;=::1681:ff,::1681:ffff,constructor:eth0,ra-names,12h&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;dhcp-option&lt;&#x2F;span&gt;&lt;span&gt;=option6:dns-server,[2001:db8:fa12:::1]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;dhcp-option&lt;&#x2F;span&gt;&lt;span&gt;=option6:information-refresh-time,1h&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;dhcp-option&lt;&#x2F;span&gt;&lt;span&gt;=option6:domain-search,int&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# Set the DHCP server to authoritative mode to &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# speed up lease acquisition.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;dhcp-authoritative&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;enable-ra&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;quiet-ra&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h2 id=&quot;current-issues&quot;&gt;Current issues&lt;&#x2F;h2&gt;
&lt;p&gt;In the end, I could not use IPv6 only the Windows machine I got from work, because the Windows Subsystem for Linux v2 does not route IPv6 connectivity to the VMs.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;credits&quot;&gt;Credits&lt;&#x2F;h2&gt;
&lt;p&gt;A lot of the credits for this setup go to &lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https:&#x2F;&#x2F;www.hillbrecht.de&#x2F;&quot;&gt;Dirk Hillbrecht&lt;&#x2F;a&gt;&#x27;s amazing &lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https:&#x2F;&#x2F;ipv6-first-guide.hillbrecht.de&#x2F;&quot;&gt;IPv6-first network guide&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;section class=&quot;footnotes&quot;&gt;
&lt;ol class=&quot;footnotes-list&quot;&gt;
&lt;li id=&quot;fn-win&quot;&gt;
&lt;p&gt;In the end, that didn&#x27;t fully work out, due to the Windows issue described at the end of this post. &lt;a href=&quot;#fr-win-1&quot;&gt;↩&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;&#x2F;section&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Mockery: returning values and throwing exceptions</title>
        <published>2015-01-24T00:00:00+00:00</published>
        <updated>2015-01-24T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Jacob Kiers
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://jacobkiers.net/post/multiple-return-values-with-mockery/"/>
        <id>https://jacobkiers.net/post/multiple-return-values-with-mockery/</id>
        
        <content type="html" xml:base="https://jacobkiers.net/post/multiple-return-values-with-mockery/">&lt;p&gt;Last week, I had to write a piece of code that contains retry logic. Naturally, I want to test it. That proved trickier than expected.&lt;&#x2F;p&gt;
&lt;p&gt;The application code looks like this:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;php&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;&amp;lt;?&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;php&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;class&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt; Sender&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;{&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;    protected&lt;&#x2F;span&gt;&lt;span&gt; $connection;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;    public function&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt; send&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        $success&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; false&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        $i&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;        do&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            $i&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;++&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;            try&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                $success&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; $this&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;-&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;doSend&lt;&#x2F;span&gt;&lt;span&gt;($i);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            }&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; catch&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;SenderException&lt;&#x2F;span&gt;&lt;span&gt; $e) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                $success&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; false&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; while&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;!&lt;&#x2F;span&gt;&lt;span&gt;$success&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; &amp;amp;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt; $i&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; &amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; 3&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span&gt; $success;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;    protected function&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt; doSend&lt;&#x2F;span&gt;&lt;span&gt;($data)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;        &#x2F;&#x2F; Can throw SenderException&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        $response&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; $this&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;-&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt;connection&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;-&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;send&lt;&#x2F;span&gt;&lt;span&gt;($data);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;&amp;#39;OK&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; ===&lt;&#x2F;span&gt;&lt;span&gt; $response) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;            return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; true&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; false&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;I specifically want to test the retry logic, so I have to mock the ::doSend() method. Then I can simulate the different outcomes (returning true or false, or throwing a SenderException).&lt;&#x2F;p&gt;
&lt;p&gt;I use &lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;mockery&#x2F;mockery&quot;&gt;Mockery&lt;&#x2F;a&gt; to do the real work. It is a great library. If you don&#x27;t know it yet, please check it out. I will wait right here...&lt;&#x2F;p&gt;
&lt;p&gt;Now, since ::doSend() is a protected method, Mockery must be instructed to allow that.&lt;&#x2F;p&gt;
&lt;p&gt;So after the first try, I ended up with:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;php&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;&amp;lt;?&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;php&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;public function&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt; testItWillRetrySending&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;{&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    $sender&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; M&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;mock&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;&amp;#39;Sender&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    $sender&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;-&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;shouldAllowMockingProtectedMethods&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    $sender&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;-&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;shouldReceive&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;&amp;#39;doSend&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;        -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;andReturn&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;false&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; new&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; Exception&lt;&#x2F;span&gt;&lt;span&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;To my surprise, this did not work. Instead of throwing the exception, Mockery returns it. So my next try was this:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;php&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;&amp;lt;?&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;php&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$sender&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;-&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;shouldReceive&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;&amp;#39;doSend&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;    -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;andReturn&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;false&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;    -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;andThrow&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; Exception&lt;&#x2F;span&gt;&lt;span&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Another surprise: with this code, Mockery will always throw the exception, and ignore the first return value (false). After some debugging, I found out that Mockery just overwrites the return values in this case.&lt;&#x2F;p&gt;
&lt;p&gt;Fortunately, there is another way to return multiple return values: the ::andReturnUsing() method. It gives full control over the return values.&lt;&#x2F;p&gt;
&lt;p&gt;So I ended up with this testing code:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;php&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;&amp;lt;?&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;php&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$return_value_generator&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; = function&lt;&#x2F;span&gt;&lt;span&gt; () {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;    static&lt;&#x2F;span&gt;&lt;span&gt; $counter&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    $counter&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;++&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;    switch&lt;&#x2F;span&gt;&lt;span&gt; ($counter) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;        case&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; false&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;        case&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; 2&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; throw new&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; SenderException&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;        case&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; 3&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; true&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;        default&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; throw new&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; Exception&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;&amp;quot;Should never reach this.&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;); &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;};&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$sender&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; M&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;mock&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;&amp;#39;Sender&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$sender&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;-&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;shouldAllowMockingProtectedMethods&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;    -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;shouldReceive&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;&amp;#39;doSend&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;    -&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;andReturnUsing&lt;&#x2F;span&gt;&lt;span&gt;($return_value_generator);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This works perfectly. It feels a bit like a hack though. So if you know a better way or have any other remarks, please let me know.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Configure nginx with SSL and SPDY on Ubuntu 12.04 Precise</title>
        <published>2014-01-17T00:00:00+00:00</published>
        <updated>2014-01-17T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Jacob Kiers
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://jacobkiers.net/post/configure-nginx-with-ssl-and-spdy-on-ubuntu-12-04-precise/"/>
        <id>https://jacobkiers.net/post/configure-nginx-with-ssl-and-spdy-on-ubuntu-12-04-precise/</id>
        
        <content type="html" xml:base="https://jacobkiers.net/post/configure-nginx-with-ssl-and-spdy-on-ubuntu-12-04-precise/">&lt;p&gt;As an experiment, last night I decided to configure nginx with SSL and SPDY.
Finding information on how to get it working with Ubuntu 12.04 wasn&#x27;t that
easy, so I decided to write the process down.&lt;&#x2F;p&gt;
&lt;p&gt;I will assume here that you already have a certificate. If you don’t, you can
get them from many vendors.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;add-the-repository&quot;&gt;Add the repository&lt;&#x2F;h2&gt;
&lt;p&gt;First, you need to have version 1.4 or higher of nginx. You can get that on Ubuntu 12.04 by installing the nginx&#x2F;stable ppa:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;sudo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; add-apt-repository ppa:nginx&#x2F;stable`&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h2 id=&quot;install-nginx&quot;&gt;Install nginx&lt;&#x2F;h2&gt;
&lt;p&gt;Then, you will have to update apt and install nginx. If you already have
installed nginx, you will have to do a dist-upgrade.&lt;&#x2F;p&gt;
&lt;p&gt;So, when nginx is not yet installed:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;sudo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; apt-get update&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;sudo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; apt-get install nginx&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;If nginx is already installed:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;sudo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; apt-get update&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;sudo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; apt-get dist-upgrade&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h2 id=&quot;install-certificates&quot;&gt;Install certificates&lt;&#x2F;h2&gt;
&lt;p&gt;Now that the right version of nginx is installed, you first need to install
your certificate.&lt;&#x2F;p&gt;
&lt;p&gt;Put your private certificate into &lt;code&gt;&#x2F;etc&#x2F;ssl&#x2F;private&#x2F;&lt;&#x2F;code&gt;, and chmod it to &lt;code&gt;0400&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;sudo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; chmod&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; 400&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; &#x2F;etc&#x2F;ssl&#x2F;private&#x2F;jacobkiers.net.key`&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Then, put your public certificate into &lt;code&gt;&#x2F;etc&#x2F;ssl&#x2F;certs&#x2F;&lt;&#x2F;code&gt;. In many cases, you
have to establish a certificate chain. That means that your web server sends
multiple certificates to the browser. Please check the documentation of the
certificate authority where you got your certificate.&lt;&#x2F;p&gt;
&lt;p&gt;You can do that as follows:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;sudo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; sh&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; -c&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; &amp;#39;cat &#x2F;path&#x2F;to&#x2F;ca&#x2F;certificate &amp;gt;&amp;gt; &#x2F;etc&#x2F;ssl&#x2F;certs&#x2F;your-certificate&amp;#39;`&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h2 id=&quot;update-site-configuration&quot;&gt;Update site configuration&lt;&#x2F;h2&gt;
&lt;p&gt;Good, we’re almost done. The last thing you need to do is updating the nginx
site configuration. You just have to tell nginx that you want SSL and SPDY,
and where it can find the certificates.&lt;&#x2F;p&gt;
&lt;p&gt;Put this in the server block of your domain:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;nginx&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;server&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;    listen&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; 443&lt;&#x2F;span&gt;&lt;span&gt; ssl spdy;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;    ssl_certificate&lt;&#x2F;span&gt;&lt;span&gt; &#x2F;etc&#x2F;ssl&#x2F;certs&#x2F;jacobkiers.net.crt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;    ssl_certificate_key&lt;&#x2F;span&gt;&lt;span&gt; &#x2F;etc&#x2F;ssl&#x2F;private&#x2F;jacobkiers.net.key;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;    server_name&lt;&#x2F;span&gt;&lt;span&gt; jacobkiers.net;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;    ####&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;    # All&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;    # other&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;    # configuration&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;    ####&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;And that’s it!&lt;&#x2F;p&gt;
&lt;p&gt;Let’s check the configuration:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;    sudo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; &#x2F;etc&#x2F;init.d&#x2F;nginx configtest&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;and when nginx indicates that everything is OK, restart it:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;    sudo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; service nginx stop&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;    sudo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; service nginx start&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Your website should now be serving SSL over SPDY!&lt;&#x2F;p&gt;
&lt;h2 id=&quot;bonus-serving-only-ssl&quot;&gt;Bonus: Serving Only SSL&lt;&#x2F;h2&gt;
&lt;p&gt;As I want to only serve my domain over SSL and only use the top-level domain, I had to add a little more configuration: two extra server blocks.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;nginx&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;server&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;    # Rewrite non-https domains.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;    listen&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; 80&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;    server_name&lt;&#x2F;span&gt;&lt;span&gt; jacobkiers.net www.jacobkiers.net;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;    return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; 301&lt;&#x2F;span&gt;&lt;span&gt; https:&#x2F;&#x2F;jacobkiers.net$request_uri;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;server&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;    # Rewrite https:&#x2F;&#x2F;www.jacobkiers.net&#x2F;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;    # to      https:&#x2F;&#x2F;jacobkiers.net&#x2F;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;    listen&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; 443&lt;&#x2F;span&gt;&lt;span&gt; ssl spdy;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;    ssl_certificate&lt;&#x2F;span&gt;&lt;span&gt; &#x2F;etc&#x2F;ssl&#x2F;certs&#x2F;jacobkiers.net.crt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;    ssl_certificate_key&lt;&#x2F;span&gt;&lt;span&gt; &#x2F;etc&#x2F;ssl&#x2F;private&#x2F;jacobkiers.net.key;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;    server_name&lt;&#x2F;span&gt;&lt;span&gt; www.jacobkiers.net;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;    return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; 301&lt;&#x2F;span&gt;&lt;span&gt; https:&#x2F;&#x2F;jacobkiers.net$request_uri;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;And that is all.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>How to Dynamically Instantiate Classes in PHP</title>
        <published>2009-03-10T00:00:00+00:00</published>
        <updated>2009-03-10T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Jacob Kiers
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://jacobkiers.net/post/how-to-dynamically-instantiate-classes-in-php/"/>
        <id>https://jacobkiers.net/post/how-to-dynamically-instantiate-classes-in-php/</id>
        
        <content type="html" xml:base="https://jacobkiers.net/post/how-to-dynamically-instantiate-classes-in-php/">&lt;p&gt;For Annabel (the name of the product that I currently work on), I need to
be able to dynamically instantiate classes, based on options in a
configuration file (Zend_Config_Ini). However, some of these classes have
constructors (some with required options), others don’t even have a constructor.
I first tried to instantiate them with call_user_func_array, like this:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;php&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;&amp;lt;?&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;php&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$datatype_options&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; explode&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;&amp;#39;,&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;, $global_config&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;-&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt;customer&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;-&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt;data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;-&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt;field&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;-&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt;$key&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;-&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt;type);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$datatype_class&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; array_shift&lt;&#x2F;span&gt;&lt;span&gt;($datatype_options);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$class&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; call_user_func_array&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;array&lt;&#x2F;span&gt;&lt;span&gt;($datatype_class,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; &amp;#39;__construct&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;), $datatype_options);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This didn’t work, since some classes don’t have a constructor, and they were
not static. Then, I came up with another solution: use a generic static
method getInstance() to do it, like this:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;php&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;&amp;lt;?&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;php&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;class&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt; Test&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;    public static function&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt; getInstance&lt;&#x2F;span&gt;&lt;span&gt;($classname)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;        return new&lt;&#x2F;span&gt;&lt;span&gt; $classname();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$datatype_options&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; explode&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;&amp;#39;,&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;, $global_config&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;-&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt;customer&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;-&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt;data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;-&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt;field&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;-&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt;$key&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;-&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt;type);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$datatype_class&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; array_shift&lt;&#x2F;span&gt;&lt;span&gt;($datatype_options);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$class&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; call_user_func_array&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;array&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;&amp;#39;Test&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; &amp;#39;getInstance&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;), $datatype_options);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This worked, as long as I don’t need any constructor parameters. But for
some classes, I &lt;em&gt;do&lt;&#x2F;em&gt; need them. So I thought some more, and came to the
conclusion that I would need the Reflection API to do what I want. Finally,
I implemented the following solution, which works perfectly. It could
probably be cleaned up a little, but it basically works:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;php&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;&amp;lt;?&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;php&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;class&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt; Annabel_Data&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;{&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;    &#x2F;**&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;     * Creates instances of classes in the Annabel_Data package.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;     * &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;     * To use this, provide arguments in the order you would need them&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;     * in the instantiated classes, with as the first argument the name&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;     * of the class to instantiate.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;     * &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;     * &lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;@param&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt; $arguments An array with arguments&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;     * &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;     * &lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;@return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; Annabel_Data_Abstract&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;     *&#x2F;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;    public static function&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt; factory&lt;&#x2F;span&gt;&lt;span&gt;($arguments)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        $class_name&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; array_shift&lt;&#x2F;span&gt;&lt;span&gt;($arguments);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        $class_name&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; &amp;#39;Annabel_Data_&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; ucfirst&lt;&#x2F;span&gt;&lt;span&gt;($class_name);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;        Zend_Loader&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;loadClass&lt;&#x2F;span&gt;&lt;span&gt;($class_name);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        $reflector&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; = new&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; ReflectionClass&lt;&#x2F;span&gt;&lt;span&gt;($class_name);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span&gt; ($reflector&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;-&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;isInstantiable&lt;&#x2F;span&gt;&lt;span&gt;()) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            $constructor&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; $reflector&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;-&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;getConstructor&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;            if&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;is_null&lt;&#x2F;span&gt;&lt;span&gt;($constructor)) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;                return&lt;&#x2F;span&gt;&lt;span&gt; $reflector&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;-&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;newInstance&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            $params&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; $constructor&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;-&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;getNumberOfParameters&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            $req_params&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; $constructor&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;-&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;getNumberOfRequiredParameters&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;            if&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;count&lt;&#x2F;span&gt;&lt;span&gt;($arguments)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; &amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; $req_params) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;                throw new&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; Annabel_Data_Exception&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;&amp;#39;Please provide &amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; .&lt;&#x2F;span&gt;&lt;span&gt; $req_params&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; &amp;#39; parameters to instantiate class &amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; .&lt;&#x2F;span&gt;&lt;span&gt; $class_name);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;            if&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; &amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; $params) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;                return&lt;&#x2F;span&gt;&lt;span&gt; $reflector&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;-&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;newInstanceArgs&lt;&#x2F;span&gt;&lt;span&gt;($arguments);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            }&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; else&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;                return&lt;&#x2F;span&gt;&lt;span&gt; $reflector&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;-&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;newInstance&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; else&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;            throw new&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; Annabel_Data_Exception&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;&amp;quot;Could not instantiate a class of type &amp;#39;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; .&lt;&#x2F;span&gt;&lt;span&gt; $class_name&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; &amp;quot;&amp;#39;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$datatype_options&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; explode&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;&amp;#39;,&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;, $global_config&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;-&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt;customer&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;-&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt;data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;-&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt;field&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;-&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt;$key&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;-&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt;type);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$class&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; Annabel_Data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;factory&lt;&#x2F;span&gt;&lt;span&gt;($datatype_options);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This works perfectly, for each case I need it (and tested it 😉). I should
add some more exception checking and things like that, but those are minor
details. Overall, I&#x27;m pretty happy with the solution!&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>40x Speedup With iconv And PHP</title>
        <published>2009-03-03T00:00:00+00:00</published>
        <updated>2009-03-03T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Jacob Kiers
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://jacobkiers.net/post/40x-speedup-with-iconv-and-php/"/>
        <id>https://jacobkiers.net/post/40x-speedup-with-iconv-and-php/</id>
        
        <content type="html" xml:base="https://jacobkiers.net/post/40x-speedup-with-iconv-and-php/">&lt;p&gt;For our product Annabel, we have to clean up the data our customers provide
us. Because this is a fully automated process, we are unable to give direct
feedback and have them fix their input. Therefore, I need a means to clean
the data on our end, so we can process it.&lt;&#x2F;p&gt;
&lt;p&gt;Since we don’t need to support any unicode stuff, we can stick with just
plain ASCII. That’s a very safe approach, which will reduce the chances of
failure greatly. To convert the UTF-8 (Unicode) input into ASCII data, we use
the &lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https:&#x2F;&#x2F;sourceware.org&#x2F;glibc&#x2F;manual&#x2F;2.43&#x2F;html_node&#x2F;Generic-Charset-Conversion.html&quot;&gt;iconv method from the GNU C Library&lt;&#x2F;a&gt; in combination with PHP.&lt;&#x2F;p&gt;
&lt;p&gt;The default iconv implementation in PHP has two caveats: it stops when a
string cannot be converted, and it prints a question mark when it does not
have an equivalent (or transliterated) character in the destination character
set. To overcome this problem, I used to just convert every single character
with the &lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https:&#x2F;&#x2F;www.php.net&#x2F;manual&#x2F;en&#x2F;function.iconv.php&quot;&gt;PHP iconv function&lt;&#x2F;a&gt;, which gave me a throughput of about 250KiB&#x2F;sec,
using the following code:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;php&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;&amp;lt;?&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;php&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;&#x2F;**&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;*  Replaces special characters with their ASCII equivalents.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;*&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;* This function uses iconv to replace each seperate character with its&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;* ASCII equivalent, using the ASCII&#x2F;&#x2F;TRANSLIT option. However, this makes&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;* the function very slow: max throughput is about 150KiB&#x2F;sec.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;*&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;* &lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;@param string&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt; $line&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;* &lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;@return string&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;*&#x2F;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;protected function&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt; _convertSpecialChars&lt;&#x2F;span&gt;&lt;span&gt;($line) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;empty&lt;&#x2F;span&gt;&lt;span&gt;($line))&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; &amp;#39;&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    $new_line&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; &amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;    &#x2F;*&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;    * This potentially could be a very long string, so don&amp;#39;t split the line&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;    * in separate tokens, for that would tak way too much memory.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;    *&#x2F;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    $line_length&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; strlen&lt;&#x2F;span&gt;&lt;span&gt;($line);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;    for&lt;&#x2F;span&gt;&lt;span&gt; ($x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;; $x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; &amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; $line_length; $x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;++&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        $old_char&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; substr&lt;&#x2F;span&gt;&lt;span&gt;($line, $x,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;        &#x2F;*&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;        * Use iconv to replace the other special characters.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;        * If iconv can&amp;#39;t convert it (and so returns &amp;#39;?&amp;#39;), just skip&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;        * the character, for it probably is something malicious and&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;        * there&amp;#39;s probably no need to keep it anyway.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;        *&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;        * Beware of the edge case if the original character is a&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;         * question mark itself.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;        *&#x2F;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        $char&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; iconv&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;&amp;#39;UTF-8&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; &amp;#39;ASCII&#x2F;&#x2F;TRANSLIT&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;, $old_char);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span&gt; ( (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;&amp;#39;?&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; !=&lt;&#x2F;span&gt;&lt;span&gt; $char)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; &amp;amp;&amp;amp;&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;&amp;#39;?&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; !=&lt;&#x2F;span&gt;&lt;span&gt; $old_char) ) $new_line&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; .=&lt;&#x2F;span&gt;&lt;span&gt; $char;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;    return&lt;&#x2F;span&gt;&lt;span&gt; $new_line;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;However, I was not satisfied with this, so I looked up the man page of the iconv
version of GNU C Library. I supposed PHP was internally using this one, so that
seemed a natural action. In that man-page I found the IGNORE option, which just
skips any character which cannot be converted or transliterated. That was exactly
what I wanted. So I tried that with the PHP function as well, and it worked.&lt;&#x2F;p&gt;
&lt;p&gt;Instead of converting every single character, I can now convert a whole file at
once, which gave me a throughput of 11MiB&#x2F;sec. The caveat, of course, is that I
have to use the GNU C Library iconv, with a version the same (or greater than)
the current one, to avoid compatibility problems. However, that’s a price I’m
surely willing to pay. The new code is like this:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;php&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;&amp;lt;?&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;php&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;&#x2F;**&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;*  Replaces special characters with their ASCII equivalents.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;*&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;* This function uses iconv to replace each seperate character with its&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;* ASCII equivalent, using the ASCII&#x2F;&#x2F;TRANSLIT,IGNORE option. Throughput&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;* is measured at about 11MiB&#x2F;sec.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;*&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;* WARNING: Using the extra IGNORE option only works with a recent&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;* GNU libc iconv, so be very picky about which iconv to use! This is an&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;* undocumented feature, which is not supported by default and is not&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;* listed in the PHP manual!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;*&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;* &lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;@param string&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt; $line&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;* &lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;@return string&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;*&#x2F;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;protected function&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt; _convertSpecialChars&lt;&#x2F;span&gt;&lt;span&gt;($line)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;{&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;    &#x2F;*&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;    * Check whether we have the right version of iconv&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;    *&#x2F;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span&gt; ( (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;&amp;#39;glibc&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; !==&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; ICONV_IMPL&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; ||&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;true&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; version_compare&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;ICONV_VERSION&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; &amp;#39;2.8.90&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; &amp;#39;&amp;gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;)) ) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;        throw new&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; Exception&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;&amp;#39;Please use the glibc iconv, version 2.8.90 or higher&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;    &#x2F;*&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;    * Use iconv for speed and glory&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;    * We use the ASCII&#x2F;&#x2F;TRANSLIT,IGNORE option to replace the string&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;    * with its ASCII transliterated equivalent. If there&amp;#39;s no ASCII&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;    * equivalent, the IGNORE option makes sure the character is just&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;    * thrown away, which is exactly what I want.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;    *&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;    *&#x2F;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    $new_line&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; iconv&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;&amp;#39;UTF-8&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; &amp;#39;ASCII&#x2F;&#x2F;TRANSLIT,IGNORE&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;, $line);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;    return&lt;&#x2F;span&gt;&lt;span&gt; $new_line;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;I guess I don’t need to give further comments on this code example 😉&lt;&#x2F;p&gt;
&lt;p&gt;If you have questions or comments, you could &lt;a href=&quot;mailto:hi@jacobkiers.net?subject=Comment%20on%20article%20about%20iconv&quot;&gt;drop me a line&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>The law of God: is it still relevant?</title>
        <published>2009-03-02T00:00:00+00:00</published>
        <updated>2009-03-02T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Jacob Kiers
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://jacobkiers.net/post/gods-law-is-it-still-relevant/"/>
        <id>https://jacobkiers.net/post/gods-law-is-it-still-relevant/</id>
        
        <content type="html" xml:base="https://jacobkiers.net/post/gods-law-is-it-still-relevant/">&lt;p&gt;Sometimes one might think: are the laws which God had given to Israel still
relevant to us, or shall we just skip them? Did the Lord Jesus not fulfill
the complete law when He died on that tree at Golgotha? Does that not mean
that we do not need to keep these laws throughout our lives?&lt;&#x2F;p&gt;
&lt;p&gt;Let us open up our Bibles and see what God has to say about this.&lt;&#x2F;p&gt;
&lt;p&gt;The law is not passed away, for the first chapter of the Sermon of The Mount
is wholly written about the way we should practise the law in our daily lives.
Paul, the Apostle, also says he delights in the law of God. (Romans 7:22).
That does not mean the law can save us (Romans 3:20), for salvation is only
by faith in Jesus Christ (Romans 8:1-4). I personally think we can say that
law in the New Testament is less like ‘rules’ and more like ‘doing the will
of God’. His will is found in the Bible, which is revealed by Himself
(2 Timothy 3:16).&lt;&#x2F;p&gt;
&lt;p&gt;The foundation of His will is love for God and for our neighbours (Matthew
22:40). Flowing from that love for God and because we are grateful for what
He did for us, we (should?) want to do his will. Then it is easy to
understand why Paul says he delights in the law.&lt;&#x2F;p&gt;
&lt;p&gt;Summarizing: the law has been fulfilled by Jesus, and we don’t need to
fulfill it anymore to get saved. However, because He did this much for
us, we want to do what He wants us to do.&lt;&#x2F;p&gt;
&lt;p&gt;Which brings us back at the law. In this case, the law of Christ,
consisting of love for God and all other people. So you might wonder how to
show your love towards God. You can do so by doing His will, which is given
in Scripture, especially in the first five books (Genesis till Deuteronomy).&lt;&#x2F;p&gt;
&lt;p&gt;Many of these books are filled with guidance and precepts which we are still
able to apply. Many parts of it seem to be quite obsolete for everyday life,
though, for example the sacrificial laws. I think it is good to apply many of
these laws in a practical way, useful in our everyday life. Joshua 1:7-8 also
seems to point that out.&lt;&#x2F;p&gt;
&lt;p&gt;Many times I’m struggling with applying these laws as a general rule in my
life. It certainly isn’t easy to take 3000+ years-old laws and give them an
application in the 21st century. However, it really is worth a try.&lt;&#x2F;p&gt;
&lt;p&gt;Are you in?&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a href=&quot;mailto:hi@jacobkiers.net?subject=Comment%20on%20article%20about%20the%20law%20of%20God&quot;&gt;Feel free to comment&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>PHP daemon with fork howto part 3: Creating a Hello World daemon with fork</title>
        <published>2008-12-24T00:00:00+00:00</published>
        <updated>2008-12-24T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Jacob Kiers
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://jacobkiers.net/post/php-daemon-with-fork-howto-part-3-creating-a-hello-world-daemon-with-fork/"/>
        <id>https://jacobkiers.net/post/php-daemon-with-fork-howto-part-3-creating-a-hello-world-daemon-with-fork/</id>
        
        <content type="html" xml:base="https://jacobkiers.net/post/php-daemon-with-fork-howto-part-3-creating-a-hello-world-daemon-with-fork/">&lt;p&gt;Well, it took some time, but now I’m back again with part 3 of the series
on creating a PHP daemon with fork. In &lt;a href=&quot;https:&#x2F;&#x2F;jacobkiers.net&#x2F;post&#x2F;php-daemon-with-fork-howto-part-1-introduction&#x2F;&quot;&gt;part 1, the introduction&lt;&#x2F;a&gt;
I talked about why I would write this series and gave an outline of it.
In part 2 we talked &lt;a href=&quot;https:&#x2F;&#x2F;jacobkiers.net&#x2F;post&#x2F;php-daemon-with-fork-howto-part-2-about-unix-processes-and-php&#x2F;&quot;&gt;about the way UNIX processes work, what forking is&lt;&#x2F;a&gt;
and so on. In this part, we will see how to &lt;a href=&quot;https:&#x2F;&#x2F;jacobkiers.net&#x2F;post&#x2F;php-daemon-with-fork-howto-part-3-creating-a-hello-world-daemon-with-fork&#x2F;&quot;&gt;create daemon in PHP&lt;&#x2F;a&gt;
which launches processes saying the famous Hello World!&lt;&#x2F;p&gt;
&lt;p&gt;Let’s first create a basic Hello World script. And no, I’m not going to
explain that 😏&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;php&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;&amp;lt;?&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;php&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;echo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; &amp;quot;Hello World&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;\n&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Okay, we’ve covered the basics. Next thing is to create a daemon. This can
be done with &lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https:&#x2F;&#x2F;www.php.net&#x2F;pcntl_fork&quot;&gt;&lt;code&gt;pcntl_fork()&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;php&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #1B1F234D;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;&amp;lt;?&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;php&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #1B1F234D;&quot;&gt; 2&lt;&#x2F;span&gt;&lt;span&gt;$newpid&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; pcntl_fork&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #1B1F234D;&quot;&gt; 3&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #1B1F234D;&quot;&gt; 4&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;if&lt;&#x2F;span&gt;&lt;span&gt; ($newpid&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; === -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #1B1F234D;&quot;&gt; 5&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;    die&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;&amp;quot;Couldn&amp;#39;t fork()!&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #1B1F234D;&quot;&gt; 6&lt;&#x2F;span&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; else if&lt;&#x2F;span&gt;&lt;span&gt; ($newpid) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #1B1F234D;&quot;&gt; 7&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;    &#x2F;&#x2F; I&amp;#39;m the parent, and I&amp;#39;m going to self-destruct&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #1B1F234D;&quot;&gt; 8&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;    exit&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #1B1F234D;&quot;&gt; 9&lt;&#x2F;span&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #1B1F234D;&quot;&gt;10&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #1B1F234D;&quot;&gt;11&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;&#x2F;&#x2F; Become the session leader&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #1B1F234D;&quot;&gt;12&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;posix_setsid&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #1B1F234D;&quot;&gt;13&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;usleep&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;100000&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #1B1F234D;&quot;&gt;14&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #1B1F234D;&quot;&gt;15&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;&#x2F;&#x2F; Fork again, but now as session leader.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #1B1F234D;&quot;&gt;16&lt;&#x2F;span&gt;&lt;span&gt;$newpid&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; pcntl_fork&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #1B1F234D;&quot;&gt;17&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #1B1F234D;&quot;&gt;18&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;if&lt;&#x2F;span&gt;&lt;span&gt; ($newpid&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; === -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #1B1F234D;&quot;&gt;19&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;    die&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;&amp;quot;Couldn&amp;#39;t fork()!&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #1B1F234D;&quot;&gt;20&lt;&#x2F;span&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; else if&lt;&#x2F;span&gt;&lt;span&gt; ($newpid) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #1B1F234D;&quot;&gt;21&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;    &#x2F;&#x2F; I&amp;#39;m the parent, and I&amp;#39;m going to self-destruct&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #1B1F234D;&quot;&gt;22&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;    exit&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #1B1F234D;&quot;&gt;23&lt;&#x2F;span&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #1B1F234D;&quot;&gt;24&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #1B1F234D;&quot;&gt;25&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;echo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; &amp;quot;Master started with pid &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; posix_getpid&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;\n&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #1B1F234D;&quot;&gt;26&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #1B1F234D;&quot;&gt;27&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;for&lt;&#x2F;span&gt;&lt;span&gt;($i&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;; $i&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; &amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; 10&lt;&#x2F;span&gt;&lt;span&gt;; $i&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;++&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #1B1F234D;&quot;&gt;28&lt;&#x2F;span&gt;&lt;span&gt;    $pid&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; pcntl_fork&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #1B1F234D;&quot;&gt;29&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span&gt; $pid) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #1B1F234D;&quot;&gt;30&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;        echo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; &amp;quot;Couldn&amp;#39;t fork!&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;\n&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #1B1F234D;&quot;&gt;31&lt;&#x2F;span&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; elseif&lt;&#x2F;span&gt;&lt;span&gt; ($pid&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; ===&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #1B1F234D;&quot;&gt;32&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;        &#x2F;&#x2F; I&amp;#39;m the child, and I&amp;#39;m going to say hello world!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #1B1F234D;&quot;&gt;33&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;        echo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; &amp;quot;Hello world! from child with pid &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; posix_getpid&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;\n&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #1B1F234D;&quot;&gt;34&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;        exit&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #1B1F234D;&quot;&gt;35&lt;&#x2F;span&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; else&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #1B1F234D;&quot;&gt;36&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;        &#x2F;&#x2F; I&amp;#39;m the parent, do nothing&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #1B1F234D;&quot;&gt;37&lt;&#x2F;span&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #1B1F234D;&quot;&gt;38&lt;&#x2F;span&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #1B1F234D;&quot;&gt;39&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #1B1F234D;&quot;&gt;40&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;exit&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Well, this is all of it. Let’s explain the various parts.&lt;&#x2F;p&gt;
&lt;p&gt;In the first nine lines we fork. The actual forking is done with:&lt;&#x2F;p&gt;
&lt;p&gt;&lt;code&gt;$newpid = pcntl_fork();&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;This function spawns a new process, and then continues both in the parent
and the child process at the first line after the fork (line 4). Usually,
that will be an if-else clause. This if-else clause checks whether the
forking was successful. If it was not, the return value will be &lt;code&gt;-1&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;If it was successful, the parent process kills itself (lines 6-9). Note
that after that there is no check whether the child process is running.
That is not necessary: if the current process is not the parent, and
forking did not fail, then by default it is the child. So the next part of
this script runs as the child process.&lt;&#x2F;p&gt;
&lt;p&gt;After forking, the script detaches from the console, and become the session
leader. This means that a new process group is created, and that all child
processes that might be started from now on will become part of this new
process group, and not of the process group that started the script.&lt;&#x2F;p&gt;
&lt;p&gt;When a process is started on the command line, then the shell is the session
leader of that command. That is not very useful for a deamon, because when the
session leaders stops, then all the child processes will be killed as well.
Therefore, a new process group is created, with the daemon itself as the
session leader.&lt;&#x2F;p&gt;
&lt;p&gt;After that, we sleep for 0.1 seconds. This is all done on lines 12 and 13:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;php&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;posix_setsid&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;usleep&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;100000&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;At this point, the executing script is now the session leader of its own
process group. So it is time to start the real parent process of the daemon.
This is just basic forking again, as you can see in lines 15-23. After that,
the current process id is printed on line 25.&lt;&#x2F;p&gt;
&lt;p&gt;By forking again, the script becomes totally detached from the context from
which it was called, in this case probably the shell. This is a technique
called double-forking, and it is necessary to make a long-running daemon
completely independent.&lt;&#x2F;p&gt;
&lt;p&gt;Next comes the &lt;code&gt;Hello World!&lt;&#x2F;code&gt; part. First a loop is started with 10 iterations.
In that loop, the script is &lt;code&gt;fork()&lt;&#x2F;code&gt;ed again, but now we do nothing in the
parent (it just keeps running). So the else statement for checking the parent
could safely be left out; I kept it here for the sake of clarity.&lt;&#x2F;p&gt;
&lt;p&gt;In the child process the famous &lt;code&gt;Hello World!&lt;&#x2F;code&gt; is printed, along with the
new process id. After printing, we stop the child, for there’s no need to
keep it around any longer. When all child processes are done running, then
parent process (the daemon) also stops. This can all be seen in lines 27-40.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;php&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;&amp;lt;?&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;php&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;for&lt;&#x2F;span&gt;&lt;span&gt;($i&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;; $i&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; &amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; 10&lt;&#x2F;span&gt;&lt;span&gt;; $i&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;++&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    $pid&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; pcntl_fork&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span&gt; $pid) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;        echo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; &amp;quot;Couldn&amp;#39;t fork!&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;\n&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; elseif&lt;&#x2F;span&gt;&lt;span&gt; ($pid&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; ===&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;        &#x2F;&#x2F; I&amp;#39;m the child, and I&amp;#39;m going to say hello world!&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;        echo&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; &amp;quot;Hello world! from child with pid &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt; posix_getpid&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;\n&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;        exit&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt; else&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;        &#x2F;&#x2F; I&amp;#39;m the parent, do nothing&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;exit&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Congratulations! This is all there is to it. At this point you created your first fully functional PHP
daemon 🚀&lt;&#x2F;p&gt;
&lt;p&gt;In the next part, we will add some communication between the parent and the child processes.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Automatically add user to Ubuntu Linux and set password</title>
        <published>2008-12-23T00:00:00+00:00</published>
        <updated>2008-12-23T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Jacob Kiers
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://jacobkiers.net/post/automatically-add-user-to-ubuntu-linux-and-set-password/"/>
        <id>https://jacobkiers.net/post/automatically-add-user-to-ubuntu-linux-and-set-password/</id>
        
        <content type="html" xml:base="https://jacobkiers.net/post/automatically-add-user-to-ubuntu-linux-and-set-password/">&lt;p&gt;I was wondering how to create a user on my system without requiring a
prompt or CLI access. The following script is the result:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;#!&#x2F;bin&#x2F;bash&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;UADD&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;&#x2F;usr&#x2F;sbin&#x2F;useradd&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;OPENSSL&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;&#x2F;usr&#x2F;bin&#x2F;openssl&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;SHELL&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;&#x2F;bin&#x2F;bash&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# Generate 12 characters long password and print it.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;PASS&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;`&lt;&#x2F;span&gt;&lt;span&gt;$OPENSSL&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt; rand -base64 12`&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #005CC5;&quot;&gt;echo&lt;&#x2F;span&gt;&lt;span&gt; $PASS&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# Make the password usable for the useradd utility&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;PASS&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D73A49;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;`&lt;&#x2F;span&gt;&lt;span style=&quot;color: #6F42C1;&quot;&gt;mkpasswd&lt;&#x2F;span&gt;&lt;span&gt; $PASS&lt;&#x2F;span&gt;&lt;span style=&quot;color: #032F62;&quot;&gt;`&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #6A737D;&quot;&gt;# Create the user&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;$UADD -s $SHELL -m &lt;&#x2F;span&gt;&lt;span style=&quot;color: #E36209;&quot;&gt;$1&lt;&#x2F;span&gt;&lt;span&gt; -p $PASS&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;</content>
        
    </entry>
    <entry xml:lang="en">
        <title>PHP daemon with fork howto part 2: About UNIX processes and PHP</title>
        <published>2008-10-17T00:00:00+00:00</published>
        <updated>2008-10-17T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Jacob Kiers
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://jacobkiers.net/post/php-daemon-with-fork-howto-part-2-about-unix-processes-and-php/"/>
        <id>https://jacobkiers.net/post/php-daemon-with-fork-howto-part-2-about-unix-processes-and-php/</id>
        
        <content type="html" xml:base="https://jacobkiers.net/post/php-daemon-with-fork-howto-part-2-about-unix-processes-and-php/">&lt;p&gt;As promised in &lt;a href=&quot;https:&#x2F;&#x2F;jacobkiers.net&#x2F;post&#x2F;php-daemon-with-fork-howto-part-1-introduction&#x2F;&quot;&gt;part 1, the introduction&lt;&#x2F;a&gt; of this series on PHP fork,
now we will talk about the way processes work in UNIX and Linux, and how we
can use these from PHP.&lt;&#x2F;p&gt;
&lt;p&gt;Much of the information in this article is based on the IBM Developerworks
article on &lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20080529064539&#x2F;http:&#x2F;&#x2F;www.ibm.com&#x2F;developerworks&#x2F;aix&#x2F;library&#x2F;au-speakingunix8&#x2F;&quot;&gt;UNIX Processes&lt;&#x2F;a&gt;. I added this part for
your convenience and for completeness, but I won’t go into detail about
UNIX processes. If you want to know more, read the aforementioned article.&lt;&#x2F;p&gt;
&lt;p&gt;Any program in UNIX is a process, except for the kernel. A program is in
fact a bunch of data, with some instructions to do something with that data.
A process tells when and how these instructions should be executed.&lt;&#x2F;p&gt;
&lt;p&gt;Each process has its own and unique (at that point in time) process id. It
is impossible for two processes to have the same process id at the same time.
It is, however, possible that some process id is assigned to another process.
This only happens when the counter for process id’s runs out of space, and is
reset, so that it starts with process id 2 (for process id 1 one never ever
stops as long as the system is running).&lt;&#x2F;p&gt;
&lt;p&gt;So, when a new process is launched, that process will get its own, unique
process id, which is an identifier in the whole system. Furthermore, the
process id is used to identify all resources in use by that process. A
resource can be defined as anything which is needed to run, such as memory,
disk space, a network socket, open files such as logfiles or input&#x2F;output
files and anything else you can think of.&lt;&#x2F;p&gt;
&lt;p&gt;This also means that each PHP program or script you are running, has its own
process id, with the possible exception of the PHP scripts running inside a
webserver process, like Apache httpd sometimes does.&lt;&#x2F;p&gt;
&lt;p&gt;Spawning a new process is done by calling the &lt;code&gt;fork(1)&lt;&#x2F;code&gt; system call, which
returns one of three values:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;In the calling process, when successful, the process id of the child.&lt;&#x2F;li&gt;
&lt;li&gt;In the calling process, &lt;code&gt;-1&lt;&#x2F;code&gt; when something went wrong.&lt;&#x2F;li&gt;
&lt;li&gt;In the child process: always &lt;code&gt;0&lt;&#x2F;code&gt;.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Using this knowledge, we can check whether we are in the parent or in the
child process, and act appropriately.&lt;&#x2F;p&gt;
&lt;p&gt;More on that in the &lt;a href=&quot;https:&#x2F;&#x2F;jacobkiers.net&#x2F;post&#x2F;php-daemon-with-fork-howto-part-3-creating-a-hello-world-daemon-with-fork&#x2F;&quot;&gt;next part&lt;&#x2F;a&gt; of this series. There we will create a &lt;a href=&quot;https:&#x2F;&#x2F;jacobkiers.net&#x2F;post&#x2F;php-daemon-with-fork-howto-part-3-creating-a-hello-world-daemon-with-fork&#x2F;&quot;&gt;PHP
daemon&lt;&#x2F;a&gt;, which will start processes for the sole purpose of saying Hello
World multiple times.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>PHP daemon with fork howto part 1: Introduction</title>
        <published>2008-10-16T00:00:00+00:00</published>
        <updated>2008-10-16T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Jacob Kiers
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://jacobkiers.net/post/php-daemon-with-fork-howto-part-1-introduction/"/>
        <id>https://jacobkiers.net/post/php-daemon-with-fork-howto-part-1-introduction/</id>
        
        <content type="html" xml:base="https://jacobkiers.net/post/php-daemon-with-fork-howto-part-1-introduction/">&lt;p&gt;In the past weeks, I have been writing a daemon in PHP for my work at Alphacomm.
It now is quite finished, and I decided to share this knowledge with you in a tutorial.&lt;&#x2F;p&gt;
&lt;p&gt;Another reason for writing this tutorial, is the lack of information
available at the web on this subject. Generally, it’s very scattered
and not really accessible. Also, most information I found about it,
talked about a specific solution, rather than taking a more general
approach. So, I decided to write a howto in a series of articles on
PHP &lt;code&gt;fork()&lt;&#x2F;code&gt;-ing and daemons. I expect to add another part each week.&lt;&#x2F;p&gt;
&lt;p&gt;In this series, I will cover the following subjects:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;jacobkiers.net&#x2F;post&#x2F;php-daemon-with-fork-howto-part-1-introduction&#x2F;&quot;&gt;Part 1: An introduction to this series, links to all parts&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;jacobkiers.net&#x2F;post&#x2F;php-daemon-with-fork-howto-part-2-about-unix-processes-and-php&#x2F;&quot;&gt;Part 2: About UNIX processes and PHP&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;jacobkiers.net&#x2F;post&#x2F;php-daemon-with-fork-howto-part-3-creating-a-hello-world-daemon-with-fork&#x2F;&quot;&gt;Part 3: Creating a Hello World daemon with fork()&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Part 4: Adding IPC (Inter Process Communication) with PHP sockets&lt;&#x2F;li&gt;
&lt;li&gt;Part 5: Talking to the outer world (also with PHP sockets)&lt;&#x2F;li&gt;
&lt;li&gt;Part 6: Errata and other stuff (not sure of this one)&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;Disclaimer: these can change ;)&lt;&#x2F;p&gt;
&lt;p&gt;At last, I’d like to thank the guys who wrote &lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20081012102826&#x2F;http:&#x2F;&#x2F;nanoweb.si.kz&#x2F;&quot;&gt;Nanoweb&lt;&#x2F;a&gt;, which really helped me to understand the whole process of creating and managing processes with PHP fork(). However, if you ever plan to actually read that sourcecode yourself, be warned. It is not for the faint-hearted.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Grace alone</title>
        <published>2008-06-26T00:00:00+00:00</published>
        <updated>2008-06-26T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Jacob Kiers
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://jacobkiers.net/post/grace-alone/"/>
        <id>https://jacobkiers.net/post/grace-alone/</id>
        
        <content type="html" xml:base="https://jacobkiers.net/post/grace-alone/">&lt;p&gt;Did someone ever want to give you something of a very, very great value? Then you know how hard it can be to just accept it. It is nearly impossible to take it, and if you take it, you nearly drop it.&lt;&#x2F;p&gt;
&lt;p&gt;An even greater value has the grace which our Saviour, Jesus Christ, achieved for us. To give us this, Hes had to die.&lt;&#x2F;p&gt;
&lt;p&gt;Is the grace which He gives to us a consequence of our goodness towards Him? No way! If his grace depends on that, we will immediately and definitely go to hell, But luckely it doesn’t depend on that. It only depends on Him.&lt;&#x2F;p&gt;
&lt;p&gt;He knows us better than we know ourselves, nevertheless, he wants to give us His grace, which the apostle Paul calls an immeasurable richness. This is about the strongest expression I know to use when I want to show the greatness of something. And this grace, this richness, we can get from Him for free.&lt;&#x2F;p&gt;
&lt;p&gt;At last, in the sixth verse the apostle states that we are now, at this moment, with the Lord in heaven, due to his resurrection.&lt;&#x2F;p&gt;
&lt;p&gt;If I think about this, I can’t do anything but say: “how little do I think about my future”.&lt;&#x2F;p&gt;
&lt;p&gt;Do you show in your life His grace?&lt;&#x2F;p&gt;
&lt;p&gt;Based on Ephesians 2:6-9&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>PHP subversion post-commit hook</title>
        <published>2008-06-11T00:00:00+00:00</published>
        <updated>2008-06-11T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Jacob Kiers
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://jacobkiers.net/post/php-subversion-post-commit-hook/"/>
        <id>https://jacobkiers.net/post/php-subversion-post-commit-hook/</id>
        
        <content type="html" xml:base="https://jacobkiers.net/post/php-subversion-post-commit-hook/">&lt;p&gt;Some time ago I’ve written a post-commit hook for Subversion in PHP, to make it easier to track code changes via email.&lt;&#x2F;p&gt;
&lt;p&gt;I based it on &lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20150906135345&#x2F;https:&#x2F;&#x2F;elliotth.blogspot.com&#x2F;2005&#x2F;02&#x2F;better-subversion-post-commit-hook.html&quot;&gt;another hook&lt;&#x2F;a&gt;, written in Ruby. Because it had no license attached to it, and because I had to rewrite it myself, I decided to license it under the new BSD license.&lt;&#x2F;p&gt;
&lt;p&gt;You can find the hook here: &lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https:&#x2F;&#x2F;gist.github.com&#x2F;jacobkiers&#x2F;2a035367a56be1428487&quot;&gt;commit-email-color.php&lt;&#x2F;a&gt;. It has the new BSD license attached to it.&lt;&#x2F;p&gt;
&lt;p&gt;Enjoy it!&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #24292E; background-color: #FFFFFF;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;2009-06-17: fixed a bug: now displays the full commit message instead of just the first line.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;2008-06-13: added an option to disable color-code the diffs.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;</content>
        
    </entry>
</feed>
