Backend Configuration and Deployment
These instructions are for setting up the backend alone in production. You probably want to start with the following two guides, and only refer back to this document for some more advanced things you might not find in those guides.
Step 0 - Configure your database
You must provide a postgresql database for data storage. We require postgres 9.4 or above.
If you are running in a restricted environment such as Amazon RDS, you will need to execute some sql against the database:
CREATE EXTENSION IF NOT EXISTS citext;
Step 1 - Configure the backend
The app needs some environment variables to be configured in order to work (a list of which can be found in the file
config/docker.env in this same repository).
config/ directory, there are following default config files:
config.exs: default base configuration
dev.exs: default extra configuration for
prod.exs: default extra configuration for
Do NOT modify the files above. Instead, overload any settings from the above files using env variables (a list of which can be found in the file
config/docker.env in this same repository), or if necessary by editing the following files:
dev.secret.exs: custom extra configuration for
prod.secret.exs: custom extra configuration for
MAIL_KEY are needed to configure transactional email, sign up at Mailgun and then configure the domain name and key.
Step 2 - Install
Option A - Install using Docker containers (recommended)
The easiest way to launch the docker image is using the
config/docker.env to launch a container along with its dependencies, currently that means an extra postgres container. You may want to add a webserver / reverse proxy yourself.
Install with docker-compose
docker version Docker version 18.09.1-ce docker-compose -v docker-compose version 1.23.2 make --version GNU Make 4.2.1 ...
- Clone this repository and change into the directory:
git clone https://github.com/dyne/zenpub cd zenpub
- Build the docker image.
- Setup the database schemas
The previous step will start building the database schemas, but it may lead to this error:
[debug] QUERY ERROR db=13.0ms CREATE INDEX IF NOT EXISTS "character_actor_id_index" ON "character" ("actor_id")  ** (Postgrex.Error) ERROR 42P01 (undefined_table) relation "character" does not exist
In case it does, then run:
Then continue issuing again:
- The backend should now be running at http://localhost:4000/.
Option B - Manual installation without Docker
- Postgres version 9.6 or newer
- Build tools
- Elixir version 1.9.0 with OTP 22 (or possibly newer). If your distribution only has an old version available, check Elixir's install page or use a tool like asdf (run
asdf installin this directory).
The quick way to get started with building a release, assuming that elixir and erlang are already installed.
$ export MIX_ENV=prod $ mix deps.get $ mix release # TODO: load required env variables $ _build/prod/rel/moodle_net/bin/moodle_net eval 'MoodleNet.ReleaseTasks.create_db()' # DB created $ _build/prod/rel/moodle_net/bin/moodle_net eval 'MoodleNet.ReleaseTasks.migrate_db()' # DB migrated $ _build/prod/rel/moodle_net/bin/moodle_net start # App started in foreground
See the section on Runtime Configuration for information on exporting environment variables.
B-1. Building the release
- Clone this repo.
- Make sure you have erlang and elixir installed (check
Dockerfilefor what version we're currently using)
mix deps.getto install elixir dependencies.
- From here on out, you may want to consider what your
MIX_ENVis set to. For production, ensure that you either export
MIX_ENV=prodor use it for each command. Continuing, we are assuming
mix releaseto create an elixir release. This will create an executable in your
_build/prod/rel/moodle_netdirectory. We will be using the
bin/moodle_netexecutable from here on.
B-2. Running the release
Export all required environment variables. See Runtime Configuration section.
Create a database, if one is not created already with
bin/moodle_net eval 'MoodleNet.ReleaseTasks.create_db()'.
You will likely also want to run the migrations. This is done similarly with
bin/moodle_net eval 'MoodleNet.ReleaseTasks.migrate_db()'.
If you’re using RDS or some other locked down DB, you may need to run
CREATE EXTENSION IF NOT EXISTS citext WITH SCHEMA public;on your database with elevated privileges.
You can check if your instance is configured correctly by running it with
To run the instance as a daemon, use
B-3. Adding HTTPS
The common and convenient way for adding HTTPS is by using Nginx or Caddyserver as a reverse proxy.
Caddyserver handles generating and setting up HTTPS certificates automatically, but if you need TLS/SSL certificates for nginx, you can look get some for free with letsencrypt. The simplest way to obtain and install a certificate is to use Certbot.. Depending on your specific setup, certbot may be able to get a certificate and configure your web server automatically.
You will need to load the required environment variables for the release to run properly.
Step 3 - Run
By default, the backend listens on port 4000 (TCP), so you can access it on http://localhost:4000/ (if you are on the same machine). In case of an error it will restart automatically.
The frontend is developed in a seperate repository.
Once you've signed up, you may want to make yourself an instance admin, by running this in the iex console: