-
Notifications
You must be signed in to change notification settings - Fork 0
/
directories.html
53 lines (48 loc) · 10.9 KB
/
directories.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<html><head><title>Orkestra: Directories</title><meta charset="utf-8" /><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="author" content="tech.orkestra" /><meta name="description" content="Functional DevOps with Scala and Kubernetes" /><meta name="og:image" content="/img/poster.png" /><meta name="og:title" content="Orkestra: Directories" /><meta name="og:site_name" content="Orkestra" /><meta name="og:url" content="https://orkestra.tech" /><meta name="og:type" content="website" /><meta name="og:description" content="Functional DevOps with Scala and Kubernetes" /><link rel="icon" type="image/png" href="/img/favicon.png" /><meta name="twitter:title" content="Orkestra: Directories" /><meta name="twitter:image" content="https://orkestra.techimg/poster.png" /><meta name="twitter:description" content="Functional DevOps with Scala and Kubernetes" /><meta name="twitter:card" content="summary_large_image" /><link rel="icon" type="image/png" sizes="16x16" href="/img/favicon16x16.png" /><link rel="icon" type="image/png" sizes="24x24" href="/img/favicon24x24.png" /><link rel="icon" type="image/png" sizes="32x32" href="/img/favicon32x32.png" /><link rel="icon" type="image/png" sizes="48x48" href="/img/favicon48x48.png" /><link rel="icon" type="image/png" sizes="57x57" href="/img/favicon57x57.png" /><link rel="icon" type="image/png" sizes="60x60" href="/img/favicon60x60.png" /><link rel="icon" type="image/png" sizes="64x64" href="/img/favicon64x64.png" /><link rel="icon" type="image/png" sizes="70x70" href="/img/favicon70x70.png" /><link rel="icon" type="image/png" sizes="72x72" href="/img/favicon72x72.png" /><link rel="icon" type="image/png" sizes="76x76" href="/img/favicon76x76.png" /><link rel="icon" type="image/png" sizes="96x96" href="/img/favicon96x96.png" /><link rel="icon" type="image/png" sizes="114x114" href="/img/favicon114x114.png" /><link rel="icon" type="image/png" sizes="120x120" href="/img/favicon120x120.png" /><link rel="icon" type="image/png" sizes="128x128" href="/img/favicon128x128.png" /><link rel="icon" type="image/png" sizes="144x144" href="/img/favicon144x144.png" /><link rel="icon" type="image/png" sizes="150x150" href="/img/favicon150x150.png" /><link rel="icon" type="image/png" sizes="152x152" href="/img/favicon152x152.png" /><link rel="icon" type="image/png" sizes="196x196" href="/img/favicon196x196.png" /><link rel="icon" type="image/png" sizes="310x310" href="/img/favicon310x310.png" /><link rel="icon" type="image/png" sizes="310x150" href="/img/favicon310x150.png" /><link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" /><link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" /><link rel="stylesheet" href="/highlight/styles/atom-one-light.css" /><link rel="stylesheet" href="/css/style.css" /><link rel="stylesheet" href="/css/palette.css" /><link rel="stylesheet" href="/css/codemirror.css" /><link rel="stylesheet" href="/css/override.css" /></head><body class="docs"><div id="wrapper"><div id="sidebar-wrapper"><ul id="sidebar" class="sidebar-nav"><li class="sidebar-brand"><a href="/" class="brand"><div class="brand-wrapper"><span>Orkestra</span></div></a></li> <li><a href="/jobsboards.html" class="">Jobs & Boards</a></li> <li><a href="/config.html" class="">Config</a></li> <li><a href="/parameters.html" class="">Parameters</a></li> <li><a href="/stages.html" class="">Stages</a></li> <li><a href="/shells.html" class="">Shell scripts</a></li> <li><a href="/directories.html" class=" active ">Directories</a></li> <li><a href="/secrets.html" class="">Secrets</a></li> <li><a href="/triggers.html" class="">Triggering jobs</a></li> <li><a href="/runid.html" class="">RunId</a></li> <li><a href="/containers.html" class="">Containers</a></li> <li><a href="/plugins" class="">Plugins</a> <ul class="sub_section"> <li><a href="/plugins/github.html" class="">Github</a></li> <li><a href="/plugins/cron.html" class="">Cron jobs</a></li> <li><a href="/plugins/locking.html" class="">Locking</a></li></ul></li></ul></div><div id="page-content-wrapper"><div class="nav"><div class="container-fluid"><div class="row"><div class="col-lg-12"><div class="action-menu pull-left clearfix"><a href="#menu-toggle" id="menu-toggle"><i class="fa fa-bars" aria-hidden="true"></i></a></div><ul class="pull-right"><li id="gh-eyes-item" class="hidden-xs"><a href="https://github.com/Orkestra-Tech/orkestra"><i class="fa fa-eye"></i><span>WATCH<span id="eyes" class="label label-default">--</span></span></a></li><li id="gh-stars-item" class="hidden-xs"><a href="https://github.com/Orkestra-Tech/orkestra"><i class="fa fa-star-o"></i><span>STARS<span id="stars" class="label label-default">--</span></span></a></li><li><a href="#" onclick="shareSiteTwitter('Orkestra Functional DevOps with Scala and Kubernetes');"><i class="fa fa-twitter"></i></a></li><li><a href="#" onclick="shareSiteFacebook('Orkestra Functional DevOps with Scala and Kubernetes');"><i class="fa fa-facebook"></i></a></li><li><a href="#" onclick="shareSiteGoogle();"><i class="fa fa-google-plus"></i></a></li></ul></div></div></div></div><div id="content" data-github-owner="Orkestra-Tech" data-github-repo="orkestra"><div class="content-wrapper"><section><h1 id="directories">Directories</h1>
<p>When playing with files we often need to change directories, so you might wonder if we do that in Orkestra!<br />
First of all this is now time to explain what the <code class="highlighter-rouge">implicit workDir</code>. This implicit is used for example by the function
<code class="highlighter-rouge">sh()</code> as seen in <a href="shells.html">Shell scripts</a> to know where to run the shell script.<br />
So if we’d like to change directory we would use the function <code class="highlighter-rouge">dir</code> that changes the current directory only for the
scope of the function passed to it:</p>
<div class="language-scala highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">import</span> <span class="nn">scala.concurrent.Await</span>
<span class="k">import</span> <span class="nn">scala.concurrent.duration._</span>
<span class="k">import</span> <span class="nn">tech.orkestra._</span>
<span class="k">import</span> <span class="nn">tech.orkestra.Dsl._</span>
<span class="k">import</span> <span class="nn">tech.orkestra.board._</span>
<span class="c1">// We import the directories DSL
</span><span class="k">import</span> <span class="nn">tech.orkestra.utils.Directories._</span>
<span class="k">import</span> <span class="nn">tech.orkestra.job._</span>
<span class="k">import</span> <span class="nn">tech.orkestra.model._</span>
<span class="k">import</span> <span class="nn">tech.orkestra.utils.Shells._</span>
<span class="k">lazy</span> <span class="k">val</span> <span class="n">directoryJobBoard</span> <span class="k">=</span> <span class="nc">JobBoard</span><span class="o">[()</span> <span class="k">=></span> <span class="kt">Unit</span><span class="o">](</span><span class="nc">JobId</span><span class="o">(</span><span class="s">"directory"</span><span class="o">),</span> <span class="s">"Directory"</span><span class="o">)()</span>
<span class="k">lazy</span> <span class="k">val</span> <span class="n">directoryJob</span> <span class="k">=</span> <span class="nc">Job</span><span class="o">(</span><span class="n">directoryJobBoard</span><span class="o">)</span> <span class="o">{</span> <span class="k">implicit</span> <span class="n">workDir</span> <span class="k">=></span> <span class="o">()</span> <span class="k">=></span>
<span class="nc">Await</span><span class="o">.</span><span class="n">result</span><span class="o">(</span><span class="k">for</span> <span class="o">{</span>
<span class="c1">// Create the directory subDir
</span> <span class="k">_</span> <span class="k"><-</span> <span class="n">sh</span><span class="o">(</span><span class="s">"mkdir subDir"</span><span class="o">)</span>
<span class="c1">// Moving in the subDir
</span> <span class="k">_</span> <span class="k"><-</span> <span class="n">dir</span><span class="o">(</span><span class="s">"subDir"</span><span class="o">)</span> <span class="o">{</span> <span class="k">implicit</span> <span class="n">workDir</span> <span class="k">=></span>
<span class="c1">// Print the working directory
</span> <span class="n">sh</span><span class="o">(</span><span class="s">"pwd"</span><span class="o">)</span>
<span class="o">}</span>
<span class="o">}</span> <span class="k">yield</span> <span class="o">(),</span> <span class="mf">1.</span><span class="n">second</span><span class="o">)</span>
<span class="o">}</span>
</code></pre></div></div>
<p>Note that we need to take this <code class="highlighter-rouge">implicit workDir =></code> again in the function passed to <code class="highlighter-rouge">dir</code>.</p>
<h2 id="localfile">LocalFile</h2>
<p>When dealing with files in Scala we usually use the <code class="highlighter-rouge">java.io.File</code>. In Orkestra as we can change the current working
directory we need the relative <code class="highlighter-rouge">File</code> to be aware of it. This is why we have the <code class="highlighter-rouge">LocalFile</code> class that extends <code class="highlighter-rouge">File</code>
so that we can use it in Scala or Java libraries.<br />
Here is an example of how to use it:</p>
<div class="language-scala highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">import</span> <span class="nn">tech.orkestra.filesystem._</span>
<span class="k">def</span> <span class="n">createFile</span><span class="o">()(</span><span class="k">implicit</span> <span class="n">workDir</span><span class="k">:</span> <span class="kt">Directory</span><span class="o">)</span><span class="k">:</span> <span class="kt">Unit</span> <span class="o">=</span> <span class="o">{</span>
<span class="n">dir</span><span class="o">(</span><span class="s">"subDir"</span><span class="o">)</span> <span class="o">{</span> <span class="k">implicit</span> <span class="n">workDir</span> <span class="k">=></span>
<span class="nc">LocalFile</span><span class="o">(</span><span class="s">"myFile"</span><span class="o">).</span><span class="n">createNewFile</span><span class="o">()</span>
<span class="o">}</span>
<span class="o">}</span>
</code></pre></div></div>
</section></div></div></div></div><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script><script src="/highlight/highlight.pack.js"></script><script>hljs.configure({
languages:['scala','java','bash']
});
hljs.initHighlighting();
</script><script>((window.gitter = {}).chat = {}).options = {
room: 'orkestra-tech/Orkestra'};</script><script src="https://sidecar.gitter.im/dist/sidecar.v1.js"></script><script src="/js/main.js"></script></body></html>