Refactor much needed docker setup
- Build static files inside seperate container - Remove unnecessary env variables
This commit is contained in:
parent
d61b3a9498
commit
7fc899937d
5 changed files with 59 additions and 37 deletions
|
|
@ -1,52 +1,56 @@
|
||||||
version: '3'
|
version: '3'
|
||||||
|
volumes:
|
||||||
|
postgres-data:
|
||||||
|
static-files:
|
||||||
|
node-modules:
|
||||||
|
|
||||||
services:
|
services:
|
||||||
db:
|
db:
|
||||||
# See https://hub.docker.com/_/postgres
|
|
||||||
image: postgres
|
image: postgres
|
||||||
container_name: postgres
|
|
||||||
environment:
|
environment:
|
||||||
- POSTGRES_DB=$POSTGRES_NAME
|
POSTGRES_DB: "newsreader"
|
||||||
- POSTGRES_USER=$POSTGRES_USER
|
POSTGRES_USER: "newsreader"
|
||||||
- POSTGRES_PASSWORD=$POSTGRES_PASSWORD
|
POSTGRES_PASSWORD: "newsreader"
|
||||||
|
volumes:
|
||||||
|
- postgres-data:/var/lib/postgresql/data
|
||||||
rabbitmq:
|
rabbitmq:
|
||||||
image: rabbitmq:3.7
|
image: rabbitmq:3.7
|
||||||
container_name: rabbitmq
|
|
||||||
celery:
|
|
||||||
build: .
|
|
||||||
container_name: celery
|
|
||||||
command: poetry run celery -A newsreader worker -l INFO --beat --scheduler django --workdir=/app/src/
|
|
||||||
environment:
|
|
||||||
- POSTGRES_HOST=$POSTGRES_HOST
|
|
||||||
- POSTGRES_NAME=$POSTGRES_NAME
|
|
||||||
- POSTGRES_USER=$POSTGRES_USER
|
|
||||||
- POSTGRES_PASSWORD=$POSTGRES_PASSWORD
|
|
||||||
- DJANGO_SETTINGS_MODULE=newsreader.conf.docker
|
|
||||||
volumes:
|
|
||||||
- .:/app
|
|
||||||
depends_on:
|
|
||||||
- rabbitmq
|
|
||||||
memcached:
|
memcached:
|
||||||
image: memcached:1.5.22
|
image: memcached:1.5.22
|
||||||
container_name: memcached
|
|
||||||
ports:
|
ports:
|
||||||
- "11211:11211"
|
- "11211:11211"
|
||||||
entrypoint:
|
entrypoint:
|
||||||
- memcached
|
- memcached
|
||||||
- -m 64
|
- -m 64
|
||||||
web:
|
celery:
|
||||||
build: .
|
build:
|
||||||
container_name: web
|
context: .
|
||||||
|
dockerfile: ./docker/django
|
||||||
|
command: celery worker --app newsreader --loglevel INFO --beat --scheduler django --workdir /app/src/
|
||||||
|
environment:
|
||||||
|
- DJANGO_SETTINGS_MODULE=newsreader.conf.docker
|
||||||
|
depends_on:
|
||||||
|
- rabbitmq
|
||||||
|
django:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: ./docker/django
|
||||||
command: src/entrypoint.sh
|
command: src/entrypoint.sh
|
||||||
environment:
|
environment:
|
||||||
- POSTGRES_HOST=$POSTGRES_HOST
|
|
||||||
- POSTGRES_NAME=$POSTGRES_NAME
|
|
||||||
- POSTGRES_USER=$POSTGRES_USER
|
|
||||||
- POSTGRES_PASSWORD=$POSTGRES_PASSWORD
|
|
||||||
- DJANGO_SETTINGS_MODULE=newsreader.conf.docker
|
- DJANGO_SETTINGS_MODULE=newsreader.conf.docker
|
||||||
volumes:
|
|
||||||
- .:/app
|
|
||||||
ports:
|
ports:
|
||||||
- '8000:8000'
|
- '8000:8000'
|
||||||
depends_on:
|
depends_on:
|
||||||
- db
|
- db
|
||||||
|
volumes:
|
||||||
|
- .:/app
|
||||||
|
- static-files:/app/src/newsreader/static
|
||||||
|
webpack:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: ./docker/webpack
|
||||||
|
command: npm run build:watch
|
||||||
|
volumes:
|
||||||
|
- .:/app
|
||||||
|
- static-files:/app/src/newsreader/static
|
||||||
|
- node-modules:/app/node_modules
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ RUN pip install poetry
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY poetry.lock pyproject.toml /app/
|
COPY poetry.lock pyproject.toml /app/
|
||||||
|
|
||||||
RUN poetry config virtualenvs.create false
|
RUN poetry config virtualenvs.create false && poetry install --no-interaction
|
||||||
RUN poetry install --no-interaction
|
|
||||||
|
|
||||||
COPY . /app/
|
COPY . /app/
|
||||||
9
docker/webpack
Normal file
9
docker/webpack
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
FROM node:12
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY package.json package-lock.json /app/
|
||||||
|
|
||||||
|
RUN npm install
|
||||||
|
|
||||||
|
COPY . /app/
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# This file should only be used in conjuction with docker-compose
|
# This file should only be used in conjuction with docker-compose
|
||||||
|
|
||||||
poetry run /app/src/manage.py migrate
|
python /app/src/manage.py migrate
|
||||||
poetry run /app/src/manage.py runserver 0.0.0.0:8000
|
python /app/src/manage.py runserver 0.0.0.0:8000
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,15 @@ from .dev import * # isort:skip
|
||||||
|
|
||||||
SECRET_KEY = "=q(ztyo)b6noom#a164g&s9vcj1aawa^g#ing_ir99=_zl4g&$"
|
SECRET_KEY = "=q(ztyo)b6noom#a164g&s9vcj1aawa^g#ing_ir99=_zl4g&$"
|
||||||
|
|
||||||
# Celery
|
DATABASES = {
|
||||||
# https://docs.celeryproject.org/en/latest/userguide/configuration.html
|
"default": {
|
||||||
BROKER_URL = "amqp://guest:guest@rabbitmq:5672//"
|
"ENGINE": "django.db.backends.postgresql",
|
||||||
|
"NAME": "newsreader",
|
||||||
|
"USER": "newsreader",
|
||||||
|
"PASSWORD": "newsreader",
|
||||||
|
"HOST": "db",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CACHES = {
|
CACHES = {
|
||||||
"default": {
|
"default": {
|
||||||
|
|
@ -17,3 +23,7 @@ CACHES = {
|
||||||
"LOCATION": "memcached:11211",
|
"LOCATION": "memcached:11211",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Celery
|
||||||
|
# https://docs.celeryproject.org/en/latest/userguide/configuration.html
|
||||||
|
CELERY_BROKER_URL = "amqp://guest:guest@rabbitmq:5672//"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue