Installation with Docker

Prerequisites

Before installing Prophecies, ensure you have the following tools installed:

  • Docker: A platform for developing, shipping, and running applications inside isolated environments known as containers. Learn more about Docker.

  • Docker Compose: A tool for defining and running multi-container Docker applications. It uses a YAML file to configure your application's services, making it easier to manage complex setups. Get started with Docker Compose.

These tools are essential for running Prophecies efficiently and are widely used in the development and deployment of modern applications.

Setup steps

1. Prepare the Working Directory

Place this docker-compose.yml file in your chosen directory. This will be the working directory for your Docker Compose setup:

version: '3'

volumes:
  shared_static: {}
  postgresql_data: {}

services:
  nginx:
      image: nginx:latest
      ports:
        - "9999:9999"
      volumes:
        - ./nginx.conf:/etc/nginx/conf.d/default.conf
        - shared_static:/static/:ro
      depends_on:
        - web

  web:
    image: icij/prophecies:0.5.9
    environment:
      - ALLOWED_HOSTS=0.0.0.0,localhost,web
      - CSRF_TRUSTED_ORIGINS=http://localhost:9999
      - DATABASE_URL=postgres://postgres:postgres@db/prophecies
      - DEBUG=false
      - DJANGO_SETTINGS_MODULE=prophecies.settings.production
      - DJANGO_ADMIN_LOGIN=true
      - PROPHECIES_APP_LOGIN_URL=/admin/login/?next=/
      - PORT=8008
      - WAIT_HOSTS_TIMEOUT=60
      - WAIT_HOSTS=db:5432
    volumes:
      - shared_static:/code/prophecies/run/static
    depends_on:
      - db
      - migration
      - collectstatic
    expose:
      - "8008"

  migration:
    image: icij/prophecies:0.5.9
    command: sh -c '/usr/bin/wait && poetry run python manage.py migrate --noinput'
    environment:
      - WAIT_HOSTS=db:5432
      - WAIT_HOSTS_TIMEOUT=60
      - DATABASE_URL=postgres://postgres:postgres@db/prophecies
    depends_on:
      - db

  collectstatic:
    image: icij/prophecies:0.5.9
    command: poetry run python manage.py collectstatic --noinput
    volumes:
      - shared_static:/code/prophecies/run/static

  db:
    image: postgres:16
    restart: always
    environment:
      POSTGRES_PASSWORD: postgres
      POSTGRES_USER: postgres
      POSTGRES_DB: prophecies
    command: postgres -c shared_preload_libraries=pg_stat_statements -c 'pg_stat_statements.track=all'
    volumes:
      - postgresql_data:/var/lib/postgresql/data

2. Configure NGINX

You need to create an NGINX configuration file as referenced in your Docker Compose file (./nginx.conf). Ensure this file is correctly configured to serve your Prophecies. It should be set up to listen on port 9999 and serve static files from the /static/ directory:

upstream web {
  ip_hash;
  server web:8008;
}

server {

    location /static/ {
        autoindex on;
        alias /static/;
    }

    location / {
        proxy_pass http://web/;
    }
    
    listen 9999;
    server_name localhost;
}

3. Starting Services

In your working directory, run the following command:

docker compose up -d

This command will download the necessary images (if not already downloaded), create the defined volumes, and start the services as background processes.

3. Database Migrations and Static Files

The docker-compose.yml file specifies services for running database migrations (migration) and collecting static files so they can be served by NGINX (collectstatic). These services should automatically perform these tasks when you start Docker Compose.

4. Create Admin User

The database is currently empty, without user. To provision your first admin user, you must use the command line:

docker compose exec -it web make createsuperuser

5. Accessing the Application

Once all services are up and running, the application should be accessible via : http://localhost:9999

6. Monitoring and Logs

To monitor the status of your Docker containers and check for any issues, you can use the Docker Compose logs command:

docker compose logs -f

The -f flag will follow the log output, allowing you to see real-time logs as they are generated.

7. Stopping and Removing Services

To stop the services without removing them, you can run:

docker compose stop

If you need to stop and remove all the containers, networks, and volumes associated with your Docker Compose setup, use the down command:

docker compose down --volumes

This will clean up everything you have created and is particularly useful for starting from scratch. Please make sure you know what you're doing before running this command.

Additional Notes

  • This configuration doesn't include SSL setup for NGINX, which is recommended for production.

  • Regularly check for updates to the icij/prophecies image to keep your application up to date.

  • To use custom domain, don't forget to update the ALLOWED_HOSTS variable.

  • The application can be configured with many environment variables.

Last updated

Prophecies is an open source project by the International Consortium of Investigative Journalists