Skip to content

Commit

Permalink
Document typescript function exec runtime example
Browse files Browse the repository at this point in the history
  • Loading branch information
prachirp committed Jun 26, 2020
1 parent 66f3f05 commit fe5b370
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 10 deletions.
47 changes: 47 additions & 0 deletions docs/guides/producer/functions/exec/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,20 @@



<nav id="TableOfContents">
<ul>
<li><a href="#imperative-run">Imperative Run</a></li>
<li><a href="#declarative-run">Declarative Run</a></li>
<li><a href="#typescript-function-example">Typescript Function Example</a>
<ul>
<li><a href="#prerequisites">Prerequisites</a></li>
<li><a href="#steps">Steps</a></li>
</ul>
</li>
<li><a href="#next-steps">Next Steps</a></li>
</ul>
</nav>



</div>
Expand Down Expand Up @@ -875,6 +889,39 @@ <h2 id="imperative-run">Imperative Run</h2>
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">path</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span>/path/to/executable<span style="color:#f8f8f8;text-decoration:underline">
</span></code></pre></div><p>Note: if the <code>--enable-exec</code> flag is not provided, <code>kpt fn run DIR/</code> will ignore the exec
function and exit 0.</p>
<h2 id="typescript-function-example">Typescript Function Example</h2>
<p>You may want to run a function developed with one of the config function SDKs using the exec
runtime in order to avoid the overhead associated with running a container. To run your function
in the exec runtime, you will first need to package your function as an executable.</p>
<p>We walk through an example of running a typescript function using the kpt exec runtime.</p>
<h3 id="prerequisites">Prerequisites</h3>
<ul>
<li>
<p>Install the pkg CLI.</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-sh" data-lang="sh">npm install -g pkg
</code></pre></div></li>
<li>
<p>Install your kpt-functions package module to create your function&rsquo;s distributable file.</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-sh" data-lang="sh">npm i
</code></pre></div></li>
</ul>
<h3 id="steps">Steps</h3>
<ol>
<li>
<p>Use the pkg CLI to create an executable from your function&rsquo;s distributable file. For a my_func
function built using the typescript SDK, this is <code>dist/my_func_run.js</code>.</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-sh" data-lang="sh">npx pkg dist/my_func_run.js
</code></pre></div></li>
<li>
<p>Pass the path to the appropriate executable for your OS when running kpt using the exec runtime.</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-sh" data-lang="sh">kpt fn run DIR/ --enable-exec --exec-path /path/to/my_func_run-macos -- <span style="color:#000">foo</span><span style="color:#ce5c00;font-weight:bold">=</span>bar <span style="color:#000">baz</span><span style="color:#ce5c00;font-weight:bold">=</span>qux
</code></pre></div></li>
</ol>
<h2 id="next-steps">Next Steps</h2>
<ul>
<li>Find out how to structure a pipeline of functions from the <a href="../../../../concepts/functions/">functions concepts</a> page.</li>
<li>Consult the <a href="../../../../reference/fn/">fn command reference</a>.</li>
</ul>

<div class="section-index">

Expand Down
33 changes: 33 additions & 0 deletions docs/guides/producer/functions/index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,39 @@ the example.&lt;/p&gt;
&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt; &lt;/span&gt;&lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;path&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;:&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt; &lt;/span&gt;/path/to/executable&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Note: if the &lt;code&gt;--enable-exec&lt;/code&gt; flag is not provided, &lt;code&gt;kpt fn run DIR/&lt;/code&gt; will ignore the exec
function and exit 0.&lt;/p&gt;
&lt;h2 id=&#34;typescript-function-example&#34;&gt;Typescript Function Example&lt;/h2&gt;
&lt;p&gt;You may want to run a function developed with one of the config function SDKs using the exec
runtime in order to avoid the overhead associated with running a container. To run your function
in the exec runtime, you will first need to package your function as an executable.&lt;/p&gt;
&lt;p&gt;We walk through an example of running a typescript function using the kpt exec runtime.&lt;/p&gt;
&lt;h3 id=&#34;prerequisites&#34;&gt;Prerequisites&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Install the pkg CLI.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;npm install -g pkg
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Install your kpt-functions package module to create your function&amp;rsquo;s distributable file.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;npm i
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;steps&#34;&gt;Steps&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Use the pkg CLI to create an executable from your function&amp;rsquo;s distributable file. For a my_func
function built using the typescript SDK, this is &lt;code&gt;dist/my_func_run.js&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;npx pkg dist/my_func_run.js
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Pass the path to the appropriate executable for your OS when running kpt using the exec runtime.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;kpt fn run DIR/ --enable-exec --exec-path /path/to/my_func_run-macos -- &lt;span style=&#34;color:#000&#34;&gt;foo&lt;/span&gt;&lt;span style=&#34;color:#ce5c00;font-weight:bold&#34;&gt;=&lt;/span&gt;bar &lt;span style=&#34;color:#000&#34;&gt;baz&lt;/span&gt;&lt;span style=&#34;color:#ce5c00;font-weight:bold&#34;&gt;=&lt;/span&gt;qux
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;next-steps&#34;&gt;Next Steps&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Find out how to structure a pipeline of functions from the &lt;a href=&#34;../../../../concepts/functions/&#34;&gt;functions concepts&lt;/a&gt; page.&lt;/li&gt;
&lt;li&gt;Consult the &lt;a href=&#34;../../../../reference/fn/&#34;&gt;fn command reference&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

