Skip to content
Ethan Nguyen edited this page Jan 21, 2021 · 6 revisions

Welcome to the photomanager wiki!

This wiki is a work in progress (well, the entire project is). Definitely not ready for production usage.

Production Setup

WARNING: This is not ready for production usage. If you want to deploy in production, that's on you. (Well, regardless of production-ready status, everything is on you regardless.)

The only supported deployment method is Docker deployment.

You will need:

Non-Swarm Docker Compose Deployment

  1. Clone this repository. Alternatively, you can just download docker-compose.yml, and change the mount for secret.py accordingly.

  2. Modify docker-compose.yml as follows:

    1. Change POSTGRES_PASSWORD in the postgres container definition to a secure password.

    2. Change the mount for /data in the photomanager container definition to your Nextcloud instance's data directory. You may want to make this mount read-only.

      For instance:

      - /docker/nextcloud/data:/data:ro

      or

      - /var/www/nextcloud/data:/data:ro

      Your source directory depends on your specific setup.

  3. Copy photomanager/settings/secret.sample.py to photomanager/settings/secret.py and enter your settings as follows:

    • SECRET_KEY: the Django secret key, as described here. You could generate one using

      from django.core.management.utils import get_random_secret_key
      print(get_random_secret_key())
    • DEBUG: Set to False in production.

    • ALLOWED_HOSTS: You will need to add a list of hostnames where this photomanager instance can be accessed here.

      Example:

      ALLOWED_HOSTS = ["photomanager.example.com"]
    • SOCIAL_AUTH_REDIRECT_IS_HTTPS: If you are running this behind a reverse proxy and you are using HTTPS, set this to True.

    • SOCIAL_AUTH_NEXTCLOUD_KEY and SOCIAL_AUTH_NEXTCLOUD_SECRET: Create an OAuth2 application in your Nextcloud instance, as described here, then place your client identifier and secret in these variables respectively. The redirect URL is http[s]://[HOST]/complete/nextcloud.

    • NEXTCLOUD_URI is the hostname (not the URL) of your Nextcloud instance, and it is used when redirecting a user to Nextcloud for authentication.

      Example:

      NEXTCLOUD_URI = "nextcloud.example.com"
    • DATABASES should be:

      DATABASES = {
          "default": {
              "ENGINE": "django.db.backends.postgresql_psycopg2",
              "NAME": "photomanager",
              "USER": "photomanager",
              "PASSWORD": "{{ ENTER YOUR POSTGRES PASSWORD HERE }}",  # Database password
              "HOST": "postgres",
              "PORT": "5432",
          }
      }
    • CACHES should be:

      CACHES = {
          "default": {
              "BACKEND": "django_redis.cache.RedisCache",
              "LOCATION": "redis://redis:6379/1",
              "OPTIONS": {
                  "CLIENT_CLASS": "django_redis.client.DefaultClient",
              },
          }
      }
  4. docker-compose up -d

Docker Swarm Deployment

To be written. (However, it's pretty similar to the non-Swarm deployment.)

Development Environment Setup

  • You want to have Vagrant installed.

  • You also need Virtualbox.

  • You need a Nextcloud instance for authentication. You may be able to get away with adding the following to secret.py (see below):

    AUTHENTICATION_BACKENDS += ['django.contrib.auth.backends.ModelBackend']

    and then using pipenv run ./manage.py createsuperuser to create a user, and authenticating using the Django administration login (localhost:8000/admin).

Clone this repository.

You will then need to copy photomanager/settings/secret.sample.py to photomanager/settings/secret.py, and change the settings in there as follows:

  • SECRET_KEY: the Django secret key, as described here. You could generate one using

    from django.core.management.utils import get_random_secret_key
    print(get_random_secret_key())
  • DEBUG: Set to False in production, True in development. See this.

  • ALLOWED_HOSTS: If DEBUG is False, then you will need to add a list of hosts where this photomanager instance can be accessed here.

  • SOCIAL_AUTH_REDIRECT_IS_HTTPS: If you are running this behind a reverse proxy and you are using HTTPS, set this to True.

  • SOCIAL_AUTH_NEXTCLOUD_KEY and SOCIAL_AUTH_NEXTCLOUD_SECRET: Create an OAuth2 application in your Nextcloud instance, as described here, then place your client identifier and secret in these variables respectively. The redirect URL is http[s]://[HOST]/complete/nextcloud.

  • NEXTCLOUD_URI is the hostname of your Nextcloud instance, and it is used when redirecting a user to Nextcloud for authentication.

Then run

vagrant up

in the root directory. Vagrant will take care of the rest of the provisioning.

Then, to get a shell inside your virtual machine that Vagrant just provisioned, run

vagrant ssh

Then, within this shell, to start the development servers, run

/home/vagrant/photomanager/scripts/install_dependencies.sh
/home/vagrant/photomanager/scripts/start_servers.sh

The first script installs dependencies twice: one time as the vagrant user, and a second time as the root user.

The second script starts a tmux session with celery -A photomanager worker -l DEBUG, pipenv run celery -A photomanager beat -l DEBUG, and ./manage.py runserver 0.0.0.0:8000.

Point your browser to localhost:8000 to access photomanager.

You will need to do something like this (pipenv run ./manage.py shell_plus to get a Django shell) to make your user an admin:

user = User.objects.get(username='[USERNAME - your Nextcloud username]')
user.is_superuser = True
user.is_staff = True
user.save()