From 4300c497f42e553e09ff6a11d28a59bf65bc0ff0 Mon Sep 17 00:00:00 2001 From: Michael Hiiva Date: Sun, 23 Aug 2020 15:55:59 -0700 Subject: [PATCH] Reverted Dockerfile to Python2.7 Added Dockerfile and docker-compose-python3.yml for Python3.7 Development --- Dockerfile | 4 ++-- Dockerfile.python3 | 46 +++++++++++++++++++++++++++++++++++++ docker-compose-python3.yml | 47 ++++++++++++++++++++++++++++++++++++++ docs/docker.md | 12 +++++++++- 4 files changed, 106 insertions(+), 3 deletions(-) create mode 100644 Dockerfile.python3 create mode 100644 docker-compose-python3.yml diff --git a/Dockerfile b/Dockerfile index 7cfb98cd..21e7ae79 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,7 @@ # * MYSQL_PASSWORD - database password (the docker entrypoint sets MYSQL_PASS to this value for app compatibility) ### Build stage, to avoid leaving dev dependencies in the final image -FROM python:3.7-slim AS build +FROM python:2.7-slim AS build WORKDIR /build @@ -22,7 +22,7 @@ COPY requirements.txt /build/ RUN pip install --user --no-cache-dir -r requirements.txt && pip install --user --no-cache-dir uwsgi ### Final image -FROM python:3.7-slim +FROM python:2.7-slim WORKDIR /srv RUN useradd django diff --git a/Dockerfile.python3 b/Dockerfile.python3 new file mode 100644 index 00000000..7cfb98cd --- /dev/null +++ b/Dockerfile.python3 @@ -0,0 +1,46 @@ +# Dockerfile for agagd application local development environment. +# +# In addition to environment variables used by the application, the entrypoint script is affected by the following. docker-compose.yml sets reasonable defaults for a development environment: +# * DB_HOST - database hostname +# * DB_PORT - database port +# * APP_DB_NAME - name of the database to use +# * AGAGD_USER - database username +# * MYSQL_PASSWORD - database password (the docker entrypoint sets MYSQL_PASS to this value for app compatibility) + +### Build stage, to avoid leaving dev dependencies in the final image +FROM python:3.7-slim AS build + +WORKDIR /build + +RUN apt-get update && apt-get install -y \ + libsqlite3-dev \ + libmariadb-dev \ + build-essential +RUN pip install --no-cache-dir -U pip + +COPY requirements.txt /build/ +RUN pip install --user --no-cache-dir -r requirements.txt && pip install --user --no-cache-dir uwsgi + +### Final image +FROM python:3.7-slim + +WORKDIR /srv +RUN useradd django + +COPY --from=build --chown=django:django /root/.local /home/django/.local + +RUN apt-get update && apt-get install -y \ + default-mysql-client \ + libmariadb3 + +USER django + +ENV PATH=/home/django/.local/bin:$PATH +ENV DJANGO_SETTINGS_MODULE=agagd.settings.prod +ENV PROJECT_ROOT=/srv +ENV TEMPLATE_DIR=/srv/templates + +COPY --chown=django:django scripts/entrypoint.sh agagd/ /srv/ +RUN SECRET_KEY=stub-for-build python manage.py collectstatic --noinput + +CMD ["/srv/entrypoint.sh"] diff --git a/docker-compose-python3.yml b/docker-compose-python3.yml new file mode 100644 index 00000000..37084a62 --- /dev/null +++ b/docker-compose-python3.yml @@ -0,0 +1,47 @@ +# docker-compose setup for a development environment. +# To use this file, populate config-docker.env with the following: +# +# MYSQL_PASSWORD - a password for the mysql user +# MYSQL_ROOT_PASSWORD - a password for the mysql *root* user +# +# Then you can run: +# - docker-compose -f docker-compose-python3.yaml build +# - docker-compose -f docker-compose-python3.yaml up + +version: '3.5' + +services: + app: + build: ./Dockerfile.python3 + restart: always + ports: + - "8000:3031" + env_file: + config-docker.env + environment: + DB_HOST: db + DB_PORT: 3306 + APP_DB_NAME: agagd + AGAGD_USER: agagd + SECRET_KEY: insecure-key-for-testing + DEBUG: "true" + LOAD_FIXTURES: "true" + + db: + build: + context: ./ + dockerfile: Dockerfile.mysql + restart: always + volumes: + - database:/var/lib/mysql + env_file: + config-docker.env + environment: + # this is safer than it looks, since without a 'ports' section, docker-compose + # isolates this app to a network local to this compose file. + MYSQL_ROOT_HOST: "%" + MYSQL_USER: agagd + MYSQL_DATABASE: agagd + +volumes: + database: diff --git a/docs/docker.md b/docs/docker.md index edcd8fb7..ba0ab6e8 100644 --- a/docs/docker.md +++ b/docs/docker.md @@ -20,12 +20,22 @@ Copy `config-docker.env.sample` to `config-docker.env` (in the repository root) $ cp config-docker.env.sample config-docker.env ~~~ -These values will be used by both the database and the app. Now, run: +These values will be used by both the database and the app. Now, run either: + +#### For Python 2.7 ~~~ $ docker-compose up --build ~~~ +#### For Python 3.7 + +##### Note: Python 3.7+ is not fully supported by the AGAGD Application. More information can be found in issue #112. + +~~~ +$ docker-compose -f docker-compose-python3.yml up --build +~~~ + Wait for the database to initialize and the app to start up. (there will be something like `spawned uWSGI worker` in the logs) You should now be serving the app at http://localhost:8000.