MediaWiki-Docker-Dev

From MediaWiki.org
Jump to navigation Jump to search

MediaWiki-Docker-Dev (or MDD) is a development environment for MediaWiki, based on Docker. It was authored by Addshore, with contributions from others. It can be installed from GitHub, and you can find instructions for setup in the README.

Configuration[edit]

Adjusting database replication delay[edit]

This is very useful for reproducing production bugs caused by replication delay.

First, connect to the replica database: docker-compose exec db-slave mysql -uroot -ptoor default

Then execute this SQL to set the delay to 2 seconds.

STOP SLAVE;
CHANGE MASTER TO MASTER_DELAY = 2;
START SLAVE;
SHOW SLAVE STATUS\G

The output should show SQL_Delay: 2

Log to STDERR[edit]

With this configuration, you can view MediaWiki's logs by running docker-compose logs -f web, or docker-compose logs -f web | grep '\[error\]' to view only error messages.

if ( !defined( 'STDERR' ) ) {
	define( 'STDERR', fopen( 'php://stderr', 'w' ) );
}

if ( !isset( $maintClass ) || ( isset( $maintClass ) && $maintClass !== 'PHPUnitMaintClass' ) ) {
	$wgMWLoggerDefaultSpi = [
		'class' => \MediaWiki\Logger\ConsoleSpi::class,
	];
}

Improve file system sync on macOS[edit]

Docker for Mac users may notice a performance improvement by adjusting docker-compose.yml so that the volumes section under web has :cached set:

- ${DOCKER_MW_PATH}:/var/www/mediawiki:cached

Additional services[edit]

EventLogging[edit]

  1. Clone the eventlogging repository
  2. Run ./bin/eventlogging-devserver. (Optional) If you have jq installed, you can run ./bin/eventlogging-devserver | jq '.' for improved formatting of the JSON output.

In Docker for Mac, add this to your LocalSettings.php:

$wgEventLoggingBaseUri = 'http://host.docker.internal:8100/event.gif';

Redis[edit]

In docker-compose.yml add:

  redis:
    image: redis

In MediaWiki's LocalSettings.php, add:

$wgObjectCaches['redis'] = [
	'class' => 'RedisBagOStuff',
	'servers'=> [ 'redis:6379' ],
];
$wgMainCacheType = 'redis';
$wgSessionCacheType = 'redis';
$wgMainStash = 'redis';

$wgJobTypeConf['default'] = [
	'class' => 'JobQueueRedis',
	'redisServer' => 'redis:6379',
	'redisConfig' => [],
	'claimTTL' => 3600,
	'daemonized' => true
];

Parsoid / VisualEditor[edit]

See https://github.com/addshore/mediawiki-docker-dev/pull/83 for how to running Parsoid as a service locally.

Alternatively, you can use the approach from boxwiki:

$wgVirtualRestConfig['modules']['parsoid'] = array(
    // URL to the Parsoid instance
    // Use port 8142 if you use the Debian package
    'url' => 'https://en.wikipedia.org',
    // Parsoid "domain", see below (optional)
    'domain' => 'en.wikipedia.org',
    // Parsoid "prefix", see below (optional)
    'prefix' => 'localhost'
);
$wgVisualEditorFullRestbaseURL = 'https://en.wikipedia.org/api/rest_';

ElasticSearch[edit]

In docker-compose.yml add:

  elasticsearch:
    image: elasticsearch:6.8.2
    ports: 
      - 9200:9200
      - 9300:9300
    environment:
      - discovery.type=single-node

Then follow the installation and configuration instructions from Extension:CirrusSearch, taking care to specify the hostname as elasticsearch rather than localhost.