<?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" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Doug Campbell on Medium]]></title>
        <description><![CDATA[Stories by Doug Campbell on Medium]]></description>
        <link>https://medium.com/@ndougops?source=rss-27f19a2c8a9d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*EEJGkiVcPV4QflV8AiG6nA.jpeg</url>
            <title>Stories by Doug Campbell on Medium</title>
            <link>https://medium.com/@ndougops?source=rss-27f19a2c8a9d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 10:03:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ndougops/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Artifactory Retention Policies with Lavatory]]></title>
            <link>https://medium.com/gogoair-tech/artifactory-retention-policies-with-lavatory-f1a134c38c7f?source=rss-27f19a2c8a9d------2</link>
            <guid isPermaLink="false">https://medium.com/p/f1a134c38c7f</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[artifactory]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Doug Campbell]]></dc:creator>
            <pubDate>Mon, 13 Nov 2017 17:17:12 GMT</pubDate>
            <atom:updated>2017-11-13T17:25:51.432Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xmz-ksbqJrcsgwYLMLiXeA.jpeg" /></figure><p><a href="https://github.com/gogoair/lavatory">Lavatory</a> is a new tool we created to handle retention policies in <a href="https://www.jfrog.com/artifactory/">Artifactory</a>. When you have a continuous delivery model it is easy to end up with thousands and thousands of old and broken artifacts. At Gogo we have over 45,000 artifacts spread across approximately 50 repositories, all of which need different levels of retention. Lavatory was created to solve this issue by allowing highly customizable and repository specific retention policies.</p><p>Lavatory is open source as we felt other organizations are likely experiencing similar problems, and we were unable to find any other tools that met our needs.</p><ul><li><a href="https://github.com/gogoair/lavatory">gogoair/lavatory</a></li><li><a href="http://lavatory.readthedocs.io/en/latest/">Welcome to lavatory&#39;s documentation! - lavatory documentation</a></li></ul><h3>Why You Need Retention Policies</h3><p>Lavatory was created to solve the issue of artifact retention in Artifactory. Retention policies are necessary for the following reasons:</p><ul><li>Too many artifacts in a repository can cause slow indexing and make delivering applications slower.</li><li>Indefinitely keeping all artifacts leads to a build up of stale or broken artifacts. With how often we build and deploy, most artifacts would never make it to production and had no need for long term retention</li><li>Storage is not free. Artifacts can be very large and in order to control costs we need to eventually purge old artifacts.</li></ul><h3>Lavatory Features</h3><p>Lavatory has one main goal, clean up Artifactory with repositority specific retention policies. It has the following features to enable this:</p><ul><li>Uses Python plugins for repository policies. One plugin per repository that can have as much Python logic as necessary</li><li>Time-based retention. Easy helper function for applying a time-based retention policy, such as “keep all artifacts created in the last 120 days”.</li><li>Count-based retention. Easy helper function for keep last N number of artifacts, such as “keep the last 5 built artifacts</li><li>AQL based retention. You can use the <a href="https://www.jfrog.com/confluence/display/RTF/Artifactory+Query+Language">Artifactory query language</a> for searching for artifacts to delete. This can be combined with time-based and count-based retention.</li><li>A default policy that applies to all repos without a specific policy.</li></ul><h3>Creating a Policy</h3><p>Each policy in Lavatory is a Python plugin. The plugin should be named &lt;repo_name&gt;.py, replacing — in the repository name with _ . Each policy needs one function, def purgelist(artifactory) and this needs to return a list of artifacts to delete. Other than that, the policies can do anything that Python can do. The default policy is named default.py and applied to all repositories without a specific retention policy.</p><p><a href="http://lavatory.readthedocs.io/en/latest/policies/index.html">Creating Retention Policies - lavatory documentation</a></p><h4>Example Policies</h4><p>Below are some example policies to show how these can be used.</p><p><strong>Keep last 120 days of artifacts</strong></p><pre><strong>def</strong> <strong>purgelist</strong>(artifactory):<br>    &quot;&quot;&quot;Policy to purge all artifacts older than 120 days&quot;&quot;&quot;<br>    purgeable <strong>=</strong> artifactory<strong>.</strong>time_based_retention(keep_days<strong>=</strong>120)<br>    <strong>return</strong> purgeable</pre><p><strong>Keep 5 most recent artifacts</strong></p><pre><strong>def</strong> <strong>purgelist</strong>(artifactory):<br>    &quot;&quot;&quot;Policy to keep just the 5 most recent artifacts.&quot;&quot;&quot;<br>    purgeable <strong>=</strong> artifactory<strong>.</strong>count_based_retention(retention_count<strong>=</strong>5)<br>    <strong>return</strong> purgeable</pre><p><strong>Purge artifacts based on environments deployed to</strong></p><pre><strong>def</strong> <strong>purgelist</strong>(artifactory):<br>    &quot;&quot;&quot;If deployed to prod, keep artifact forever,<br>    if deployed to stage, keep 30 days,<br>    if never deployed, keep 14 days.&quot;&quot;&quot;<br><br>    not_deployed <strong>=</strong> [ { &quot;@deployed&quot;: { &quot;$nmatch&quot;: &quot;*&quot; }}]<br><br>    only_dev <strong>=</strong>  [ { &quot;@deployed&quot;: { &quot;$match&quot;: &quot;*stage*&quot;} },<br>                { &quot;@deployed&quot;: {&quot;$nmatch&quot;: &quot;*prod*&quot;} } ]<br><br>    undeployed <strong>=</strong> artifactory<strong>.</strong>time_based_retention(keep_days<strong>=</strong>14,<br>                                        extra_aql<strong>=</strong>not_deployed)<br>    <br>    only_stage <strong>=</strong> artifactory<strong>.</strong>time_based_retention(keep_days<strong>=</strong>30,<br>                                            extra_aql<strong>=</strong>only_dev)<br><br>    all_purgable <strong>=</strong> undeployed <strong>+</strong> only_stage<br>    <strong>return</strong> sorted(all_purgable, key<strong>=lambda</strong> k: k[&#39;path&#39;])</pre><p><strong>Move artifacts to different repository after 3 days</strong></p><pre>def purgelist(artifactory):<br>    &quot;&quot;&quot;Moves artifacts to yum-local after 3 days.&quot;&quot;&quot;<br>    movable = artifactory.time_based_retention(keep_days=3)<br>    artifactory.move_artifacts(artifacts=movable,<br>                               dest_repository=&#39;yum-local&#39;)<br>    return []</pre><h3>Running Lavatory</h3><p>Lavatory is just a CLI tool. We run this nightly in a Jenkins job but could be done from any shell.</p><p>Lavatory can be installed from PyPI: pip install lavatory</p><p>Authentication to Artifactory looks for 3 environment variables: ARTIFACTORY_URL, ARITFACTORY_USERNAME, ARTIFACTORY_PASSWORD</p><h4>Purging Artifacts</h4><p>The purge command will run your retention policies and delete the artifacts. This runs in dry mode by default so you must include --nodryrun if you want to actually remove the artifacts.</p><p>lavatory purge --policies-path /path/to/policies</p><p>If you want to only run against specific repos, you add multiple --repo &lt;repo_name&gt; flags to the command. If not provided Lavatory will run against all repositories.</p><h4>Listing Policies</h4><p>You can use the policies command if you want to list all policies and their descriptions but not run the policies. This is useful for generating a list of all policies for documentation purposes. This uses the policy functions docstring for determining the policy description.</p><p>lavatory policies --policies-path /path/to/policies</p><p>This will return a JSON list of all repositories and the policies that apply to them.</p><h3>Conclusion</h3><p>If you are interested in Lavatory take a look at the <a href="http://lavatory.readthedocs.io/en/latest/">documentation</a> for more information. We are always open to contribution and actively review any GitHub issues. Thanks!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f1a134c38c7f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/gogoair-tech/artifactory-retention-policies-with-lavatory-f1a134c38c7f">Artifactory Retention Policies with Lavatory</a> was originally published in <a href="https://medium.com/gogoair-tech">Gogo Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Super Secret Dynamic Secrets with Vault]]></title>
            <link>https://medium.com/gogoair-tech/super-secret-dynamic-secrets-with-vault-cf6f29fefc8f?source=rss-27f19a2c8a9d------2</link>
            <guid isPermaLink="false">https://medium.com/p/cf6f29fefc8f</guid>
            <category><![CDATA[vault]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[secrets]]></category>
            <dc:creator><![CDATA[Doug Campbell]]></dc:creator>
            <pubDate>Thu, 06 Jul 2017 21:06:56 GMT</pubDate>
            <atom:updated>2017-07-06T21:06:56.047Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v3CgDzRaJZyJ8yR4yBqW_A.jpeg" /></figure><p><a href="https://www.vaultproject.io/">Vault</a> is a really neat tool from HashiCorp for managing secrets. It aims to solve common problems around key rotations, provisioning, revocations, auditing and more. One of my favorite features from Vault is the ability to generate temporary credentials on demand for a variety of different backends.</p><h3>Dynamic Backends</h3><p>Vault ships with some useful backends for managing dynamic secrets. Dynamic backends generate secrets on demand. For example, every time you request the username and password for a database, Vault generates new ones and returns that to the application. Here’s is a list of some of the dynamic backends that Vault ships with:</p><ul><li>AWS</li><li>Relational Databases (MySQL, PostgreSQL, MSSQL)</li><li>MongoDB</li><li>Cassandra</li><li>PKI (Certificates)</li><li>RabbitMQ</li><li>Consul</li></ul><h4>Why?</h4><p>Dynamic passwords provide a bunch of benefits:</p><ul><li>No need to write down, store, or share passwords</li><li>Enables very short lived passwords, less exposure if compromised</li><li>For distributed applications, every instance gets unique credentials</li><li>Constantly changing and expiring usernames/passwords are much harder to brute force</li><li>Automatic password rotation/expiration</li><li>Better auditing trail</li></ul><h3>PostgreSQL Example</h3><p>Vault has the ability to provide dynamic database usernames and passwords. This means that a new username and password is generated and returned every time you read a secret from Vault, and it will handle revocations from the database automatically. Vault uses a plugin abstraction for databases and supports MySQL, PostgreSQL, MSSQL, and others out of the box. To setup dynamic database passwords, follow these steps:</p><ol><li>Mount the database backend to Vault</li><li>Configure connection to database</li><li>Configure a role in Vault for generating credentials</li></ol><pre>$ vault mount database<br>Successfully mounted &#39;database&#39; at &#39;database&#39;!</pre><pre>$ vault write database/config/postgresql \<br>    plugin_name=postgresql-database-plugin \<br>    allowed_roles=&quot;readonly&quot; \<br>    connection_url=&quot;postgresql://root:pass@example.com:5432/&quot;</pre><pre>$ vault write database/roles/readonly \<br>    db_name=testDb \<br>    creation_statements=&quot;CREATE ROLE \&quot;{{name}}\&quot; WITH LOGIN PASSWORD &#39;{{password}}&#39; VALID UNTIL &#39;{{expiration}}&#39;; \<br>        GRANT SELECT ON ALL TABLES IN SCHEMA public TO \&quot;{{name}}\&quot;;&quot; \<br>    default_ttl=&quot;1h&quot; \<br>    max_ttl=&quot;24h&quot;</pre><p>In the above example, we use a readonly role. Multiple roles can be setup per database for generating different levels of credentials. Now you just need to read the credentials from your desired role and Vault will generate these in the database.</p><pre>$ vault read database/creds/readonly<br>Key             Value<br>---             -----<br>lease_id        database/creds/readonly/4287c6b5-19c5-94e5-773c-f85d05989be3<br>lease_duration  60m0s<br>lease_renewable true<br>password        f1m3a90b-f5e8-0263-f008-a96f373d84232<br>username        412dde25-cdde-8184-87f1-854da621395c</pre><p>In this example, the credentials have a 60 minute TTL and Vault will handle the revocation of these credentials from the database once they expire. All of the commands above can also be done using Vault’s API</p><p>You can see the full Vault database docs at <a href="https://www.vaultproject.io/docs/secrets/databases/index.html">https://www.vaultproject.io/docs/secrets/databases/index.html</a></p><h3>AWS IAM Example</h3><p>Vault can also provide dynamic AWS credentials. When you make a credential request to Vault, you will get back a new set of access/secret keys each time. Run through the following steps to accomplish this:</p><ol><li>Mount the AWS backend to Vault</li><li>Configure the root account in Vault</li><li>Assign an AWS policy to a Vault role that the dynamic credentials use</li></ol><pre>$ vault mount aws</pre><pre>Successfully mounted &#39;aws&#39; at &#39;aws&#39;!</pre><pre># If this step is skipped, it will use standard AWS credential chain or instance profile if running Vault on EC2<br>$ vault write aws/config/root \<br>    access_key=$ROOT_ACCESS_KEY \<br>    secret_key=$ROOT_SECRET_KEY \<br>    region=us-east-1</pre><pre>$ vault write aws/roles/specialrole arn=arn:aws:iam::aws:policy/SuperSpecialCustomPolicy</pre><p>Now that the AWS backend is setup, every time you read the credentials from Vault, you will get back unique credentials that are tied to the arn:aws:iam::aws:policy/SuperSpecialCustomPolicy policy and configured AWS account.</p><pre>$ vault read aws/creds/specialrole<br>Key             Value<br>lease_id        aws/creds/specialrole/7cb8df71-782f-3de1-79dd-251778e49f58<br>lease_duration  3600<br>access_key      AKIAIOMYUTSLGJYQIDFGF<br>secret_key      BK9++oBABaBvRKcT5KEF69xQGcH7ZpPRF3qovRt<br>security_token  &lt;nil&gt;</pre><p>By default, this credential set only exists for 3600 seconds (although this is configurable). If you execute the same vault read aws/creds/specialrole command again you will get back entirely new credentials. All of the commands above can also be done using Vault’s API</p><p>You can see the full docs on dynamic AWS secrets in Vault at <a href="https://www.vaultproject.io/docs/secrets/aws/index.html">https://www.vaultproject.io/docs/secrets/aws/index.html</a></p><h3>Conclusion</h3><p>Dynamic secrets are a neat feature of Vault and can be useful to any organization with a lot of secrets to manage. It can also do other cool things like “cryptography as a service” and easier storage of static passwords. At Gogo we even use Vault to store binary blobs like p12 certs and client certificates. Vault also has a robust API and client libraries for almost any language so that it is easy to get started and integrate with existing applications.</p><p>Vault Docs: <a href="https://www.vaultproject.io/">https://www.vaultproject.io/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cf6f29fefc8f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/gogoair-tech/super-secret-dynamic-secrets-with-vault-cf6f29fefc8f">Super Secret Dynamic Secrets with Vault</a> was originally published in <a href="https://medium.com/gogoair-tech">Gogo Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Jenkins Jobs as Code with Groovy DSL]]></title>
            <link>https://medium.com/gogoair-tech/jenkins-jobs-as-code-with-groovy-dsl-c8143837593a?source=rss-27f19a2c8a9d------2</link>
            <guid isPermaLink="false">https://medium.com/p/c8143837593a</guid>
            <category><![CDATA[groovy]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[jenkins]]></category>
            <dc:creator><![CDATA[Doug Campbell]]></dc:creator>
            <pubDate>Fri, 12 May 2017 16:59:35 GMT</pubDate>
            <atom:updated>2017-05-12T17:00:11.684Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EUWG_tnKbLpsfTBRkNmXnA.jpeg" /></figure><p>At Gogo, we use Jenkins very heavily for CI/CD. We leverage it for building all our deployable artifacts; it’s the critical first step in our continuous deployment pipeline.</p><p>Currently, we have over 500 Jenkins jobs. Anyone who is familiar with Jenkins knows it is very tedious to create jobs manually. That is where the <a href="https://wiki.jenkins-ci.org/display/JENKINS/Job+DSL+Plugin">Job DSL plugin</a> comes in. To quote the plugin summary:</p><blockquote>The <a href="https://wiki.jenkins-ci.org/display/JENKINS/Job+DSL+Plugin">Jenkins job-dsl-plugin</a> attempts to solve this problem by allowing jobs to be defined with the absolute minimum necessary in a programmatic form, with the help of templates that are synced with the generated jobs</blockquote><p><em>i.e</em>: You can define your Jenkins jobs as code.</p><h3>Usage</h3><p><a href="https://github.com/jenkinsci/job-dsl-plugin/wiki/Tutorial---Using-the-Jenkins-Job-DSL">View full tutorial here.</a></p><p>To use the Job DSL plugin, you first need to create a <em>seed job</em>. The seed job is a Jenkins job which runs a DSL scripts, and then generates a new job. The seed job is a normal free-style Jenkins job that you add the “Process Job DSL” build step. This step takes the DSL and generates the configured jobs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/892/1*3GaSxkluFgABLisB-Bosbg.png" /><figcaption>Process Job DSLs build step</figcaption></figure><h3>The DSL</h3><p>The DSL is scriptable via Groovy and so it is extremely flexible. The DSL also provides direct control over a job’s XML; this makes it possible to automate the creation of any job, regardless of what has been implemented in the DSL. A lot of helper methods are provided which makes it very easy to setup things such as build triggers, version control, shell scripts, and more. There is also a great <a href="https://jenkinsci.github.io/job-dsl-plugin/">API Viewer</a> to help you discover the helper methods.</p><h4>Basic Example</h4><pre>def gitUrl = &#39;git://github.com/test/test&#39;<br><br>job(&#39;test-job&#39;) {<br>    scm {<br>        git(gitUrl)<br>    }<br>    triggers {<br>        scm(&#39;*/15 * * * *&#39;)<br>    }<br>    steps {<br>        maven(&#39;-e clean test&#39;)<br>    }<br>}</pre><p>If you pass the above script to the DSL seed job, it will dynamically generate a Jenkins job named “test-job”. If you submit an updated DSL, it will run the seed job and update “test-job” but not delete any history/builds.</p><h4>Complicated Example</h4><p>Below is a more detailed and complicated example in which we generate one of our <a href="https://tech.gogoair.com/foremast-automate-spinnaker-pipeline-creation-2b2aa7b2c5e4">Foremas</a>t related jobs. In this example, we do the following:</p><ol><li>Define BASE_STEPS, this is just a Groovy string that allows our shell script to be reusable across multiple jobs.</li><li>Define a new job named “foremast-pipeline-prepare”</li><li>Setup job parameters, default values, and descriptions</li><li>Setup job log rotation</li><li>Setup git repositories and link with credentials</li><li>Define what Jenkins slave labels this should run on</li><li>Add a Shell build step to run our previously defined BASE_STEPS</li></ol><pre>BASE_STEPS = &#39;&#39;&#39;#!/bin/bash<br>mkdir -p ~/.foremast<br>aws s3 sync s3://example-bucket/ . --exclude &quot;*&quot; --include &quot;foremast.cfg&quot;</pre><pre>virtualenv -p python3 venv<br>. venv/bin/activate<br>pip install -U --quiet foremast==3.10.1<br>&#39;&#39;&#39;</pre><pre>APP_STEPS = BASE_STEPS + &#39;&#39;&#39;<br>prepare-app-pipeline<br>&#39;&#39;&#39;</pre><pre>job(&quot;foremast-pipeline-prepare&quot;) {<br>  parameters {<br>    stringParam(&#39;APP&#39;, &#39;&#39;, &#39;Application name&#39;)<br>    stringParam(&#39;EMAIL&#39;, &#39;<a href="/service/mailto:psdevopstooling@gogoair.com">a</a>dmin@example.com&#39;, &#39;Associated email&#39;)<br>    stringParam(&#39;PROJECT&#39;, &#39;None&#39;, &#39;Git project associated with application&#39;)<br>    stringParam(&#39;GIT_REPO&#39;, &#39;None&#39;, &#39;The repository name to associate with application&#39;)<br>  }</pre><pre>configure { project -&gt;<br>    project / &#39;authToken&#39;(&#39;xxxxxxxxxxxxyyyyyyyyyydddddddddddyyyyyyyzzzzzzz&#39;)<br>  }</pre><pre>logRotator {<br>    numToKeep(50)<br>    artifactNumToKeep(50)<br>  }</pre><pre>multiscm {<br>    git {<br>      remote {<br>        url(https://medium.com/&quot;%3Ca%20href=%22/service/mailto:git@git.gogoair.com%22%3Egit@g%3C/a%3Eit.example.com:spinnaker/foremast-templates.git&quot;)<br>        credentials(&#39;gitlab-jenkinsci&#39;)<br>      }<br>      extensions {<br>        relativeTargetDirectory(&#39;foremast-templates&#39;)<br>        }<br>      branch(&#39;*/master&#39;)<br>    }<br>  }</pre><pre>label(&#39;script&#39;)</pre><pre>steps {<br>    shell(APP_STEPS)<br>  }</pre><pre>wrappers {<br>    colorizeOutput()<br>  }</pre><pre>}</pre><p>Now our entire Jenkins job is defined as code. This makes it automated, easily versioned, reproducible, and allows for jobs to be more standardized.</p><h3>Our Workflow</h3><p>At Gogo, we have a simple workflow that allows our developers to control their own Jenkins jobs and ties the DSL directly to their application repository.</p><ol><li>Developers create a runway/dsl.groovy file in their repository</li><li>Developers modify their dsl.groovy and customize it for their specific needs</li><li>Developers push their changes and a pre-receive git hook determines that the dsl.groovy file was changed</li><li>If the dsl.groovy file was modified, the pre-receive git hook passes it to the Jenkins DSL seed job (<a href="https://github.com/jenkinsci/job-dsl-plugin/wiki/Tutorial---Using-the-Jenkins-Job-DSL">see tutorial</a>) and regenerates the applications job</li><li>The git hook monitors the status of the DSL seed job and reports back to the developer if the job fails or succeeds and rejects the push if the DSL is not properly generated</li></ol><p>This workflow is great for us as it allows our developers full control over their Jenkins job and gives them quick feedback if there are any issues.</p><h4>Standardizing the DSL</h4><p>This workflow can cause some issues though. What if you need to change the URL of where the artifacts should be stored for the whole organization? Would you need to coordinate the update of 100+ DSL configurations in all the repositories? To solve this, we made a bunch of internal helper functions. Since the DSL is ultimately just groovy, you can do anything that the language is capable of, such as importing a model. Below is an example of how this can work.</p><ol><li>First you create a DSL utilities class. In this example, we have a function addNVM() that will add in the nvmWrapper DSL settings.</li></ol><pre>package DslUtilties</pre><pre>class Utilities {<br>    def addNVM(def nvmversion=&#39;v6.1.0&#39;){<br>        this.job.with {<br>            configure { project -&gt;<br>                project / buildWrappers &lt;&lt;      &#39;org.jenkinsci.plugins.nvm.NvmWrapper&#39; {<br>                version(nvmversion)<br>                }<br>            }<br>        }<br>        return this<br>    }<br>}</pre><p>2. Then, in your dsl.groovy script, where the job is actually defined, you can import the utilities and add the helper function</p><pre>import DslUtilities.Utilities</pre><pre>def myJob = job(&quot;test-job&quot;) {<br>    // job parameters and options...<br>} </pre><pre>utils = new Utilities(job: myJob)<br>utils.addNVM()</pre><p>This will take your defined job and add in the standardized NVM helper utility. This is useful for providing a centralized spot for DSL configurations while still allowing the individual apps to customize for specific needs</p><h3>Further Resources</h3><p>This is just a very quick overview of how the DSL plugin for Jenkins can work. For more information, you can check out the following resources</p><ul><li><a href="https://marcesher.com/2016/06/09/jenkins-as-code-job-dsl/">https://marcesher.com/2016/06/09/jenkins-as-code-job-dsl/</a></li><li><a href="https://github.com/jenkinsci/job-dsl-plugin">https://github.com/jenkinsci/job-dsl-plugin</a></li><li><a href="https://wiki.jenkins-ci.org/display/JENKINS/Job+DSL+Plugin">https://wiki.jenkins-ci.org/display/JENKINS/Job+DSL+Plugin</a></li><li><a href="https://github.com/jenkinsci/job-dsl-plugin/wiki/Job-DSL-Commands">https://github.com/jenkinsci/job-dsl-plugin/wiki/Job-DSL-Commands</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c8143837593a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/gogoair-tech/jenkins-jobs-as-code-with-groovy-dsl-c8143837593a">Jenkins Jobs as Code with Groovy DSL</a> was originally published in <a href="https://medium.com/gogoair-tech">Gogo Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Foremast — Lambda Pipelines]]></title>
            <link>https://medium.com/gogoair-tech/foremast-lambda-pipelines-8d49b1126ef7?source=rss-27f19a2c8a9d------2</link>
            <guid isPermaLink="false">https://medium.com/p/8d49b1126ef7</guid>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[pipeline]]></category>
            <dc:creator><![CDATA[Doug Campbell]]></dc:creator>
            <pubDate>Tue, 04 Oct 2016 17:50:11 GMT</pubDate>
            <atom:updated>2016-10-04T17:51:26.707Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*k6KoP-bsw86ru1q_7r2h8w.png" /></figure><p>This post is part of our series on Foremast, an open source tool that we released for dynamically generating Spinnaker pipelines and infrastructure. If you haven’t already, take a look at our first post for an intro to Foremast.</p><p><a href="https://tech.gogoair.com/foremast-automate-spinnaker-pipeline-creation-2b2aa7b2c5e4">Foremast — Automate Spinnaker Pipeline Creation</a></p><p>One of the features of Foremast is that it can be used to deploy Lambda functions through a Spinnaker pipeline. Foremast takes care of setting up the function, event triggers, and roles necessary for Lambda to work. This post will go into details on how Foremast works with Lambda and how it can enable continuous delivery of Lambda functions.</p><h3>Lambda Overview</h3><p>Lambda is super cool. It is an offering from AWS that is becoming the cornerstone of <em>server-less </em>infrastructure. I like the term functions-as-a-service to describe how Lambda works. All you have to do is upload code to Lambda and everything else is taken care of. You can then setup different events that dictate when the Lambda function is triggered. It can be triggered from a schedule, changing a file in S3, updating a DynamoDB table, hitting an API endpoint, and more. Some common use-cases include:</p><ul><li>Scheduled tasks</li><li>Backend processing for API Gateway</li><li>Analyzing streams of data</li><li>AWS management tasks</li></ul><p>Take a look at the <a href="https://aws.amazon.com/lambda/">AWS docs</a> to get a better idea of Lambda features and use-cases.</p><h3>Lambda Deployment Pipeline</h3><p>This is the basic pipeline that we have defined in Spinnaker for Lambda deployments. Out of the box, Foremast will generate the below pipeline.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/731/1*pt3iZSDjblg7fFBDmABonw.png" /></figure><h4>Pipeline Steps</h4><ol><li><em>Configuration</em>: Monitor a Jenkins job for completion. This Jenkins job generates a ZIP artifact that is later uploaded to Lambda</li><li><em>Infrastructure Setup: </em>Runs Foremast with the application <a href="http://foremast.readthedocs.io/en/latest/configuration_files/index.html">configs</a>. This creates an empty Lambda function, sets up IAM roles, and attaches the configured Lambda triggers.</li><li><em>Deploy Lambda:</em> Runs a Jenkins job that uploads the ZIP artifact to the created Lambda infrastructure</li><li><em>Checkpoint:</em> This is a Spinnaker manual judgment stage. It waits for human input before deploying the Lambda function to the next environment</li></ol><p>These steps repeat for all environments defined in the application’s <a href="http://foremast.readthedocs.io/en/latest/configuration_files/pipeline_json/index.html#envs">pipeline.json</a> configuration.</p><h3>Foremast Lambda Configuration</h3><p>Foremast works the same for Lambda as it does EC2 deployments. It relies on the same configuration files but with a few specific differences.</p><h4><strong>pipeline.json</strong></h4><p><em>pipeline.json</em> for Lambda is used to define pipeline-wide settings. The Lambda runtime to use, the function handler, and if a VPC is enabled.</p><pre>{<br>  &quot;type&quot;: &quot;lambda&quot;,<br>  &quot;lambda&quot;: {<br>    &quot;app_description&quot;: &quot;Hello World in Python&quot;,<br>    &quot;runtime&quot;: &quot;python2.7&quot;,<br>    &quot;handler&quot;: &quot;main.main&quot;,<br>    &quot;vpc_enabled&quot;: true<br>  },<br>  &quot;env&quot;: [<br>    &quot;dev&quot;,<br>    &quot;stage&quot;,<br>    &quot;prod&quot;<br>  ],<br>  &quot;regions&quot;: [<br>    &quot;us-east-1&quot;<br>  ]<br>}</pre><h4>application-master-&lt;env&gt;.json</h4><p><em>application-master-&lt;env&gt;.json</em> is where the function settings are configured such as how much memory a function gets and how long the timeout is. This can be different per deployment environment.</p><p>This config is also where all Lambda events are configured. Multiple triggers can be set for one function. Take a look at <a href="http://foremast.readthedocs.io/en/latest/lambda/lambda_events.html#lambda-events">the docs</a> for all options.</p><pre>{<br>  &quot;app&quot;: {<br>    &quot;app_description&quot;: &quot;LambdaPython&quot;,<br>    &quot;memory&quot;: &quot;128&quot;,<br>    &quot;timeout&quot;: &quot;3600&quot;<br>  },</pre><pre>  &quot;lambda_triggers&quot;: [<br>    {<br>      &quot;type&quot;: &quot;cloudwatch-event&quot;,<br>      &quot;schedule&quot;: &quot;rate(5 minutes)&quot;,<br>      &quot;rule_name&quot;: &quot;LambdaPython-rule&quot;,<br>      &quot;rule_description&quot;: &quot;triggers lambda function every five minutes&quot;<br>    }<br>  ]<br>}</pre><h4>Supported Events</h4><p>At the time of writing this post, Foremast supports the following Lambda event - which are all part of the AWS eco-system.</p><ul><li>Cloudwatch</li><li>Cloudwatch Logs</li><li>S3</li><li>API Gateway</li><li>SNS</li></ul><p>There are different levels of automation around each event. For example, if you set an API Gateway event, Foremast will create the API, methods, and resources if they do not already exist.</p><p>If an event you want is not supported just file an issue on <a href="https://github.com/gogoair/foremast">Github</a> or put in a pull request!</p><h3>Uploading the Code</h3><p>Foremast does not handle uploading the code to the created Lambda function. We decided there were already better ways to do this and currently utilize the <a href="https://wiki.jenkins-ci.org/display/JENKINS/AWS+Lambda+Plugin">AWS Lambda Jenkins plugin</a>.</p><p>Once Foremast has run and created the empty Lambda function, connected the event triggers, and setup permissions, we have the Spinnaker pipeline kick off a Jenkins job. The job uploads a ZIP file to the Foremast created infrastructure.</p><h3>Spinnaker Lambda Support</h3><p>Spinnaker is adding official support of Lambda and we are very excited to see what this will look like. We will likely update Foremast when it is released in order to support automation around the Spinnaker methodology. Our developers were just so excited to start using Lambda that we got a jump start in making our own deployment pipeline.</p><h3>More Info</h3><p>If you want more info about Foremast, Lambda, Spinnaker, or friendly conversation, you can find us on Gitter: <a href="https://gitter.im/gogoair/foremast">https://gitter.im/gogoair/foremast</a></p><p><a href="https://github.com/gogoair/foremast">View the code here</a></p><p><a href="http://foremast.readthedocs.io/en/latest/">View the docs here</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/229/1*-XZQI0Gzqf5eZqCnSfB4DQ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8d49b1126ef7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/gogoair-tech/foremast-lambda-pipelines-8d49b1126ef7">Foremast — Lambda Pipelines</a> was originally published in <a href="https://medium.com/gogoair-tech">Gogo Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Foremast — Automate Spinnaker Pipeline Creation]]></title>
            <link>https://medium.com/gogoair-tech/foremast-automate-spinnaker-pipeline-creation-2b2aa7b2c5e4?source=rss-27f19a2c8a9d------2</link>
            <guid isPermaLink="false">https://medium.com/p/2b2aa7b2c5e4</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[deployment-pipelines]]></category>
            <category><![CDATA[jenkins]]></category>
            <dc:creator><![CDATA[Doug Campbell]]></dc:creator>
            <pubDate>Wed, 14 Sep 2016 14:46:30 GMT</pubDate>
            <atom:updated>2016-09-27T15:25:30.562Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hseoANKTMiRk-lg2_XheGw.jpeg" /><figcaption>Set sail for easy deployments</figcaption></figure><p><a href="http://www.spinnaker.io/">Spinnaker</a> is an awesome tool from Netflix. If you haven’t checked it out yet, stop reading and go take a look right now at <a href="http://www.spinnaker.io/">http://www.spinnaker.io/</a> . Spinnaker has become a core part of Gogo’s deployments to AWS and we wrote a tool called Foremast to help automate pipeline and infrastructure creation within Spinnaker.</p><p>We are excited to make Foremast open source and will be writing a few blog posts to detail usage and features.</p><p><a href="https://github.com/gogoair/foremast">Get the code here</a></p><p><a href="http://foremast.readthedocs.io/en/latest/">Read the docs here</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/229/1*-XZQI0Gzqf5eZqCnSfB4DQ.png" /></figure><h3>The Problem</h3><p>Foremast was created to solve some workflow issues we were having in Spinnaker:</p><ol><li>We didn’t want to create each pipeline by hand in the UI.</li><li>We did want pipelines to be versioned, have a change log, and be easily reproducible</li><li>We wanted to provide a standardized pipeline to all developers in the organization but be flexible enough to meet the specific needs of each application.</li></ol><h3>The Solution</h3><p>The solution was to make Foremast. It takes a couple of JSON configuration files and Jinja2 templates to dynamically create unique Spinnaker pipelines for each application.</p><p>Developers create some simple JSON configurations per application. These configurations provide details on the pipeline and infrastructure needs. Foremast takes those configurations, renders a bunch of Jinja2 templates, and then acts as a client for the Spinnaker Gate API. Foremast comes with generic templates for creating a simple pipeline but it can also point to external templates for custom pipelines that fit any workflow.</p><h3>The Configs</h3><p>Pipeline creation relies on a couple configuration files per application. We like to put these configs in the same repository as the application so that they are versioned the same. See the documentation at <a href="http://foremast.readthedocs.io/en/latest/">http://foremast.readthedocs.io</a> for all configuration options.</p><h4>pipeline.json</h4><p>This config is used to define pipeline-wide settings. What accounts to deploy to, what regions, where to send notifications, etc. Below is the bare minimum that the config needs.</p><pre>{<br>  &quot;env&quot;: [<br>    &quot;dev&quot;,<br>    &quot;stage&quot;,<br>    &quot;prod&quot;<br>  ],<br>  &quot;regions&quot;: [<br>    &quot;us-east-1&quot;<br>  ]<br>}</pre><h4>application-master-&lt;env&gt;.json</h4><p>This config defines environment specific settings such as security groups, instance sizing, health checks, and scaling policies. This config needs to exist for each AWS account that the application is deployed to.</p><p>This config can be completely blank and it will use sane defaults. Below is an example of what this config can include.</p><pre>{<br>  &quot;security_group&quot;: {<br>    &quot;description&quot;: &quot;something useful&quot;,<br>    &quot;elb_extras&quot;: [&quot;offices_access&quot;],<br>    &quot;egress&quot;: &quot;0.0.0.0/0&quot;<br>  },<br>  &quot;app&quot;: {<br>    &quot;instance_type&quot;: &quot;t2.small&quot;,<br>    &quot;app_description&quot;: &quot;Demo Application&quot;,<br>    &quot;instance_profile&quot;: &quot;app_profile&quot;<br>  },<br>  &quot;elb&quot;: {<br>    &quot;subnet_purpose&quot;: &quot;internal&quot;,<br>    &quot;target&quot;: &quot;TCP:8080&quot;,<br>    &quot;ports&quot;: [<br>      {&quot;loadbalancer&quot;: &quot;HTTP:80&quot;, &quot;instance&quot;: &quot;HTTP:8080&quot;}<br>    ]<br>  },<br>  &quot;asg&quot;: {<br>    &quot;subnet_purpose&quot;: &quot;internal&quot;,<br>    &quot;min_inst&quot;: 1,<br>    &quot;max_inst&quot;: 4,<br>    &quot;scaling_policy&quot;: {<br>        &quot;metric&quot;: &quot;CPUUtilization&quot;,<br>        &quot;threshold&quot;: 90,<br>        {<br>        &quot;period_minutes&quot;: 10,<br>        &quot;statistic&quot;: &quot;Average&quot;<br>        }<br>  },<br>  &quot;regions&quot;: [&quot;us-east-1&quot;],<br>  &quot;dns&quot; : {<br>    &quot;ttl&quot;: 120<br>    }<br>}</pre><h4>foremast.cfg</h4><p>foremast.cfg is the config that drives Foremast execution. This should live in <em>/etc/foremast/foremast.cfg</em> or <em>~/.foremast/foremast.cfg</em>. It holds info such as Gate URL, environments, and formatting.</p><pre>[base]<br>domain = example.com<br>envs = dev,stage,prod<br>regions = us-east-1,us-west-2<br>gate_api_url = <a href="https://gate.example.com:7777/">https://gate.example.com:</a>8084</pre><pre>[formats]<br>domain = example.com<br>iam_policy = {project}_{repo}_policy<br>iam_profile = {project}_{repo}_profile<br>jenkins_job_name = {project}_{repo}_job</pre><h3>Running Foremast</h3><p>Foremast has a few easy CLI endpoints for running tasks. These endpoints read in environment variables which makes them ideal for running in a Jenkins job. In this post we will just cover how to generate a pipeline.</p><h4>Installing</h4><p>Foremast requires Python3 and ideally runs in a virtualenv.</p><pre>virtualenv -p python3 venv<br>source venv/bin/activate<br>pip install foremast</pre><h4>Environment Variables</h4><pre>GIT_REPO = The name of the application repository<br>PROJECT = The group/project of the application<br>RUNWAY_DIR = The directory of your application-*.json and pipeline.json configs</pre><h4>foremast-pipeline</h4><p>‘<em>foremast-pipeline</em>’ is the CLI endpoint that will create a Spinnaker application and generate the pipeline. When successfully complete, you should see your application in Spinnaker</p><pre>GIT_REPO=&quot;demo&quot; PROJECT=&quot;appgroup&quot; EMAIL=&quot;developer<a href="/service/mailto:ps-devopstooling@gogoair.com">@example.com</a>&quot; RUNWAY_DIR=/path/to/configs foremast-pipeline</pre><h3>The Results</h3><p>Once Foremast has successfully ran the “<em>foremast-pipeline</em>” endpoint you should see a pipeline in Spinnaker that looks similar to below example.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2t-qxXoexaZOxCTwoJQCxA.png" /><figcaption>Basic dev -&gt; stage -&gt; prod pipeline generated from Foremast</figcaption></figure><p>With Foremast this pipeline is now easily reproducible and customizable for each application needs.</p><h4>Gogo’s Workflow</h4><p>At Gogo, we have a workflow with Foremast that we feel works pretty well.</p><ol><li>Developer makes a change to any of the <em>*.json</em> Foremast configs and push the change to a central Git repository</li><li>A server-side Git hook detects a change to the files and triggers a Jenkins job with parameters based on the changed files.</li><li>The Jenkins job runs the “<em>foremast-pipeline</em>” endpoint and dynamically creates or updates the Spinnaker pipeline.</li><li>Almost immediately after pushing a change, the Developer has their updated pipeline created in Spinnaker and ready to use.</li></ol><h3>But Wait, There is More!</h3><p>Dynamically building Spinnaker pipelines is not all that Foremast does. Some other features include:</p><ul><li>Generating AWS Infrastructure based on the JSON configs</li><li>Create AWS Lambda infrastructure and pipelines in Spinnaker</li><li>Highly customizable pipelines via external Jinja2 templates</li></ul><p>We will go into more depth on those features in later blog posts.</p><p>If you are super interested, want some help, or just want to chat about Spinnaker and Foremast, we are active on <a href="https://gitter.im/gogoair/foremast">Gitter</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2b2aa7b2c5e4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/gogoair-tech/foremast-automate-spinnaker-pipeline-creation-2b2aa7b2c5e4">Foremast — Automate Spinnaker Pipeline Creation</a> was originally published in <a href="https://medium.com/gogoair-tech">Gogo Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>