Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve TL;DR documentation for starters #215

Closed
wants to merge 12 commits into from
106 changes: 105 additions & 1 deletion bulletin_board/server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,111 @@ The Bulletin Board is a service composed by an Encryption Engine and an Append-O

The Bulletin Board depends on the existence of a Decidim installation.

- Installation:

## Running on Docker

You can run this application conveniently packaged with docker compose.

You can use the existing [docker-composer.yml](docker-composer.yml) as start point.
It requires you to define a `.env` file with the following ENV variables:

```
SECRET_KEY_BASE=-your-rails-application-secret-
DATABASE_URL=postgres://USERNAME:PASSWOR@DATABASE/BULLETIN_DB
IDENTIFICATION_PRIVATE_KEY=-private-key-for-this-bulletin-board

```

#### Notes:

- Generate `SECRET_KEY_BASE` with `bin/rails secret`
- Generate `IDENTIFICATION_PRIVATE_KEY` with `bin/rails client:generate_identification_private_key`

### Configuration steps in this server (bulletin app):

- Initialize the database, database is not included in this docker compose file but it should be pretty straightforward.
In order to initialize the database you need to run the comand `bin/rails db:create db:migrate`

- In you Decidim server (the one you want to connect with this one), execute
`bin/rails decidim_elections:generate_identification_keys` (save the private key in you decidim environment)
copy the public key as is presented (url encoded) and, now in this server, execute:

`bin/rails 'client:add_authority[Authority name, public-key]'`

Note that "Authority name" can be anything as long is the same in Decidim than here.

**Important**: This step throws also an `API KEY` secret that needs to be configured in Decidim too.

#### Running the app with docker-compose


```bash
docker-compose up -d
```

Note that you still need to configure some proxy around it.
For instance, a simple Nginx conf for a server that's configured at bulletin-board.example.org can be:

```
server {
server_name bulletin-board.example.org;
client_max_body_size 32M;
listen 80 ;
listen [::]:80 ;

location / {
proxy_pass http://127.0.0.1:8000;
}
}

```

Note: you should add SSL configuration, for instance with [Let's Encrypt](https://certbot.eff.org/lets-encrypt)

This server is ready, you can access the hompage either at http://localhost:8000 or https:/bulletin-board.example.org depending on your final configuration.

#### Executing console commands when using docker-compose

All previously specified commands need to be executed inside the running docker container. It is pretty easy to do that with docker compose, simply do:

Enter the container

```
docker-compose exec bulletin bash
```

Which gives you direct access to the console:

```
root@7805a01fbabb:/code/bulletin_board/server#
```

In there, you can execute the `bin/rails c` to access the rails console, or any other command.

It is also possible to directly execut rails (or rake) comands:

```
docker-compose exec bulletin bin/rails db:migrate
```

**Important**, your application needs to be up and running for this to work (aka: `docker-compose up`)

### Configuration steps in Decidim server

This steps needs to be performed in the Decidim instance that wants to use the elections module.

Once you have this server configured, you will need the public key corresponding to the private key used in the
env var `IDENTIFICATION_PRIVATE_KEY`, simply use a browser and navigate to the homepage of the application, it will show the public key.

- Copy the public key to the env var `BULLETIN_BOARD_PUBLIC_KEY`
- Copy the `API KEY` obtained previously into the env var `BULLETIN_BOARD_API_KEY`
- Ensure you have the env var `AUTHORITY_PRIVATE_KEY` with the **private key** generate with the command `bin/rails decidim_elections:generate_identification_keys`
- Ensure that the `Authority name` is the same in both places (in Decidim needs to be declarated in the env var `AUTHORITY_NAME`)
- Be sure to point the env var `BULLETIN_BOARD_SERVER` to the bulletin server API path (that is usually http://bulletin-board.example.org/api)
- Env var `ELECTIONS_SCHEME_NAME` can currently be only `electionguard` (unless for testing purposes)
- Set up `ELECTIONS_NUMBER_OF_TRUSTEES` and `ELECTIONS_QUORUM` to, at least, the number 2

## Useful commands

First, clone the repository and enter in the new folder:

Expand Down
7 changes: 5 additions & 2 deletions bulletin_board/server/config/initializers/sidekiq.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# frozen_string_literal: true

if Rails.env.production? || ENV["SANDBOX"]
redis_host = ENV["REDIS_HOST"] || "localhost"
redis_port = ENV["REDIS_PORT"] || 6379

Sidekiq.configure_server do |config|
config.redis = { ssl_params: { verify_mode: OpenSSL::SSL::VERIFY_NONE } }
config.redis = {host: redis_host, port: redis_port, ssl_params: { verify_mode: OpenSSL::SSL::VERIFY_NONE } }
end

Sidekiq.configure_client do |config|
config.redis = { ssl_params: { verify_mode: OpenSSL::SSL::VERIFY_NONE } }
config.redis = {host: redis_host, port: redis_port, ssl_params: { verify_mode: OpenSSL::SSL::VERIFY_NONE } }
end
end
49 changes: 49 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
version: "3.9"
services:
bulletin:
build:
context: .
dockerfile: Dockerfile.release
env_file: .env
environment:
- RAILS_LOG_TO_STDOUT=1
- RAILS_SERVE_STATIC_FILES=1
- RACK_ENV=production
- RAILS_ENV=production
- REDIS_HOST=redis
- REDIS_PORT=6379
volumes:
- ./docker-entrypoint.sh:/docker-entrypoint.sh
entrypoint: /docker-entrypoint.sh
command: ""
ports:
- "8000:8000"
depends_on:
- redis
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this is for production, shouldn't we add restart: unless-stopped for all the services?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, although I imagine a real production docker-compose pulling a image directly from dockerhub instead of building it here. Let's say that this also work for development

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, production configurations can be very personal. I imagine most people would use a Nginx service integrated here instead of exposing the 8000 port form rails.


worker:
build:
context: .
dockerfile: Dockerfile.release
env_file: .env
environment:
- RAILS_LOG_TO_STDOUT=1
- RACK_ENV=production
- RAILS_ENV=production
- REDIS_HOST=redis
- REDIS_PORT=6379
command: ""
volumes:
- ./docker-entrypoint-worker.sh:/docker-entrypoint.sh
entrypoint: /docker-entrypoint.sh
depends_on:
- redis

redis:
image: "redis:alpine"
command: redis-server
volumes:
- redis_data:/data

volumes:
redis_data: