Skip to content

Commit 4c253b0

Browse files
authored
Merge pull request #7 from elekto-io/user-docs
WIP: Add user documentation
2 parents 3320e81 + 8695eb1 commit 4c253b0

8 files changed

Lines changed: 503 additions & 84 deletions

File tree

content/en/docs/Getting started/_index.md

Lines changed: 6 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -5,88 +5,13 @@ weight: 2
55
description: >
66
Start using elekto for your organisation.
77
---
8-
#### Create a development environment
98

10-
The application is written in `python` using `flask` and `sqlalchemy`. This repository ships a `requirements.txt` and a `environment.yml` for conda users.
9+
Elekto is a DIY service, so in order to start using it, you're going to have to install it:
1110

12-
```bash
13-
# Installation with pip
14-
pip install -r requirements.txt
11+
* [Developer Installation]({{< relref "devinstall.md" >}})
12+
* [Server Installation]({{< relref "installation.md" >}})
13+
* [Kubernetes Installation]({{< relref "kubernetes.md" >}})
1514

16-
# Installation with Conda
17-
conda env create -f environment.yml && conda activate elekto
18-
```
15+
And then regardless of how you installed it:
1916

20-
#### Setup env variables
21-
22-
The repository has a `.env.example` file which can be used as a template for `.env` file, update the environment file after copying from `.env.example`.
23-
24-
```bash
25-
# create a new .env file from .env.example
26-
cp .env.example .env
27-
```
28-
29-
Set the basic information about the application in the upper section
30-
```bash
31-
APP_NAME=k8s.elections # set the name of the application
32-
APP_ENV=development # development | production
33-
APP_KEY= # random secret key (!! important !!)
34-
APP_DEBUG=True # True | False (production)
35-
APP_URL=http://localhost # Url where the application is hosted
36-
APP_PORT=5000 # Default Running port for development
37-
APP_HOST=localhost # Default Host for developmemt
38-
```
39-
40-
Update the database credentials,
41-
```bash
42-
DB_CONNECTION=mysql # Mysql is only supported
43-
DB_HOST=localhost
44-
DB_PORT=3306
45-
DB_DATABASE=name
46-
DB_USERNAME=user
47-
DB_PASSWORD=password
48-
```
49-
50-
Update the meta repository info
51-
```bash
52-
META_REPO=https://github.com/elekto-io/elekto.meta.test.git
53-
META_DEPLOYMENT=local
54-
META_PATH=meta
55-
META_BRANCH=main
56-
META_SECRET=db5a951969c379e75d0bf15ad6ff8b4a36fbeb02 # same as webhook of the same meta repository
57-
```
58-
59-
Update the Oauth info, create an github oauth app if already not created.
60-
```bash
61-
GITHUB_REDIRECT=/oauth/github/callback
62-
GITHUB_CLIENT_ID=d79f002c1d2e3cf20521
63-
GITHUB_CLIENT_SECRET=2f64fff6612c46f87314ad5bb81d05c8fd29c561
64-
```
65-
66-
#### Migrate and Sync DB with Meta
67-
68-
The `console` script in the repository is used to perform all the table creations and syncing of the meta.
69-
70-
```bash
71-
# to migrate the database from command line
72-
python console --migrate
73-
```
74-
75-
To sync the database with the meta files
76-
77-
```bash
78-
# to the sync the database with the meta
79-
python console --sync
80-
```
81-
82-
#### Run the application Server locally
83-
84-
The flask server will start on `5000` by default but can be changed using `--port` option.
85-
86-
```bash
87-
# to run the server on default configs
88-
python console --run
89-
90-
# to change host and port
91-
python console --port 8080 --host 0.0.0.0 --run
92-
```
17+
* [Configuration]({{< relref "installation.md" >}})
Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
---
2+
title: "Configuration"
3+
linkTitle: "Configuration"
4+
weight: 2
5+
description: >
6+
Setting up and configuring Elekto for operation
7+
---
8+
9+
# Configuration and Setup
10+
11+
Elekto's configuration is divided into three parts:
12+
13+
1. Oauth and GitHub configuration
14+
2. Runtime environment
15+
3. Per-election configuration
16+
17+
This document covers the first two, which consists of the items that need to be configured before Elekto will run. The third part is covered in the [Administrator Guide].
18+
19+
## Oauth and Repository Configuration
20+
21+
Elekto relies on an external Oauth provider for user authentication, by design. This provider must be configured to accept authentication requests from Elekto. You may only have one Oauth provider per Elekto instance, as authentication happens before selecting an election.
22+
23+
You must also configure the repository that contains the election metadata (hereafter "the repo") to push changes to Elekto.
24+
25+
Currently, the only Oauth provider offered is GitHub. Contributions of additional providers are extremely welcome.
26+
27+
### GitHub Setup
28+
29+
#### GitHub Oauth
30+
31+
You must set up an "Oauth Application" that Elekto can use. In GitHub, this is under Settings-->Developer Tools-->Oauth Applications. Note that Oauth Apps are belong to *accounts* rather than organizations, so you'll want to set up an account with shared access in your infra team. We also recommend setting up a separate Oauth App for Elekto rather than re-using ones created for other purposes, and giving each Elekto instance its own secret key.
32+
33+
The Oauth App must have the following settings:
34+
35+
* Application Name: whatever you've named your Elekto instance
36+
* Homepage URL: the url of your Elekto instance
37+
* Authorization Callback URL: `https://your.elekto.domain/oauth/github/callback` (note that this can be changed in ENV)
38+
39+
Once you create the Oauth App, GitHub will create a ClientID for it, which you populate in GITHUB_CLIENT_ID in ENV. You then create a new Oauth secret under the app and copy the value for that, and that gets populated in GITHUB_CLIENT_SECRET.
40+
41+
#### GitHub Repository Webhook
42+
43+
To receive changes from the repo, you need to add a webhook that pushes changes whenever you merge. Webhooks are under "settings" for the individual repository (which also means you must be a repo owner).
44+
45+
The Webhook should have the following settings:
46+
47+
* Payload URL: `https://your.election.domain/v1/webhooks/meta/sync`
48+
* Content type: application/json
49+
* Secret set to the same as META_SECRET
50+
* Enable SSL Verification
51+
* Just The Push Event
52+
* Check "Active" to turn it on
53+
54+
This "secret" is an arbitrary string that authenticates the push to the Elekto server. It can be any string, such as one created by a password generator or a passphrase you like. This string then gets set in META_SECRET.
55+
56+
## The Environment File
57+
58+
Elekto is designed to accept its runtime configuration as ENV variables in its shell environment. A sample `.env.example` file can be found in the base directory of the Elekto source. These ENV configuration variables are not expected to change frequently, or at all, for any particular running Elekto instance. Changing them generally requires restarting Elekto.
59+
60+
All of these env variables need to be set before starting Elekto as a uWSGI application, or even in developer mode; without them, Elekto will error out and refuse to start. You can set this up however you please:
61+
62+
* as the `.bashrc` for the elekto application user
63+
* as ENV variables for a container running Elekto
64+
* preloaded in a systemd unit file
65+
* injected through a ConfigMap and a Secret into a Kubernetes pod
66+
67+
Since we use ENV for Elekto configuration, this does mean that Elekto must be launched under a shell.
68+
69+
### ENV Variables
70+
71+
What follows are the ENV variables that must be set for Elekto to run.
72+
73+
#### Application Information
74+
75+
**APP_NAME**
76+
77+
*Required* Name of the Elekto instance you are running. Displays in some parts of the UI. For user information only.
78+
79+
Example: `k8s.elections`
80+
81+
**APP_ENV**
82+
83+
*Optional* Status of this Elekto instance, for CI/CD purposes. Not used internally by Elekto.
84+
85+
Example: `production` or `development`
86+
87+
**APP_KEY**
88+
89+
*Optional* Encryption seed for application cookies. Deprecated; will be set automatically by Elekto in the future, but for now set it to a random 8byte+ value.
90+
91+
Example: `2400229255`
92+
93+
**APP_DEBUG**
94+
95+
*Required* Whether to run in Debug mode for troubleshooting purposes. In Debug mode, will output stack traces for errors and reload templates.
96+
97+
Example: `True` or `False`
98+
99+
**APP_URL**
100+
101+
*Optional* URL of the Elekto instance. Used by some uWSGI and/or Nginx configurations. Not used internally by Elekto.
102+
103+
Example: `http://elections.knative.dev`
104+
105+
**APP_PORT**
106+
107+
*Optional* Used in some uWSGI start scripts, and when running Flask in standalone mode. Port on which to serve Elekto.
108+
109+
Example: `5000`
110+
111+
**APP_HOST**
112+
113+
*Optional* Used in some webserver startup scripts, and by the Flask server in standalone mode. Name of the host served by this Elekto instance.
114+
115+
Example: `localhost`
116+
117+
**APP_CONNECT**
118+
119+
*Optional* Whether to serve uWSGI over HTTP or via a local Unix socket. Used by some startup scripts; see `entrypoint.sh` for an example.
120+
121+
Example: `http` or `socket`
122+
123+
#### Database Connection
124+
125+
**DB_CONNECTION**
126+
127+
*Required* Which database connection type to use. Currently only PostgreSQL, MySQL, and SQLite backends are supported.
128+
129+
Example: `postgresql`, `mysql`, or `sqlite`
130+
131+
**DB_HOST**
132+
133+
*Required* The URL, IP, or hostname of the database server. Ignored if using SQLite (set to `N/A`).
134+
135+
Example: `pgdb-1a.prod.elekto.dev`
136+
137+
**DB_PORT**
138+
139+
*Required* The network port for the database server. Ignored if using SQLite (set to `1001`).
140+
141+
Example: `3306`
142+
143+
**DB_PATH**
144+
145+
*Optional* Used only for SQLite. Path to the database filesystem.
146+
147+
Example: `/var/db/elekto-db`
148+
149+
**DB_USERNAME**
150+
151+
*Required* Login user for the Elekto database. Not used by SQLite.
152+
153+
Example: `elekto`
154+
155+
**DB_PASSWORD**
156+
157+
*Required* Authentication password for the Elekto database. Not used by SQLite.
158+
159+
Example: `1a6e4b3f55dc`
160+
161+
#### Repository Configuration
162+
163+
**META_REPO**
164+
165+
*Required* GIT clone URL for the repository which contains the election configurations. Should be the `.git` link, not the `.html` one.
166+
167+
Example: `https://github.com/kalkayan/k8s.elections.meta.git`
168+
169+
**ELECTION_DIR**
170+
171+
*Required* Directory, relative to the Git repository root, containing the set of election subdirectories. Must be a parent directory. Can be an arbitrarily deep path. Do not use a leading or trailing `/`.
172+
173+
Example: `elections`, `gov/steering/elections`
174+
175+
**META_DEPLOYMENT**
176+
177+
*Optional* Reserved for future advanced configuration use.
178+
179+
Example: `local`, `sidecar`
180+
181+
**META_PATH**
182+
183+
*Required* Local file location at which to store a clone of the election data repository. This directory will be created by Elekto at sync time, so the application must have the ability to write to the parent directory. The directory may be absolute or relative; if it is relative, it will be under the Eletko source directory. Otherwise it defaults to `meta`. For containers, a directory under `/tmp` is recommended to make sure the location is writeable.
184+
185+
Example: `meta`, `/tmp/meta`
186+
187+
**META_BRANCH**
188+
189+
*Required* Which git branch has the merged version of the election data. Defaults to `main`.
190+
191+
Example: `main`, `master`, `prod`
192+
193+
**META_SECRET**
194+
195+
*Required* The shared secret string used in the Github webhook for updates of the election data repository. Can be set to anything you like; we recommend a random md5 string or generated password.
196+
197+
Example: `92a488d11c0d27bbfea0a97e3332e08a`
198+
199+
#### Oauth Settings
200+
201+
At this time, there are only settings available for GitHub because other Oauth sources haven't been implemented. When other sources get added to Elekto, each will get its own configuration variables.
202+
203+
**GITHUB_REDIRECT**
204+
205+
*Required* Flask path for the GitHub authentication callback. Defaults to `/oauth/github/callback`, and there's no good reason to change it.
206+
207+
Example: `/oauth/github/callback`
208+
209+
**GITHUB_CLIENT_ID**
210+
211+
*Required* The Client ID from the GitHub Oauth Application.
212+
213+
Example: `0b9138c0b2ffeefd9fc1`
214+
215+
**GITHUB_CLIENT_SECRET**
216+
217+
*Required* The Client Secret from the GitHub Oauth Application.
218+
219+
Example: `dd37278f8e9d57571590ad9288f0aae62228c2e8`

0 commit comments

Comments
 (0)