Introducing Template Namespaces
<p>We’ve reworked templates to filter by namespace! Namespaces are meant for easier grouping in the UI.</p><figure data-orig-width="2348" data-orig-height="764" class="tmblr-full"><img src="https://66.media.tumblr.com/31c7f52f9e15c2cd62dbd4048f568070/tumblr_inline_pb3wiq8XXw1uvhog4_540.png" alt="image" data-orig-width="2348" data-orig-height="764"/></figure><p>From a template creator perspective, template creation still works the same; however, you now have the ability to explicitly define a template namespace. For Screwdriver cluster admins, you will need to migrate existing templates in your database to the new schema in order for them to be displayed correctly in the new UI. These steps will be covered below.</p><!-- more --><h2>Screwdriver Users</h2><p>For Screwdriver template users, you can still use templates the same way.</p><pre><code>jobs:
main:
template: templateNamespace/templateName@1.2.3
requires: [~pr, ~commit]
</code></pre><p>In the UI, you can navigate to the template namespace page by clicking on the namespace or going to <code>/templates/namespaces/<namespace></code>. Any templates with no defined template namespace will be available at <code>/templates/namespaces/default</code>.</p><h2>Template owners</h2><p>To create a template with a designated namespace, you can either:
Implicitly define a namespace (same as before)
Explicitly define a namespace
Use the default namespace (same as before)</p><p>Templates will still be used by users the same way.</p><p><b>Implicit namespace</b></p><p>Screwdriver will interpret anything before a template name’s slash (<code>/</code>) as the namespace. If you define a sd-template.yaml with <code>name: nodejs/lib</code>, Screwdriver will store <code>namespace: nodejs</code> and <code>name: lib</code>.</p><p>User’s screwdriver.yaml:</p><pre><code>jobs:
main:
template: nodejs/lib@1.2.3
requires: [~pr, ~commit]
</code></pre><p><b>Explicit namespace</b></p><p>You can explicitly define a template namespace. If you do, you cannot have any slashes (<code>/</code>) in your template name.</p><p>Template yaml snippet:</p><pre><code>namespace: nodejs
name: lib
...
</code></pre><p>User’s screwdriver.yaml:</p><pre><code>jobs:
main:
template: nodejs/lib@1.2.3
requires: [~pr, ~commit]
</code></pre><p><b>Default namespace</b></p><p>If you don’t explicitly or implicitly define a namespace, Screwdriver will assign <code>namespace: default</code> to your template. Users will still use your template as you defined it, but it will be grouped with other templates with default namespaces in the UI.</p><p>Template yaml snippet:</p><pre><code>name: lib
</code></pre><p>User’s screwdriver.yaml:</p><pre><code>jobs:
main:
template: lib@1.2.3
requires: [~pr, ~commit]
</code></pre><h2>Screwdriver Cluster Admins</h2><p><b>Database Migration</b></p><p>This feature has breaking changes that will affect your DB if you already have existing templates. In order to migrate your templates properly, you will need to do the following steps:</p><p>1. Make sure you’ve updated your unique constraints on your <code>templates</code> and <code>templateTags</code> tables to include <code>namespace</code>.</p><p>2. Set a <code>default</code> namespace when no namespace exists.<br/></p><p>In postgresql, run:</p><pre><code>UPDATE public."templates"
SET namespace = 'default'
WHERE name !~ '.*/.*'
</code></pre><p>3. Set implicit namespaces if users defined them. This requires two calls in postgres, one to split by namespace and name, the second to remove the curly braces (<code>{</code> and <code>}</code>) injected by the <code>regexp</code> call.</p><pre><code>UPDATE public."templates"
SET namespace = regexp_matches(name, '(.*)/.*'), name = regexp_matches(name, '.*/(.*)')
WHERE name ~ '.*/.*'
</code></pre><pre><code>UPDATE public."templates"
SET namespace = btrim(namespace, '{}'), name = btrim(name, '{}')
</code></pre><h2>Compatibility List</h2><p>Template namespaces require the following minimum versions of Screwdriver:</p><ul><li><a href="https://hub.docker.com/r/screwdrivercd/screwdriver/"><b>screwdrivercd/screwdriver</b></a>:v0.5.396</li>
<li><a href="https://hub.docker.com/r/screwdrivercd/ui/"><b>screwdrivercd/ui</b></a>:v1.0.297</li>
<li><a href="https://hub.docker.com/r/screwdrivercd/launcher/"><b>screwdrivercd/launcher</b></a>:v4.0.117</li>
<li><a href="https://hub.docker.com/r/screwdrivercd/store/"><b>screwdrivercd/store</b></a>:v3.1.2</li>
<li><a href="https://hub.docker.com/r/screwdrivercd/launcher/"><b>screwdrivercd/queue-worker</b></a>:v1.12.18</li>
</ul><h2>Contributors</h2><p>Thanks to the following people for making this feature possible:</p><ul><li><a href="https://github.com/jithin1987"><b>jithin1987</b></a></li>
<li><a href="https://github.com/lusol"><b>lusol</b></a></li>
<li><a href="https://github.com/tkyi"><b>tkyi</b></a></li>
</ul><p>Screwdriver is an open-source build automation platform designed for Continuous Delivery. It is built (and used) by Yahoo. Don’t hesitate to reach out if you have questions or would like to contribute: <a href="http://docs.screwdriver.cd/about/support.">http://docs.screwdriver.cd/about/support.</a></p>