Skip to content

Add docker env for local development #471

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
FROM ubuntu:focal

ENV PYTHONUNBUFFERED 1
ENV LC_ALL=C.UTF-8
ARG DEBIAN_FRONTEND=noninteractive

# the base image is also built using this Dockerfile, so we have to reset this
USER root

RUN apt-get -y update && apt-get -y --no-install-recommends install \
build-essential \
gcc \
gettext \
python3-dev \
python3-venv \
&& \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /usr/share/doc/* /usr/share/locale/* /usr/share/man/* && \
mkdir -p /app && \
(useradd -m app || true)

COPY --from=library/docker:latest /usr/local/bin/docker /usr/bin/docker
COPY --from=docker/compose:1.23.2 /usr/local/bin/docker-compose /usr/bin/docker-compose

WORKDIR /app

ADD runtests/requirements.txt /app/

USER app

ENV PATH /home/app/venv/bin:${PATH}

RUN python3 -m venv ~/venv && \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we really need to use virtualenv with docker?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to have my Docker setup as close as possible to my production setups which use virtualenvs.
But can be removed if you don't like it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wondering why didn't we consider using FROM python:3.8-slim-buster?

pip install -r /app/requirements.txt

ENV DJANGO_SETTINGS_MODULE settings

# *WARNING*: DO NOT "ADD . /app" because it would include the current settings in the base image, which is uploaded by
# CI to docker hub; Since the settings currently include secrets, this would leak our credentials!

EXPOSE 8000

ENTRYPOINT ["/app/manage.py"]
17 changes: 17 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: "3.5"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it python version?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the Compose file format version, see https://docs.docker.com/compose/compose-file/


services:
django:
build: .
user: app
command: "runserver 0:8000"
volumes:
- ./runtests:/app:cached
- ./actstream:/app/actstream:cached
- /var/run/docker.sock:/var/run/docker.sock
environment:
IPYTHONDIR: /app/.ipython
HISTFILE: /app/.bash_history
PYTHONDONTWRITEBYTECODE: "x"
PYTHONWARNINGS: default
restart: unless-stopped
10 changes: 10 additions & 0 deletions docs/source/development.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Developing on django-activity-stream
====================================

To simplify the development workflow, the project provides a docker container that can run the tests.

You will need `docker <https://www.docker.com/>`_ and `Docker Compose <https://docs.docker.com/compose/>`_.

.. code-block:: bash

docker-compose run --rm django test
1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Contents:
streams
templatetags
feeds
development
changelog
api

Expand Down
4 changes: 4 additions & 0 deletions runtests/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Django>=2.2.17
django-jsonfield
django-jsonfield-compat
tblib