<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Marty's Random Thoughts]]></title><description><![CDATA[I love building and things, particularly when they involve adversarial interoperability.]]></description><link>https://penner.me</link><generator>RSS for Node</generator><lastBuildDate>Sun, 08 Nov 2026 17:03:47 GMT</lastBuildDate><atom:link href="https://penner.me/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Generating TLS certificates for external domains in SST]]></title><description><![CDATA[You know how sometimes, you can spend hours and hours debugging something, only to discover the fix is a few lines of code? That's what creating…]]></description><link>https://penner.me/generating-tls-certificates-for-external-domains-in-sst</link><guid isPermaLink="true">https://penner.me/generating-tls-certificates-for-external-domains-in-sst</guid><category><![CDATA[General Programming]]></category><category><![CDATA[sst]]></category><category><![CDATA[Devops]]></category><dc:creator><![CDATA[Marty Penner]]></dc:creator><pubDate>Mon, 29 Jan 2024 05:00:00 GMT</pubDate><content:encoded><![CDATA[<p>You know how sometimes, you can spend hours and hours debugging something, only to discover the fix is a few lines of code? That's what creating certificates in <a target="_blank" href="http://sst.dev">sst.dev</a> was like. I kept forgetting that SST wraps <a target="_blank" href="https://aws.amazon.com/cdk/">AWS Cloud Development Kit (CDK)</a>, and that any construct not available in SST could be grabbed from the underlying CDK. Oops. Score one for "I should've read the docs more thoroughly and slowly".</p>
<p>Anyways, here's the entire SST config you'd need to add a custom certificate to your site stack in SST:</p>
<pre><code class="lang-ts"><span class="hljs-keyword">import</span> { Certificate, CertificateValidation } <span class="hljs-keyword">from</span> <span class="hljs-string">'aws-cdk-lib/aws-certificatemanager'</span>;
<span class="hljs-keyword">import</span> <span class="hljs-keyword">type</span> { SSTConfig } <span class="hljs-keyword">from</span> <span class="hljs-string">'sst'</span>;
<span class="hljs-keyword">import</span> { Config, SvelteKitSite } <span class="hljs-keyword">from</span> <span class="hljs-string">'sst/constructs'</span>;

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {
    config(_input) {
        <span class="hljs-keyword">return</span> {
            name: <span class="hljs-string">'your-site'</span>,
            region: <span class="hljs-string">'us-east-1'</span>,
        };
    },
    stacks(app) {
        app.stack(<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Site</span>(<span class="hljs-params">{ stack }</span>) </span>{
            <span class="hljs-keyword">const</span> certificate = <span class="hljs-keyword">new</span> Certificate(<span class="hljs-built_in">this</span>, <span class="hljs-string">'Certificate'</span>, {
                domainName: <span class="hljs-string">'*.yourdomain.com'</span>,
                subjectAlternativeNames: [<span class="hljs-string">'yourdomain.com'</span>],
                <span class="hljs-comment">// Can also do `fromEmail`, but DNS is more maintainable if you</span>
                <span class="hljs-comment">// have control of the DNS records.</span>
                validation: CertificateValidation.fromDns(),
            });
            <span class="hljs-keyword">if</span> (stack.stage !== <span class="hljs-string">'prod'</span>) {
                <span class="hljs-comment">// Don't need to keep dev certs around forever.</span>
                certificate.applyRemovalPolicy(RemovalPolicy.DESTROY);
            }

            <span class="hljs-keyword">const</span> site = <span class="hljs-keyword">new</span> SvelteKitSite(stack, <span class="hljs-string">'site'</span>, { <span class="hljs-comment">// or whatever site stack you want to use</span>
                customDomain: {
                    <span class="hljs-comment">// Note that we're supplying the root domain, not the subdomain wildcard.</span>
                    domainName: <span class="hljs-string">'yourdomain.com'</span>,
                    isExternalDomain: <span class="hljs-literal">true</span>,
                    cdk: {
                        certificate,
                    },
                },
            });

            stack.addOutputs({
                url: site.url,
            });
        });
    },
} satisfies SSTConfig;
</code></pre>
<p>Voila! SST is actually pretty cool. Knowing just a bit about AWS Lambda has unlocked a lot of ideas for me.</p>
]]></content:encoded></item><item><title><![CDATA[Getting Tauri working in WSL]]></title><description><![CDATA[Update: Tauri has good guidelines for working with homebrew and a clear set of prerequisites for linux. Not sure if I missed these before or they were…]]></description><link>https://penner.me/getting-tauri-working-in-wsl</link><guid isPermaLink="true">https://penner.me/getting-tauri-working-in-wsl</guid><category><![CDATA[Tauri]]></category><category><![CDATA[desktop apps]]></category><category><![CDATA[Linux]]></category><category><![CDATA[Electron]]></category><dc:creator><![CDATA[Marty Penner]]></dc:creator><pubDate>Tue, 25 Oct 2022 16:00:00 GMT</pubDate><content:encoded><![CDATA[<table><tbody><tr><td><p><strong>Update:</strong> Tauri has good guidelines for <a target="_blank" class="rgh-seen--5229989788" href="https://tauri.app/v1/guides/faq#build-conflict-with-homebrew-on-linux">working with homebrew</a> and a clear set of <a target="_blank" class="rgh-seen--5229989788" href="https://tauri.app/v1/guides/getting-started/prerequisites#setting-up-linux">prerequisites for linux</a>. Not sure if I missed these before or they were added later, but those docs basically describe how to avoid the installation problems I ran into.</p></td></tr></tbody></table>

