version: '3'

services:
    postgres:
        image: postgres:13
        restart: always
        environment:
            POSTGRES_DB: smash
            POSTGRES_USER: runner
            POSTGRES_PASSWORD: password
        ports: 
            - "5432:5432"
    web:
        build: .
        expose: 
            - '8888'
        entrypoint: bash -c "sleep 5
                          && python manage.py makemigrations web 
                          && python manage.py migrate
                          && python manage.py migrate sessions
                          && python manage.py collectstatic --noinput
                          && echo && echo && echo 'The server will start now...'
                          && gunicorn -b 0.0.0.0:8888 smash.wsgi:application --access-logfile access.log --error-logfile error.log"
                          ### To run the server through manage.py, use:
                          #  && python manage.py runserver 0.0.0.0:8888"
                          ### To run the verbose tests, uncomment:
                          # python manage.py test -v3"
        command: ""
        ports:
            - "8888:8888"
        volumes:
            - static_files:/tmp/static/
        depends_on:
            - postgres
    nginx:
        command:
            - nginx-debug
            - "-g"
            - "daemon off;"
        image: "nginx:alpine"
        ports:
            - "80:80"
            - "443:443"
            - "8080:8080"
        expose:
            - "80"
            - "443"
            - "8080"
        depends_on:
            - web
            - postgres
        volumes:
            - "./docker/nginx/nginx.conf:/etc/nginx/nginx.conf"
            - "./docker/nginx/nginx-selfsigned.crt:/etc/ssl/certs/nginx-selfsigned.crt"
            - "./docker/nginx/nginx-selfsigned.key:/etc/ssl/private/nginx-selfsigned.key"
            - "./docker/nginx/dhparam.pem:/etc/ssl/certs/dhparam.pem"
            - "./docker/nginx/smasch.conf:/etc/nginx/conf.d/smasch.conf"
            - static_files:/var/www/shared/static/
            - nginx_logs:/log
volumes:
    static_files:
    nginx_logs:
