# Installation

## Prerequisites

Python 3.x + virtualenv

### CentOS/RHEL 7.x (with EPEL enabled!)

```bash
yum install python34-virtualenv.noarch
```

### Debian 11

```
sudo apt-get update
sudo apt-get install git python3-virtualenv libmariadb-dev libldap2-dev libsasl2-dev
```

## Checkout

```bash
git clone https://git.linux-kernel.at/oliver/ivatar.git
cd ivatar
```

## Virtual environment

```bash
virtualenv -p python3 .virtualenv
source .virtualenv/bin/activate
pip install pillow
pip install -r requirements.txt
```

## (SQL) Migrations

```bash
./manage.py migrate
```

## Collect static files

```bash
./manage.py collectstatic -l --no-input
```

## Run local (development) server

```bash
./manage.py runserver 0:8080 # or any other free port
```

## Create superuser (optional)

```bash
./manage.py createsuperuser # Follow the instructions
```

## Running the testsuite

```
./manage.py test -v3 # Or any other verbosity level you like
```

## Configuration

### Gravatar Proxy and Redirect Settings

By default, ivatar is configured to work well for public instances like libravatar.org. However, for local or private instances, you may want to disable external requests to Gravatar. You can configure the default behavior by adding these settings to your `config_local.py`:

```python
# Default settings for Gravatar proxy and redirect behavior
# These can be overridden by URL parameters (?gravatarproxy=n&gravatarredirect=n)

# Whether to proxy requests to Gravatar when no local avatar is found (default: True)
DEFAULT_GRAVATARPROXY = False

# Whether to redirect directly to Gravatar when no local avatar is found (default: False)
DEFAULT_GRAVATARREDIRECT = False

# Whether to force default behavior even when a user avatar exists (default: False)
FORCEDEFAULT = False
```

**Use cases:**

- **Private/Local instances**: Set `DEFAULT_GRAVATARPROXY = False` and `DEFAULT_GRAVATARREDIRECT = False` to prevent external requests
- **Gravatar-first instances**: Set `DEFAULT_GRAVATARREDIRECT = True` to redirect to Gravatar instead of proxying
- **Testing/Development**: Set `FORCEDEFAULT = True` to always use default avatars

**Note**: URL parameters (`?gravatarproxy=n`, `?gravatarredirect=y`, `?forcedefault=y`) will always override these configuration defaults.

### OpenID Connect authentication with Fedora

To enable OpenID Connect (OIDC) authentication with Fedora, you must have obtained a `client_id` and `client_secret` pair from the Fedora Infrastructure.
Then you must set these values in `config_local.py`:

```
SOCIAL_AUTH_FEDORA_KEY = "the-client-id"
SOCIAL_AUTH_FEDORA_SECRET = "the-client-secret"
```

You can override the location of the OIDC provider with the `SOCIAL_AUTH_FEDORA_OIDC_ENDPOINT` setting. For example, to authenticate with Fedora's staging environment, set this in `config_local.py`:

```
SOCIAL_AUTH_FEDORA_OIDC_ENDPOINT = "https://id.stg.fedoraproject.org"
```

# Production deployment Webserver (non-cloudy)

To deploy this Django application with WSGI on Apache, NGINX or any other web server, please refer to the the webserver documentation; There are also plenty of howtos on the net (I'll not LMGTFY...)

# Production deloyment (cloudy)

## Red Hat OpenShift (Online)

There is already a file called create.sh, which can be reused to create an OpenShift online instance of ivatar. However, you need to have the correct environment variables set, as well as a working oc installation.

## Amazon AWS

Pretty sure this work as well; As OpenShift (Online).

I once wrote an Django (1.x) application in 2016, that used AWS. It can be found here:
[Gewusel from ofalk @ GitHub](https://github.com/ofalk/gewusel)
There is a file called ebcreate.txt as well as a directory called .ebextensions, which you need to check out in order to get an idea of how to deploy the application on AWS.

## Database

It should work with SQLite (do _not_ use in production!), MySQL/MariaDB, as well as PostgreSQL.