<blockquote>
<p>TL;DR:</p>
<ul>
<li><p>Don't use homebrew; use your distro's package manager instead (I used apt on ubuntu 20.04).</p>
</li>
<li><p>Install wslg according to instructions.</p>
</li>
<li><p>Install latest GPU drivers.</p>
</li>
<li><p>DON'T install a 3rd-party X server like VcXsrv.</p>
</li>
<li><p>DON'T install xfce4.</p>
</li>
<li><p>Add <code>export DISPLAY=:0</code> to your shell file, e.g. <code>~/.zshrc</code>.</p>
</li>
</ul>
</blockquote>
<p>I've been chipping away at a <a target="_blank" href="https://github.com/martypenner/tasks-app">personal task manager clone</a> (who isn't these days?), and wanted to begin packaging the app for desktop. I recently heard about <a target="_blank" href="https://tauri.app/">tauri.app</a>, which sounds like a very promising electron alternative. I love their philosophy of security and local-first apps; this has been something on my mind for quite a while. I appreciate cloud connectivity as an option, but for something like a simple task manager, why do you need to talk to your servers?! Let me choose that please.</p>
<p>Tauri is built in Rust, and because it's a desktop app, it obviously has some visual components that run outside of the cli. I do a lot of my personal development on my windows machine in <a target="_blank" href="https://learn.microsoft.com/en-us/windows/wsl/install">WSL</a>. It's fantastic overall, but how do I run desktop apps from it? There's no way I wanted to set up Tauri in windows and pollute my environment again.</p>
<p>It turns out that <a target="_blank" href="https://github.com/microsoft/wslg">wslg</a> has been around for a bit and provides a way to run linux desktop apps as companion apps to the rest of your windows app. That's so cool. Through a process of trial and error, I discovered that getting wslg going was pretty easy, but getting tauri from within wsl was not. Essentially, I found that using homebrew to install wslg packages in my wsl distro (Ubuntu 20.04) caused a lot of issues. Resorting to the native package manager to install the same dependencies worked much better.</p>
<p>A number of <code>*-dev</code> packages were required to be present to boot tauri properly. I noticed a number of issues with <code>pkg-config</code> and missing packages. I used the <a target="_blank" href="https://packages.ubuntu.com/">ubuntu 20.04 package repository search</a> whenever I saw an error message about a missing package to determine which packages to install.</p>
<p>The full install line was this:</p>
<pre><code class="lang-dockerfile">sudo apt install pkg-config \
  libdbus-<span class="hljs-number">1</span>-dev \
  libgtk-<span class="hljs-number">3</span>-dev \
  libsoup2.<span class="hljs-number">4</span>-dev \
  libjavascriptcoregtk-<span class="hljs-number">4.0</span>-dev \
  libwebkit2gtk-<span class="hljs-number">4.0</span>-dev
