MediaWiki-Docker/Configuration recipes/Dev containers

Category:Under construction

Dev containers is a specification for creating and executing development environments inside of containers. This page details how to instantiate a dev container for MediaWiki with IDEs that support it.

Visual Studio Code

  1. Down all docker containers inside the repo: docker compose down.
  2. Install the Dev Containers extension.
  3. Create a devcontainers.json file:
    1. Open the command palette and search "Reopen in container".
    2. Select "From 'docker-compose.yml'".
    3. Choose the "mediawiki" service.
    4. Choose which tools to add.
    5. Skip adding any optional files or directories.
    6. The container will fail to open. This is because a specific devcontainer.json file is needed for the IDE.
    7. Copy and paste the following into your devcontainers.json file:
      // For format details, see https://aka.ms/devcontainer.json. For config options, see the
      // README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-docker-compose
      {
      	"name": "MediaWiki Core",
      
      	// Update the 'dockerComposeFile' list if you have more compose files or use different names.
      	// The .devcontainer/docker-compose.yml file contains any overrides you need/want to make.
      	"dockerComposeFile": [
      		"../docker-compose.yml",
      		"../docker-compose.override.yml",
      		"docker-compose.yml"
      	],
      
      	// The 'service' property is the name of the service for the container that VS Code should
      	// use. Update this value and .devcontainer/docker-compose.yml to the real service name.
      	"service": "mediawiki",
      
      	// The optional 'workspaceFolder' property is the path VS Code should open by default when
      	// connected. This is typically a file mount in .devcontainer/docker-compose.yml
      	"workspaceFolder": "/var/www/html/w",
      
      	// Features to add to the dev container. More info: https://containers.dev/features.
      	// "features": {},
      
      	// Use 'forwardPorts' to make a list of ports inside the container available locally.
      	"forwardPorts": [
      		9003
      	],
      
      	// Uncomment the next line if you want start specific services in your Docker Compose config.
      	// "runServices": [],
      
      	// Uncomment the next line if you want to keep your containers running after VS Code shuts down.
      	// "shutdownAction": "none",
      
      	// Uncomment the next line to run commands after the container is created.
      	"postCreateCommand": "composer update\n/docker/install.sh\nchmod -R o+rwx cache/sqlite",
      
      	// Configure tool-specific properties.
      	"customizations": {
      		"vscode": {
      			"settings": {
      				"terminal.integrated.defaultProfile.linux": "bash"
      			},
      			"extensions": [
      				"xdebug.php-debug"
      			]
      		}
      	},
      
      	// Container environment variables.
      	"containerEnv": {
      		"MW_SCRIPT_PATH": "/w",
      		"MW_SERVER": "http://localhost:8080",
      		"MW_DOCKER_PORT": "8080",
      		"MEDIAWIKI_USER": "Admin",
      		"MEDIAWIKI_PASSWORD": "dockerpass",
      		"XDEBUG_CONFIG": "mode=debug start_with_request=yes discover_client_host=1",
      		"XDEBUG_MODE": "debug",
      		"XDEBUG_ENABLE": "true",
      		"XDEBUG_TRIGGER": "1",
      		"XHPROF_ENABLE": "true"
      	},
      
      	// Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root.
      	"remoteUser": "www-data"
      }
      
  4. Make sure you still have a .env file set with just the MW_DOCKER_UID and MW_DOCKER_GID set up.
  5. Create a launch.json that you can use to connect to Xdebug.
  6. It is best to use the operating system the dev container is located in to make and submit reviews to Gerrit.
Category:Under construction