</description>
</item>
Expand Down
4 changes: 2 additions & 2 deletions docs/reference/fn/index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ of CRDs:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;: Declare two functions in &lt;code&gt;DIR/functions/my-functions.yaml&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-yaml&#34; data-lang=&#34;yaml&#34;&gt;&lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;apiVersion&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;:&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt; &lt;/span&gt;v1&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;
&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;kind&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;:&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt; &lt;/span&gt;ConfigMap&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;
&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;metdata&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;:&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;
&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;metadata&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;:&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;
&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt; &lt;/span&gt;&lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;annotations&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;:&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;
&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt; &lt;/span&gt;&lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;config.kubernetes.io/function&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;:&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt; &lt;/span&gt;&lt;span style=&#34;color:#8f5902;font-style:italic&#34;&gt;|
&lt;/span&gt;&lt;span style=&#34;color:#8f5902;font-style:italic&#34;&gt; container:&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;
Expand All @@ -128,7 +128,7 @@ of CRDs:&lt;/p&gt;
&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;&lt;/span&gt;---&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;
&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;apiVersion&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;:&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt; &lt;/span&gt;v1&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;
&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;kind&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;:&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt; &lt;/span&gt;MyType&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;
&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;metdata&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;:&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;
&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;metadata&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;:&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;
&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt; &lt;/span&gt;&lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;annotations&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;:&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;
&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt; &lt;/span&gt;&lt;span style=&#34;color:#204a87;font-weight:bold&#34;&gt;config.kubernetes.io/function&lt;/span&gt;&lt;span style=&#34;color:#000;font-weight:bold&#34;&gt;:&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt; &lt;/span&gt;&lt;span style=&#34;color:#8f5902;font-style:italic&#34;&gt;|
&lt;/span&gt;&lt;span style=&#34;color:#8f5902;font-style:italic&#34;&gt; container:&lt;/span&gt;&lt;span style=&#34;color:#f8f8f8;text-decoration:underline&#34;&gt;
Expand Down
6 changes: 3 additions & 3 deletions docs/reference/fn/run/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,7 @@ <h5 id="custom-functionconfig">Custom <code>functionConfig</code></h5>
<p><strong>Example</strong>: Declare two functions in <code>DIR/functions/my-functions.yaml</code>:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-yaml" data-lang="yaml"><span style="color:#204a87;font-weight:bold">apiVersion</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span>v1<span style="color:#f8f8f8;text-decoration:underline">
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">kind</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span>ConfigMap<span style="color:#f8f8f8;text-decoration:underline">
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">metdata</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">metadata</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">annotations</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">config.kubernetes.io/function</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#8f5902;font-style:italic">|
</span><span style="color:#8f5902;font-style:italic"> container:</span><span style="color:#f8f8f8;text-decoration:underline">
Expand All @@ -1002,7 +1002,7 @@ <h5 id="custom-functionconfig">Custom <code>functionConfig</code></h5>
</span><span style="color:#f8f8f8;text-decoration:underline"></span>---<span style="color:#f8f8f8;text-decoration:underline">
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">apiVersion</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span>v1<span style="color:#f8f8f8;text-decoration:underline">
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">kind</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span>MyType<span style="color:#f8f8f8;text-decoration:underline">
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">metdata</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">metadata</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">annotations</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">config.kubernetes.io/function</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#8f5902;font-style:italic">|
</span><span style="color:#8f5902;font-style:italic"> container:</span><span style="color:#f8f8f8;text-decoration:underline">
Expand Down Expand Up @@ -1089,7 +1089,7 @@ <h5 id="custom-functionconfig">Custom <code>functionConfig</code></h5>



<div class="text-muted mt-5 pt-3 border-top">Last modified March 27, 2020: <a href="https://github.com/GoogleContainerTools/kpt/commit/6b418959c1bf4331616a69e634b15891cda8017e">Fix typo in declarative config example (6b418959)</a>
<div class="text-muted mt-5 pt-3 border-top">Last modified June 25, 2020: <a href="https://github.com/GoogleContainerTools/kpt/commit/f46e09cc8f8912d9d2f22ef5dfab412524c399bd">Fix typo in function doc (f46e09cc)</a>
</div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion docs/sitemap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@

<url>
<loc>https://googlecontainertools.github.io/kpt/reference/fn/run/</loc>
<lastmod>2020-03-27T22:50:08-04:00</lastmod>
<lastmod>2020-06-25T14:16:35-07:00</lastmod>
</url>

<url>
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/go-errors/errors v1.0.1
github.com/go-openapi/spec v0.19.5
github.com/gogo/protobuf v1.3.1 // indirect
github.com/google/addlicense v0.0.0-20200422172452-68a83edd47bc // indirect
github.com/google/addlicense v0.0.0-20200622132530-df58acafd6d5 // indirect
github.com/olekukonko/tablewriter v0.0.4
github.com/pkg/errors v0.9.1
github.com/posener/complete/v2 v2.0.1-alpha.12
Expand Down
Loading

0 comments on commit fe5b370

Please sign in to comment.