zk_html/diary/2016-12-16-part-2.html

311 lines
31 KiB
HTML
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!doctype html>
<html>
<head>
<title>Zk | 2016-12-16-part-2</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Gentium+Plus&family=Lato&family=Ubuntu+Monodisplay=swap" />
<link rel="stylesheet" type="text/css" href="/style.css?2024-05-04" />
<meta name="viewport" content="width=device-width" />
<meta charset="utf-8" />
</head>
<body>
<main>
<header>
<h1>Zk | 2016-12-16-part-2</h1>
</header>
<article class="content">
<hr />
<p>type: post
date: 2016-12-16
slug: part-2
title: How Charming - Part 2</p>
<hr />
<p><em>In the previous part, we started to nail down what it is that we&rsquo;re going to do to try and accomplish our task. We&rsquo;re going to write a charm - a package that represents a way to deploy a piece of software repeatably to the cloud - which does all that&rsquo;s needed to host a WSGI app. It will be able to talk to several different services and use any WSGI server. If you haven&rsquo;t yet, <a href="/posts/tech/how-charming/2016/12/13/part-1.html">check that post out first</a>!</em></p>
<p>&ldquo;Hey! I think I have deployment all figured out for Honeycomb!&rdquo; I blurted out in the Guild chat, sharing the link to the previous post.</p>
<p>Blank stares, then finally, &ldquo;You wrote about the furry website you&rsquo;re building for work<sup id="fnref:disclaimer"><a class="footnote-ref" href="#fn:disclaimer">1</a></sup>..?&rdquo;</p>
<p><img alt="It's true" src="/assets/tech/how-charming/part-2-furries.jpg" style="max-width: 150px; float: left; margin: 0 1em 1em 0;" /></p>
<p>Point. But hey, furries make the internet go<sup id="fnref:furries-tech"><a class="footnote-ref" href="#fn:furries-tech">2</a></sup>.</p>
<p>Anyhow, I digress. The goal of Honeycomb is not to be a furry website but a writing one, and besides, none of the guild really cared about deployment strategies; that&rsquo;s something for me to worry about. And as a developer with a fascination with the Ops side of things, I <em>do</em> care about deployment strategies.</p>
<p>Chat aside, Juju is a delightful step in making things much easier for us DevOpsy critters, because it allows us to write general and repeatable solutions that can be used within a ecosystem of other solutions to accomplish a specific goal. In our case, we want to be able to deploy any WSGI compliant application that can connect to a variety of other services and be hosted in the cloud.</p>
<p>These solutions, charms, are what we&rsquo;ll need to have to get our stack up and running, so let&rsquo;s get started in making our <code>wsgi-app</code> charm.</p>
<hr />
<h3 id="bootstrapping-the-charm">Bootstrapping the charm</h3>
<p>As Juju is a Canonical offering (and I&rsquo;m a Canonical employee), I&rsquo;ll be working in Ubuntu, so if you&rsquo;re following along, you&rsquo;ll need that running on a machine or VM at your disposal (you&rsquo;ll need 15.10 Wily or 16.04 Xenial, to be specific). Once you&rsquo;ve got your system up and running, installation of juju and the tools we need is fairly easy:</p>
<div class="codehilite"><pre><span></span><code>sudo apt install juju lxd charm-tools
</code></pre></div>
<p>This will install just about everything we need: we&rsquo;ll get juju itself, of course, as well as LXD, which is used for local and development environments, and <code>charm-tools</code>, which contains a few applications we&rsquo;ll be using for creating, building, and testing our charm.</p>
<p>Getting our charm set up after this point is fairly easy, but it does require deciding on how you&rsquo;re going to work with your charm. I have a work directory in which I keep all of my projects, and when developing a charm, it&rsquo;s often easiest to have all of your charm related work in its own directory structure. With that in mind, I&rsquo;m going to set up the following directory structure for working with <code>wsgi-app</code>:</p>
<div class="codehilite"><pre><span></span><code>~
└── work
└── charms
   ├── builds
   ├── interfaces
   └── layers
