From b775f9339d93e85d9f21fc9cb4d597b8fcc2b9ed Mon Sep 17 00:00:00 2001 From: Nathan Levesque Date: Thu, 5 Jan 2023 16:29:25 -0500 Subject: [PATCH] Simplify the docker/compose setup --- .gitignore | 5 ++++- Dockerfile | 28 +++++++++++++++++-------- Dockerfile-nb | 10 --------- README.md | 6 +++--- apt.txt | 2 ++ docker-compose-notebook.yml | 41 ------------------------------------- docker-compose.override.yml | 34 ------------------------------ docker-compose.yml | 37 +++++++++++++++++++++++++++++++-- 8 files changed, 63 insertions(+), 100 deletions(-) delete mode 100644 Dockerfile-nb delete mode 100644 docker-compose-notebook.yml delete mode 100644 docker-compose.override.yml diff --git a/.gitignore b/.gitignore index 0a546f4264..ce1752eefa 100644 --- a/.gitignore +++ b/.gitignore @@ -124,4 +124,7 @@ docs/_site tsconfig.tsbuildinfo # VS-Code -.vscode \ No newline at end of file +.vscode + +# docker +docker-compose.override.yml \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index f5687fc02b..3e1dfa0b82 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.9.13 +FROM python:3.9.13 as base LABEL maintainer "ODL DevOps " # Add package files, install updated node and pip @@ -8,13 +8,12 @@ WORKDIR /tmp COPY apt.txt /tmp/apt.txt RUN apt-get update RUN apt-get install -y $(grep -vE "^\s*#" apt.txt | tr "\n" " ") -RUN apt-get update && apt-get install libpq-dev postgresql-client -y # pip RUN curl --silent --location https://bootstrap.pypa.io/get-pip.py | python3 - # Add, and run as, non-root user. -RUN mkdir /src +RUN mkdir /app RUN adduser --disabled-password --gecos "" mitodl RUN mkdir /var/media && chown -R mitodl:mitodl /var/media @@ -24,16 +23,27 @@ COPY test_requirements.txt /tmp/test_requirements.txt RUN pip install -r requirements.txt -r test_requirements.txt # Add project -COPY . /src -WORKDIR /src -RUN chown -R mitodl:mitodl /src +COPY . /app +WORKDIR /app +RUN chown -R mitodl:mitodl /app RUN apt-get clean && apt-get purge -USER mitodl # Set pip cache folder, as it is breaking pip when it is on a shared volume ENV XDG_CACHE_HOME /tmp/.cache -EXPOSE 8063 -ENV PORT 8063 +FROM base as django + +USER mitodl + +FROM base as django-server + +EXPOSE 8013 +ENV PORT 8013 CMD uwsgi uwsgi.ini + +FROM base as jupyter-notebook + +RUN pip install --force-reinstall jupyter + +USER mitodl diff --git a/Dockerfile-nb b/Dockerfile-nb deleted file mode 100644 index a627804f48..0000000000 --- a/Dockerfile-nb +++ /dev/null @@ -1,10 +0,0 @@ -FROM open-discussions_web - -USER root - -WORKDIR /tmp - -RUN pip install --force-reinstall jupyter - -USER mitodl -WORKDIR /src diff --git a/README.md b/README.md index 0246747905..15313bbec5 100644 --- a/README.md +++ b/README.md @@ -242,12 +242,12 @@ otherwise do in a Django shell. To get started: ``` - Build the `notebook` container _(for first time use, or when requirements change)_ ```bash - docker-compose -f docker-compose-notebook.yml build + docker-compose --profile notebook build ``` - Run all the standard containers (`docker-compose up`) -- In another terminal window, run the `notebook` container +- In another terminal window, run the app with the `notebook` container ```bash - docker-compose -f docker-compose-notebook.yml run --rm --service-ports notebook + docker-compose --profile notebook up ``` - Visit the running notebook server in your browser. The `notebook` container log output will indicate the URL and `token` param with some output that looks like this: diff --git a/apt.txt b/apt.txt index 5388bb90bd..0ab16b777e 100644 --- a/apt.txt +++ b/apt.txt @@ -7,3 +7,5 @@ net-tools pkg-config libffi-dev libxmlsec1-dev +libpq-dev +postgresql-client \ No newline at end of file diff --git a/docker-compose-notebook.yml b/docker-compose-notebook.yml deleted file mode 100644 index 6d951b9774..0000000000 --- a/docker-compose-notebook.yml +++ /dev/null @@ -1,41 +0,0 @@ -version: '3.7' - -x-environment: - &py-environment - DEBUG: 'False' - DEV_ENV: 'True' # necessary to have nginx connect to web container - NODE_ENV: 'production' - DATABASE_URL: postgres://postgres@db:5432/postgres - OPEN_DISCUSSIONS_SECURE_SSL_REDIRECT: 'False' - OPEN_DISCUSSIONS_DB_DISABLE_SSL: 'True' - OPEN_DISCUSSIONS_REDDIT_URL: https://reddit.local - OPEN_DISCUSSIONS_REDDIT_VALIDATE_SSL: 'False' - OPEN_DISCUSSIONS_REDDIT_CLIENT_ID: od_client_id - OPEN_DISCUSSIONS_REDDIT_SECRET: od_client_secret - OPEN_DISCUSSIONS_FEATURES_DEFAULT: 'True' - ELASTICSEARCH_URL: elastic:9200 - CELERY_TASK_ALWAYS_EAGER: 'False' - CELERY_BROKER_URL: redis://redis:6379/4 - CELERY_RESULT_BACKEND: redis://redis:6379/4 - DOCKER_HOST: ${DOCKER_HOST:-missing} - WEBPACK_DEV_SERVER_HOST: ${WEBPACK_DEV_SERVER_HOST:-localhost} - TIKA_SERVER_ENDPOINT: ${TIKA_SERVER_ENDPOINT:-http://tika:9998/} - TIKA_CLIENT_ONLY: 'True' - -services: - notebook: - build: - context: . - dockerfile: Dockerfile-nb - volumes: - - .:/src - environment: - <<: *py-environment - BASE_DJANGO_APP_NAME: open_discussions - env_file: .env - command: > - /bin/bash -c ' - sleep 3 && - jupyter notebook --no-browser --ip=0.0.0.0 --port=8080' - ports: - - "8080:8080" diff --git a/docker-compose.override.yml b/docker-compose.override.yml deleted file mode 100644 index 64cf0090d1..0000000000 --- a/docker-compose.override.yml +++ /dev/null @@ -1,34 +0,0 @@ -version: '3.7' -services: - web: - volumes: - - .:/src - - django_media:/var/media - environment: - DEBUG: ${DEBUG:-True} - NODE_ENV: ${NODE_ENV:-development} - - celery: - volumes: - - .:/src - - django_media:/var/media - environment: - DEBUG: ${DEBUG:-True} - NODE_ENV: ${NODE_ENV:-development} - - nginx: - volumes: - - ./config/nginx.conf:/etc/nginx/conf.d/web.conf - - ./:/src - - watch: - environment: - NODE_ENV: ${NODE_ENV:-development} - volumes: - - .:/src - - yarn-cache:/home/mitodl/.cache/yarn - - -volumes: - django_media: {} - yarn-cache: {} diff --git a/docker-compose.yml b/docker-compose.yml index edaf3f3235..ec4c4782f1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,9 +2,9 @@ version: '3.7' x-environment: &py-environment - DEBUG: 'False' + DEBUG: ${DEBUG:-True} DEV_ENV: 'True' # necessary to have nginx connect to web container - NODE_ENV: 'production' + NODE_ENV: ${NODE_ENV:-development} DATABASE_URL: postgres://postgres@db:5432/postgres OPEN_DISCUSSIONS_SECURE_SSL_REDIRECT: 'False' OPEN_DISCUSSIONS_DB_DISABLE_SSL: 'True' @@ -55,6 +55,9 @@ services: - "8063:8063" links: - web + volumes: + - ./config/nginx.conf:/etc/nginx/conf.d/web.conf + - ./:/src web: build: @@ -75,6 +78,9 @@ services: - redis - watch extra_hosts: *default-extra-hosts + volumes: + - .:/src + - django_media:/var/media watch: image: node:16.15.1 @@ -92,6 +98,7 @@ services: env_file: .env volumes: - .:/src + - yarn-cache:/home/mitodl/.cache/yarn celery: build: @@ -107,9 +114,35 @@ services: - db - redis extra_hosts: *default-extra-hosts + volumes: + - .:/src + - django_media:/var/media tika: image: apache/tika:1.23 entrypoint: java -jar tika-server-1.23.jar -h 0.0.0.0 -spawnChild ports: - "9998:9998" + + notebook: + build: + context: . + dockerfile: Dockerfile + target: jupyter-notebook + profiles: ["notebook"] + volumes: + - .:/app + environment: + << : *py-environment + BASE_DJANGO_APP_NAME: open_discussions + env_file: .env + command: > + /bin/bash -c ' + sleep 3 && + jupyter notebook --no-browser --ip=0.0.0.0 --port=8080' + ports: + - "8080:8080" + +volumes: + django_media: {} + yarn-cache: {}