<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.9.0">Jekyll</generator><link href="https://xkortex.github.io/feed.xml" rel="self" type="application/atom+xml" /><link href="https://xkortex.github.io/" rel="alternate" type="text/html" /><updated>2021-10-08T15:23:02+00:00</updated><id>https://xkortex.github.io/feed.xml</id><title type="html">Michael McDermott</title><subtitle>Developer, Engineer, McGyver</subtitle><entry><title type="html">The Noble Python Eightfold Path</title><link href="https://xkortex.github.io/noble8/" rel="alternate" type="text/html" title="The Noble Python Eightfold Path" /><published>2021-10-08T00:00:00+00:00</published><updated>2021-10-08T00:00:00+00:00</updated><id>https://xkortex.github.io/noble8</id><content type="html" xml:base="https://xkortex.github.io/noble8/">&lt;h4 id=&quot;the-way-to-python-nirvana-is-through-proper-isolation&quot;&gt;The way to Python Nirvana is through proper isolation.&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Subtext: do not mind the pseudo-spiritual undertones. Take it with a grain of salt - I’m doing a bit.&lt;/em&gt;&lt;/p&gt;

&lt;h1 id=&quot;the-four-noble-truths&quot;&gt;The Four Noble Truths&lt;/h1&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;Python package and environment management has inevitable suffering&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;There is a cause to our suffering - entangement of environments&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;There is an end to our suffering - isolate python environments&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;The Python Eightfold Path is the way to end suffering and achieve Python Nirvana&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;the-eightfold-path&quot;&gt;The Eightfold Path&lt;/h1&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Right Version&lt;/strong&gt; - Use the python version that works for you. For some, this may be the bleeding edge, others 
 may want to hold back for stability and library availability. Avoid python2, for it is the past. Python3 
 is the present and the future.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Right Installation&lt;/strong&gt; - Use &lt;a href=&quot;https://github.com/pyenv/pyenv&quot;&gt;pyenv&lt;/a&gt; to manage your python installations. 
 Avoid using system or package-manager-installed python for development. 
Use &lt;a href=&quot;https://github.com/pypa/pipx&quot;&gt;pipx&lt;/a&gt; to install 
stand-alone tools and utilities such as poetry, black, mypy, virtualenvwrapper, etc.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Right Environment&lt;/strong&gt; - Always use an isolated environment, be it virtualenv, conda, poetry env, 
 &lt;a href=&quot;https://www.python.org/dev/peps/pep-0582/&quot;&gt;PEP-582&lt;/a&gt;, or containers†. 
 Avoid using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pip install --user&lt;/code&gt; (unless to install &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pipx&lt;/code&gt;). 
 &lt;strong&gt;Never&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sudo pip install&lt;/code&gt;. Ever. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sudo pip&lt;/code&gt; is the way to eternal suffering.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Right Isolation&lt;/strong&gt; - &lt;em&gt;Keep&lt;/em&gt; your environments isolated. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LD_LIBRARY_PATH&lt;/code&gt; is a 
 necessary evil at times (typically some GPU libraries), but beyond that, keep your environment self-contained. 
Editable installs are a double-edged sword, they are incredibly useful, and you 
&lt;em&gt;should&lt;/em&gt; use them, but be aware that they may complicate your environment. Learn to use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sys.path&lt;/code&gt; to track 
down sources.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Right Structure&lt;/strong&gt; - Use installable packages, rather than stand alone &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.py&lt;/code&gt; scripts. Use modules, with a 
 folder structure that matches the import namespace. Leverage &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;python -m modulename&lt;/code&gt;, 
&lt;a href=&quot;https://packaging.python.org/specifications/entry-points/&quot;&gt;entry points&lt;/a&gt;, and 
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;__main__.py&lt;/code&gt;&lt;a href=&quot;https://docs.python.org/3/library/__main__.html&quot;&gt;files&lt;/a&gt;. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PYTHONPATH&lt;/code&gt; is often a code smell.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Right Tooling&lt;/strong&gt; - Python has a rich ecosystem of tools for packaging, building, publishing, formatting, 
 linting, style enforcement, and type checking. Discover them and take advantage of the ones that 
