<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: kinzal</title>
    <description>The latest articles on DEV Community by kinzal (@kinzal).</description>
    <link>https://dev.to/kinzal</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F127874%2F52f7d7c0-902f-47f2-86a6-a5a952280413.jpeg</url>
      <title>DEV Community: kinzal</title>
      <link>https://dev.to/kinzal</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kinzal"/>
    <language>en</language>
    <item>
      <title>aliases: Convert from container to command</title>
      <dc:creator>kinzal</dc:creator>
      <pubDate>Fri, 11 Jan 2019 15:59:25 +0000</pubDate>
      <link>https://dev.to/kinzal/aliases-convert-from-container-to-command-1839</link>
      <guid>https://dev.to/kinzal/aliases-convert-from-container-to-command-1839</guid>
      <description>&lt;p&gt;We developed a tool called "aliases" that defines &lt;code&gt;docker run&lt;/code&gt; as YAML and executes it as a command.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/k-kinzal/aliases"&gt;GitHub - k-kinzal/aliases: Resolve dependency on all commands by container&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Since aliases uses containers, installing the only docker allows you to execute commands in the same way without depending on the environment.&lt;/p&gt;

&lt;h2&gt;
  
  
  Get Started
&lt;/h2&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;curl &lt;span class="nt"&gt;-sSL&lt;/span&gt; &lt;span class="s1"&gt;'https://github.com/k-kinzal/aliases/releases/download/v0.2.1/darwin-amd64.tar.gz'&lt;/span&gt; | &lt;span class="nb"&gt;tar &lt;/span&gt;xvz
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cp &lt;/span&gt;aliases /usr/local/bin/aliases
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;$HOME/.aliases/aliases.yaml&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="s"&gt;/usr/local/bin/kubectl&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;chatwork/kubectl&lt;/span&gt;
    &lt;span class="s"&gt;tag&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;1.11.2&lt;/span&gt;
  &lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;KUBECONFIG&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;$KUBECONFIG&lt;/span&gt;
    &lt;span class="na"&gt;volume&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;$HOME/.kube:/root/.kube&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;$PWD:/work&lt;/span&gt;
  &lt;span class="na"&gt;workdir&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;/work&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Aliases can be used as a command by defining command names, images, and tags, and &lt;code&gt;docker run&lt;/code&gt; options.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;eval&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;aliases gen &lt;span class="nt"&gt;--export&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;By executing &lt;code&gt;aliases gen&lt;/code&gt; the command will be set to &lt;code&gt;PATH&lt;/code&gt; and made available.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;kubectl get all
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You can execute the command with just this.&lt;br&gt;
The command defined in aliases will work the same in your environment, your colleague's environment, or the CI environment.&lt;/p&gt;

&lt;p&gt;You can solve the problem from  which the command suffers regarding the installation method as it does not work with the need version.&lt;/p&gt;
&lt;h2&gt;
  
  
  Switch the version of the command to execute
&lt;/h2&gt;

&lt;p&gt;The kubernetes cluster and the &lt;code&gt;kubectl&lt;/code&gt; command must be the same version.&lt;br&gt;
So, if you have multiple kubernetesk clusters, you will be troubled about how to make the kubernetes cluster and &lt;code&gt;kubectl&lt;/code&gt; versions the same.&lt;/p&gt;

&lt;p&gt;Aaliases can do that.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ kubectl get all                       # It works with the version defined by aliases.yaml
$ KUBECTL_VERSION=1.8.4 kubectl get all # It works with the version by environment variable
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Aaliases overrides &lt;code&gt;tag&lt;/code&gt; of &lt;code&gt;aliases.yaml&lt;/code&gt; with an environment variable of &lt;code&gt;[COMMAND NAME] _VERSION&lt;/code&gt;.&lt;br&gt;
You can easily switch versions with just this one.&lt;br&gt;
You do not have to think about using version switch mechanisms like &lt;code&gt;rbenv&lt;/code&gt; or &lt;code&gt;nvm&lt;/code&gt; anymore.&lt;/p&gt;
&lt;h2&gt;
  
  
  Combine multiple containers and resolve dependency on commands
&lt;/h2&gt;

&lt;p&gt;One of the problems when executing a container is that you can not execute a command that not install in the container image.&lt;/p&gt;

