diff --git a/.gitignore b/.gitignore index 76639ed..6bb42f8 100644 --- a/.gitignore +++ b/.gitignore @@ -331,5 +331,7 @@ tags # Custom venv +.env +static # End of https://www.gitignore.io/api/vim,linux,macos,django,python,intellij+all,visualstudiocode diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e66c5a4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,28 @@ +FROM python:3.8 + +WORKDIR /src/ + +ENV PYTHONDONTWRITEBYTECODE 1 +ENV PYTHONUNBUFFERED 1 + +RUN mkdir media static logs +VOLUME ["/src/logs"] + +RUN apt-get update +RUN apt-get install -y libpq-dev gcc python-dev + +RUN pip install --upgrade pip +RUN pip install setuptools +COPY ./requirements.txt /src/requirements.txt +RUN pip install -r requirements.txt + + +COPY . /src/ +COPY ./start.sh /start.sh +COPY ./entrypoint.sh /entrypoint.sh + +RUN chmod +x /entrypoint.sh +RUN chmod +x /start.sh + +ENTRYPOINT ["/entrypoint.sh"] +CMD ["/start.sh"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..ab5446e --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,27 @@ +version: '3.3' + +services: + db: + image: "postgres:12" + container_name: "debunkbot" + hostname: postgres + volumes: + - postgres_data:/var/lib/postgresql/data/ + environment: + - POSTGRES_USER=debunkbot + - POSTGRES_PASSWORD=debunkbot + - POSTGRES_DB=debunkbot + web: + build: + context: . + volumes: + - ./:/src + ports: + - 8000:8000 + env_file: + - ./.env + depends_on: + - db + +volumes: + postgres_data: diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..de69381 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +if [ "$DATABASE" = "postgres" ] +then + echo "Waiting for postgres..." + + while ! nc -z $SQL_HOST $SQL_PORT; do + sleep 0.1 + done + + echo "PostgreSQL started" +fi + +python manage.py flush --no-input +python manage.py migrate + +exec "$@" diff --git a/requirements.txt b/requirements.txt index 6493b5e..353f60b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,27 @@ asgiref==3.2.7 +cachetools==4.1.0 +certifi==2020.4.5.1 +chardet==3.0.4 dj-database-url==0.5.0 Django==2.2 +gevent==20.4.0 +google-auth==1.14.1 +google-auth-oauthlib==0.4.1 +greenlet==0.4.15 +gspread==3.5.0 +gunicorn==20.0.4 +httplib2==0.17.3 +idna==2.9 +oauth2client==4.1.3 +oauthlib==3.1.0 +psycopg2==2.8.3 +pyasn1==0.4.8 +pyasn1-modules==0.2.8 +python-dotenv==0.13.0 pytz==2019.3 +requests==2.23.0 +requests-oauthlib==1.3.0 +rsa==4.0 +six==1.14.0 sqlparse==0.3.1 +urllib3==1.25.9 diff --git a/start.sh b/start.sh new file mode 100644 index 0000000..a4c82a1 --- /dev/null +++ b/start.sh @@ -0,0 +1,20 @@ +#!/bin/sh +python manage.py migrate --noinput # Apply database migrations +python manage.py collectstatic --clear --noinput # Collect static files + +# Prepare log files and start outputting logs to stdout +touch /src/logs/gunicorn.log +touch /src/logs/access.log +tail -n 0 -f /src/logs/*.log & + +# Start Gunicorn processes +echo Starting Gunicorn. +exec gunicorn \ + --bind 0.0.0.0:8000 \ + --workers 3 \ + --worker-class gevent \ + --log-level=info \ + --log-file=/src/logs/gunicorn.log \ + --access-logfile=/src/logs/access.log \ + --name debunkbot --reload debunkbot.wsgi:application \ + --chdir debunkbot/