docs: Add chapter on upgrading, inc. system Python upgrades [#972].
[mediagoblin.git] / Dockerfile-debian-python3-sqlite
CommitLineData
63a92e3b 1# A Dockerfile for MediaGoblin hacking.
86891869
BS
2#
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
5# root.
6#
7# To build this Docker image, run:
8#
cbd11916 9# docker build -t mediagoblin-python3 -f Dockerfile-debian-python3-sqlite . # or
486f90a7 10# docker build -t mediagoblin-python3 - < Dockerfile-debian-python3-sqlite # with no build context
86891869
BS
11#
12# The "- < Dockerfile" format advises Docker not to include the current
13# directory as build context.
14#
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):
18#
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 {} \;
22#
23# Then you can run the image with the upstream MediaGoblin code:
24#
cbd11916 25# docker run --interactive --tty --publish 6543:6543 mediagoblin-python3
86891869
BS
26#
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
29# persistence:
30#
cbd11916 31# # TODO: Not working.
86891869
BS
32# docker run --interactive --tty --publish 6543:6543 --volume ./mediagoblin:/opt/mediagoblin/mediagoblin --volume ./extlib:/opt/mediagoblin/extlib mediagoblin-python3
33#
34# Alternatively you use docker-compose instead of separate build/run steps:
35#
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
cbd11916
BS
40#
41# You can run the test suite with:
42#
43# docker run --tty mediagoblin-python3 bash -c "bin/python -m pytest ./mediagoblin/tests --boxed"
44
63a92e3b
BS
45
46FROM debian:buster
47
48# Install bootstrap and configure dependencies. Currently requires virtualenv
49# rather than the more modern python3-venv (should be fixed).
50RUN apt-get update && apt-get install -y \
51automake \
52git \
53nodejs \
54npm \
55python3-dev \
56virtualenv
57
58# Install make and runtime dependencies.
86891869
BS
59#
60# Excluding python3-celery here due to conflict with dist-packges for a
61# compatible version of billiard.
63a92e3b
BS
62RUN apt-get install -y \
63python3-alembic \
63a92e3b
BS
64python3-jsonschema \
65python3-kombu \
66python3-lxml \
86891869 67python3-migrate \
63a92e3b
BS
68python3-py \
69python3-pytest \
70python3-pytest-xdist \
71python3-six \
86891869 72python3-snowballstemmer \
63a92e3b 73python3-sphinx \
86891869 74python3-sphinxcontrib.websupport \
63a92e3b
BS
75python3-webtest
76
77# Install audio dependencies.
78RUN apt-get install -y \
79gstreamer1.0-libav \
80gstreamer1.0-plugins-bad \
81gstreamer1.0-plugins-base \
82gstreamer1.0-plugins-good \
83gstreamer1.0-plugins-ugly \
4f3f70d1 84python3-gst-1.0
63a92e3b
BS
85
86# Install video dependencies.
87RUN apt-get install -y \
88gir1.2-gst-plugins-base-1.0 \
89gir1.2-gstreamer-1.0 \
90gstreamer1.0-tools \
91python3-gi
92
0798a889
BS
93# Install document (PDF-only) dependencies.
94# TODO: Check that PDF tests aren't skipped.
95RUN apt-get install -y \
96poppler-utils
97
63a92e3b
BS
98# Create working directory.
99RUN mkdir /opt/mediagoblin
100RUN chown -R www-data:www-data /opt/mediagoblin
101WORKDIR /opt/mediagoblin
102
103# Create /var/www because Bower writes some cache files into /var/www during
104# make, failing if it doesn't exist.
486f90a7 105RUN mkdir --mode=g+w /var/www
63a92e3b 106RUN chown root:www-data /var/www
63a92e3b 107
86891869
BS
108# Set up custom group to align with volume permissions for mounted
109# "mediagoblin/mediagoblin" and "mediagoblin/user_dev".
110#
111# The problem here is that the host's UID, GID and mode are used in the
112# container, but of course the container's user www-data is running under a
113# different UID/GID so can't read or write to the volume. It seems like there
114# should be a better approach, but we'll align volume permissions between host
115# and container as per
116# https://medium.com/@nielssj/docker-volumes-and-file-system-permissions-772c1aee23ca
117RUN groupadd --system mediagoblin --gid 1024 && adduser www-data mediagoblin
118
63a92e3b
BS
119USER www-data
120
86891869
BS
121# Copy upstream MediaGoblin into the image for use in the build process.
122#
123# This build process is somewhat complicated, because of Bower/NPM, translations
124# and Python dependencies, so it's not really feasible just to copy over a
125# requirements.txt like many Python Dockerfiles examples do. We need the full
126# source.
127#
128# While it is possible to copy the source from the current directory like this:
129#
130# COPY --chown=www-data:www-data . /opt/mediagoblin
131#
132# that approach to lots of confusing problems when your working directory has
133# changed from the default - say you've enabled some plugins or switched
134# database type. So instead we're doing a git clone. We could potentially use
135# `git archive` but this still wouldn't account for the submodules.
16fbe852
BS
136#
137# TODO: Figure out a docker-only way to do the build and run from our local
138# version, so that local changes are immediately available to the running
139# container. Not as easy as it sounds. We have this working with docker-compose,
140# but still uses upstream MediaGoblin for the build.
e77430eb
BS
141# RUN git clone --depth=1 git://git.savannah.gnu.org/mediagoblin.git --branch master .
142RUN git clone --depth=1 https://gitlab.com/BenSturmfels/mediagoblin.git --branch spectrograms .
63a92e3b
BS
143
144RUN ./bootstrap.sh
100f6265 145RUN VIRTUALENV_FLAGS='--system-site-packages' ./configure
63a92e3b
BS
146RUN make
147
16fbe852
BS
148# Run the tests.
149RUN ./bin/python -m pytest ./mediagoblin/tests --boxed
150
86891869
BS
151# Only safe if being run on a clean git checkout. Otherwise you may have already
152# customised mediagoblin.ini to already install these.
63a92e3b
BS
153RUN echo '[[mediagoblin.media_types.audio]]' >> mediagoblin.ini
154RUN echo '[[mediagoblin.media_types.video]]' >> mediagoblin.ini
155
86891869
BS
156# Prepare the SQLite database.
157#
158# TODO: Should probably be done at runtime.
63a92e3b 159RUN ./bin/gmg dbupdate
63a92e3b
BS
160RUN ./bin/gmg adduser --username admin --password a --email admin@example.com
161RUN ./bin/gmg makeadmin admin
162
86891869
BS
163EXPOSE 6543/tcp
164
165# TODO: Is it possible to have a CMD here that is overriden by docker-compose?
166CMD ["./lazyserver.sh", "--server-name=broadcast"]