Page MenuHomePhabricator

Support bringing text files into the container for one-off maintenance scripts
Closed, ResolvedPublic

Description

Is it possible to include a text file from disk in the container where a script runs in? Some scripts (like extensions/CentralAuth/maintenance/attachAccount.php) use those for lists of things to process.

We should be able to pull text files from the deployment host (where mwscript-k8s is executed) into a ConfigMap-provided Volume to make them available to the maintenance script.

As a workaround in the meantime for new and updated scripts, instead of reading from a file in the container, read from stdin and use mwscript-k8s --attach to pipe in the contents of the file on the deployment host.

To use scripts like attachAccount.php that take a filename on the command line, without modifying the code, passing --userlist php://stdin should work (not tested).

Event Timeline

To use scripts like attachAccount.php that take a filename on the command line, without modifying the code, passing --userlist php://stdin should work (not tested).

I tested it, and I can't get it to work:

[urbanecm@deploy2002 ~]$ cat > users.txt
MediaWiki message delivery
[urbanecm@deploy2002 ~]$ mwscript-k8s --attach extensions/CentralAuth/maintenance/attachAccount.php -- --wiki=zhwiki --userlist=php://stdin < users.txt 
⏳ Starting extensions/CentralAuth/maintenance/attachAccount.php on Kubernetes as job mw-script.codfw.88buxkba ...
⏳ Waiting for the container to start...
🚀 Job is running.
📜 Attached to stdin/stdout:
error: unable to upgrade connection: container mediawiki-88buxkba-app not found in pod mw-script.codfw.88buxkba-h8lh8_mw-script
☠️ Command failed with status 1: /usr/bin/kubectl attach --quiet job/mw-script.codfw.88buxkba --container mediawiki-88buxkba-app -i
For logs (may not work) run:
K8S_CLUSTER=codfw KUBECONFIG=/etc/kubernetes/mw-script-deploy-codfw.config kubectl logs -f job/mw-script.codfw.88buxkba mediawiki-88buxkba-app
[urbanecm@deploy2002 ~]$ K8S_CLUSTER=codfw KUBECONFIG=/etc/kubernetes/mw-script-deploy-codfw.config kubectl logs -f job/mw-script.codfw.88buxkba mediawiki-88buxkba-app
ERROR - File not found: php://stdin
[urbanecm@deploy2002 ~]$

Reading from stdin doesn't seem to work in the old way either.

So for now, this kind of operation seems to be only possible in the old system.

Ha, attachAccount.php specifically blocks this from working:

if ( !is_file( $list ) ) {
	$this->fatalError( "ERROR - File not found: {$list}" );
}

So, this specific script will need modification, but only to adjust that check (since is_file insists on a regular file and no other kind of stream). The subsequent fopen and fgets calls ought to work fine with php://stdin.

Change #1085506 had a related patch set uploaded (by RLazarus; author: RLazarus):

[operations/deployment-charts@master] mediawiki: Support copying text files into mw-script containers

https://gerrit.wikimedia.org/r/1085506

Change #1085507 had a related patch set uploaded (by RLazarus; author: RLazarus):

[operations/puppet@production] deployment_server: Add --file to mwscript-k8s

https://gerrit.wikimedia.org/r/1085507

Change #1085506 merged by RLazarus:

[operations/deployment-charts@master] mediawiki: Support copying text files into mw-script containers

https://gerrit.wikimedia.org/r/1085506

Change #1085507 merged by RLazarus:

[operations/puppet@production] deployment_server: Add --file to mwscript-k8s

https://gerrit.wikimedia.org/r/1085507

This is now supported, and documented at https://wikitech.wikimedia.org/wiki/Maintenance_scripts#Input_from_a_file.

@Urbanecm_WMF If you get a chance to try it out, let me know how it works for you.

Seems to work perfectly now, thanks!

[urbanecm@deploy2002 ~]$ cat > users.txt
MediaWiki message delivery
[urbanecm@deploy2002 ~]$ mwscript-k8s --file users.txt -f extensions/CentralAuth/maintenance/attachAccount.php -- --wiki=cswiki --userlist users.txt 
⏳ Starting extensions/CentralAuth/maintenance/attachAccount.php on Kubernetes as job mw-script.codfw.w1hr2123 ...
⏳ Waiting for the container to start...
🚀 Job is running.
📜 Streaming logs:
CentralAuth account attach for: MediaWiki message delivery
ATTACHING: MediaWiki message delivery@cswiki
[2024-11-27 18:13:34] processed: 1 (5.7/sec); ok: 0 (0.0%); attached: 1 (100.0%); partial: 0 (0.0%); failed: 0 (0.0%); missing: 0 (0.0%);
done.
[urbanecm@deploy2002 ~]$