</code></pre>
<p>Finally, I need to add <code>export DISPLAY=:0</code> to my <code>~/.zshrc</code> file.</p>
<p>After running through the various required steps and navigating around some speedbumps, I got it working! Tauri has a very easy-to-use init script. Watching that desktop GUI come up the first time after running <code>npm run tauri dev</code> is very satisfying. I'm looking forward to exploring its APIs.</p>
<p>For more info on potential issues with tauri and wslg, have a look at this: <a target="_blank" href="https://github.com/tauri-apps/tauri/issues/380">tauri-apps/tauri#380</a></p>
<p><a target="_blank" href="https://user-images.githubusercontent.com/1819798/194204056-fd6048e4-db00-49af-9d64-27a90db7f3c9.png"><img src="https://user-images.githubusercontent.com/1819798/194204056-fd6048e4-db00-49af-9d64-27a90db7f3c9.png" alt="tauri" /></a></p>
]]></content:encoded></item><item><title><![CDATA[Sharing music with friends using fly.io, Azuracast, and Mopidy]]></title><description><![CDATA[TL;DR: Use Mopidy with Iris + Azuracast to live stream your music for cheap on fly.io. Here's the repo with my deployments. Feel free to fork and follow…]]></description><link>https://penner.me/sharing-music-with-friends-using-flyio-azuracast-and-mopidy</link><guid isPermaLink="true">https://penner.me/sharing-music-with-friends-using-flyio-azuracast-and-mopidy</guid><category><![CDATA[General Programming]]></category><category><![CDATA[Frontend Development]]></category><category><![CDATA[radio]]></category><category><![CDATA[Docker]]></category><category><![CDATA[fly.io]]></category><category><![CDATA[self-hosted]]></category><dc:creator><![CDATA[Marty Penner]]></dc:creator><pubDate>Mon, 26 Sep 2022 04:00:00 GMT</pubDate><content:encoded><![CDATA[<blockquote>
<p>TL;DR: Use Mopidy with Iris + Azuracast to live stream your music for cheap on fly.io. Here's <a target="_blank" href="https://github.com/martypenner/music-services">the repo with my deployments.</a> Feel free to fork and follow the instructions to have a self-hosted music and streaming service up and running quickly.</p>
</blockquote>
<p>In my search for a simple self-hosted, highly available music service to play music for my friends, I've finally landed on <a target="_blank" href="https://navidrome.org/">navidrome</a> for the player and <a target="_blank" href="https://azuracast.com/">azuracast</a> for sharing the stream with friends. One of my goals is to be able to run roleplaying games for my friends wherever I am using a tablet or a low-spec laptop. So I need services that run somewhere in the cloud. By using navidrome, I can grab free apps like <a target="_blank" href="https://substreamerapp.com/">Substreamer</a> to connect to my personal music library.</p>
<p>Substreamer is great because I can make select albums or playlists available offline, limiting my bandwidth usage.</p>
<p>If I'm on an iPad, I can stream from Substreamer to Azuracast using the IziCast app. Basically, IziCast provides a way of connecting to any Icecast server.</p>
<p>Tired of hearing the word "cast"? Same.</p>
<p>One downside of this approach is having to use an external audio loopback device to route my device audio. It's clunky and expensive. So I've opted to use Mopidy with the Iris frontend instead. In this case, Mopidy connects directly to Azuracast; no intermediary device or software required. Win!</p>
<p>I'm deploying all of this on the <strong>excellent</strong> <a target="_blank" href="https://fly.io/">fly.io</a> platform. Their free tier is quite generous. Azuracast needs more resources than that unfortunately, so I'm using a beefier instance. In order to mitigate the expense, I've set up a GitHub action to scale down all instances every night at midnight. By adding <code>workflow_dispatch</code> to the action, I can trigger it manually. By adding an input dropdown allowing <code>start</code> and <code>stop</code> values, I can start or stop the instances at will.</p>
<p>In the future, I suspect fly.io machines will allow auto-scaling based on requests. Looking forward to that!</p>
<p>Since my music exists locally, I needed to tell fly.io to build locally only, then push the built images up. This seemed a lot more resilient than having it push up the docker context before building remotely. The downside is long upload times since the entire music library is being bsked in to the docker image. Bit of a tradeoff. I could probably set up syncthing, or curl a tar from an S3 bucket, but that seems less fun to me for now.</p>
<p>Re: azuracast, since it uses a few different internal paths for storage and fly.io does not currently allow multiple volume mounts, we resort to copying a <a target="_blank" href="https://www.streambeats.com/">copyright-free track</a> to the station media directory every time the app boots up, i.e. after a new deploy. One caveat here is that we have to manually restart broadcasting after every new deploy or machine restart. Kind of a bummer, but not a huge deal.</p>
<p><a target="_blank" href="https://user-images.githubusercontent.com/1819798/192398075-15146c78-805c-46a3-8a92-748202cbbaa1.png"><img src="https://user-images.githubusercontent.com/1819798/192398075-15146c78-805c-46a3-8a92-748202cbbaa1.png" alt="restart broadcasting" /></a></p>
<p>Lastly, in order to avoid opening public ports, I'm running every container with a <a target="_blank" href="https://tailscale.com/">tailscale</a> sidecar process. This allows only me to access Mopidy and Navidrome while locking it down for everyone else.</p>
]]></content:encoded></item><item><title><![CDATA[Using NVM to enforce node versions]]></title><description><![CDATA[At work, we previously used docker to give us a common node version by running every node and npm command through a wrapper script. This meant we wouldn't…]]></description><link>https://penner.me/using-nvm-to-enforce-node-versions</link><guid isPermaLink="true">https://penner.me/using-nvm-to-enforce-node-versions</guid><category><![CDATA[Node.js]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[nvm]]></category><dc:creator><![CDATA[Marty Penner]]></dc:creator><pubDate>Wed, 05 Feb 2020 17:00:00 GMT</pubDate><content:encoded><![CDATA[<p>At work, we previously used docker to give us a common node version by running every node and npm command through a wrapper script. This meant we wouldn't run into strange gotchas between different versions of node and npm. But it also created more problems:</p>
<ul>
<li><p>We couldn't use different node versions per package. This means we had to find the lowest common denominator among all packages, so we were stuck on an older, slower version with fewer features.</p>
</li>
<li><p>We couldn't debug node scripts the usual way because of the docker proxy.</p>
</li>
<li><p>Running e2e tests through a real browser required <a target="_blank" href="https://www.cypress.io/blog/2019/05/02/run-cypress-with-a-single-docker-command/#Interactive-mode">installing and configuring XQuartz</a>, which was really wonky and not easy to train people on.</p>
</li>
<li><p>Performance was <strong>really bad</strong>. People were waiting many minutes for basic builds to finish.</p>
</li>
<li><p><code>Ctrl + C</code> didn't always work because of terminal shenanigans between docker and the host, so you could end up with hanging processes.</p>
</li>
<li><p>Watch/live-reload scripts didn't work sometimes for reasons I don't understand, meaning they had to run a full build for every change.</p>
</li>
</ul>
<p>Tools like <a target="_blank" href="https://github.com/nvm-sh/nvm#installing-and-updating">nvm</a> were made to deal with stuff like this, so why not use it? By modifying the previous wrapper script, but adding <code>.nvmrc</code> files to each package, the wrapper can ensure that nvm installs the needed node version before running. It also avoids polluting your shell, so your active node version doesn't change simply because you ran <code>npm i</code> inside of a package. Works like a charm!</p>
<p>I also investigated <a target="_blank" href="https://volta.sh/">volta</a>, but it simply isn't ready for me to use yet, primarily because it doesn't allow installing "global" npm packages yet.</p>
<p>Here's the full code the wrapper script:</p>
<pre><code class="lang-dockerfile"><span class="hljs-comment">#!/usr/bin/env bash</span>

<span class="hljs-comment"># This file mainly exists to be a facade for our watch/build/install scripts. By</span>
<span class="hljs-comment"># providing a thin layer on top, we can theoretically change out the underlying</span>
<span class="hljs-comment"># implementation without having to change our workflow too much.</span>
<span class="hljs-comment">#</span>
<span class="hljs-comment"># As of the time of this writing, we're enforcing the desired node and npm</span>
<span class="hljs-comment"># versions within each package by using `.nvmrc`.</span>

<span class="hljs-comment"># Fail fast</span>
set -euo pipefail

<span class="hljs-comment"># Set up nvm</span>
. <span class="hljs-string">"$NVM_DIR/nvm.sh"</span>
nvm install

COMMAND=<span class="hljs-string">"$1"</span>

case <span class="hljs-string">"$COMMAND"</span> in
  <span class="hljs-comment"># Expose npx directly to do whatever we need</span>
  npx)
    npx <span class="hljs-string">"${@:2}"</span>
    ;;
  <span class="hljs-comment"># Expose npm directly to do whatever we need</span>
  npm)
    npm <span class="hljs-string">"${@:2}"</span>
    ;;
  <span class="hljs-comment"># Expose node directly to do whatever we need</span>
  node)
    node <span class="hljs-string">"${@:2}"</span>
    ;;
  <span class="hljs-comment"># Remove all node_modules and bower components inside all packages</span>
  clean)
    find . -type d -iname node_modules -maxdepth <span class="hljs-number">3</span> -exec rm -rf {} +
    find . -type d -iname bower_components -maxdepth <span class="hljs-number">3</span> -exec rm -rf {} +
    ;;

  *)
    echo <span class="hljs-string">"That command doesn't exist."</span>
    exit <span class="hljs-number">1</span>
    ;;
esac
</code></pre>
]]></content:encoded></item><item><title><![CDATA[Manipulating SVGs using CSS]]></title><description><![CDATA[At Race Roster, I've been experimenting with using SVGs to show real-time theme updates as a user changes the theme colours in their branding settings. A…]]></description><link>https://penner.me/manipulating-svgs-using-css</link><guid isPermaLink="true">https://penner.me/manipulating-svgs-using-css</guid><category><![CDATA[SVG]]></category><category><![CDATA[CSS]]></category><dc:creator><![CDATA[Marty Penner]]></dc:creator><pubDate>Sun, 24 Mar 2019 16:00:00 GMT</pubDate><content:encoded><![CDATA[<p>At <a target="_blank" href="https://raceroster.com/">Race Roster</a>, I've been experimenting with using SVGs to show real-time theme updates as a user changes the theme colours in their branding settings. A more traditional approach would require using a set of <code>&lt;div&gt;</code> and <code>&lt;span&gt;</code> elements with border or background color CSS attributes to achieve this. I opted instead to try using SVGs instead, since path and color manipulation seemed to be one of their strong points. Here's a very basic example SVG:</p>
<p>After inspecting the SVG structure using the browser's devtools, I can target the <code>&lt;path&gt;</code> element I care about in CSS and modify the <code>fill</code> and <code>stroke</code> attributes like so:</p>
<pre><code class="lang-css"><span class="hljs-selector-id">#arbitrary-id-of-path-element</span> {
  <span class="hljs-attribute">fill</span>: <span class="hljs-built_in">hsla</span>(<span class="hljs-number">335</span>, <span class="hljs-number">52%</span>, <span class="hljs-number">89%</span>, <span class="hljs-number">1</span>);
  <span class="hljs-attribute">stroke</span>: <span class="hljs-built_in">hsla</span>(<span class="hljs-number">335</span>, <span class="hljs-number">52%</span>, <span class="hljs-number">56%</span>, <span class="hljs-number">1</span>);
}
</code></pre>
<p>This gives me an SVG that looks like this:</p>
<pre><code class="lang-css"><span class="hljs-selector-id">#modified</span> {
  <span class="hljs-attribute">fill</span>: <span class="hljs-built_in">hsla</span>(<span class="hljs-number">335</span>, <span class="hljs-number">52%</span>, <span class="hljs-number">89%</span>, <span class="hljs-number">1</span>);
  <span class="hljs-attribute">stroke</span>: <span class="hljs-built_in">hsla</span>(<span class="hljs-number">335</span>, <span class="hljs-number">52%</span>, <span class="hljs-number">56%</span>, <span class="hljs-number">1</span>);
}
</code></pre>
<p>Pretty simple! It also allows me to export an SVG from a visual design file and manipulate in the browser. Very cool.</p>
]]></content:encoded></item><item><title><![CDATA[How I'm running this ghost blog in docker]]></title><description><![CDATA[Update: I'm now running this on hashnode. May as well start simple, hey? I wanted to start a blog to help organize my thoughts in a public way, because…]]></description><link>https://penner.me/how-im-running-this-ghost-blog-in-docker</link><guid isPermaLink="true">https://penner.me/how-im-running-this-ghost-blog-in-docker</guid><category><![CDATA[General Programming]]></category><category><![CDATA[ghost]]></category><category><![CDATA[Blogging]]></category><category><![CDATA[Docker]]></category><category><![CDATA[self-hosted]]></category><dc:creator><![CDATA[Marty Penner]]></dc:creator><pubDate>Tue, 07 Apr 2015 04:00:00 GMT</pubDate><content:encoded><![CDATA[<p><strong><em>Update</em></strong>: I'm now running this on hashnode.</p>
<p>May as well start simple, hey? I wanted to start a blog to help organize my thoughts in a public way, because surely I'm not the only one who can benefit from what I learn. Scott Hanselman talks about wasting your keystrokes:</p>
<p><a target="_blank" href="http://www.hanselman.com/blog/DoTheyDeserveTheGiftOfYourKeystrokes.aspx">http://www.hanselman.com/blog/DoTheyDeserveTheGiftOfYourKeystrokes.aspx</a></p>
<p>I hate waste of any kind, but time especially. So here we go.</p>
<h2 id="heading-docker-and-digital-ocean-lt3">Docker and Digital Ocean &lt;3</h2>
<p>As you may have already determined, I'm running this blog using the ghost blogging platform inside of a <a target="_blank" href="https://docs.docker.com/engine/examples/">Docker container</a>. In case you don't know, Docker is a great way to "containerize" your apps, meaning you can define the application's environment alongside your app code. This is super great for ensuring consistency among your teammates, not to mention you avoid polluting your host machine with all kinds of dependencies. I don't know about you, but I hate <strong>globally</strong> changing PHP + Apache versions, booting redis, installing npm packages, etc. just to satisfy different project requirements (note the emphasis on <strong>globally</strong>; obviously, you'll need to satisfy your project's requirements by using the right tools). Docker is great for providing that much-needed isolation. <a target="_blank" href="https://docs.docker.com/installation/">See here</a> for installation instructions.</p>
<p>To start, I booted up a Digital Ocean droplet preconfigured with Docker:</p>
<p><img src="https://github.com/martypenner/personal-blog/blob/main/static/assets/blog/digital-ocean-droplet-type-list.png?raw=true" alt="digital-ocean-droplet-type-list.png" /></p>
<p>Note that I chose the Docker starting point instead of the Ghost droplet in the left column. I did this because I'll be sharing this droplet with other containerized apps, so I wanted to keep the host environment clean and stripped down.</p>
<p>Next, I created a super-simple Dockerfile that looks like this:</p>
<pre><code class="lang-dockerfile"><span class="hljs-keyword">FROM</span> ghost
</code></pre>
<h2 id="heading-docker-compose-for-orchestration">Docker Compose for Orchestration</h2>
<p>Here's where things start to get cool. By default, your data is not persisted in a Docker container. Only files you share in what Docker calls a "volume" will be persisted. Obviously, I want this blog to live on even if I screw up the container somehow. So of course, I need set up a volume. However, my preference is to go one step further and store persisted data in its own volume container and link it to the app container. For that, a tool called <a target="_blank" href="https://docs.docker.com/compose/"><strong>Docker Compose</strong></a> (formerly Fig) makes things super easy. Here's my docker-compose.yml:</p>
<pre><code class="lang-yaml"><span class="hljs-attr">ghost:</span>
  <span class="hljs-attr">build:</span> <span class="hljs-string">.</span>
  <span class="hljs-attr">ports:</span>
    <span class="hljs-bullet">-</span> <span class="hljs-string">"8000:2368"</span>
  <span class="hljs-attr">volumes_from:</span>
    <span class="hljs-bullet">-</span> <span class="hljs-string">ghostdata</span>
  <span class="hljs-attr">environment:</span>
    <span class="hljs-attr">NODE_ENV:</span> <span class="hljs-string">production</span>

<span class="hljs-attr">ghostdata:</span>
  <span class="hljs-attr">image:</span> <span class="hljs-string">busybox:ubuntu-14.04</span>
  <span class="hljs-attr">command:</span> <span class="hljs-string">"true"</span>
  <span class="hljs-attr">volumes:</span>
    <span class="hljs-bullet">-</span> <span class="hljs-string">/var/lib/ghost</span>
</code></pre>
<p>Note how I'm mapping the host port 8000 to the container port 2368 (Ghost's default port), and using the "volumes from" the ghostdata container. And voila! We get persisted data. Note that the data container is using a very small image with a command that executes successfully so the data container is not actually ever <em>running</em>. Cool.</p>
<p><a target="_blank" href="https://docs.docker.com/userguide/dockervolumes/">See here</a> for more info on Docker data management.</p>
<p>At this point, I wanted to start customizing the config.js file Ghost ships with. That was easy enough; just create a config.js in the same host directory as the Dockerfile, and add the current directory as a volume to the ghost container. That looks like this in docker-compose.yml:</p>
<pre><code class="lang-yaml"><span class="hljs-attr">ghost:</span>
<span class="hljs-string">...</span>
  <span class="hljs-attr">volumes:</span>
    <span class="hljs-bullet">-</span> <span class="hljs-string">./:/var/lib/ghost</span>
