Docker
Prerequisites
Docker and Docker Compose should be installed on your machine. The installation process depends on your operating system.
macOS
You can follow the official Docker installation documentation.
Or, if you have homebrew installed, you can just:
brew install docker
brew install docker-compose
brew install --cask docker
open -a dockerYou'll be asked to give permissions to the Docker app and type your password; then, you're set.
Linux
Install Docker and Docker Compose. For example, in Ubuntu 22.04:
sudo apt-get install docker.io docker-compose-v2Windows
The official Docker documentation includes a page with instructions to install Docker Desktop on Windows. From there, download Docker Desktop for Windows and execute it.
Installation
Clone the repo on your computer and enter the folder:
git clone https://github.com/consuldemocracy/consuldemocracy.git
cd consuldemocracyThen create the secrets and database config files based on the example files:
cp config/secrets.yml.example config/secrets.yml
cp config/database.yml.example config/database.ymlThen build the image with:
POSTGRES_PASSWORD=password docker-compose buildAnd create the containers:
POSTGRES_PASSWORD=password docker-compose createYou can now initialize your development DB and populate it with:
POSTGRES_PASSWORD=password docker-compose run app rake db:create db:migrate
POSTGRES_PASSWORD=password docker-compose run app rake db:dev_seedRunning Consul Democracy in development with Docker
Now we can finally run the application with:
POSTGRES_PASSWORD=password docker-compose upAnd you'll be able to access it by opening your browser and visiting http://localhost:3000.
Additionally, if you'd like to run the rails console:
POSTGRES_PASSWORD=password docker-compose run app rails consoleTo verify the containers are up execute:
docker psYou should see an output similar to this:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
603ec83b78a6 consuldemocracy-app "./docker-entrypoint…" 23 seconds ago Up 22 seconds consuldemocracy-app-run-afb6d68e2d99
d57fdd9637d6 postgres:14.19 "docker-entrypoint.s…" 50 minutes ago Up 22 seconds 5432/tcp consuldemocracy-database-1Running tests with RSpec
Consul Democracy includes more than 6000 tests checking the way the application behaves. While we recommend you configure your fork to use a continuous integration system to run the whole test suite and verify that the latest changes don't break anything, while developing you probably want to run the tests related to the code you're working on.
First, setup the database for the test environment:
POSTGRES_PASSWORD=password docker-compose run app bundle exec rake db:test:prepareThen you can run tests using RSpec. For example, to run the tests for the proposal model:
POSTGRES_PASSWORD=password docker-compose run app bundle exec rspec spec/models/proposal_spec.rbSystem tests also work out of the box, although they might fail the first time while the tool running the tests downloads the right version of Chromedriver (which is needed to run them), and only "headless" mode (with a browser running in the background) is supported, which is the mode you'd probably use more than 95% of the time anyway. For example, to run the tests for the homepage:
POSTGRES_PASSWORD=password docker-compose run app bundle exec rspec spec/system/welcome_spec.rbTroubleshooting
Run these commands inside Consul Democracy's directory, to erase all your previous Consul Democracy's Docker images and containers. Then start the Docker installation process once again.
Remove all Consul Democracy images:
docker-compose down --rmi all -v --remove-orphansRemove all Consul Democracy containers:
docker-compose rm -f -s -vCheck whether there are still containers left:
docker ps -aIn case there are, remove each one manually:
docker container rm <container_id>Last updated