15

We are using the official MediaWiki Docker image and want to be able to add additional MediaWiki extensions.

Questions:

  1. What is the recommended next step here if we are currently using the docker-compose file below were we mount volumes on the host? Is it to build a new image that wraps the official image? Is there an example somewhere of this modified new image for adding a mediawiki extension?
  2. Or can we just mount an extensions volume on the host in the current docker-compose and if needed make any adjustments the LocalSettings.php?

This link on the docker website refers to adding PHP extensions and libraries but its not clear to me if this is attempting to be the same answer if wanting to add MediaWiki specific extensions since it does clearly say "PHP Extensions". Or should this documentation page have actually said "MediaWiki Extensions" even though that implies they are written in PHP?

Here is our current docker-compose file entry for mediawiki:

mediawiki:
  image: mediawiki
  container_name: mediawiki_production
  mem_limit: 4g
  volumes:
    - /var/www/mediawiki/uploads:/var/www/html/uploads
    - /var/www/mediawiki/LocalSettings.php:/var/www/html/LocalSettings.php
  environment:
    - MEDIAWIKI_DB_NAME=
    - MEDIAWIKI_DB_HOST=
    - MEDIAWIKI_DB_USER=
    - MEDIAWIKI_DB_PASSWORD=
    - VIRTUAL_HOST=wiki.exmaple.com
    - TERM=xterm
  restart: always
  network_mode: bridge

The extensions we are considering that are not part of the official image first off are (but would like a scalable solution for more later):

Any examples of an downstream docker image that uses the official mediawiki image as its "FROM" to include a mediawiki extension(s) and an updated docker-compose (if both are required) to be able to add mediawiki extensions would be helpful. Perhaps it may be good to explain what needs to change if the mediawiki extension itself relies on php extensions or libraries that are not already included in base image already vs adding a mediawiki extension that doesn't rely on any additional php extensions or libraries.

Nemo
  • 2,441
  • 2
  • 29
  • 63
Streamline
  • 2,040
  • 4
  • 37
  • 56

1 Answers1

14

As OP suggested, you need to create an image which wraps the official MediaWiki image.

Write instructions to make an image with extra extensions

As a minimal example we'll create an image which includes the EmbedVideo extension, which is not bundled with MediaWiki as of version 1.31. Add the following instructions the file my-mediawiki/Dockerfile:

FROM mediawiki:latest

RUN git clone --depth 1 https://github.com/HydraWiki/mediawiki-embedvideo.git /var/www/html/extensions/EmbedVideo

Build the image

Turn this Dockerfile into an image using docker build:

$ docker build -t username/mediawiki ./my-mediawiki
Sending build context to Docker daemon  2.048kB
Step 1/2 : FROM mediawiki:latest
latest: Pulling from library/mediawiki
802b00ed6f79: Pull complete
# [lines omitted]
8b47ece631d8: Pull complete 
Digest: sha256:5922653b254073c6d6a535bbdb0101f8a5eadbf557e2f31d590c234001c55b60
Status: Downloaded newer image for mediawiki:latest
 ---> 27fe73856ca7
Step 2/2 : RUN git clone --depth 1 https://github.com/HydraWiki/mediawiki-embedvideo.git /var/www/html/extensions/EmbedVideo
 ---> Running in 30a411511341
Cloning into '/var/www/html/extensions/EmbedVideo'...
Removing intermediate container 30a411511341
 ---> 5b297228bb08
Successfully built 5b297228bb08
Successfully tagged username/mediawiki:latest

Test the image

Test the image using docker run:

$ docker run --rm -p 8080:80 username/mediawiki

While this container is running visit localhost:8080 with a web browser. You will be asked to perform the setup procedure. When you get to the options page the EmbedVideo extension will be included in the list of extensions.

Perform the rest of setup

Other steps are needed to get MediaWiki running in docker, such as providing a LocalSettings.php file and connecting it to a database. Follow the official MediaWiki Docker documentation for these steps, substituting your username/mediawiki image for the official mediawiki image.

Add additional plugins

Multiple plugins can be installed by appending more RUN instructions to the end of my-mediawiki/Dockerfile. For example, to add Scribunto, append the following to the bottom of the file:

RUN git clone --depth 1 -b $MEDIAWIKI_BRANCH \
      https://gerrit.wikimedia.org/r/p/mediawiki/extensions/Scribunto \
      /var/www/html/extensions/Scribunto \
      && chmod a+x /var/www/html/extensions/Scribunto/includes/engines/LuaStandalone/binaries/lua*_linux_*/lua

After modifying the Dockerfile update the image using:

docker build -t username/mediawiki ./my-mediawiki

Most extensions require you to modify LocalSettings.php, and like Scribunto some will require additional installation commands to be run after download (check each extensions's README). Complex extensions like VisualEditor will require additional containers to run daemons such as Parsoid. My own Dockerfile and docker-compose.yml illustrate how other plugins can be configured.

Divinenephron
  • 756
  • 8
  • 18
  • Looks good. I ended up with something similar for the simpler extensions as you say and haven't yet completed the more complex extension VisualEditor. Do you have a reference to an example of what it takes (setup, configuration, docker-compose file, etc) to implement VisualEditor with the additional containers to run Parsoid, etc. in the way you mention? – Streamline Oct 04 '18 at 10:33
  • I did make a `docker-compose.yml` file which got VisualEditor working. I'll link to it as an example once I get home, though that won't be until November '18 :(. – Divinenephron Oct 05 '18 at 11:11
  • 2
    I uploaded and linked to [my own configuration](https://github.com/divinenephron/docker-mediawiki) as @Streamline requested. – Divinenephron Nov 03 '18 at 16:25
  • Returning to this while updating various images in our environment. It seems like things have changed. I can longer build my original image from this original effort nor can I build the image you linked. I suspect things are different now in `mediawiki:latest` from when you originally built it. Do you have a recent version of your dockerfile and docker-compose or do you have tips on how to do the same (add extensions like VisualEditor and EmbedVideo) with current official mediawiki docker image? – Streamline Nov 02 '21 at 15:56
  • A little deeper dive into the issue causing the build to fail and it appears it was because since we last had to build this (back on 1.31.0), the official image now (1.36.2) includes more extensions, namely VisualEditor (added some point between the two versions) which was one we were trying to install and it failed due to path already existing. So I suppose the lesson here is you need to determine first if the extension you are trying to install as an "added extension" has since been included in the newer official image as you migrate forward. – Streamline Nov 02 '21 at 23:05
  • Unfortunately I didn't do any maintenance, and when I tried to build it a few months ago I also couldn't get it to work, and I was too rusty on Docker and Mediawiki to fix it. – Divinenephron Nov 03 '21 at 18:55
  • No problem. The issue for yours is likely a combination of remote or local paths needing to be updated and resolving local conflicts (such as I had mentioned above if the extension now exists already it will fail), etc. like it was with mine. Each extension steps needs to be determined and tested in a container with fresh install, then move that to the dockerfile. It was good to see that more extensions appear to be included as the versions of mediawiki advance therefore reducing the need to install them separately. – Streamline Nov 04 '21 at 19:28