work with your philosophy.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Right Dependencies - Python is well-known for its batteries-included standard library, and sprawling expanse
 of open-source libraries. However, every dependency is a liability, and managing dependency versions is 
an art. Poetry and pipenv are helpful for keeping the dependency graph of applications consistent. 
Use lockfiles for applications, but not libraries.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Right Testing - Exercising your code in a variety of environments is the key to robustness. Your code should not 
 care what current working directory it is run from, if it does, revisit structure. If you are writing a library, 
test with a matrix of python versions, operating systems, and architectures.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;-which-isolation-method-should-i-use&quot;&gt;† Which isolation method should I use?&lt;/h4&gt;
&lt;p&gt;This is a matter of personal preference. Some argue that &lt;a href=&quot;https://frostming.com/2021/01-22/introducing-pdm/&quot;&gt;you don’t really need a virtualenv&lt;/a&gt;,
however they may reconsider when each repository wants its own multi-gigabyte machine learning stack. PDM purports to 
avoid “nested venvs”, however &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pipx&lt;/code&gt; does an even better job at this, by allowing python utilities to be 
installed user-wide or system-wide. &lt;br /&gt;
Personally, I use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pipx&lt;/code&gt; to manage all my CLI tools (poetry, black, virtualenvwrapper), 
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;poetry&lt;/code&gt; for dependency management, and put everything else in virtualenvs based on a pyenv-installed python.
Sometimes I use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;brew&lt;/code&gt;, but it tends to automatically change python versions on me unexpectedly. 
Some folks swear by anaconda, I swear at it. I use docker heavily for application deployment, but I prefer 
developing locally in a virtualenv, it’s just easier and less messy to work with Pycharm and Jupyter. But 
some folks only like to develop in containers. The point is, I can’t tell you the best isolation technique,
you must discover that for yourself.&lt;/p&gt;</content><author><name></name></author><category term="python" /><category term="pip" /><category term="virtualenv" /><category term="version" /><category term="package" /><summary type="html">The way to Python Nirvana is through proper isolation.</summary></entry><entry><title type="html">Perils of Pip Pinning in Production</title><link href="https://xkortex.github.io/pippinperil/" rel="alternate" type="text/html" title="Perils of Pip Pinning in Production" /><published>2020-01-30T00:00:00+00:00</published><updated>2020-01-30T00:00:00+00:00</updated><id>https://xkortex.github.io/pippinperil</id><content type="html" xml:base="https://xkortex.github.io/pippinperil/">&lt;h1 id=&quot;just-pip-freeze-it-bro&quot;&gt;just pip freeze it, bro&lt;/h1&gt;

&lt;p&gt;Tell me if this sounds familiar. You have your python project, and you want to make
it ready for production/deployment/tech transfer. It’s been sitting on your system
for a few months and now you have to get your 
coworker/devops/that-one-dude-obsessed-with-docker to build your project, reliably 
from scratch. You say, I know, I’ll just &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pip freeze &amp;gt; requirements.txt&lt;/code&gt; and then
the install script can just &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pip install -r requirements.txt&lt;/code&gt; and you’re golden!
Right?&lt;/p&gt;

&lt;p&gt;What could &lt;em&gt;possibly&lt;/em&gt; go wrong?&lt;/p&gt;

&lt;p&gt;Well, you’ll likely be able to restore that state exactly. Exact same python, 
exact same packages.&lt;/p&gt;

&lt;h1 id=&quot;overconstrained&quot;&gt;overconstrained&lt;/h1&gt;

