Skip to content

Commit

Permalink
Merge pull request #114 from EarthSchlange/revert_Dockerfile_to_pytho…
Browse files Browse the repository at this point in the history
…n2.7

Reverted Dockerfile to Python2.7
  • Loading branch information
Michael Hiiva authored Aug 23, 2020
2 parents 317c5bd + 4300c49 commit eda17ce
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
46 changes: 46 additions & 0 deletions Dockerfile.python3
Original file line number Diff line number Diff line change
@@ -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"]
47 changes: 47 additions & 0 deletions docker-compose-python3.yml
Original file line number Diff line number Diff line change
@@ -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:
12 changes: 11 additions & 1 deletion docs/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit eda17ce

Please sign in to comment.