If you're interested in deploying Polis, or setting up a development environment, you've come to the right place.
First things first, it helps to understand a bit how the system is set up.
Component Name | Tech | Description |
---|---|---|
server |
Node.js | The main server. Handles client web requests (page loads, vote activity, etc.) |
math |
Clojure/JVM | The math engine. |
client-participation |
Javascript | The client code for end-users. |
client-admin |
Javascript | The client code for administrators. |
client-report |
Node.js | The code for detailed analytics reports. |
The code in the two client-side repos compile to static assets.
We push these to s3 for CDN via deployPreprod
and deploy_TO_PRODUCTION
, but there is a config file for each of these projects which will allow you to configure the behavior of these scripts as described in the READMEs.
Of note though, you can use a static file server, and deploy via these scripts over sshfs
.
Finally, for local development, these repos have hot-reload able servers you can run with the ./x
command, but note that this is not the recommended approach for serving the client assets in production.
Each of these applications currently takes configuration from a set of environment variables. In the future we'll be moving away from this towards configuration files, but for now, the easiest way to configure the application is to have a shared set of environment variables that you keep in a file somewhere. You might do something like the following to set up a single secure file for these purposes:
mkdir ~/.polis
touch ~/.polis/envvars.sh
# set environment variables here with your text editor of choice (cough; vim)
nano ~/.polis/envvars.sh
# make sure only your user can read the directory and its contents can only be read by your user for security purposes
chmod -R og-rwx ~/.polis
# if you really want to get fancy you can encrypt the file as well...
Then you can run source ~/.polis/envvars.sh
to prepare any of the servers for running.
Each of the repo READMEs should have notes on what environment variables are needed, as well as templates to start off from (please raise an issue if something is missing). And as noted, some scripts require that configuration is in a specific file somewhere, so please refer to individual repo READMEs for full details.
Of particular note, the polisServer runs on environment variables which tell it where to look for the client repositories (host & port), and affording you a lot of flexibility in how you deploy.
TODO Compile complete starter template somewhere in this repo...
- Get the main server running using the Readme here:
/server
- This includes instructions on setting up a local postgres database
- Get the math server running using the Readme here:
/math
- Build client repo assets using the instructions in the respective Readmes:
- Each of the above repos also contains instructions for running a server with HMR; By default, the server should forward requests for these compiled assets to the HMR server.
Go through all steps in the Development environment, but at step (4) take compiled assets and serve with a/several static webserver(s), making sure to configure ports as described in the main polisServer Readme.
There's a docker-compose.yml
file in the project root, which can be used for running a fully functional docker development environment.
It is NOT suited for production, but it may be in the future.
🎉 Contributors to Docker support:
Note: This feature is optional.
We use Google to automatically translate submitted comments into the language of participants, as detected by the browser's language.
- Ensure the
client-participation
user interface is manually translated into participant language(s).- Noteworthy strings include:
showTranslationButton
,hideTranslationButton
,thirdPartyTranslationDisclaimer
- Noteworthy strings include:
- Click
Set up a project
button within the Cloud Translation Quickstart Guide.- Follow the wizard and download the JSON private key, aka credentials file.
- Convert the file contents into a base64-encoded string. You can do this in many ways, including:
- copying its contents into a client-side base64 encoder web app (inspect the simple JS code), or
- using your workstation terminal:
cat path/to/My-Project-abcdef0123456789.json | base64
(linux/mac)
- Configure
GOOGLE_CREDENTIALS_BASE64
withinserver/docker-dev.env
- Configure
SHOULD_USE_TRANSLATION_API=true
withinserver/docker-dev.env
Important: These instructions use an insecure, self-signed SSL certificate, which is pre-generated and stored publicly in the source code. This method of implementing HTTPS is ONLY suitable for testing.
For testing some functionality (e.g., social login via Facebook), some external services must interact with the Polis app via HTTPS.
To modify these settings, edit file-server/nginx/nginx-ssl.site.default.conf
before building the nginx-proxy
docker container:
vim file-server/nginx/nginx-ssl.site.default.conf
docker-compose up --detach --build --no-deps nginx-proxy
We use Nodemailer to send email. Nodemailer uses various built-in and packaged email transports to send email via SMTP or API, either directly or via third-party platforms.
Each transport needs a bit of hardcoded scaffold configuration to make it work, which we welcome via code contribution. But after this, others can easily use the same email transport by setting some configuration values via environment variable or otherwise.
We use EMAIL_TRANSPORT_TYPES
to set email transports and their fallback
order. Each transport has a keyword (e.g., maildev
). You may set one or more
transports, separated by commas. If you set more than one, then each transport
will "fallback" to the next on failure.
For example, if you set aws-ses,mailgun
, then we'll try to send via
aws-ses
, but on failure, we'll try to send via mailgun
. If Mailgun fails,
the email will not be sent.
Note: The MailDev email transport is for development purposes only. Ensure it's disabled in production!
- Add
maildev
into theEMAIL_TRANSPORT_TYPES
configuration.
This transport will work automatically when running via Docker Compose, accessible on port 1080.
- Add
aws-ses
into theEMAIL_TRANSPORT_TYPES
configuration. - Set the
AWS_ACCESS_KEY_ID
andAWS_SECRET_ACCESS_KEY
configuration.
- Add
mailgun
into theEMAIL_TRANSPORT_TYPES
configuration. - Set the
MAILGUN_API_KEY
andMAILGUN_DOMAIN
configuration.
- Find a transport for the service you require (or write your own!)
- Add any new transport configuration to
getMailOptions(...)
inserver/email/senders.js
. - Submit a pull request.
When we need to update the Polis database, we use SQL migration files.
During initial provisioning of your Docker containers, all the migrations will be applied in order, and you won't need to think about this.
But if we update the database schema after your initial provisioning of your server via Docker, you'll need to manually apply each new SQL migration.
- Please note: Backups are your responsibility. These instructions assume
the data is disposable, and do not attempt to make backups.
- Pull requests are welcome if you'd like to see more guidance on this.
- Your database data is stored on a docker volume, which means that it will
persist even when you destroy all your docker containers. Be mindful of this.
- You can remove ALL volumes defined within a
docker-compose
file via:docker-compose down --volumes
- You can remove ONE volume via
docker volume ls
anddocker volume rm <name>
- You can remove ALL volumes defined within a
- SQL migrations can be found in
server/postgres/migrations/
of this repo. - The path to the SQL file will be relative to its location in the docker container filesystem, not your host system.
For example, if we add the migration file
server/postgres/migrations/000001_update_pwreset_table.sql
, you'd run on your
host system:
docker-compose exec postgres psql --username postgres --dbname polis-dev --file=/docker-entrypoint-initdb.d/000001_update_pwreset_table.sql
You'd do this for each new file.
Please help us out as you go in setting things up by improving the deployment code and documentation!
- General/system-wide issues you come across can go in https://github.com/pol-is/polis-issues/issues, and repo specific issues in their respective issues lists
- PRs improving either documentation or deployment code are welcome, but please submit an issue to discuss before making any substantial code changes
- After you've made an issue, you can try to chat folks up at https://gitter.im/pol-is/polisDeployment