<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Posts on Youniverse</title><link>https://youniverse.site/posts/</link><description>Recent content in Posts on Youniverse</description><generator>Hugo -- gohugo.io</generator><language>en-au</language><lastBuildDate>Fri, 06 Jan 2023 15:23:23 +1100</lastBuildDate><atom:link href="https://youniverse.site/posts/index.xml" rel="self" type="application/rss+xml"/><item><title>📚 | Show Your Work</title><link>https://youniverse.site/posts/2023/01/show-your-work/</link><pubDate>Tue, 03 Jan 2023 22:39:35 +1100</pubDate><guid>https://youniverse.site/posts/2023/01/show-your-work/</guid><description>&amp;ldquo;Build sharing into my routine.&amp;rdquo;</description><content type="html"><![CDATA[<p><img src="./images/bookcover-show-your-work.jpg" alt=""></p>
<p>&ldquo;Build sharing into my routine.&rdquo;</p>
]]></content></item><item><title>YAK8s 101: 1 | What is K8s? [Note]</title><link>https://youniverse.site/posts/2021/09/yak8s-101-1-what-is-k8s-note/</link><pubDate>Wed, 08 Sep 2021 22:17:58 +1000</pubDate><guid>https://youniverse.site/posts/2021/09/yak8s-101-1-what-is-k8s-note/</guid><description>What is K8s? | Kubernetes is a platform to orchestrate containers.
It looks like this:
ref: Kubernetes Documentation (Kubernetes Components). Accessed 8 Sep 2021, https://kubernetes.io/docs/concepts/overview/components/</description><content type="html"><![CDATA[<h2 id="what-is-k8s">What is K8s?</h2>
<p>| Kubernetes is a platform to orchestrate containers.</p>
<p>It looks like this:</p>
<p><img src="https://d33wubrfki0l68.cloudfront.net/2475489eaf20163ec0f54ddc1d92aa8d4c87c96b/e7c81/images/docs/components-of-kubernetes.svg" alt=""></p>
<ul>
<li>ref: Kubernetes Documentation (Kubernetes Components). Accessed 8 Sep 2021, <a href="https://kubernetes.io/docs/concepts/overview/components/">https://kubernetes.io/docs/concepts/overview/components/</a></li>
</ul>
]]></content></item><item><title>Install Golang From Source</title><link>https://youniverse.site/posts/2021/06/install-golang-from-source/</link><pubDate>Thu, 17 Jun 2021 00:09:57 +1000</pubDate><guid>https://youniverse.site/posts/2021/06/install-golang-from-source/</guid><description>Why? When setting up a Golang working environment, broadly speaking, there are two ways: using a package manager/installer or installing from source. Most of the time it&amp;rsquo;s much easier to use a package manager or installer and by executing one or two commands, the entire working environment is ready to use. Well, this time, I just would like to see how manual installation works.
Head Let me first list all the steps that I can think of for the installation:</description><content type="html"><![CDATA[<h2 id="why">Why?</h2>
<p>When setting up a Golang working environment, broadly speaking, there are two ways: using a package manager/installer or installing from source. Most of the time it&rsquo;s much easier to use a package manager or installer and by executing one or two commands, the entire working environment is ready to use. Well, this time, I just would like to see how manual installation works.</p>
<h2 id="head">Head</h2>
<p>Let me first list all the steps that I can think of for the installation:</p>
<ol>
<li>Get the Golang source code from somewhere, maybe a Github repo</li>
<li>Build the Golang source into executable binaries</li>
<li>😱 It seems that I need to have a Go compiler ready before Step 2 (<strong>bootstrap</strong>)</li>
<li>Install the executable binaries, there might be scripts doing this or there are standard places to put these binaries</li>
<li>A working Go installation depends on several environment varialbes, I may need to set up those variables</li>
<li>Verify the installation</li>
</ol>
<p>Let me think through the process carefully.</p>
<h3 id="the-result-of-the-process">The result of the process</h3>
<p>Of course, after running through the process I should have a working Go environment available on my computer, but since I&rsquo;m building from source, I&rsquo;ll have to <code>git clone</code> two copies of the Golang source code, one for the the <a href="#the-compiler">compiler</a> and the other for the <a href="#the-source">actual source</a>. Again, since I will have two copies of Go, I need to tell the system which one to use for the <code>go</code> command.</p>
<h3 id="the-compiler">The compiler</h3>
<p>The Go toolchain is written in Go. To build it, I need a Go compiler installed (<a href="https://golang.org/doc/install/source#go14">ref</a>).</p>
<p>This is the compiler that is used for &ldquo;bootstrapping&rdquo; the installation. This compiler can be a fully working Go toolchain already setup on my computer or a designated version of Go commands setup just for building and installing of Golang from source.</p>
<ul>
<li>😱 A working version of Golang means in order to build Go from source, I need to have a working version of Golang on my system.</li>
<li>👻 A designated version of Go setup just for building and installing Golang requires the use of an environment variable named <code>GOROOT_BOOTSTRAP</code>, which directs the bootstrap process to the designated Go compiler.
<ul>
<li>In this case, <code>$GOROOT_BOOTSTRAP/bin/go</code> should be the <code>go</code> command to use.</li>
</ul>
</li>
</ul>
<h3 id="the-source">The source</h3>
<p>The source code of Golang is obtained with Git, which means I need to have Git installed locally. I need to find a good place to put the source code, and as suggested by the doc (<a href="https://golang.org/doc/install/source#fetch">ref</a>), I can use <code>goroot</code> as the folder name. I need to run a build script to build this copy of source code and the Go tool chain will be installed in <code>&lt;parent dir&gt;/goroot/bin</code>.</p>
<h3 id="use-environment-variables-to-tell-the-difference">Use environment variables to tell the difference</h3>
<p>The Go environment uses environment vairables (<a href="https://golang.org/doc/install/source#environment">link</a>) to help the OS to locate Go distributions:</p>
<ul>
<li><code>GOROOT</code>: the directory containing the Golang distribution (binary files <code>bin</code>, archive files <code>pkg</code>, source code <code>src</code>,  and others)
<ul>
<li>The Go distribution&rsquo;s executables are in <code>GOROOT/bin</code>, e.g., the <code>go</code> command</li>
</ul>
</li>
<li><code>GOPATH</code>: the directorying containing projects outside the Go distribution (three subdirectories, i.e., <code>bin</code>, <code>pkg</code>, and <code>src</code>)</li>
<li><code>GOBIN</code>: the directory containing executables outside the Go distribution, by default, <code>GOBIN</code> is set to <code>$GOPATH/bin</code></li>
</ul>
<h4 id="note">Note:</h4>
<p>When using the official Go installer (<a href="https://golang.org/doc/install#download">link</a>) to do the installation, the Go distribution will be installed in <code>/usr/local/go</code> (<a href="https://golang.org/doc/install#install">ref</a>) and its structure is something like this:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-shell" data-lang="shell"><span style="display:flex;"><span>/
</span></span><span style="display:flex;"><span>├─ usr/
</span></span><span style="display:flex;"><span>│  ├─ local/
</span></span><span style="display:flex;"><span>│  │  ├─ go/
</span></span><span style="display:flex;"><span>│  │  │  ├─ bin/
</span></span><span style="display:flex;"><span>│  │  │  ├─ pkg/
</span></span><span style="display:flex;"><span>│  │  │  ├─ src/
</span></span><span style="display:flex;"><span>|  |  |  ├─ &lt;other dirs or files&gt;
</span></span></code></pre></div><ul>
<li>
<p>This directory, <code>/usr/local/go</code>, is the <code>GOPATH</code> and it has three subdirectories containing the source files (<code>src</code>), archive files (<code>pkg</code>), and binary files (<code>bin</code>).</p>
</li>
<li>
<p>The <code>/usr/local/go/bin</code> (the value for <code>GOROOT/bin</code> if <code>GOROOT</code> is set) directory is also added to the <code>PATH</code> environment variable so that all go binaries are accessible as executables from the terminal.</p>
</li>
</ul>
<h2 id="fetch-the-source-step-1-and-3">Fetch the source (Step 1 and 3)</h2>
<p>I need to have a version of Go toolchain just for bootstrapping the building process. I can use Go 1.4, &ldquo;the last Go release with a compiler written in C&rdquo;. This version is available in the official Golang Github repo.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-shell" data-lang="shell"><span style="display:flex;"><span><span style="color:#75715e"># clone the go source repo into a folder, go1.4 in this case</span>
</span></span><span style="display:flex;"><span>git clone git@github.com:golang/go.git go1.4
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># navigate to the source folder</span>
</span></span><span style="display:flex;"><span>cd go1.4
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># checkout the release-branch.go1.4 branch</span>
</span></span><span style="display:flex;"><span>git checkout release-branch.go1.4
</span></span></code></pre></div><p><code>cd</code> into the <code>src</code> subdirectory, and set <code>CGO_ENABLED=0</code> in the envionment, and run <code>make.bash</code></p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-shell" data-lang="shell"><span style="display:flex;"><span><span style="color:#75715e"># navigate into the src directory</span>
</span></span><span style="display:flex;"><span>cd src
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># set environment variable CGO_ENABLED to 0</span>
</span></span><span style="display:flex;"><span>CGO_ENABLED<span style="color:#f92672">=</span><span style="color:#ae81ff">0</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># run make.bash</span>
</span></span><span style="display:flex;"><span>./make.bash
</span></span></code></pre></div><p>Once the Golang v1.4 has been unpacked, I need to set the <code>GOROOT_BOOTSTRAP</code> environment variable to its directory, so that <code>$GOROOT_BOOTSTRAP/bin/go</code> is the <code>go</code> command to use for building the Golang source code.</p>
<ul>
<li>❗️ Do not attempt to reuse this git clone in the later steps, this is the bootstrapping compiler&rsquo;s repo.</li>
<li>❗️ The go1.4 bootstrap toolchain must be able to properly traverse the go1.4 sources that it assumes are present under this repository root</li>
</ul>
<h2 id="fetch-the-source-step-1-again-">Fetch the source (Step 1 again 😓)</h2>
<p>This time I need to get the copy of Golang source code that will be built.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-shell" data-lang="shell"><span style="display:flex;"><span><span style="color:#75715e"># clone the source code into a folder, in this case, a folder named goroot</span>
</span></span><span style="display:flex;"><span>git clone https://go.googlesource.com/go goroot
</span></span><span style="display:flex;"><span><span style="color:#75715e"># or</span>
</span></span><span style="display:flex;"><span>git clone git@github.com:golang/go.git goroot
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># navigate into goroot</span>
</span></span><span style="display:flex;"><span>cd goroot
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># get all the tags (so that I can select a particular version)</span>
</span></span><span style="display:flex;"><span>git fetch --all --tags 
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># checkout a particular tag, e.g., go1.16.3</span>
</span></span><span style="display:flex;"><span>git checkout go1.16.3
</span></span><span style="display:flex;"><span><span style="color:#75715e"># or create a new branch from a tag</span>
</span></span><span style="display:flex;"><span>git checkout -b go1.16.3 go1.16.3
</span></span></code></pre></div><p>Go will be installed in the directory where it is checkout out. If Go is checked out in <code>$HOME/goroot</code>, executables will then be installed in <code>$HOME/goroot/bin</code>.</p>
<p>The directory containing the Golang source code may have any name, but if that folder is <code>$HOME/go</code>, it will conflict with the default location of <code>$GOPATH</code>.</p>
<h2 id="build-and-install-step-2">Build and install (Step 2)</h2>
<p>To build the Go distribution, just run the commands below, and once the commands finish executing, the building part is done and the Go executables should be in <code>$HOME/goroot/bin</code>.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-shell" data-lang="shell"><span style="display:flex;"><span><span style="color:#75715e"># navigate into the src subfolder</span>
</span></span><span style="display:flex;"><span>cd src
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># run all.bash</span>
</span></span><span style="display:flex;"><span>./all.bash
</span></span></code></pre></div><p>The &ldquo;installation&rdquo; is done by setting up environment variables (<a href="https://golang.org/doc/install/source#environment">ref</a>):</p>
<ul>
<li><code>GOROOT</code>: The root of the Go distribution, often <code>$HOME/go1.X</code>.
<ul>
<li>Its value is built into the tree when it is compiled, and defaults to the parent of the directory where <code>all.bash</code> was run. There is no need to set this unless I want to switch between multiple local copies of the repository.</li>
<li>The value should be the directory where the second copy of Go source code is check out into</li>
</ul>
</li>
<li><code>GOPATH</code>: The directory where Go projects outside the Go distribution are typically checked out.
<ul>
<li>The value to this variable should be the parent directory of the <code>bin</code>, <code>pkg</code>, and <code>src</code> directory, where the <code>go install</code> result, library archives, and source dependencies are placed respectively.</li>
</ul>
</li>
<li><code>GOBIN</code>: The directory where executables outside the Go distribution are installed using the go command.
<ul>
<li>Most of the time it&rsquo;s just <code>$GOPATH/bin</code></li>
</ul>
</li>
</ul>
<p>Because the Go toolchain (commands) should be available in terminals, <code>$GOROOT/bin</code> and <code>$GOBIN</code> should be added to the <code>PATH</code> environment variable.</p>
<h2 id="test-the-installation">Test the installation</h2>
<p>Once the environment variables are set, I can test the installation.</p>
<p>Check the current go version by executing the command below in a termianl:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-shell" data-lang="shell"><span style="display:flex;"><span>go version
</span></span></code></pre></div><p>Check whether the installed Golang is able to build a &ldquo;Hello, world!&rdquo; project (<a href="https://golang.org/doc/code#Command">ref</a>):</p>
<ul>
<li>Create a <code>main.go</code> file</li>
<li>Do something simple with Golang, e.g., printing &ldquo;Hello, world!&rdquo; to the terminal (shown below).</li>
</ul>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-golang" data-lang="golang"><span style="display:flex;"><span><span style="color:#f92672">package</span> <span style="color:#a6e22e">main</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">import</span> <span style="color:#e6db74">&#34;fmt&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">func</span> <span style="color:#a6e22e">main</span>() {
</span></span><span style="display:flex;"><span>	<span style="color:#a6e22e">fmt</span>.<span style="color:#a6e22e">Println</span>(<span style="color:#e6db74">&#34;Hello, world!&#34;</span>)
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><ul>
<li>In a terminal, navigate to the directory containing the <code>main.go</code> file and execute:</li>
</ul>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-shell" data-lang="shell"><span style="display:flex;"><span>go run main.go
</span></span></code></pre></div><p>When I see &ldquo;Hello, world!&rdquo; gets printed in the terminal, I know the installation is good.</p>
<h2 id="update">Update</h2>
<p>How do I update the current installed version to a different one or how do I experiment with my local changes to the Golang source code?</p>
<p>The answer is: just rebuild the updated source.</p>
<p>The code in the <code>$GOROOT/src</code> folder reflects the version of Golang source code I want to build, otherwise <code>git checkout</code> the correct version. Then run</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-shell" data-lang="shell"><span style="display:flex;"><span><span style="color:#75715e"># navigate into the src subfolder</span>
</span></span><span style="display:flex;"><span>cd $GOROOT/src
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># run all.bash</span>
</span></span><span style="display:flex;"><span>./all.bash
</span></span></code></pre></div><h2 id="tail">Tail</h2>
<p>Now that I have a working Go environment, I can build a 3rd copy of Go source and play with it or I can have multiple Go versions installed at the same time (<a href="https://golang.org/doc/manage-install#installing-multiple">ref</a>).</p>
]]></content></item><item><title>Hello World</title><link>https://youniverse.site/posts/2021/04/hello-world/</link><pubDate>Mon, 26 Apr 2021 01:52:58 +1000</pubDate><guid>https://youniverse.site/posts/2021/04/hello-world/</guid><description>😊</description><content type="html">&lt;p>😊&lt;/p>
</content></item></channel></rss>