Installation guide

Development

There are two supported ways to start the development server:

  1. Start only the auxiliary servers (database and redis) in docker but start the django dev server locally in your virtual env. This is the preferred way if you actively develop this application.

  2. Start everything inside docker containers. This is the “easy” way to start a dev server and fiddle around with it, hot reloading included. But you will not have the local pre-commit setup.

In both cases there are some common steps to follow:

  • Install docker with compose plugin for your system

  • Clone git repository and checkout branch develop:

    git clone https://github.com/base-angewandte/image-backend.git
    cd image-backend
    git checkout develop
    
  • Check and adapt settings (if you need more details on the single settings, than the comments in the skeleton env file give you, take a look at the Configuration section) :

    cp env-skel .env
    vi .env
    
  • Create the docker compose override file:

    cp compose.override.dev.yaml compose.override.yaml
    

Now, depending on which path you want to go, take one of the following two subsections.

Everything inside docker

  • Make sure that the DOCKER variable in .env is set to TRUE. Otherwise, django will assume that postgres and redis are accessible on localhost ports.

  • Also in .env, make sure the variable FORCE_SCRIPT_NAME= is uncommented and set to an empty string.

  • Start everything:

    make start-dev-docker
    

    If this is your first start, you will also need to apply the initial migrations (can be skipped, unless you reset your database):

    make init
    

    To stop all services again hit CTRL-C to stop following the logs and then use make stop.

  • To additionally get some initial test data into the database:

    make test-data
    

    If you also want to include a test data set with artworks containing discriminatory terms that should be contextualised (and sometimes, depending on context not), you need to do the following (after you loaded the test-data with the last command):

    docker compose exec image-django python manage.py loaddata artworks/fixtures/artworks_word_filter_test.json
    

The full developer setup

  • Install the latest python 3.12 and create virtualenv e.g. via pyenv and pyenv-virtualenv.

  • Install uv and requirements in your virtualenv:

    pip install uv
    uv pip sync src/requirements-dev.txt
    
  • Ensure DOCKER=False in your .env file.

  • Check the compose.override.dev.yaml file you created before from the template and uncomment the port mounts for Redis and Postgres, so your local Django can access them.

  • Start required services:

    make start-dev
    
  • Run migrations and install the pre-commit hooks:

    make init-dev
    
  • Start development server:

    cd src && python manage.py runserver 8300
    
  • To additionally get some initial test data into the database:

    python manage.py loaddata artworks/fixtures/artists.json
    python manage.py loaddata artworks/fixtures/keywords.json
    python manage.py loaddata artworks/fixtures/locations.json
    python manage.py loaddata artworks/fixtures/discriminatory_terms.json
    python manage.py loaddata artworks/fixtures/artworks.json
    cp ../test-data/image-placeholder-*.png assets/media
    python manage.py load_test_images
    rm assets/media/image-placeholder-*.png
    

    If you also want to include a test data set with artworks containing discriminatory terms that should be contextualised (and sometimes, depending on context not), you need to do the following (after you loaded the discriminatory terms):

    python manage.py loaddata artworks/fixtures/artworks_word_filter_test.json
    

Resetting your database and/or the cache

In both cases you sometimes might want to start with a fresh database, or need to clear the whole cache. If you need to do so, make sure to stop the containers first (make stop). Then delete the ./dockerdata/postgres folder (for the database) and/or the ./dockerdata/redis folder (for the cache). Once you start the containers again as described above, you have a new database and/or a fresh cache. If you cleared the database you have to apply the migrations again, so start again from the make init or python manage.py migrate steps above

Production

  • Update package index:

    # RHEL
    sudo yum update
    
    # Debian
    sudo apt-get update
    
  • Install docker with compose plugin

  • Create and change to user base

  • Create and change to /opt/base

  • Clone git repository and checkout branch main:

    git clone https://github.com/base-angewandte/image-backend.git
    cd image-backend
    git checkout main
    
  • Check and adapt settings (see Configuration for further details about the configuration possibilities):

    cp env-skel .env
    vi .env
    
  • Use Makefile to initialize and run project:

    make start init init-static restart-gunicorn
    
  • Install nginx and configure it accordingly