From 670a81c3f5aa4b3d6cb235d5c1677483cd1a098a Mon Sep 17 00:00:00 2001 From: mpeltriaux Date: Mon, 10 Jan 2022 13:52:40 +0100 Subject: [PATCH] # Docker * adds docker related configurations * directly working configuration provided --- Dockerfile | 17 ++++++++ docker-compose.yml | 55 ++++++++++++++++++++++++++ konova/celery.py | 2 +- konova/sub_settings/django_settings.py | 9 +++-- 4 files changed, 78 insertions(+), 5 deletions(-) create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..e97a087b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM python:3.7-slim +ENV PYTHONUNBUFFERED 1 + +WORKDIR /konova + +# Install some dependencies +RUN apt update +RUN apt install -y gdal-bin + +# Copy requirements file into workspace +COPY ./requirements.txt /konova/ +RUN pip install --upgrade pip +RUN pip install -r requirements.txt + +# Copy rest of project into workspace +COPY . /konova/ + diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..5bddc633 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,55 @@ +version: '3.3' + +services: + redis: + image: redis + volumes: + - /redis/data:/bitnami/redis/data + environment: + - REDIS_PASSWORD=CHANGE_ME + + konova: + external_links: + - postgis:db + build: . + container_name: "konova-docker" + command: python manage.py runserver 0.0.0.0:8000 + volumes: + - .:/konova + ports: + - "8001:8000" + depends_on: + - redis + environment: + - POSTGRES_NAME=konova + - POSTGRES_PORT=5432 + - POSTGRES_PASSWORD=michel + - POSTGRES_USER=konova + - POSTGRES_HOST=db + - REDIS_HOST=redis + +# To provide a celery worker instance, we need to add the celery worker as an own service + celery_worker: + external_links: + - postgis:db + build: . + container_name: "konova-worker-docker" + command: celery -A konova worker -l INFO + volumes: + - .:/konova + depends_on: + - konova + environment: + - POSTGRES_NAME=konova + - POSTGRES_PORT=5432 + - POSTGRES_PASSWORD=michel + - POSTGRES_USER=konova + - POSTGRES_HOST=db + - REDIS_HOST=redis + +# Instead of an own, new network, we need to connect to the existing one, which is provided by the postgis container +# NOTE: THIS NETWORK MUST EXIST +networks: + default: + external: + name: postgis_nat_it_backend \ No newline at end of file diff --git a/konova/celery.py b/konova/celery.py index 478f2844..ab06cf7c 100644 --- a/konova/celery.py +++ b/konova/celery.py @@ -17,7 +17,7 @@ app.config_from_object('django.conf:settings', namespace='CELERY') app.autodiscover_tasks() # Declare redis as broker -app.conf.broker_url = 'redis://localhost:6379/0' +app.conf.broker_url = f"redis://{os.environ.get('REDIS_HOST')}:6379/0" @app.task(bind=True) diff --git a/konova/sub_settings/django_settings.py b/konova/sub_settings/django_settings.py index bc1a7511..92561481 100644 --- a/konova/sub_settings/django_settings.py +++ b/konova/sub_settings/django_settings.py @@ -119,10 +119,11 @@ WSGI_APPLICATION = 'konova.wsgi.application' DATABASES = { 'default': { 'ENGINE': 'django.contrib.gis.db.backends.postgis', - 'NAME': 'konova', - 'USER': 'postgres', - 'HOST': '127.0.0.1', - 'PORT': '5432', + 'NAME': os.environ.get('POSTGRES_NAME'), + 'USER': os.environ.get('POSTGRES_USER'), + 'HOST': os.environ.get('POSTGRES_HOST'), + 'PASSWORD': os.environ.get('POSTGRES_PASSWORD'), + 'PORT': os.environ.get('POSTGRES_PORT'), } }