services:
  db:
    image: mariadb
    ports:
      - 3306:3306
    environment:
      # MYSQL_DATABASE: gawa
      # MYSQL_USER: gawa
      # MYSQL_PASSWORD: changethisforprod
      MYSQL_ROOT_PASSWORD: root
    volumes:
      # - db_data:/var/lib/mysql
      - ./docker/db/scripts:/docker-entrypoint-initdb.d/

  main:
    build: ./docker/main
    command: bash -c "echo 'setting django up'
        && python manage.py collectstatic --noinput
        && sleep 3
        && python manage.py migrate
        && DJANGO_SUPERUSER_PASSWORD='root' python manage.py createsuperuser\
            --username root --noinput --email software@cscherr.de || true
        && python manage.py runserver 0.0.0.0:80
      "
    volumes:
      - ./gawa:/app
    environment:
      - MARIADB_NAME=gawa
      - MARIADB_USER=gawa
      - MARIADB_PASSWORD=changethisforprod
    depends_on:
      - db

  caddy:
    image: caddy
    restart: unless-stopped
    ports:
      - "80:80"
      - "8081:8081"
      # - "443:443"
      # - "443:443/udp"
    volumes:
      - $PWD/docker/caddy/Caddyfile:/etc/caddy/Caddyfile
      - caddy_data:/data
      - caddy_config:/config
      - ./gawa/static:/srv/static
      - ./gawa/media:/srv/media

  db-admin:
    image: phpmyadmin
    ports:
      - 8080:80
    environment:
      - PMA_HOST=db
      - PMA_ABSOLUTE_URI=http://localhost:8080
    depends_on:
      - db

volumes:
  caddy_data:
  caddy_config:
  # db_data:
