Skip to content

Commit

Permalink
setup docker for project
Browse files Browse the repository at this point in the history
  • Loading branch information
ascii-dev committed Apr 29, 2020
1 parent 1c334f9 commit 4713d3e
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -331,5 +331,7 @@ tags

# Custom
venv
.env
static

# End of https://www.gitignore.io/api/vim,linux,macos,django,python,intellij+all,visualstudiocode
28 changes: 28 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
27 changes: 27 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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:
17 changes: 17 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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 "$@"
22 changes: 22 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions start.sh
Original file line number Diff line number Diff line change
@@ -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/

0 comments on commit 4713d3e

Please sign in to comment.