&lt;p&gt;For example, when using &lt;code&gt;helmfile&lt;/code&gt; you need to install &lt;code&gt;helm&lt;/code&gt; in the same container.&lt;br&gt;
However, when you want to use the &lt;code&gt;kubectl&lt;/code&gt; command and other commands from&lt;code&gt;helmfile&lt;/code&gt;, you have to recreate the container image many times.&lt;/p&gt;

&lt;p&gt;In aliases you can resolve dependencies on other commands by defining command dependencies without re-creating container images.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="s"&gt;/usr/local/bin/kubectl&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;chatwork/kubectl&lt;/span&gt;
    &lt;span class="s"&gt;tag&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;1.11.2&lt;/span&gt;
  &lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;KUBECONFIG&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;$KUBECONFIG&lt;/span&gt;
    &lt;span class="na"&gt;volume&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;$HOME/.kube:/root/.kube&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;$PWD:/work&lt;/span&gt;
  &lt;span class="na"&gt;workdir&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;/work&lt;/span&gt;

&lt;span class="s"&gt;/usr/local/bin/helm&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;chatwork/helm&lt;/span&gt;
  &lt;span class="na"&gt;tag&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;2.11.0&lt;/span&gt;
  &lt;span class="na"&gt;volumes&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;/tmp:/tmp&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;$HOME/.helm:/root/.helm&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;$PWD:/work&lt;/span&gt;
  &lt;span class="na"&gt;workdir&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;/work&lt;/span&gt;

&lt;span class="s"&gt;/usr/local/bin/helmfile&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;chatwork/helmfile&lt;/span&gt;
  &lt;span class="na"&gt;tag&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;0.40.1-2.11.0-1.11.2&lt;/span&gt;
  &lt;span class="na"&gt;volumes&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;/tmp:/tmp&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;$HOME/.kube:/root/.kube&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;$HOME/.helm:/root/.helm&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;$PWD:/work&lt;/span&gt;
  &lt;span class="na"&gt;workdir&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;/work&lt;/span&gt;
  &lt;span class="na"&gt;dependencies&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;/usr/local/bin/kubectl&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;/usr/local/bin/helm&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;By defining &lt;code&gt;dependencies&lt;/code&gt; like this you can execute&lt;code&gt;kubectl&lt;/code&gt; or &lt;code&gt;helm&lt;/code&gt; from &lt;code&gt;helmfile&lt;/code&gt;.&lt;br&gt;
You no longer need to create your own container image.&lt;br&gt;
You use it if there is a container image that is officially distributed. If you need dependencies on new commands, you can combine them.&lt;/p&gt;

&lt;p&gt;However, this feature uses docker &lt;code&gt;privileged&lt;/code&gt;.&lt;br&gt;
Use with untrustworthy images is not safe.&lt;/p&gt;
&lt;h2&gt;
  
  
  Execute on CircleCI
&lt;/h2&gt;

&lt;p&gt;Environment-independent aliases makes it easy to execute in CI such as CircleCI.&lt;br&gt;
To use it with CircleCI, please use &lt;a href="https://circleci.com/orbs/registry/orb/k-kinzal/aliases"&gt;CircleCI Orb&lt;/a&gt; provided by aliases.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;version&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;2.1"&lt;/span&gt;

&lt;span class="na"&gt;orbs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;aliases&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;k-kinzal/aliases@0.2.1&lt;/span&gt;

&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;aliases&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;machine&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="no"&gt;true&lt;/span&gt;
    &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;checkout&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;aliases/install&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;aliases/gen&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;make build&lt;/span&gt;

&lt;span class="na"&gt;workflows&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;version&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;

  &lt;span class="na"&gt;aliases&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;aliases&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Please prepare &lt;code&gt;aliases.yaml&lt;/code&gt; in the project root.&lt;br&gt;
Then you can execute the same command as local without writing command installation.&lt;br&gt;
You no longer need to debug many times with the &lt;code&gt;circleci&lt;/code&gt; command.。&lt;br&gt;
You only need to define commands that work locally.&lt;/p&gt;

&lt;h2&gt;
  
  
  We want feedback
&lt;/h2&gt;

&lt;p&gt;Aliases is a newborn baby.&lt;br&gt;
Please give us your feedback for better growth.&lt;/p&gt;

</description>
      <category>docker</category>
      <category>kubernetes</category>
      <category>operations</category>
    </item>
  </channel>
</rss>