</code></pre>
<p>Unfortunately, the ghost container wasn't honouring the volume. I'm not sure if this is a bug in Ghost's build process for the container, or in Docker itself. I need to investigate some more. To get around this, I added config.js explicitly as a volume:</p>
<pre><code class="lang-yaml"><span class="hljs-attr">volumes:</span>
  <span class="hljs-bullet">-</span> <span class="hljs-string">./config.js:/var/lib/ghost/config.js</span>
</code></pre>
<p>That worked great.</p>
<p>Next, I started customizing the default casper theme to add prismjs (for syntax highlighting), integration with Disqus, and other tweaks. Rather than copy the whole theme into the host directory, I chose to add individual theme files and add them as explicit volumes, like so:</p>
<pre><code class="lang-yaml"><span class="hljs-attr">ghost:</span>
<span class="hljs-string">...</span>
  <span class="hljs-attr">volumes:</span>
    <span class="hljs-string">...</span>
    <span class="hljs-bullet">-</span> <span class="hljs-string">./themes/casper/post.hbs:/var/lib/ghost/themes/casper/post.hbs</span>
    <span class="hljs-bullet">-</span> <span class="hljs-string">./themes/casper/default.hbs:/var/lib/ghost/themes/casper/default.hbs</span>
    <span class="hljs-bullet">-</span> <span class="hljs-string">./themes/casper/partials/loop.hbs:/var/lib/ghost/themes/casper/partials/loop.hbs</span>
    <span class="hljs-bullet">-</span> <span class="hljs-string">./themes/casper/assets/css/prism.css:/var/lib/ghost/themes/casper/assets/css/prism.css</span>
    <span class="hljs-bullet">-</span> <span class="hljs-string">./themes/casper/assets/js/prism.js:/var/lib/ghost/themes/casper/assets/css/prism.js</span>
