1 # A Dockerfile for MediaGoblin hacking.
3 # Most development Docker images are built and run as root. That doesn't work
4 # here because the `bower` command run within the `make` step, refuses to run as
7 # To build this Docker image, run:
9 # docker build -t mediagoblin-python3 -f Dockerfile-debian-python3-sqlite . # or
10 # docker build -t mediagoblin-python3 - < Dockerfile-debian-python3-sqlite # with no build context
12 # The "- < Dockerfile" format advises Docker not to include the current
13 # directory as build context.
15 # Before running the image you first need to first assign the "mediagoblin" and
16 # "user_dev" directories to an artificial group (1024) on the host that is
17 # mirrored within the image (details below):
19 # sudo chown --recursive :1024 mediagoblin user_dev
20 # find mediagoblin user_dev -type d -exec chmod 775 {} \;
21 # find mediagoblin user_dev -type f -exec chmod 664 {} \;
23 # Then you can run the image with the upstream MediaGoblin code:
25 # docker run --interactive --tty --publish 6543:6543 mediagoblin-python3
27 # Or you can run with your local "mediagoblin" and "user_dev" directories
28 # bind-mounted into the container. This provides automatic code reloading and
31 # # TODO: Not working.
32 # docker run --interactive --tty --publish 6543:6543 --volume ./mediagoblin:/opt/mediagoblin/mediagoblin --volume ./extlib:/opt/mediagoblin/extlib mediagoblin-python3
34 # Alternatively you use docker-compose instead of separate build/run steps:
36 # sudo chown --recursive :1024 mediagoblin user_dev
37 # find mediagoblin user_dev -type d -exec chmod 775 {} \;
38 # find mediagoblin user_dev -type f -exec chmod 664 {} \;
39 # docker-compose up --build
41 # You can run the test suite with:
43 # docker run --tty mediagoblin-python3 bash -c "bin/python -m pytest ./mediagoblin/tests --boxed"
48 # Install bootstrap and configure dependencies. Currently requires virtualenv
49 # rather than the more modern python3-venv (should be fixed).
50 RUN apt-get update && apt-get install -y \
58 # Install make and runtime dependencies.
60 # Excluding python3-celery here due to conflict with dist-packges for a
61 # compatible version of billiard.
62 RUN apt-get install -y \
70 python3-pytest-xdist \
72 python3-snowballstemmer \
74 python3-sphinxcontrib.websupport \
77 # Install audio dependencies.
78 RUN apt-get install -y \
80 gstreamer1.0-plugins-bad \
81 gstreamer1.0-plugins-base \
82 gstreamer1.0-plugins-good \
83 gstreamer1.0-plugins-ugly \
89 # Install video dependencies.
90 RUN apt-get install -y \
91 gir1.2-gst-plugins-base-1.0 \
92 gir1.2-gstreamer-1.0 \
96 # Install document (PDF-only) dependencies.
97 # TODO: Check that PDF tests aren't skipped.
98 RUN apt-get install -y \
101 # Create working directory.
102 RUN mkdir /opt/mediagoblin
103 RUN chown -R www-data:www-data /opt/mediagoblin
104 WORKDIR /opt/mediagoblin
106 # Create /var/www because Bower writes some cache files into /var/www during
107 # make, failing if it doesn't exist.
108 RUN mkdir --mode=g+w /var/www
109 RUN chown root:www-data /var/www
111 # Set up custom group to align with volume permissions for mounted
112 # "mediagoblin/mediagoblin" and "mediagoblin/user_dev".
114 # The problem here is that the host's UID, GID and mode are used in the
115 # container, but of course the container's user www-data is running under a
116 # different UID/GID so can't read or write to the volume. It seems like there
117 # should be a better approach, but we'll align volume permissions between host
118 # and container as per
119 # https://medium.com/@nielssj/docker-volumes-and-file-system-permissions-772c1aee23ca
120 RUN groupadd --system mediagoblin --gid 1024 && adduser www-data mediagoblin
124 # Copy upstream MediaGoblin into the image for use in the build process.
126 # This build process is somewhat complicated, because of Bower/NPM, translations
127 # and Python dependencies, so it's not really feasible just to copy over a
128 # requirements.txt like many Python Dockerfiles examples do. We need the full
131 # While it is possible to copy the source from the current directory like this:
133 # COPY --chown=www-data:www-data . /opt/mediagoblin
135 # that approach to lots of confusing problems when your working directory has
136 # changed from the default - say you've enabled some plugins or switched
137 # database type. So instead we're doing a git clone. We could potentially use
138 # `git archive` but this still wouldn't account for the submodules.
139 RUN git clone --depth=1 git://git.savannah.gnu.org/mediagoblin.git -b master .
142 RUN VIRTUALENV_FLAGS='--system-site-packages' ./configure
145 # Only supported on Python 2.
146 # RUN ./bin/pip install scikits.audiolab
148 # Only safe if being run on a clean git checkout. Otherwise you may have already
149 # customised mediagoblin.ini to already install these.
150 RUN echo '[[mediagoblin.media_types.audio]]' >> mediagoblin.ini
151 RUN echo '[[mediagoblin.media_types.video]]' >> mediagoblin.ini
153 # Prepare the SQLite database.
155 # TODO: Should probably be done at runtime.
156 RUN ./bin/gmg dbupdate
157 RUN ./bin/gmg adduser --username admin --password a --email admin@example.com
158 RUN ./bin/gmg makeadmin admin
162 # TODO: Is it possible to have a CMD here that is overriden by docker-compose?
163 CMD ["./lazyserver.sh", "--server-name=broadcast"]