CINXE.COM

How to integrate with GitHub the right way with GitHub Apps | OpenFaaS - Serverless Functions Made Simple

<!DOCTYPE html> <html class="has-navbar-fixed-top" lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- Begin Jekyll SEO tag v2.8.0 --> <title>How to integrate with GitHub the right way with GitHub Apps | OpenFaaS - Serverless Functions Made Simple</title> <meta name="generator" content="Jekyll v3.10.0" /> <meta property="og:title" content="How to integrate with GitHub the right way with GitHub Apps" /> <meta name="author" content="OpenFaaS Ltd" /> <meta property="og:locale" content="en_US" /> <meta name="description" content="In this guide, we are going to demonstrate how to build your own GitHub App to get a fine-grained integration with GitHub’s API and to act on the behalf of its users." /> <meta property="og:description" content="In this guide, we are going to demonstrate how to build your own GitHub App to get a fine-grained integration with GitHub’s API and to act on the behalf of its users." /> <link rel="canonical" href="https://www.openfaas.com/blog/integrate-with-github-apps-and-faasd/" /> <meta property="og:url" content="https://www.openfaas.com/blog/integrate-with-github-apps-and-faasd/" /> <meta property="og:site_name" content="OpenFaaS - Serverless Functions Made Simple" /> <meta property="og:image" content="https://www.openfaas.com/images/2021-01-15-github-application-using-go-and-inlets-pro/githubpic.jpg" /> <meta property="og:type" content="article" /> <meta property="article:published_time" content="2021-01-26T00:00:00+00:00" /> <meta name="twitter:card" content="summary_large_image" /> <meta property="twitter:image" content="https://www.openfaas.com/images/2021-01-15-github-application-using-go-and-inlets-pro/githubpic.jpg" /> <meta property="twitter:title" content="How to integrate with GitHub the right way with GitHub Apps" /> <script type="application/ld+json"> {"@context":"https://schema.org","@type":"BlogPosting","author":{"@type":"Person","name":"OpenFaaS Ltd"},"dateModified":"2021-01-26T00:00:00+00:00","datePublished":"2021-01-26T00:00:00+00:00","description":"In this guide, we are going to demonstrate how to build your own GitHub App to get a fine-grained integration with GitHub’s API and to act on the behalf of its users.","headline":"How to integrate with GitHub the right way with GitHub Apps","image":"https://www.openfaas.com/images/2021-01-15-github-application-using-go-and-inlets-pro/githubpic.jpg","mainEntityOfPage":{"@type":"WebPage","@id":"https://www.openfaas.com/blog/integrate-with-github-apps-and-faasd/"},"publisher":{"@type":"Organization","logo":{"@type":"ImageObject","url":"https://www.openfaas.com/siteicon.png"},"name":"OpenFaaS Ltd"},"url":"https://www.openfaas.com/blog/integrate-with-github-apps-and-faasd/"}</script> <!-- End Jekyll SEO tag --> <link type="application/atom+xml" rel="alternate" href="https://www.openfaas.com/feed.xml" title="OpenFaaS - Serverless Functions Made Simple" /> <link rel="apple-touch-icon" href="/apple-touch-icon.png"> <link rel="icon" type="image/png" href="/touch-icon.png" sizes="192x192"> <link rel="icon" type="image/png" href="/images/favicon.png"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@creativebulma/bulma-tooltip@1.2.0/dist/bulma-tooltip.min.css"> <link href="https://fonts.googleapis.com/css?family=Lato:300,400,700,900%7CRubik:300,400,500,700,900" rel="stylesheet"> <link rel="stylesheet" href="/css/openfaas.css"> <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable = yes"> <script defer src="https://use.fontawesome.com/releases/v5.14.0/js/all.js"></script> <!-- Google tag (gtag.js) --> <script async src="https://www.googletagmanager.com/gtag/js?id=G-MX51E38CEB"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'G-MX51E38CEB', { 'anonymize_ip': true }); </script> </head> <body> <div class="app app-default"> <!-- Top navigation bar --> <nav id="top-nav" class="navbar is-fixed-top is-primary" role="navigation" aria-label="main navigation"> <div class="container is-fluid"> <div class="navbar-brand"> <a class="navbar-item" href="/"> <img src="/images/openfaas_light.png" alt="Title Image"> </a> <a role="button" class="navbar-burger burger" aria-label="menu" aria-expanded="false"> <span aria-hidden="true"></span> <span aria-hidden="true"></span> <span aria-hidden="true"></span> </a> </div> <div class="navbar-menu"> <div class="navbar-middle"> <a href="/" class="navbar-item" >About</a> <a href="/blog/" class="navbar-item" >Blog</a> <a href="/pricing/" class="navbar-item" >Pricing</a> <a href="/support/" class="navbar-item" >Support</a> <a href="https://openfaas.gumroad.com/" class="navbar-item" >eBooks</a> <a href="/team/" class="navbar-item" >Team</a> <a href="https://docs.openfaas.com/" class="navbar-item" >Docs</a> </div> </div> <div class="navbar-end"> <div class="navbar-item"> <div id="git-stars" class="navigation-item github-repo"> <a href="https://github.com/openfaas" target="_blank"> <i class="fab fa-github"></i> <span id="stars-counter">31.1k</span> <span>View on github</span> </a> </div> </div> </div> </div> </nav> <!-- Content --> <div class="post-page-full"> <section class="hero is-medium is-bold cover" style="background-image: url(/images/2021-01-15-github-application-using-go-and-inlets-pro/githubpic.jpg)" > <div class="hero-body"> <div class="container"> <h1 class="title is-size-3 is-size-1-desktop has-text-weight-normal"> How to integrate with GitHub the right way with GitHub Apps </h1> <h2 class="subtitle is-size-4"> In this guide, we are going to demonstrate how to build your own GitHub App to get a fine-grained integration with GitHub's API and to act on the behalf of its users. </h2> </div> </div> </section> <section class="hero is-medium"> <div class="hero-body hero-blog-content"> <div class="container"> <div class="post-tabs-date"> <div class="subtitle has-text-grey-darker"> <span class="post-date is-pulled-right">January 26, 2021</span> </div> <hr> </div> <div class="content"> <div class="post-content"> <p>In this guide, we are going to demonstrate how to build your own GitHub App to get a fine-grained integration with GitHub’s API and to act on the behalf of its users</p> <h1 id="introduction">Introduction</h1> <p>With <a href="https://www.theverge.com/2018/6/18/17474284/microsoft-github-acquisition-developer-reaction">56 million developers on the platform and 85 million repositories</a>, integrating with GitHub is not just fun, it’s essential. Some companies have even built integrations so good, <a href="https://techcrunch.com/2019/09/18/github-acquires-code-analysis-tool-semmle/">that GitHub bought them</a> and made them part of the core platform. This has happened multiple times.</p> <blockquote> <p>Even faster than that. When we reached out to GitHub for comment, <a href="https://twitter.com/martinwoodward">Martin Woodward, Director of DevRel</a> told us that <a href="https://octoverse.github.com/">this year they saw 60 million new repositories created</a>.</p> </blockquote> <p>So why is it that so many of you are doing it wrong? Many of you are still using OAuth apps which are considered legacy and have scopes which are far too broad. Many more of you are taking extreme risks by using Personal Access Tokens (PATs), most of which can do anything to your account and repositories.</p> <blockquote> <p>GitHub Apps are first-class actors within GitHub and unlike the legacy OAuth apps, allow or fine-grained actions to be performed on your user’s repositories.</p> </blockquote> <p>In this guide, we are going to develop a <a href="https://docs.github.com/en/free-pro-team@latest/developers/apps">GitHub App</a> using Go, then we deploy it as a serverless function to make use of <a href="https://github.com/openfaas/faasd">faasd</a> which is a lightweight &amp; portable faas engine. We are also going to do this demo on our local environment, so we should open our function which runs on our local environment to the Internet so Github can send events to our function. In order to do that we use inlets-pro which provides secure TCP/L4 tunnels.</p> <blockquote> <p>If you are a Kubernetes or K3s user and want to follow along, you can do so and switch out faasd and inletsctl, for the <a href="https://github.com/inlets/inlets-operator">inlets-operator for Kubernetes</a> and your local cluster. Everything else will work the same.</p> </blockquote> <p><img src="/images/2021-01-15-github-application-using-go-and-inlets-pro/faasd-issue-bot.png" alt="overview" /></p> <p>A GitHub App acts on its own behalf, taking actions via the API directly using its own identity, which means you don’t need to maintain a bot or service account as a separate user. GitHub Apps can be installed directly on organizations and user accounts and granted access to specific repositories. They come with built-in webhooks and narrow, specific permissions. When you set up your GitHub App, you can select the repositories you want it to access. For example, in this guide we are going to develop a Github App that respond or close the comments for your repositories that you installed Github App for.</p> <p>Two examples that make thorough use of GitHub Apps are below:</p> <ul> <li><a href="https://github.com/alexellis/derek">Derek</a></li> <li><a href="https://github.com/openfaas/openfaas-cloud">OpenFaaS Cloud</a></li> </ul> <p>Derek is a GitHub bot that reduces fatigue for maintainers by automating governance and delegating permissions to your team and community. It provides the following automation:</p> <ul> <li>Generate changelogs for releases with PRs merged and commits added, crediting everyone invokved</li> <li>Let designated non-admin users manage Issues and PRs by commenting <code class="language-plaintext highlighter-rouge">Derek &lt;command&gt;</code> or <code class="language-plaintext highlighter-rouge">/command</code></li> <li>Enforce <a href="https://developercertificate.org/">Developer Certificate of Origin (DCO)</a> checking (optional)</li> <li>Automatically label/flag PRs without a Description</li> </ul> <p>OpenFaaS Cloud is designed as Multi-user version of OpenFaaS with CI/CD built in and a new dashboard. It is aimed at platform engineers who want to give functions to their team, whilst shielding them from Kubernetes at the same time.</p> <p>With OpenFaaS Cloud functions are managed through typing <code class="language-plaintext highlighter-rouge">git push</code> which reduces the tooling and learning curve required to operate functions for your team. As soon as OpenFaaS Cloud receives a push event from git it will run through a build-workflow which clones your repo, builds a Docker image, pushes it to a registry and then deploys your functions to your cluster. Each user can access and monitor their functions through their personal dashboard.</p> <h2 id="pre-requisites">Pre-requisites</h2> <ul> <li>DigitalOcean Account - We are going to use DigitalOcean as a provider to host our exit-node.</li> <li><a href="https://arkade.dev">arkade</a> - arkade provides a portable marketplace for downloading your favourite devops CLIs and installing helm charts, with a single command.</li> <li>inletsctl - inletsctl automates the task of creating an exit-node on cloud infrastructure.</li> <li>inlets-pro - You can use inlets-pro to tunnel out any TCP traffic from an internal network to another network.</li> <li>multipass - Multipass provides a command line interface to launch, manage and generally fiddle about with instances of Linux.</li> <li>faas-cli - This is a CLI for use with OpenFaaS - a serverless functions framework for Docker &amp; Kubernetes.</li> </ul> <p>Now we are ready to go 🚀</p> <h2 id="setup-your-exit-node-server-on-digitalocean">Setup your exit-node server on DigitalOcean</h2> <p>For this tutorial you will need to have an account and API key with one of the <a href="https://github.com/inlets/inletsctl#featuresbacklog">supported providers</a>, or you can create an exit-server manually and install inlets PRO there yourself.</p> <p>For this tutorial, the DigitalOcean provider will be used. You can get <a href="https://m.do.co/c/8d4e75e9886f">free credits on DigitalOcean with this link</a>.</p> <p>Create an API key in the DigitalOcean dashboard with Read and Write permissions, and download it to a file called do-access-token in your home directory or set this token as an environment variable like this:</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span><span class="nb">export </span><span class="nv">INLETS_ACCESS_TOKEN</span><span class="o">=</span><span class="s2">"&lt;digitalocean_api_token&gt;"</span> </code></pre></div></div> <p>You need to know the IP of the machine you to connect to on your local network, for instance 192.168.0.35 or 127.0.0.1 if you are running inlets PRO on the same host as SSH.</p> <p>You can use the inletsctl utility to provision exit-servers with inlets PRO preinstalled, it can also download the inlets-pro CLI.</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>curl <span class="nt">-sLSf</span> https://inletsctl.inlets.dev | sh <span class="nb">sudo mv </span>inletsctl /usr/local/bin/ <span class="nb">sudo </span>inletsctl download <span class="nt">--pro</span> </code></pre></div></div> <p>Finally, start your exit-node server on the fra1 region.</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>inletsctl create <span class="se">\</span> <span class="nt">--provider</span> digitalocean <span class="se">\</span> <span class="nt">--access-token-file</span> ~/do-access-token <span class="se">\</span> <span class="nt">--region</span> lon1 <span class="se">\</span> <span class="nt">--pro</span> </code></pre></div></div> <p>You can also change the region flag to a DigitalOcean region close to your network</p> <blockquote> <p>See <a href="https://docs.inlets.dev/#/tools/inletsctl?id=inletsctl-reference-documentation">the docs for inletsctl</a> for examples of how to use other providers like AWS EC2, Azure and GCP.</p> </blockquote> <p>If everything goes well, you should see your newly created “exit-node” on the homepage of your the DigitalOcean account like the following:</p> <p><img src="/images/2021-01-15-github-application-using-go-and-inlets-pro/inlets-droplet.png" alt="inlets-droplet" /></p> <blockquote> <p>If you curious about what the “exit-node or exit-server” is, you can follow a link in the inlets documentation <a href="https://docs.inlets.dev/#/?id=exit-servers">here</a>.</p> </blockquote> <h2 id="create-the-new-github-app-on-github">Create the new GitHub App on GitHub</h2> <p>To register a new app, visit the app settings page in your GitHub profile, and click New GitHub App.</p> <p><img src="/images/2021-01-15-github-application-using-go-and-inlets-pro/register-github-app.png" alt="register-github-app" /> You’ll see a form where you can enter details about your app. See “Creating a GitHub App” for general information about the fields on this page. For the purposes of this guide, you’ll need to enter specific data in a few fields:</p> <p>For more details you can check it out the <a href="https://docs.github.com/en/free-pro-team@latest/developers/apps/setting-up-your-development-environment-to-create-a-github-app#step-2-register-a-new-github-app">link</a></p> <p>The most important parts of this form are “Webhook URL,Webhook Secret and Private keys”:</p> <ul> <li> <p>Webhook URL : You should set the IP address of the output of the command above. <img src="/images/2021-01-15-github-application-using-go-and-inlets-pro/webhook-url.png" alt="webhook-url" /></p> </li> <li> <p>Webhook Secret : Define a secret for your Webhook. <img src="/images/2021-01-15-github-application-using-go-and-inlets-pro/webhook-secret.png" alt="webhook-secret" /></p> </li> <li> <p>Private Key : Generate and download private key for your Github Application. <img src="/images/2021-01-15-github-application-using-go-and-inlets-pro/private-keys.png" alt="private-key" /></p> </li> </ul> <p>Also, <em>do not forget to request permissions to Read &amp; Write the repository’s issues.</em> <img src="/images/2021-01-15-github-application-using-go-and-inlets-pro/permissions.png" alt="issues" /></p> <p>Finally, we registered our application. <img src="/images/2021-01-15-github-application-using-go-and-inlets-pro/app.png" alt="github-app" /></p> <h2 id="get-up-and-running-with-your-own-faasd-installation-on-your-computer-with-multipass">Get up and running with your own faasd installation on your computer with multipass</h2> <p><a href="https://multipass.run">Multipass</a> is a tool that not enough developers are using. It’s 2020’s answer to VirtualBox and Docker Desktop in one. You just run a few commands and get a Linux host with Ubuntu pre-installed. The best part is that it supports cloud-init scripts too.</p> <p>In order to get up and running with your own faasd installation on your Mac you can use multipass. For more details you can follow the <a href="https://github.com/openfaas/faasd/blob/master/docs/MULTIPASS.md">link</a>.</p> <p>Let’s start our Ubuntu VM with multipass. First, we need a cloud-config.txt to set up faasd while bootstrapping VM.</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>curl <span class="nt">-sSLO</span> <span class="se">\</span> https://raw.githubusercontent.com/openfaas/faasd/master/cloud-config.txt </code></pre></div></div> <p>Then, we need to update the SSH key to match your own, edit cloud-config.txt:</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>ssh-keygen <span class="nt">-t</span> rsa <span class="nt">-b</span> 4096 <span class="nt">-C</span> <span class="s2">"developerguyn@gmail.com"</span> <span class="nt">-f</span> <span class="nv">$PWD</span>/id_rsa </code></pre></div></div> <p>Replace the <em>ssh_authorized_keys::ssh-rsa</em> value with the contents of <code class="language-plaintext highlighter-rouge">~/.ssh/id_rsa.pub</code>, which is defined in <code class="language-plaintext highlighter-rouge">cloud-config.txt</code>.</p> <p>Finally, boot the VM</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>multipass launch <span class="se">\</span> <span class="nt">--cloud-init</span> cloud-config.txt <span class="se">\</span> <span class="nt">--name</span> faasd </code></pre></div></div> <blockquote> <p>Note: <code class="language-plaintext highlighter-rouge">multipass launch</code> can be configured with more CPUs, RAM and additional disk capacity, just run <code class="language-plaintext highlighter-rouge">--help</code> to see how.</p> </blockquote> <p>Check the VM if it is working properly:</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>multipass list Name State IPv4 Image faasd Running 192.168.64.25 Ubuntu 20.04 LTS </code></pre></div></div> <p>You can connect to the VM through SSH or via <code class="language-plaintext highlighter-rouge">multipass exec faasd</code>.</p> <p>To get the IP address simply run <code class="language-plaintext highlighter-rouge">multipass info faasd</code>:</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>multipass info faasd Name: faasd State: Running IPv4: 192.168.64.25 Release: Ubuntu 20.04.1 LTS Image <span class="nb">hash</span>: d68d50a4067d <span class="o">(</span>Ubuntu 20.04 LTS<span class="o">)</span> Load: 0.68 1.09 0.54 Disk usage: 1.9G out of 4.7G Memory usage: 259.8M out of 981.4M </code></pre></div></div> <h2 id="build-and-deploy-a-webhook-receiver-function">Build and deploy a webhook receiver function</h2> <p>For this demo, we are going to use Golang to develop a function that responds to any webhooks sent to us from the GitHub App.</p> <p>In order to do that, first, we need to pull the corresponding function template for the Golang.</p> <p>We need to install “faas-cli” tool for that but we need to install arkade first because arkade is the marketplace for our favourite devops CLIs.</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>curl <span class="nt">-sLS</span> https://get.arkade.dev | <span class="nb">sudo </span>sh </code></pre></div></div> <p>Then, let’s install our faas-cli tool.</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>arkade get faas-cli </code></pre></div></div> <p>We can now find the Golang template we want and continue to create our function.</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># let's look at the available Go function templates within the OpenFaaS store</span> <span class="nv">$ </span>faas-cli template store list | <span class="nb">grep</span> <span class="nt">-i</span> <span class="s2">"go"</span> go openfaas Classic Golang template golang-http openfaas Golang HTTP template golang-middleware openfaas Golang Middleware template <span class="c"># We are going to use golang-middleware function template, let's pull it.</span> <span class="nv">$ </span>faas-cli template store pull golang-middleware <span class="c"># Then, create the function itself.</span> <span class="nv">$ </span>faas-cli new issues-bot <span class="nt">--lang</span> golang-middleware <span class="nt">--prefix</span> &lt;DOCKER_HUB_ID&gt; </code></pre></div></div> <p>You can find all the code details in my GitHub repository: <a href="https://github.com/developer-guy/faasd-github-bot">developer-guy/faasd-github-bot</a>.</p> <p>After you’ve created the function, you need to define a build-arg to use Go modules, an environment variable for the GitHub App ID (found in the GitHub UI) and a secret for the the webhook secret (for verifying genuine payloads) and the private key (for acting on the behalf of a user).</p> <p>Let’s add them to the YAML file created by <code class="language-plaintext highlighter-rouge">faas-cli new</code>:</p> <div class="language-yaml highlighter-rouge"><div class="highlight"><pre class="highlight"><code> <span class="na">build_args</span><span class="pi">:</span> <span class="na">GO111MODULE</span><span class="pi">:</span> <span class="s">on</span> <span class="na">secrets</span><span class="pi">:</span> <span class="pi">-</span> <span class="s">webhook-secret</span> <span class="c1"># your secret goes here</span> <span class="pi">-</span> <span class="s">private-key-secret</span> <span class="c1"># your private key goes here</span> <span class="na">environment</span><span class="pi">:</span> <span class="na">APP_ID</span><span class="pi">:</span> <span class="s2">"</span><span class="s">"</span> <span class="c1"># your app id goes here</span> </code></pre></div></div> <p>Next we need to create the above two secrets.</p> <p>Download the private key for the GitHub app to your host using the GitHub UI.</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span><span class="nb">export </span><span class="nv">WEBHOOK_SECRET</span><span class="o">=</span><span class="s2">"sup3rs3cr3t"</span> <span class="nv">$ </span>faas-cli secret create webhook-secret <span class="nt">--from-literal</span> <span class="nv">$WEBHOOK_SECRET</span> <span class="nv">$ </span>faas-cli secret create private-key-secret <span class="nt">--from-file</span> &lt;path_to_your_pem_file&gt;.pem </code></pre></div></div> <p>Now it’s time to authenticate <code class="language-plaintext highlighter-rouge">faas-cli</code> so that we can do a deployment to our faasd instance from our laptop. This would work the same if you were deploying faasd to a cloud instance.</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># Get the IP into a variable</span> <span class="nv">$ </span><span class="nb">export </span><span class="nv">IP</span><span class="o">=</span><span class="si">$(</span>multipass info faasd <span class="nt">--format</span> json| jq <span class="s1">'.info.faasd.ipv4[0]'</span> | <span class="nb">tr</span> <span class="nt">-d</span> <span class="s1">'\"'</span><span class="si">)</span> <span class="c"># Let's capture the authentication password into a file for use with faas-cli</span> <span class="nv">$ </span>ssh ubuntu@<span class="nv">$IP</span> <span class="s2">"sudo cat /var/lib/faasd/secrets/basic-auth-password"</span> <span class="o">&gt;</span> basic-auth-password <span class="c"># Login from your laptop (the host)</span> <span class="nv">$ </span><span class="nb">export </span><span class="nv">OPENFAAS_URL</span><span class="o">=</span>http://<span class="nv">$IP</span>:8080 <span class="nb">cat </span>basic-auth-password | faas-cli login <span class="nt">-s</span> </code></pre></div></div> <p>You can add the <code class="language-plaintext highlighter-rouge">OPENFAAS_URL</code> entry to your shell’s profile if you like, so you get the variable set every time you open a new terminal.</p> <h2 id="connect-your-exit-node-from-the-faasd-instance">Connect your Exit Node from the faasd instance</h2> <p>We need to establish connection between our client, and the inlets-pro server in order to get events from there.</p> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span><span class="nb">export </span><span class="nv">UPSTREAM</span><span class="o">=</span><span class="nv">$IP</span> <span class="c"># faasd gateway ip, we have already grap the URL above</span> <span class="nv">$ </span><span class="nb">export </span><span class="nv">PORTS</span><span class="o">=</span>8080 <span class="c"># faasd gateway port</span> <span class="nv">$ </span><span class="nb">export </span><span class="nv">LICENSE</span><span class="o">=</span><span class="s2">"eyJhbGciOiJFUzI..."</span> <span class="c"># Notice that this command is the output of the "inletsctl create" command above</span> <span class="nv">$ </span>inlets-pro client <span class="nt">--url</span> <span class="s2">"wss://XX.XXX.XXX.XX:8123/connect"</span> <span class="se">\</span> <span class="nt">--token</span> <span class="s2">"</span><span class="nv">$TOKEN</span><span class="s2">"</span> <span class="se">\</span> <span class="nt">--license</span> <span class="s2">"</span><span class="nv">$LICENSE</span><span class="s2">"</span> <span class="se">\</span> <span class="nt">--upstream</span> <span class="nv">$UPSTREAM</span> <span class="se">\</span> <span class="nt">--ports</span> <span class="nv">$PORTS</span> </code></pre></div></div> <h2 id="lets-test-your-github-app">Let’s test your GitHub App</h2> <p>In order to test it we need to install this app to selected repositories. Create a repository called “test-issues-bot”, then install this app for it. <img src="/images/2021-01-15-github-application-using-go-and-inlets-pro/repository-access.png" alt="repository-access" /></p> <p>If you create an issue on the <code class="language-plaintext highlighter-rouge">test-issues-bot</code> repository, then you will see a message like this:</p> <blockquote> <p>“Hello, issue opened by: developer-guy”</p> </blockquote> <p><img src="/images/2021-01-15-github-application-using-go-and-inlets-pro/test-issue-bot.png" alt="test-issue-bot" /></p> <p>Finally, let’s close the issue by typing in a command, just like how Derek works:</p> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>/close </code></pre></div></div> <p><img src="/images/2021-01-15-github-application-using-go-and-inlets-pro/close-issue.png" alt="close-issue" /></p> <h3 id="tear-down-up-the-resources-optional">Tear down up the resources (optional)</h3> <div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>multipass delete <span class="nt">--purge</span> faasd <span class="nv">$ </span>inletsctl delete <span class="nt">--provider</span> digitalocean <span class="nt">--id</span> <span class="s2">"YOUR_INSTANCE_ID"</span> </code></pre></div></div> <h2 id="so-what-next">So what next?</h2> <p>Now that you can develop first-class integrations with GitHub, with fine-grained permissions and do things the right way. OAuth works are very broadly defined and personal access tokens (PATs) are just the wrong tool for the job and very risky if someone were to find it.</p> <p>Each user that installs your app is called an installation and has their own API limit of 1000 calls per hour.</p> <p>So what will you build?</p> <p>You could develop a bot, an integration, a linter as a service, integrate a machine-learning model from the OpenFaaS function store, and a whole host of other things. It’s up to you to decide.</p> <p>Do you already have a preferred way to deploy and run HTTP servers which isn’t faasd? We’re OK with that and want you to know that what you learned here about inlets and GitHub Apps can apply whether you run with a Docker container or just deploy a binary directly to a server.</p> <h1 id="references">References</h1> <p>Other GitHub Apps:</p> <ul> <li><a href="https://github.com/alexellis/derek">Derek</a></li> <li><a href="https://github.com/openfaas/openfaas-cloud">OpenFaaS Cloud</a></li> </ul> <p>Blog posts I found useful:</p> <ul> <li><a href="https://blog.alexellis.io/deploy-serverless-faasd-with-cloud-init/">https://blog.alexellis.io/deploy-serverless-faasd-with-cloud-init/</a></li> <li><a href="https://blog.alexellis.io/share-work-using-inlets/">https://blog.alexellis.io/share-work-using-inlets/</a></li> <li><a href="https://www.x-cellent.com/blog/automating-github-with-golang-building-your-own-github-bot/">https://www.x-cellent.com/blog/automating-github-with-golang-building-your-own-github-bot/</a></li> </ul> <div class="author"> <div class="card team member"> <div class="avatar"> <img class="team avatar" src="/images/author/developer-guy.png"></img> <div class="team social"> <a target="_blank" href="https://twitter.com/developerguyba"><i class="fab fa-twitter"></i></a> <a target="_blank" href="https://github.com/developer-guy"><i class="fab fa-github"></i></a> <a target="_blank" href="https://linkedin.com/in/bthnapydin"><i class="fab fa-linkedin"></i></a> </div> </div> <div class="team about"> <p class="team name">Batuhan Apaydın</p> <p class="team blurb">Arkade team &amp; Guest Blogger <a href="https://www.trendyol.com/">@Trendyol</a></p> </div> </div> </div> <div class="blog-navigation"> <a class="prev" href="/blog/birthday-invite/">&laquo; You're invited to our 4th Birthday!</a> <a class="next" href="/blog/gitea-faas/">Extend and automate self-hosted Gitea with functions&nbsp;&raquo;</a> </div> </div> </div> </div> </div> </section> <section class="gumroad-cta"> <h3 class="gumroad-cta-title">Checkout the official eBook and video workshop for OpenFaaS</h3> <a href="http://store.openfaas.com/l/serverless-for-everyone-else"> <img src="https://www.alexellis.io/serverless.png" alt="Serverless eBook cover"> </a> <p>Learn use-cases for open-source serverless functions and how to integrate them into your existing workflows.</p> <p>Through the hands-on exercises you will build your own JavaScript functions using Node.js. You'll add custom npm modules, integrate with other HTTP APIs, enable authentication and monitor the endpoints with Grafana.</p> <p> <a href="http://store.openfaas.com/l/serverless-for-everyone-else">Find out more on Gumroad</a> </p> </section> </div> <!-- Footer nav --> <nav id="bottom-nav" class="navbar is-primary" role="navigation" aria-label="main navigation"> <div class="container is-fluid"> <div class="navbar-brand"> <a class="navbar-item" href="/"> <img src="/images/openfaas/footer-of-logo.png" alt="logo"> </a> <p class="navbar-item is-size-5 is-size-4-fullhd has-text-weight-bold is-hidden-mobile">Serverless Functions, Made Simple.</p> </div> <div class="navbar-menu is-visible-desktop"> <div class="navbar-end"> <a href="/" class="navbar-item" >About</a> <a href="/blog/" class="navbar-item" >Blog</a> <a href="/pricing/" class="navbar-item" >Pricing</a> <a href="/support/" class="navbar-item" >Support</a> <a href="https://openfaas.gumroad.com/" class="navbar-item" >eBooks</a> <a href="/team/" class="navbar-item" >Team</a> <a href="https://docs.openfaas.com/" class="navbar-item" >Docs</a> </div> </div> </div> </nav> <!-- Footer nav --> <footer class="footer"> <div class="container is-fluid"> <div class="footer-wrapper"> <div class="footer-wrapper-left"> <p> OpenFaaS &reg; was founded by <a href="https://www.alexellis.io/">Alex Ellis</a> and is hosted by OpenFaaS Ltd.<br> OpenFaaS Ltd. is a registered company in England & Wales with number: 11076587, registered address: Peterborough UK. </p> </div> <div class="footer-wrapper-right"> <a href="https://landscape.cncf.io/format=serverless"> <small>Featured on</small> <img src="/images/openfaas/cloud-native.png" alt="CNCF Logo"> </a> </div> </div> </div> </footer> </div> <script src="/js/main.js"></script> </body> </html>

Pages: 1 2 3 4 5 6 7 8 9 10