</code></pre></div>
<p>We&rsquo;ll get into what layers are in just a second and interfaces in a later article, but for now, that&rsquo;s the basic structure that one needs to get started with building a charm. This is because the various charm tools expect to find a certain structure when they do their work. This is all controlled through environment variables:</p>
<div class="codehilite"><pre><span></span><code><span class="nb">export</span> <span class="nv">JUJU_REPOSITORY</span><span class="o">=</span><span class="nv">$HOME</span>/work/charms
<span class="nb">export</span> <span class="nv">LAYER_PATH</span><span class="o">=</span><span class="nv">$JUJU_REPOSITORY</span>/layers
<span class="nb">export</span> <span class="nv">INTERFACE_PATH</span><span class="o">=</span><span class="nv">$JUJU_REPOSITORY</span>/interfaces
<span class="c1"># or, in fish:</span>
<span class="nb">set</span> -x JUJU_REPOSITORY ~/work/charms
<span class="nb">set</span> -x LAYER_PATH <span class="nv">$JUJU_REPOSITORY</span>/layers
<span class="nb">set</span> -x INTERFACE_PATH <span class="nv">$JUJU_REPOSITORY</span>/interfaces
<span class="c1"># then:</span>
mkdir -p <span class="nv">$LAYER_PATH</span> <span class="nv">$INTERFACE_PATH</span>
</code></pre></div>
<p>Now that we&rsquo;ve got our basic directory structure in place, we can start to actually build out our charm. Thankfully, the charm tools give us a way to do so with a simple command:</p>
<div class="codehilite"><pre><span></span><code><span class="c1"># First, get to the layer directory, where we&#39;ll be working on our charm</span>
makyo@corrin:~$ <span class="nb">cd</span> <span class="nv">$LAYER_PATH</span>
makyo@corrin:~/work/charms/layers$ charm create wsgi-app
INFO: Using default charm template <span class="o">(</span>reactive-python<span class="o">)</span>. To <span class="k">select</span> a different template, use the -t option.
INFO: Generating charm <span class="k">for</span> wsgi-app <span class="k">in</span> ./wsgi-app
INFO: No wsgi-app <span class="k">in</span> apt cache<span class="p">;</span> creating an empty charm instead.
Cloning into <span class="s1">&#39;/tmp/tmp52ugnq&#39;</span>...
remote: Counting objects: <span class="m">27</span>, <span class="k">done</span>.
remote: Total <span class="m">27</span> <span class="o">(</span>delta <span class="m">0</span><span class="o">)</span>, reused <span class="m">0</span> <span class="o">(</span>delta <span class="m">0</span><span class="o">)</span>, pack-reused <span class="m">27</span>
Unpacking objects: <span class="m">100</span>% <span class="o">(</span><span class="m">27</span>/27<span class="o">)</span>, <span class="k">done</span>.
Checking connectivity... <span class="k">done</span>.
</code></pre></div>
<p><code>charm create</code> will do a few things, as shown above, but in short, it will create a <code>wsgi-app</code> directory for us, and populate it with a basic template upon which we&rsquo;ll build our charm. This winds up giving you a directory like so:</p>
<div class="codehilite"><pre><span></span><code>wsgi-app
├── config.yaml
├── icon.svg
├── layer.yaml
├── metadata.yaml
├── reactive
│   └── wsgi_app.py
├── README.ex
└── tests
├── 00-setup
└── 10-deploy
</code></pre></div>
<p>There&rsquo;s a lot going on here, so it&rsquo;s time we take a step back and talk about what goes into building a charm, and the two important concepts to learn about: hooks and layers.</p>
<hr />
<h3 id="hooks">Hooks</h3>
<p>Charms, as deployment solutions, are fundamentally reactive. When you deploy a charm, it goes through several stages, and at each stage, the charm has a chance to react to what&rsquo;s going on during the deployment process. The same with other things going on around the charm: when configuration values are changed, or a relation (a means of communication between two services) is added or removed or changed, the charm can react to that as well.</p>
<p>As with many other reactive frameworks, we call these sorts of reactions &lsquo;hooks&rsquo;. For example, when you first deploy a charm with juju, the charm receives several hooks from juju once the machine on which it is to be deployed is up and running. It will start with the <code>install</code> hook, which is usually when the charm has a chance to install all of its software. After that, it will receive the <code>config-changed</code> hook, which is when the charm will learn about all of the configuration options that the user has specified and can react accordingly. Finally, it will receive a <code>start</code> hook, which is when any long-running processes such as servers will be started. <code>stop</code> is another hook, as well, of course, wherein one might back-up any charm data.</p>
<p>The hook-based lifecycle of a charm looks something like the following<sup id="fnref:rr-diagrams"><a class="footnote-ref" href="#fn:rr-diagrams">3</a></sup>:</p>
<p>{% include tech/how-charming/part-2-hooks.svg %}</p>
<p>In reality, most of the work that is done within the charm happens during the <code>config-changed</code> hook, while <code>install</code> is used only for installing ancillary software and <code>start</code> is often just ignored. This is because that is the hook which will always occur after startup and any configuration changes (such as when the user runs <code>juju set</code>). This way, you can just restart all tasks during <code>config-changed</code>, as this will cause config files changed during the hook to be reloaded and so on.</p>
<p>We&rsquo;ll get more into relations in a later part, but for now, it&rsquo;s enough to understand that relations are, primarily, ways in which one service can expose information to another. Contrary to their names or how they appear in visualizations, they&rsquo;re not means or representations of <em>communication</em> between services. Rather, one can think of them as the juju controller allowing the two services to acknowledge that they exist to each other. In our instance, this will mean that, when a relation is created between <code>wsgi-app</code> and PostGres, <code>wsgi-app</code> will receive connection information for the PostGres database server, and networking will be restructured such that the two instances <em>can</em> talk to each other.</p>
<p>{% include tech/how-charming/part-2-relation-hooks.svg %}</p>
<p>Relations follow their own cycle of hooks, through creation, change, and deletion, but again, we&rsquo;ll be diving into them later - they&rsquo;re a topic of their own!</p>
<hr />
<h3 id="layers">Layers</h3>
<p>Charms can be written in most any language that&rsquo;s available on a base ubuntu server image, such as bash or python, or any language installed during the charm hook, which covers just about everything. This works by having a hook directory in the charm with an executable file named for each hook:</p>
<div class="codehilite"><pre><span></span><code>hooks
├── config-changed
├── hook.template
├── install
├── leader-elected
├── leader-settings-changed
├── nrpe-external-master-relation-broken
├── nrpe-external-master-relation-changed
├── nrpe-external-master-relation-departed
├── nrpe-external-master-relation-joined
├── start
├── stop
├── update-status
├── upgrade-charm
├── website-relation-broken
├── website-relation-changed
├── website-relation-departed
└── website-relation-joined
</code></pre></div>
<p>Many charms are still written by hand in this fashion, as it&rsquo;s quite easy to do. In most cases, all code lives in, for instance, a <code>hooks.py</code> file with all hook files being symlinks to that. Pertinent functions are run through the use of <code>@hook</code> decorators, such as <code>@hook('config-changed')</code>.</p>
<p>Although you can always write charms more directly like this, one winds up writing a lot of boilerplate code. If you&rsquo;ve written charms before, you&rsquo;ll be well versed in this, and if you haven&rsquo;t, you may find yourself stealing from other charmers more often than not.</p>
<p>In the spirit of Don&rsquo;t Repeat Yourself, there&rsquo;s another way of writing charms: layers.</p>
<p>Layers are composable packages that allow one to include functionality in the final charm without having to write it yourself. They&rsquo;re the libraries that the charm ecosystem really needed. As yet, they only exist for python charms, but as we&rsquo;re charming up python applications, we should be good to go in using them!</p>
<p>So what can one do with layers? Well, quite a bit. Say one needs to install some software on installation - Honeycomb requires the use of <code>pandoc</code>, for instance, which allows writers to upload many different file types - in which case one require the <code>apt</code> layer, which will allow one to specify in one&rsquo;s layer configuration what one expects to have installed on the machine by the time we get to running our service. Similarly, we may want to use a git layer which will fetch our website repository as specified in a configuration and use that to deploy our application.</p>
<p><em>Hooks</em> respond to what is happening in the juju environment and are the basis of how charms work, while <em>layers</em> compose oft-repeated bits of functionality into a charm and are the basis of making it easier to conceptualize and compartmentalize different actions that a charm may make.</p>
<p>Sort of. For the most part. Ish.</p>
<p>Layers also introduce a bit of complexity in that they offer hook-like functionality through a state mechanism. For instance, an apache layer may have a state <code>apache.available</code> that is set when Apache is up and running and ready to serve your page. That layer may call <code>set_state('apache.available')</code>, which will mean that your charm will get notified through a state change. If you need to do something when Apache is made available, you can set up a function to do so based on a decorator: <code>@when('apache.available')</code>.</p>
<p>You can think of it like so:</p>
<ul>
<li><em>Hooks</em> are fired when something changes in Juju</li>
<li><em>Layers</em> compose repeatable functionality into libraries and set state, and</li>
<li><em>State changes</em> happen when something happens within the charm itself as one of the hooks is called.</li>
</ul>
<p>There&rsquo;s a lot going on here, and I&rsquo;ve already thrown a lot of words at it, with a few more posts to go. I learn best by seeing how things are implemented, though, so let&rsquo;s get onto the charm and see how this all fits together.</p>
<hr />
<h3 id="wsgi-app-as-a-layer"><code>wsgi-app</code> as a layer</h3>
<p>With the steps outlined above, we created a <code>wsgi-app</code> charm, right?</p>
<p>Well, not actually. We created a <code>wsgi-app</code> <em>layer</em>, which can be built into a charm. What we need to do is start working on what the layer will do, so that when we run <code>charm build</code> in a bit, we&rsquo;ll wind up with a complete charm that serves up a WSGI application.</p>
<p>Here&rsquo;s what we need <code>wsgi-app</code> to do:</p>
<ul>
<li>Install some python stuff - we&rsquo;ll need <code>pip</code>, for instance, to grab our frameworks and dependencies</li>
<li>Fetch our source repository and set some configuration values such as our application secret</li>
<li>Expose relation endpoints for:<ul>
<li>a WSGI server such as <code>gunicorn</code> or <code>uwsgi</code></li>
<li>a database such as PostGres or MySQL/MariaDB</li>
<li>ElasticSearch</li>
<li>memcached</li>
<li>Apache for proxying and load balancing</li>
</ul>
</li>
</ul>
<p>Remember, though, that we&rsquo;re going to save relations for a later step, so let&rsquo;s just focus on the first two steps.</p>
<p>For installing stuff, our best bet is to use the <code>apt</code> layer. Remember that layers act as libraries; in this case, we&rsquo;re aiming to install the library that will let us install packages through apt.</p>
<p>This is a fairly simple thing to do, if perhaps a little magical: open <code>layer.yaml</code>; you&rsquo;ll see the boilerplate code, which looks like so:</p>
<div class="codehilite"><pre><span></span><code><span class="nt">includes</span><span class="p">:</span><span class="w"> </span><span class="p p-Indicator">[</span><span class="s">&#39;layer:basic&#39;</span><span class="p p-Indicator">]</span><span class="w"> </span><span class="c1"># if you have any interfaces, add them here</span><span class="w"></span>
</code></pre></div>
<p>Adding a layer is as simple as adding it to that list. Add <code>layer:apt</code> so that you wind up with the following YAML file:</p>
<div class="codehilite"><pre><span></span><code><span class="nt">includes</span><span class="p">:</span><span class="w"></span>
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">layer:basic</span><span class="w"></span>
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">layer:apt</span><span class="w"></span>
</code></pre></div>
<p>Good! That was easy! Of course, we can also tell the apt layer what to install here rather than doing so programmatically (such as <code>pip</code>, perhaps even more down the line), so our <code>layer.yaml</code> will look like the following:</p>
<div class="codehilite"><pre><span></span><code><span class="nt">includes</span><span class="p">:</span><span class="w"></span>
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">layer:basic</span><span class="w"></span>
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">layer:apt</span><span class="w"></span>
<span class="nt">options</span><span class="p">:</span><span class="w"></span>
<span class="w"> </span><span class="nt">apt</span><span class="p">:</span><span class="w"></span>
<span class="w"> </span><span class="nt">packages</span><span class="p">:</span><span class="w"></span>
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">python-pip</span><span class="w"></span>
</code></pre></div>
<p>Now we can start testing things out, though lets stick with just the build step for now. When we run <code>charm build</code>, our layers will be composed together and hopefully we&rsquo;ll wind up with a built charm in our build dir!</p>
<div class="codehilite"><pre><span></span><code>makyo@corrin:~/work/charms/layers/wsgi-app$ charm build
build: Composing into /home/makyo/work/charms
build: Destination charm directory: /home/makyo/work/charms/trusty/wsgi-app
fatal: Not a git repository <span class="o">(</span>or any of the parent directories<span class="o">)</span>: .git
bzr: ERROR: Not a branch: <span class="s2">&quot;/home/makyo/work/charms/layers/wsgi-app/&quot;</span>.
build: Please add a <span class="sb">`</span>repo<span class="sb">`</span> key to your layer.yaml, with a url from which your layer can be cloned.
build: Processing layer: layer:basic
build: Processing layer: layer:apt
build: Processing layer: wsgi-app
</code></pre></div>
<p>Well that looks&hellip;promising! There&rsquo;s a lot of green, at least. There&rsquo;s a few warnings we can address, though. I hadn&rsquo;t initialized the charm as a git repo yet, because it was created through <code>charm create</code>, so let&rsquo;s do that now:</p>
<div class="codehilite"><pre><span></span><code>makyo@corrin:~/work/charms/layers/wsgi-app$ git init .
Initialized empty Git repository <span class="k">in</span> /home/makyo/work/charms/layers/wsgi-app/.git/
makyo@corrin:~/work/charms/layers/wsgi-app$ git remote add origin git@github.com:makyo/wsgi-app.git
makyo@corrin:~/work/charms/layers/wsgi-app$ git pull origin master
remote: Counting objects: <span class="m">5</span>, <span class="k">done</span>.
remote: Compressing objects: <span class="m">100</span>% <span class="o">(</span><span class="m">4</span>/4<span class="o">)</span>, <span class="k">done</span>.
remote: Total <span class="m">5</span> <span class="o">(</span>delta <span class="m">0</span><span class="o">)</span>, reused <span class="m">0</span> <span class="o">(</span>delta <span class="m">0</span><span class="o">)</span>, pack-reused <span class="m">0</span>
Unpacking objects: <span class="m">100</span>% <span class="o">(</span><span class="m">5</span>/5<span class="o">)</span>, <span class="k">done</span>.
From github.com:makyo/wsgi-app
* branch master -&gt; FETCH_HEAD
* <span class="o">[</span>new branch<span class="o">]</span> master -&gt; origin/master
makyo@corrin:~/work/charms/layers/wsgi-app$ mv README.ex README.md
</code></pre></div>
<p>And update our <code>layers.yaml</code> to add the repo key as suggested:</p>
<div class="codehilite"><pre><span></span><code><span class="nt">includes</span><span class="p">:</span><span class="w"></span>
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">layer:basic</span><span class="w"></span>
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">layer:apt</span><span class="w"></span>
<span class="nt">repo</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">https://github.com/makyo/wsgi-app.git</span><span class="w"></span>
<span class="nt">options</span><span class="p">:</span><span class="w"></span>
<span class="w"> </span><span class="nt">apt</span><span class="p">:</span><span class="w"></span>
<span class="w"> </span><span class="nt">packages</span><span class="p">:</span><span class="w"></span>
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">python-pip</span><span class="w"></span>
</code></pre></div>
<p>Now, when we run <code>charm build</code>, we should get a cleaner result:</p>
<div class="codehilite"><pre><span></span><code>makyo@corrin:~/work/charms/layers/wsgi-app$ charm build
build: Composing into /home/makyo/work/charms
build: Destination charm directory: /home/makyo/work/charms/trusty/wsgi-app
build: Processing layer: layer:basic
build: Processing layer: layer:apt
build: Processing layer: wsgi-app
</code></pre></div>
<p>Perfect! We&rsquo;re on a roll.</p>
<p>Our next step will be to clean up some of the code created by bootstrap. For starters, we can make <code>metadata.yaml</code> agree with reality as best we can for now - we&rsquo;ll leave the relations section as is until we get to that point - and to specify which series we want the charm to support (trusty and xenial, in our case):</p>
<div class="codehilite"><pre><span></span><code><span class="nt">name</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">wsgi-app</span><span class="w"></span>
<span class="nt">summary</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">charm for running any WSGI application</span><span class="w"></span>
<span class="nt">maintainer</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">Madison Scott-Clary &lt;Madison.Scott-Clary@canonical.com&gt;</span><span class="w"></span>
<span class="nt">description</span><span class="p">:</span><span class="w"> </span><span class="p p-Indicator">|</span><span class="w"></span>
<span class="w"> </span><span class="no">WSGI applications such as Django or Flask applications are web applications</span><span class="w"></span>
<span class="w"> </span><span class="no">written in python. This charm allows those applications to talk to a</span><span class="w"></span>
<span class="w"> </span><span class="no">database, a web server, a search engine, and a cache.</span><span class="w"></span>
<span class="nt">tags</span><span class="p">:</span><span class="w"></span>
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">misc</span><span class="w"></span>
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">cms</span><span class="w"></span>
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">app-servers</span><span class="w"></span>
<span class="nt">series</span><span class="p">:</span><span class="w"></span>
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">trusty</span><span class="w"></span>
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">xenial</span><span class="w"></span>
<span class="nt">subordinate</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">false</span><span class="w"></span>
<span class="nt">provides</span><span class="p">:</span><span class="w"></span>
<span class="w"> </span><span class="nt">provides-relation</span><span class="p">:</span><span class="w"></span>
<span class="w"> </span><span class="nt">interface</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">interface-name</span><span class="w"></span>
<span class="nt">requires</span><span class="p">:</span><span class="w"></span>
<span class="w"> </span><span class="nt">requires-relation</span><span class="p">:</span><span class="w"></span>
<span class="w"> </span><span class="nt">interface</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">interface-name</span><span class="w"></span>
<span class="nt">peers</span><span class="p">:</span><span class="w"></span>
<span class="w"> </span><span class="nt">peer-relation</span><span class="p">:</span><span class="w"></span>
<span class="w"> </span><span class="nt">interface</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">interface-name</span><span class="w"></span>
</code></pre></div>
<p>We&rsquo;ll also need to update <code>config.yaml</code> for some configuration settings that <code>layer:apt</code> requires, and to get rid of the placeholders. Our resulting file should look like this:</p>
<div class="codehilite"><pre><span></span><code><span class="nt">options</span><span class="p">:</span><span class="w"></span>
<span class="w"> </span><span class="nt">install_sources</span><span class="p">:</span><span class="w"></span>
<span class="w"> </span><span class="nt">type</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">string</span><span class="w"></span>
<span class="w"> </span><span class="nt">default</span><span class="p">:</span><span class="w"> </span><span class="s">&#39;&#39;</span><span class="w"></span>
<span class="w"> </span><span class="nt">description</span><span class="p">:</span><span class="w"> </span><span class="p p-Indicator">|</span><span class="w"></span>
<span class="w"> </span><span class="no">Any additional sources (such as PPAs) from which to install packages</span><span class="w"></span>
<span class="w"> </span><span class="nt">install_keys</span><span class="p">:</span><span class="w"></span>
<span class="w"> </span><span class="nt">type</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">string</span><span class="w"></span>
<span class="w"> </span><span class="nt">default</span><span class="p">:</span><span class="w"> </span><span class="s">&#39;&#39;</span><span class="w"></span>
<span class="w"> </span><span class="nt">description</span><span class="p">:</span><span class="w"> </span><span class="p p-Indicator">|</span><span class="w"></span>
<span class="w"> </span><span class="no">Any additional GPG keys required for sources added by install_sources</span><span class="w"></span>
<span class="w"> </span><span class="nt">extra_packages</span><span class="p">:</span><span class="w"></span>
<span class="w"> </span><span class="nt">type</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">string</span><span class="w"></span>
<span class="w"> </span><span class="nt">default</span><span class="p">:</span><span class="w"> </span><span class="s">&#39;&#39;</span><span class="w"></span>
<span class="w"> </span><span class="nt">description</span><span class="p">:</span><span class="w"> </span><span class="p p-Indicator">|</span><span class="w"></span>
<span class="w"> </span><span class="no">Any additional packages to install on the charm&#39;s machine</span><span class="w"></span>
</code></pre></div>
<p>Again, while we might come up with more configuration values in the future, this will do for now. Running <code>charm build</code> again gives us another successful output, though it&rsquo;s worth noting that, since we changed the charm from a single series to a multi-series charm, it is now built into <code>$JUJU_REPOSITORY/builds</code>.</p>
<hr />
<p>It&rsquo;s getting late and that was a lot of information to dump, so I&rsquo;ll pause here for now. We still have a ways to go - I&rsquo;ve got at least three future posts lined up for this project - but we&rsquo;re getting closer with each step. We&rsquo;ve started work on our <code>wsgi-app</code> layer, which, when built, produces a functional skeleton of the charm we eventually want.</p>
<p>Here are some resources for the time being:</p>
<ul>
<li><a href="https://github.com/makyo/wsgi-app/tree/710b7efe21440e49b78cb99f2f4d7b83feff938a">Source code for the <code>wsgi-app</code> layer</a> as it was at the point reached at the end of this article.</li>
<li><a href="https://jujucharms.com/docs/stable/developer-layers">Documentation on charm layers</a></li>
<li><a href="http://interfaces.juju.solutions">List of charm layers and interfaces</a></li>
<li><a href="https://jujucharms.com/docs/stable/reference-charm-hooks">Documentation on charm hooks</a></li>
</ul>
<hr />
<div class="footnote">
<hr />
<ol>
<li id="fn:disclaimer">
<p>As always, views are my own, not my employer&rsquo;s.&#160;<a class="footnote-backref" href="#fnref:disclaimer" title="Jump back to footnote 1 in the text">&#8617;</a></p>
</li>
<li id="fn:furries-tech">
<p>Seriously. After students (54%), nearly 10% of furries are employed in the tech industry, making it the most common occupation within the subculture. (The Furry Poll, conducted March-December 2015, <em>n=11831</em>)&#160;<a class="footnote-backref" href="#fnref:furries-tech" title="Jump back to footnote 2 in the text">&#8617;</a></p>
</li>
<li id="fn:rr-diagrams">
<p>Credit where it&rsquo;s due, railroad diagrams created with the help of <a href="http://bottlecaps.de/rr/ui">this tool</a> by Gunther Rademacher.&#160;<a class="footnote-backref" href="#fnref:rr-diagrams" title="Jump back to footnote 3 in the text">&#8617;</a></p>
</li>
</ol>
</div>
</article>
<footer>
<p>Page generated on 2024-05-04</p>
</footer>
</main>
<script type="text/javascript">
document.querySelectorAll('.tag').forEach(tag => {
let text = tag.innerText;
tag.innerText = '';
tag.innerHTML = `<a href="/tags.html#${text}">${text}</a>`;
});
</script>
</body>
</html>