&lt;p&gt;The first problem is the way pip freeze expresses its state. Your pip freeze 
looks something like this:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;language-.env&quot;&gt;absl-py==0.9.0
attrs==19.3.0
...
urllib3==1.25.7
Werkzeug==0.16.0
wrapt==1.10.11
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;It lists every single dependency, however important or unimportant, pinned to the 
most minute version. A snapshot frozen in time. However, the world around us is 
not static. Libraries update, sometimes for critical security reasons.
You may want to add more dependencies. 
Eventually, the time comes where you want or need to modify the dependencies. 
You go to pip install it and…everything breaks.&lt;/p&gt;

&lt;h1 id=&quot;a-better-way&quot;&gt;A better way&lt;/h1&gt;

&lt;p&gt;Let your dependencies breathe. This is more art than science, but try to give 
a library version degrees of freedom proportional to how much you “trust”
that library. By that, I mean how committed is the development team to 
using semver properly, how (un)likely are they to push a breaking change 
without bumping the appropriate version part. Numpy is old, stable, 
out of &lt;a href=&quot;https://0ver.org/&quot;&gt;zerover&lt;/a&gt;, used by thousands, and gives long 
lead times on warnings about deprecation. I use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numpy &amp;gt;= 1.21, &amp;lt;2.0&lt;/code&gt;
(&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numpy = ^1.21&lt;/code&gt; in poetry notation). Scikit-learn, on the other hand, 
I usually pin to the minor version, because they have broken internal interfaces
on me in the past. Normally, consumers should not care about private interfaces, 
however the &lt;a href=&quot;https://scikit-learn.org/stable/modules/model_persistence.html&quot;&gt;scikit-prescribed way to save models is to use pickle&lt;/a&gt;.
This means in practice, changing scikit’s version breaks your data science team’s
workflow.&lt;/p&gt;

&lt;h1 id=&quot;the-future&quot;&gt;The future&lt;/h1&gt;

&lt;p&gt;As of the past four months, I’ve started leaning heavily into &lt;a href=&quot;https://python-poetry.org/&quot;&gt;poetry&lt;/a&gt;. 
It’s not without its bugs, but it’s by and large stable. The CLI UX is fresh and intuitive,
and it provides all kinds of useful subcommands to facilitate versioning, building, and publishing.
The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pyproject.toml&lt;/code&gt; format is definitely the future of python install configuration (goodbye, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setup.py&lt;/code&gt;!)
and provides a one-stop shop for configuring development tooling (except for &lt;a href=&quot;https://github.com/PyCQA/flake8/issues/234&quot;&gt;flake8&lt;/a&gt; ).
While the solver introduces its own learning curve, it’s well and beyond a better experience overall 
for avoiding dependency hell compared to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;requirements.txt&lt;/code&gt;.&lt;/p&gt;</content><author><name></name></author><category term="python" /><category term="pip" /><category term="version" /><category term="semver" /><category term="dependency" /><summary type="html">just pip freeze it, bro</summary></entry><entry><title type="html">CUDA and SM architecture compatibility</title><link href="https://xkortex.github.io/cudachart/" rel="alternate" type="text/html" title="CUDA and SM architecture compatibility" /><published>2020-01-29T00:00:00+00:00</published><updated>2020-01-29T00:00:00+00:00</updated><id>https://xkortex.github.io/cudachart</id><content type="html" xml:base="https://xkortex.github.io/cudachart/">&lt;h1 id=&quot;cuda-architecture-funtimes&quot;&gt;CUDA architecture funtimes&lt;/h1&gt;

&lt;p&gt;First, read this: 
&lt;a href=&quot;https://arnon.dk/matching-sm-architectures-arch-and-gencode-for-various-nvidia-cards/&quot;&gt;Matching SM architectures (CUDA arch and CUDA gencode) for various NVIDIA cards&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Condensed here:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Gen&lt;/th&gt;
      &lt;th&gt;Year&lt;/th&gt;
      &lt;th&gt;CUDA Min-Max&lt;/th&gt;
      &lt;th&gt;SM/Compute Arch&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Tesla&lt;/td&gt;
      &lt;td&gt;2006&lt;/td&gt;
      &lt;td&gt;?&lt;/td&gt;
      &lt;td&gt;?&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Fermi&lt;/td&gt;
      &lt;td&gt;2010-04&lt;/td&gt;
      &lt;td&gt;3.2-8&lt;/td&gt;
      &lt;td&gt;20&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Kepler&lt;/td&gt;
      &lt;td&gt;2012-04&lt;/td&gt;
      &lt;td&gt;5-&lt;/td&gt;
      &lt;td&gt;30, 35, 37&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Maxwell&lt;/td&gt;
      &lt;td&gt;2014-02&lt;/td&gt;
      &lt;td&gt;6-&lt;/td&gt;
      &lt;td&gt;50, 52, 53&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Pascal&lt;/td&gt;
      &lt;td&gt;2016-04&lt;/td&gt;
      &lt;td&gt;8-&lt;/td&gt;
      &lt;td&gt;60, 61, 62&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Volta&lt;/td&gt;
      &lt;td&gt;2017-12&lt;/td&gt;
      &lt;td&gt;9-&lt;/td&gt;
      &lt;td&gt;70, 72&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Turing&lt;/td&gt;
      &lt;td&gt;2018-09&lt;/td&gt;
      &lt;td&gt;10-&lt;/td&gt;
      &lt;td&gt;75&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Ampere&lt;/td&gt;
      &lt;td&gt;2020?&lt;/td&gt;
      &lt;td&gt;11-&lt;/td&gt;
      &lt;td&gt;80&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Hopper&lt;/td&gt;
      &lt;td&gt;?&lt;/td&gt;
      &lt;td&gt;12?&lt;/td&gt;
      &lt;td&gt;?&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;a href=&quot;https://docs.nvidia.com/deploy/cuda-compatibility/index.html&quot;&gt;CUDA Compatibility&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Captured here, refer to the link for updates:&lt;/p&gt;

&lt;h3 id=&quot;cuda-toolkit-and-compatible-driver-versions&quot;&gt;CUDA Toolkit and Compatible Driver Versions&lt;/h3&gt;
&lt;p&gt;| CUDA Toolkit          | Linux x86_64 Driver Version |
|———————–|—————————–|
| CUDA 10.2 (10.2.89)   | &amp;gt;= 440.33                   |
| CUDA 10.1 (10.1.105)  | &amp;gt;= 418.39                   |
| CUDA 10.0 (10.0.130)  | &amp;gt;= 410.48                   |
| CUDA 9.2 (9.2.88)     | &amp;gt;= 396.26                   |
| CUDA 9.1 (9.1.85)     | &amp;gt;= 390.46                   |
| CUDA 9.0 (9.0.76)     | &amp;gt;= 384.81                   |
| CUDA 8.0 (8.0.61 GA2) | &amp;gt;= 375.26                   |
| CUDA 8.0 (8.0.44)     | &amp;gt;= 367.48                   |
| CUDA 7.5 (7.5.16)     | &amp;gt;= 352.31                   |
| CUDA 7.0 (7.0.28)     | &amp;gt;= 346.46                   |&lt;/p&gt;</content><author><name></name></author><category term="cuda" /><category term="nvidia" /><category term="sm" /><category term="architecture" /><category term="caffe" /><category term="tensorflow" /><category term="pytorch" /><summary type="html">CUDA architecture funtimes</summary></entry><entry><title type="html">App Containerization Style Guide</title><link href="https://xkortex.github.io/dockerappstyle/" rel="alternate" type="text/html" title="App Containerization Style Guide" /><published>2019-12-19T00:00:00+00:00</published><updated>2019-12-19T00:00:00+00:00</updated><id>https://xkortex.github.io/dockerappstyle</id><content type="html" xml:base="https://xkortex.github.io/dockerappstyle/">&lt;h4 id=&quot;this-will-be-a-work-in-progress-for-some-time&quot;&gt;This will be a work in progress for some time&lt;/h4&gt;

&lt;h3 id=&quot;containerized-app-dos&quot;&gt;Containerized App Do’s&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Use config management with sane defaults to minimize what needs to be passed to 
env/entrypoint&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;dockerfile-donts&quot;&gt;Dockerfile Don’t’s&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;are making an interactive/dev container)&lt;/li&gt;
&lt;/ul&gt;</content><author><name></name></author><category term="path" /><category term="environment" /><category term="docker" /><category term="container" /><category term="app" /><category term="dockerdecember" /><summary type="html">This will be a work in progress for some time</summary></entry><entry><title type="html">dockerfile style guide</title><link href="https://xkortex.github.io/dockerstyle/" rel="alternate" type="text/html" title="dockerfile style guide" /><published>2019-12-18T00:00:00+00:00</published><updated>2019-12-18T00:00:00+00:00</updated><id>https://xkortex.github.io/dockerstyle</id><content type="html" xml:base="https://xkortex.github.io/dockerstyle/">&lt;h1 id=&quot;dockerfile-style-guide&quot;&gt;dockerfile style guide&lt;/h1&gt;

