MediaWiki-Docker/Extension/WikiLambda

From mediawiki.org

This page instructs you to install Extension:WikiLambda inside MediaWiki-Docker.

Follow the Quickstart instructions at MediaWiki-Docker page. Once MediaWiki is running and available at http://localhost:8080, then continue with instructions on this page.

All commands should be run in the directory where you installed MediaWiki. All mentioned files are also located there.

Clone the repository and its sub-module[edit]

git clone "https://gerrit.wikimedia.org/r/mediawiki/skins/Vector" skins/Vector
git clone --recurse-submodules --remote-submodules https://gerrit.wikimedia.org/r/mediawiki/extensions/WikiLambda extensions/WikiLambda

If you plan on using gerrit or authenticating with ssh rather than https, it is recommended you get the code with an SSH key instead. Follow these instructions to do so.

If your Git version is older than 2.23, --remote-submodules will not be available. Use git submodule update --remote instead.

Add our composer dependencies[edit]

Extend MediaWiki's composer dependencies to use ours by adding a composer.local.json file in your mediawiki/ directory with the following:

{
    "extra": {
        "merge-plugin": {
            "include": [
                "extensions/WikiLambda/composer.json"
            ]
        }
    }
}

… and then run:

docker-compose exec mediawiki composer update

Modify LocalSettings.php[edit]

If not already there, add this to the end of LocalSettings.php.

wfLoadSkin( 'Vector' );
wfLoadExtension( 'WikiLambda' );

Run maintenance scripts[edit]

docker-compose exec mediawiki php maintenance/update.php

Optional: Setting up the services[edit]

Check[edit]

You can check whether this worked by navigating to http://localhost:8080/wiki/Special:CreateZObject, or to http://localhost:8080/wiki/Special:ApiSandbox and looking for wikilambda_fetch in the action dropdown. If they are there, all is well.

Adding the services[edit]

To add the orchestrator and executor back-end services, first copy the contents of the services block in WikiLambda's docker-compose.sample.yml file to the analogous `services` block in your mediawiki/docker-compose.override.yml file, including the environment part. Replace the <TAG> entries in the stanza you just copied with the latest builds from the Docker registry for the orchestrator and the evaluator.

[Note: This is not working, as of 2022-04-29] You can automatically test your installation by editing your local copy of ApiFunctionCallTest.php to remove @group: Broken, and running the PHPUnit test suite as described in the MediaWiki install instructions, or by using the following command:

      docker-compose exec mediawiki php tests/phpunit/phpunit.php extensions/WikiLambda/tests/phpunit/integration/API/ApiFunctionCallTest.php

You can manually evaluate a function call by navigating to http://localhost:8080/wiki/Special:EvaluateFunctionCall, selecting a function from the wiki, and choosing your inputs. If successful, the function response will be presented, having traversed the orchestrator and the evaluator to be run in one of the code executors.

You can also visit http://localhost:8080/wiki/Special:ApiSandbox and try out one or more tests as follows:

  • In the action drop-down menu, select wikilambda_function_call
  • Switch from the main to the action=wikilambda_function_call section on the left sidebar
  • Click on {} Examples, and select any of the listed examples
  • Click the blue Make request button
  • In the Results box, look for the word "success".

🎉 Congratulations! 🎉

Special configurations[edit]

Having the services with different configuration[edit]

If you wish to use the orchestrator under a different name or port, you must over-ride the $wgWikiLambdaOrchestratorLocation configuration value from its default (as set in extension.json). To override the orchestrator location variable, you should add in your LocalSettings.php file:

$wgWikiLambdaOrchestratorLocation = '<orchestrator_container_name>:6254';

If you wish to use the evaluator under a different name or port, you must change the docker-compose environmental variable FUNCTION_EVALUATOR_URL environmental configuration value from its default which you copied from docker-compose.sample.yml. To override the evaluator location environmental variables, you should change in your docker-compose.override.yml file:

FUNCTION_EVALUATOR_URL: "http://<evaluator_container_name>:6927/1/v1/evaluate/"

You can find out the exact container names by going to your MediaWiki installation directory and running docker compose ps.

Note that if your checkout of MediaWiki is not in a directory called 'mediawiki' you will need to set both of these, and also WIKI_API_URL.

Building local versions of the services[edit]

If you would instead like to use a local version of the function orchestrator or evaluator, e.g. because you wish to make local development changes and test them, there are three steps:

  1. Ensure that you are using version 2.x or above (i.e., not 1.x) of docker-compose. (If you have 1.x, you will need to upgrade, or, if using Docker Dashboard, you may be able to select a preference for "Use Composer v2".)
  2. Install Blubber: https://wikitech.wikimedia.org/wiki/Blubber/Download#Blubber_as_a_(micro)Service
  3. Clone the service you wish to alter:
    1. (For the orchestrator): git clone --recurse-submodules --remote-submodules ssh://gerrit.wikimedia.org:29418/mediawiki/services/function-orchestrator function-orchestrator
    2. (For the evaluator): git clone --recurse-submodules --remote-submodules ssh://gerrit.wikimedia.org:29418/mediawiki/services/function-evaluator function-evaluator
  4. From the root of the service you wish to alter, run either:
    • (For the orchestrator): blubber .pipeline/blubber.yaml development | docker build -t local-orchestrator -f - .
    • (For the evaluator): blubber .pipeline/blubber.yaml development | docker build -t local-evaluator -f - .
  5. Then update your mediawiki/docker-compose.override.yml file to change the service stanza to point to your new local image, with image: local-orchestrator:latest or image: local-evaluator:latest.