poa-netstats-warehouse/doc/POABackend.html

228 lines
10 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="ExDoc v0.18.4">
<title>POABackend poa_backend v0.1.0</title>
<link rel="stylesheet" href="dist/app-480ffdc169.css" />
<script src="dist/sidebar_items-f62ce50de1.js"></script>
</head>
<body data-type="modules">
<script>try { if(localStorage.getItem('night-mode')) document.body.className += ' night-mode'; } catch (e) { }</script>
<div class="main">
<button class="sidebar-button sidebar-toggle">
<span class="icon-menu" aria-hidden="true"></span>
<span class="sr-only">Toggle Sidebar</span>
</button>
<button class="sidebar-button night-mode-toggle">
<span class="icon-theme" aria-hidden="true"></span>
<span class="sr-only">Toggle Theme</span>
</button>
<section class="sidebar">
<a href="POABackend.html" class="sidebar-projectLink">
<div class="sidebar-projectDetails">
<h1 class="sidebar-projectName">
poa_backend
</h1>
<h2 class="sidebar-projectVersion">
v0.1.0
</h2>
</div>
</a>
<form class="sidebar-search" action="search.html">
<button type="submit" class="search-button">
<span class="icon-search" aria-hidden="true"></span>
</button>
<input name="q" type="text" id="search-list" class="search-input" placeholder="Search" aria-label="Search" autocomplete="off" />
</form>
<ul class="sidebar-listNav">
<li><a id="extras-list" href="#full-list">Pages</a></li>
<li><a id="modules-list" href="#full-list">Modules</a></li>
</ul>
<div class="gradient"></div>
<ul id="full-list" class="sidebar-fullList"></ul>
</section>
<section class="content">
<div class="content-outer">
<div id="content" class="content-inner">
<h1>
<small class="visible-xs">poa_backend v0.1.0</small>
POABackend
<a href="https://github.com/poanetwork/poa-netstats-wharehouse/blob/v0.1.0/lib/poa_backend.ex#L1" title="View Source" class="view-source" rel="help">
<span class="icon-code" aria-hidden="true"></span>
<span class="sr-only">View Source</span>
</a>
</h1>
<section id="moduledoc">
<h1>POABackend</h1>
<p><a href="https://coveralls.io/github/poanetwork/poa-netstats-warehouse?branch=master"><img src="https://coveralls.io/repos/github/poanetwork/poa-netstats-warehouse/badge.svg?branch=master" alt="Coverage Status"/></a>
<a href="https://codecov.io/gh/poanetwork/poa-netstats-warehouse"><img src="https://codecov.io/gh/poanetwork/poa-netstats-warehouse/branch/master/graph/badge.svg" alt="codecov"/></a></p>
<p>Storage and data-processing companion for the <a href="https://github.com/poanetwork/poa-netstats-agent">poa-netstats-agent</a></p>
<h2 id="module-documentation" class="section-heading">
<a href="#module-documentation" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
Documentation
</h2>
<ul>
<li><a href="pages/initial_architecture.md">Initial Architecture</a>
</li>
<li>You can find the online documentation <a href="index.html">here</a>
</li>
</ul>
<p>Or you can build the documenation locally running</p>
<pre><code class="elixir">mix deps.get
mix docs</code></pre>
<p>That command will create a <code class="inline">doc/</code> folder with the actual Documentation.</p>
<h2 id="module-setting-up-cert-ssl" class="section-heading">
<a href="#module-setting-up-cert-ssl" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
Setting up Cert SSL
</h2>
<p><a href="POABackend.html#content"><code class="inline">POABackend</code></a> uses <code class="inline">https</code> endpoints for Authorisation matters. In order to achieve that we have to set some configuration first.
We would need a <em>.cert and a </em>.key files. We can generate them easily running:</p>
<pre><code class="elixir">openssl genrsa -out localhost.key 2048
openssl req -new -x509 -key localhost.key -out localhost.cert -days 3650 -subj /CN=localhost</code></pre>
<p>Those command will create the needed files. Now we have to point them in the config file. Lets check the section <code class="inline">:auth_rest</code></p>
<pre><code class="elixir">config :poa_backend,
:auth_rest,
[
{:scheme, :https},
{:port, 4003},
{:keyfile, &quot;priv/keys/localhost.key&quot;},
{:certfile, &quot;priv/keys/localhost.cert&quot;}
]</code></pre>
<p>Here we can choose the port for the <code class="inline">Auth</code> endpoints and we must put the paths to the files we created previously (look <code class="inline">:keyfile</code> and <code class="inline">:certfile</code> fields)</p>
<h2 id="module-configuring-databases-for-first-time" class="section-heading">
<a href="#module-configuring-databases-for-first-time" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
Configuring Databases for first time
</h2>
<p><a href="POABackend.html#content"><code class="inline">POABackend</code></a> uses many Databases. For Authentication we use <a href="http://erlang.org/doc/man/mnesia.html">Mnesia</a> as a local database and for some receivers which require storage we use Postgres. All databases are managed on top of <a href="https://hexdocs.pm/ecto/Ecto.html">Ecto</a> a widly used database wrapper for Elixir projects.</p>
<p>For this reason we have to set the databases before running the <a href="POABackend.html#content"><code class="inline">POABackend</code></a> for the first time.</p>
<ul>
<li>Auth Database (Mnesia): Setting up Mnesia is easy since it is working localy and is built in the Erlang Virtual Machine. We only have to say “where” we are going to store the databases files. In order to do that we have to add the configuration to the config file (<code class="inline">prod.exs</code> or <code class="inline">test.exs</code> depending if you want to run tests or production)
</li>
</ul>
<pre><code class="elixir">config :mnesia,
dir: &#39;your/local/path&#39; # make sure this directory exists!</code></pre>
<ul>
<li>Receivers Database (Postgres): This is a little more complex than Mnesia. We need a Postgres instance running somewhere and we have to add the config to the config files
</li>
</ul>
<pre><code class="elixir">config :poa_backend, POABackend.Receivers.Repo,
priv: &quot;priv/receivers&quot;, # this value is not changed
adapter: Ecto.Adapters.Postgres,
database: &quot;poabackend_stats&quot;,
username: &quot;postgres&quot;,
password: &quot;postgres&quot;,
hostname: &quot;localhost&quot;</code></pre>
<p>The important fields here are <code class="inline">database</code>, <code class="inline">username</code>, <code class="inline">password</code> and <code class="inline">hostname</code>. The rest of values must remain exactly as the example.</p>
<p>Once we have set the database configuration we have to create and migrate the databases, in order to do that we should be in the root of the project and run:</p>
<ul>
<li>for production
</li>
</ul>
<pre><code class="elixir">MIX_ENV=prod mix ecto.create
MIX_ENV=prod mix ecto.migrate</code></pre>
<ul>
<li>for test
</li>
</ul>
<pre><code class="elixir">MIX_ENV=test mix ecto.create
MIX_ENV=test mix ecto.migrate</code></pre>
<p>Now the environment is ready for running <a href="POABackend.html#content"><code class="inline">POABackend</code></a></p>
<h2 id="module-run-tests" class="section-heading">
<a href="#module-run-tests" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
Run Tests
</h2>
<p>The first time you run the tests you will need having the Databases environment set up. Check the previous section and set the configuration in the <code class="inline">config/test.exs</code> file.</p>
<p>Once the environment is set. We can run the tests with:</p>
<pre><code class="elixir">mix test</code></pre>
<p><a href="POABackend.html#content"><code class="inline">POABackend</code></a> comes also with a code analysis tool <a href="https://github.com/rrrene/credo">Credo</a> and a types checker tool <a href="https://github.com/jeremyjh/dialyxir">Dialyxir</a>. In order to run them we have to run</p>
<pre><code class="elixir">mix credo
mix dialyzer</code></pre>
<h2 id="module-building-deploying-an-executable" class="section-heading">
<a href="#module-building-deploying-an-executable" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
Building &amp; Deploying an Executable
</h2>
<p>To build an executable youll need Elixir 1.6 (and Erlang/OTP 20).</p>
<ol>
<li>Once you have a copy of this repository configure the backend for production in the file <code class="inline">config/prod.exs</code>.
</li>
<li>An example configuration can be found in the current <code class="inline">config/prod.exs</code>.
</li>
<li>Do a <code class="inline">mix deps.get</code> to fetch, among other dependencies, the tooling for building server executables.
</li>
<li>A <code class="inline">env MIX_ENV=prod mix release --name=poa_backend --env=prod</code> will assemble an executable.
</li>
</ol>
<p>A resulting artifact resides at <code class="inline">_build/prod/rel/poa_backend/releases/0.1.0/poa_backend.tar.gz</code> which you can move to a remote host.
Use <code class="inline">tar xfz</code> then <code class="inline">bin/poa_agent start</code> (<code class="inline">bin/poa_agent stop</code> will stop the server cleanly).</p>
<p>If you want to run it on the local host then the procedure is as simple as: <code class="inline">_build/prod/rel/poa_backend/bin/poa_backend</code>.</p>
<p><strong>Note:</strong> executables must be built on the platform (OS and architecture) they are destined for under the projects current configuration.
Other options are possible (see <code class="inline">https://hexdocs.pm/distillery/getting-started.html</code>).</p>
</section>
<footer class="footer">
<p>
<span class="line">
Built using
<a href="https://github.com/elixir-lang/ex_doc" title="ExDoc" rel="help" target="_blank">ExDoc</a> (v0.18.4),
</span>
<span class="line">
designed by
<a href="https://twitter.com/dignifiedquire" target="_blank" title="@dignifiedquire">Friedel Ziegelmayer</a>.
</span>
</p>
</footer>
</div>
</div>
</section>
</div>
<script src="dist/app-9bd040e5e5.js"></script>
</body>
</html>