&lt;h4 id=&quot;this-will-be-a-work-in-progress-for-some-time&quot;&gt;This will be a work in progress for some time&lt;/h4&gt;

&lt;h3 id=&quot;dockerfile-dos&quot;&gt;Dockerfile Do’s&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Follow the official &lt;a href=&quot;https://docs.docker.com/develop/develop-images/dockerfile_best-practices/&quot;&gt;best practices&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Use staged builds&lt;/li&gt;
  &lt;li&gt;One line per target/arg on provisioning commands (apt, pip, cmake)&lt;/li&gt;
  &lt;li&gt;Avoid cache cruft with installers (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rm -rf /var/lib/apt/lists/*&lt;/code&gt; for apt, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--no-cache-dir&lt;/code&gt; for pip)&lt;/li&gt;
  &lt;li&gt;Use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.dockerignore&lt;/code&gt; and limit size of your docker context (I could do an entire post on this)&lt;/li&gt;
  &lt;li&gt;Use &lt;a href=&quot;https://github.com/krallin/tini&quot;&gt;tini&lt;/a&gt; instead of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;bash&lt;/code&gt; for entrypoints&lt;/li&gt;
  &lt;li&gt;Mount large assets (models, databases) rather than include in the image&lt;/li&gt;
  &lt;li&gt;Split long lines with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;\ &lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;dockerfile-donts&quot;&gt;Dockerfile Don’t’s&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Put source code and build artifacts in the same parent dir&lt;/li&gt;
  &lt;li&gt;Separate operations that add files and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rm&lt;/code&gt; into separate &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;RUN&lt;/code&gt; directives. 
This creates bloat due to the way overlayfs works&lt;/li&gt;
  &lt;li&gt;Use command-line flags in entrypoint for anything which might vary between deploys&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;interactive-container-dockerfile-donts&quot;&gt;Interactive Container Dockerfile Don’t’s&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Don’t put anything in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/root&lt;/code&gt; (or whatever is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$HOME&lt;/code&gt; for app user) you are not willing 
  to mount-over
    &lt;ul&gt;
      &lt;li&gt;this facilitates things like mounting your &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$HOME&lt;/code&gt; into a named volume for persistence&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;exceptions&quot;&gt;Exceptions&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;Generally avoid adding any large assets to the image directly. However, if you do not
control the deployment of the image, it may be adviseable to include these in your
production image. If you do so, put them &lt;em&gt;before&lt;/em&gt; any steps which copy in code that 
changes frequently&lt;/li&gt;
  &lt;li&gt;Use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pip install -e&lt;/code&gt; (unless you are making an interactive/dev container)&lt;/li&gt;
&lt;/ul&gt;</content><author><name></name></author><category term="docker" /><category term="container" /><category term="dockerfile" /><category term="dockerdecember" /><summary type="html">dockerfile style guide</summary></entry><entry><title type="html">Environment Patterns</title><link href="https://xkortex.github.io/environ/" rel="alternate" type="text/html" title="Environment Patterns" /><published>2019-12-17T00:00:00+00:00</published><updated>2019-12-17T00:00:00+00:00</updated><id>https://xkortex.github.io/environ</id><content type="html" xml:base="https://xkortex.github.io/environ/">&lt;h1 id=&quot;env&quot;&gt;env&lt;/h1&gt;
&lt;p&gt;Oh, the environment. No, I’m not talking about the biosphere that we humans are 
trashing with wanton disregard. I’m talking about the 
&lt;a href=&quot;https://en.wikipedia.org/wiki/Operating_environment&quot;&gt;operating environment&lt;/a&gt;,
specifically with &lt;a href=&quot;https://en.wikipedia.org/wiki/Environment_variable&quot;&gt;environment variables&lt;/a&gt;,
that we developers are trashing with wanton disregard. Kidding. Mostly.&lt;/p&gt;

&lt;p&gt;The env is essentialy a giant global kv namespace where devs/programs can stuff a bunch of
configuration. &lt;a href=&quot;https://12factor.net/config&quot;&gt;12-Factor design recommends using env for config&lt;/a&gt;,
however I personally do not like their choice of words for “config” here, which they 
define as&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;An app’s &lt;em&gt;config&lt;/em&gt; is everything that is likely to vary between &lt;strong&gt;deploys&lt;/strong&gt;.
&lt;br /&gt;… &lt;br /&gt; 
Note that this definition of “config” does not include internal application config, 
such as config/routes.rb in Rails, or how code modules are connected in Spring. This 
type of config does not vary between deploys, and so is best done in the code.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;and&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;A &lt;em&gt;deploy&lt;/em&gt; is a running instance of the app.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Maybe there is some sort of litmus test for whether something is config or not?&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;A litmus test for whether an app has all config correctly factored out of the
 code is whether the codebase could be made open source at any moment, without 
 compromising any credentials.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So config is basically just secrets and site-specific domains/IPs? Still clear as mud.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Apps sometimes store config as constants in the code&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Uhh, yeah. Apps (in particular in my field of computer vision) usually require all 
kinds of static configuration which isn’t &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;code&lt;/code&gt; in the strict sense, but is nonetheless
essential for the correct functioning of the app. Things like paths to assets, 
hyperparameters, topic names, and packaging metadata, to name a few. 
Colloquially, these types of files are often referred to as “config”. And these are all
things you &lt;em&gt;definitely&lt;/em&gt; want in VCS. It’s pretty silly to take a very broad&lt;/p&gt;

&lt;p&gt;Looking at the 12F definition of codebase gives a bit more insight into
intent of these statements. What I read into the philosophy is that here, “config” is 
not the same as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;repo/config/my_app_config_file.yml&lt;/code&gt;. “config” is what I am going to 
henceforth call &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;runconfig&lt;/code&gt;. As in, the things that vary only between runtimes.&lt;/p&gt;

&lt;p&gt;It’s nearly 2020, everyone and their dog knows you should always use sane defaults. 
&lt;a href=&quot;https://github.com/spf13/viper&quot;&gt;Viper&lt;/a&gt; perfectly illustrates how configuration ought 
to be done.&lt;/p&gt;

&lt;p&gt;1) You have a certain amount of static configuration which lives entirely in code as a 
config file
2) You allow the user/deploy to specify an additional config file, which takes precedence
over the primary config (1)
3) The app reads in env variables and overrides (1) and (2)&lt;/p&gt;

&lt;h1 id=&quot;one-more-thing&quot;&gt;one more thing&lt;/h1&gt;

&lt;p&gt;Speaking of env, setting debug levels by command line flags is &lt;em&gt;so&lt;/em&gt; last 
 century. Actually Viper/12F suggests &lt;em&gt;anything&lt;/em&gt; you could set by CLI should also be 
 available as config file path and pass in through env.&lt;/p&gt;</content><author><name></name></author><category term="path" /><category term="environment" /><category term="docker" /><category term="container" /><summary type="html">env Oh, the environment. No, I’m not talking about the biosphere that we humans are trashing with wanton disregard. I’m talking about the operating environment, specifically with environment variables, that we developers are trashing with wanton disregard. Kidding. Mostly.</summary></entry><entry><title type="html">App Containerization Style Guide</title><link href="https://xkortex.github.io/dockerdecember/" rel="alternate" type="text/html" title="App Containerization Style Guide" /><published>2019-12-15T00:00:00+00:00</published><updated>2019-12-15T00:00:00+00:00</updated><id>https://xkortex.github.io/dockerdecember</id><content type="html" xml:base="https://xkortex.github.io/dockerdecember/">&lt;p&gt;It’s #dockerdecember! Ok, I completely just made that up. I shall be putting together
a series of blogs covering all sorts of fun things I’ve learned (often the hard way)
about docker, containerization, and microservices.&lt;/p&gt;

&lt;p&gt;It’s also going to likely be updated periodically in bits and pieces as I am mostly 
writing this while &lt;a href=&quot;https://xkcd.com/303/&quot;&gt;waiting for images to build&lt;/a&gt;.&lt;/p&gt;</content><author><name></name></author><category term="path" /><category term="environment" /><category term="docker" /><category term="container" /><category term="app" /><category term="dockerdecember" /><summary type="html">It’s #dockerdecember! Ok, I completely just made that up. I shall be putting together a series of blogs covering all sorts of fun things I’ve learned (often the hard way) about docker, containerization, and microservices.</summary></entry><entry><title type="html">xkortex’s github blag</title><link href="https://xkortex.github.io/First/" rel="alternate" type="text/html" title="xkortex’s github blag" /><published>2019-10-28T00:00:00+00:00</published><updated>2019-10-28T00:00:00+00:00</updated><id>https://xkortex.github.io/First</id><content type="html" xml:base="https://xkortex.github.io/First/">&lt;p&gt;Need to keep track of various tricks, hacks, and fixes that I find over time, so 
why not a github blog?&lt;/p&gt;</content><author><name></name></author><category term="highlevel" /><summary type="html">Need to keep track of various tricks, hacks, and fixes that I find over time, so why not a github blog?</summary></entry><entry><title type="html"></title><link href="https://xkortex.github.io/2019-10-28-hax/" rel="alternate" type="text/html" title="" /><published></published><updated></updated><id>https://xkortex.github.io/2019-10-28-hax</id><content type="html" xml:base="https://xkortex.github.io/2019-10-28-hax/">&lt;h1 id=&quot;docker-network-stack-is-a-jerk&quot;&gt;docker network stack is a jerk&lt;/h1&gt;
&lt;p&gt;Was getting segfaults in a containerized camera driver. Could see the camera fine on the
network, and was using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;network_mode: host&lt;/code&gt; in compose.yml. Turns out in my project, 
I had a lingering &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;project_default&lt;/code&gt; docker network. No idea why this was causing havoc, 
but &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;docker network rm project_default&lt;/code&gt; fixed the problem. It’s not the first time 
I have been bitten by docker network stack weirdness&lt;/p&gt;

&lt;h1 id=&quot;all-executables-passed-to-tini-need-to-be-execd&quot;&gt;All executables passed to tini need to be exec’d&lt;/h1&gt;
&lt;p&gt;SIGTERM was not properly getting passed to aforementioned containerized ROS camera
driver. Tried adding &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tini&lt;/code&gt; to the stack, still no luck, even though my &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;entry.sh&lt;/code&gt;
script used exec on the subsequent launcher script. Well, turns out &lt;em&gt;that&lt;/em&gt; launcher 
script was calling &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;roslaunch&lt;/code&gt;, which is a subprocess. Switching to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;exec roslaunch foo:=bar&lt;/code&gt;
solved the signal transmission and now getting clean teardown, woot!&lt;/p&gt;

&lt;p&gt;Tini in general seems to help with init/teardown of processes.&lt;/p&gt;</content><author><name></name></author></entry><entry><title type="html"></title><link href="https://xkortex.github.io/2019-10-29-homing/" rel="alternate" type="text/html" title="" /><published></published><updated></updated><id>https://xkortex.github.io/2019-10-29-homing</id><content type="html" xml:base="https://xkortex.github.io/2019-10-29-homing/">&lt;h1 id=&quot;homing-pigeon-pattern&quot;&gt;Homing Pigeon Pattern&lt;/h1&gt;
&lt;p&gt;Raise your hand if you have run into the following situation. You have a codebase, 
located in userspace, and you need to load some files from that codebase from a 
bunch of different places. You can’t guarantee the location of that directory across
instances/containers, but you still really want a $REPO_DIR variable you can hit to 
serve as the root of various relative paths.&lt;/p&gt;

&lt;p&gt;There are &lt;em&gt;a lot&lt;/em&gt; of ways to solve this problem. Probably too many. I believe I have 
found, perhaps not the &lt;strong&gt;One True Pattern&lt;/strong&gt;, but at least a &lt;strong&gt;Rather Good Pattern&lt;/strong&gt; 
for dealing with this.&lt;/p&gt;

&lt;h3 id=&quot;put-your-configs-in-config_home&quot;&gt;Put your configs in $CONFIG_HOME&lt;/h3&gt;
&lt;p&gt;It’s basically that simple.&lt;/p&gt;

&lt;p&gt;There are cross-platform libraries (&lt;a href=&quot;https://godoc.org/github.com/Wessie/appdirs&quot;&gt;go&lt;/a&gt;, 
&lt;a href=&quot;https://github.com/ActiveState/appdirs&quot;&gt;python&lt;/a&gt;) 
for what is usually called something like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$CONFIG_HOME&lt;/code&gt;.
On linux, it’s usually at &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$HOME/.config&lt;/code&gt;, and often can be overridden by setting 
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$XDG_CONFIG_HOME&lt;/code&gt;. I still haven’t figured out exactly where the best spot to initialize
this variable is, so for now, I tend to ignore it and just dump configs to 
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$HOME/.config/myapp/config.yml&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This works great out of the box and saves a ton of headache (trust me). But let’s say
you still really want to locate the repo directory?&lt;/p&gt;

&lt;h3 id=&quot;breadcrumbs-back-to-the-repo&quot;&gt;Breadcrumbs back to the repo&lt;/h3&gt;

&lt;p&gt;Put this file in the root of your repo:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;repo_dir.sh:&lt;/strong&gt;&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;#!/usr/bin/env bash&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;HEREDIR&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;cd&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;dirname&lt;/span&gt; &lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;realpath&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;))&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;pwd&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt;  &lt;span class=&quot;c&quot;&gt;# Reliably get the filename and dir&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;HEREDIR&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt;  &lt;span class=&quot;c&quot;&gt;# pure function scripts are better than source-ing&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Symlink it to your known config location:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;ln&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-sf&lt;/span&gt; /path/to/your/app_repo/repo_dir.bash ~/.config/appname/
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And access it from any script like such:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;REPO_DIR&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;~/.config/appname/repo_dir.sh&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The linking step can be automated with a script which similarly uses the HEREDIR script to
 locate the repo in the first place, and then dump the link to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.config&lt;/code&gt;. Links vs copying
 also let you bind-mount your source code inside the container to allow for rapid 
 development and debugging in-situ.&lt;/p&gt;

&lt;h2 id=&quot;better-options&quot;&gt;Better options&lt;/h2&gt;
&lt;p&gt;Overall, you are probably better off using something like Consul to manage your configs 
using the dns and kv store features. But that can be a bit cumbersome.&lt;/p&gt;</content><author><name></name></author></entry></feed>