</code></pre>
<p>And that sums up the config. Now it was time to fire it up! This was as simple as running <code>docker-compose build &amp;&amp; docker-compose up -d</code> in the directory where docker-compose.yml lives. Once I logged in to the Ghost admin and ran through the basic settings, I was happy.</p>
<h2 id="heading-supervisord">Supervisord</h2>
<p>Finally, I wanted to ensure the blog would keep running in the event of a container failure or host machine reboot. For that, I installed <strong>supervisord</strong> on the host machine and added this config:</p>
<pre><code class="lang-plaintext">[program:marty_blog]
command=/usr/local/bin/docker-compose up
directory=/path/to/marty_blog
autostart=true
autorestart=true
</code></pre>
<p>Then I ran <code>supervisord</code> to kick things off. Now when I update the blog files or configuration, I can run <code>docker-compose build &amp;&amp; docker-compose stop</code> and supervisord will take care of restarting the containers. Schawing!</p>
<p>All in all, I'm pretty happy with the workflow for running this blog containerized. A few hiccups were encountered, but using Docker significantly helped ease the mental burden for me of getting this blog running. Shoot me a comment if you have any questions or corrections, and thanks for reading!</p>
<p>Note: You may have noticed that I set the host port of the Ghost container to 8000, yet you're accessing this blog on the standard port 80. To accomplish that, I'm actually running an nginx container as a reverse proxy. That's how I'm running multiple apps on the same host with no global clutter. Shoot me a comment if you'd like to know how I configured that.</p>
]]></content:encoded></item></channel></rss>