diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..c008b2c --- /dev/null +++ b/.dockerignore @@ -0,0 +1,10 @@ +# Dockerignore whitelist +* + +!Pipfile +!Pipfile.lock +!cbreader +!comic +!comic_auth +!manage.py +!pytest \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 3cf4e4e..40af9c6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,28 @@ FROM python:3-alpine + ENV PYTHONUNBUFFERED 1 + RUN apk update -RUN apk add --no-cache tini bash unrar dcron postgresql-dev -RUN mkdir /src -WORKDIR /src -ADD Pipfile /src -ADD Pipfile.lock /src +RUN apk add --no-cache tini bash unrar dcron postgresql-dev gcc python3-dev musl-dev + RUN apk add --no-cache --virtual .build-deps mariadb-dev build-base \ && pip install pipenv \ - && pipenv install --system \ && apk add --virtual .runtime-deps mariadb-connector-c-dev mariadb-connector-c \ && apk del .build-deps -ADD . /src/ + +RUN mkdir /src + +WORKDIR /src + +ADD Pipfile /src +ADD Pipfile.lock /src + +RUN pipenv install --deploy --dev --ignore-pipfile --system + +COPY . /src/ + RUN cat /src/cbreader/crontab >> /etc/crontabs/root -EXPOSE 8000 \ No newline at end of file + +EXPOSE 8000 + + diff --git a/cbreader/settings.py b/cbreader/settings.py index ea8548c..9b79bdd 100644 --- a/cbreader/settings.py +++ b/cbreader/settings.py @@ -13,6 +13,8 @@ https://docs.djangoproject.com/en/1.8/ref/settings/ # Build paths inside the project like this: os.path.join(BASE_DIR, ...) import os +import dj_database_url + BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -76,12 +78,17 @@ WSGI_APPLICATION = 'cbreader.wsgi.application' # Database # https://docs.djangoproject.com/en/1.8/ref/settings/#databases -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), +DATABASE_URL = os.getenv("DATABASE_URL") + +if DATABASE_URL: + DATABASES = {"default": dj_database_url.config(conn_max_age=500)} +else: + DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } } -} # Internationalization diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..d61cda9 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,37 @@ +version: '3.7' + +services: + + app: + build: . + environment: + - DATABASE_URL=postgres://admin:password@database:5432/cbwebreader + - DJANGO_SETTINGS_MODULE=cbreader.settings + links: + - database + depends_on: + - database + ports: + - "8000:8000" + volumes: + - ./cbreader:/src/cbreader + - ./comic:/src/comic + - ./comic_auth:/src/comic_auth + - D:\Downloads\comics:/data + command: python manage.py runserver 0.0.0.0:8000 + + database: + image: postgres:11.4-alpine + ports: + - 5432:5432 + volumes: + - /var/lib/postgresql/data + environment: + - POSTGRES_USER=admin + - POSTGRES_PASSWORD=password + - POSTGRES_DB=cbwebreader + +# volumes: +# comic-volume: +# name: comic-volume +# external: true \ No newline at end of file