(core) add python2 to gvisor Dockerfile, for use in making comparisons

Summary:
This adds python2 to the gvisor sandbox image.  It can be used instead
of the default python3 by setting PYTHON_VERSION to 2 (or calling run.py with python2).
This is useful for making side-by-side comparisons with code running python3.

Test Plan: manual

Reviewers: alexmojaki

Reviewed By: alexmojaki

Differential Revision: https://phab.getgrist.com/D2957
This commit is contained in:
Paul Fitzpatrick 2021-08-03 17:21:11 -04:00
parent 521bbd9ac1
commit 750c78763e

View File

@ -350,7 +350,7 @@ const spawners = {
* flavor of sandbox (which at the time of writing differs between hosted grist and
* grist-core), and trying to regularize creation options a bit.
*
* The flavor of sandbox to use can be overridden by two environment variables:
* The flavor of sandbox to use can be overridden by some environment variables:
* - GRIST_SANDBOX_FLAVOR: should be one of the spawners (pynbox, unsandboxed, docker,
* gvisor)
* - GRIST_SANDBOX: a program or image name to run as the sandbox. Not needed for
@ -361,6 +361,8 @@ const spawners = {
* to `sandbox/gvisor/run.py` (if runsc available locally) or to
* `sandbox/gvisor/wrap_in_docker.sh` (if runsc should be run using the docker
* image built in that directory). Gvisor is not yet available in grist-core.
* - PYTHON_VERSION: for gvisor, this is mandatory, and must be set to "2" or "3".
* It is ignored by other flavors.
*/
export class NSandboxCreator implements ISandboxCreator {
private _flavor: keyof typeof spawners;
@ -540,7 +542,11 @@ function gvisor(options: ISandboxOptions): ChildProcess {
if (options.deterministicMode) {
wrapperArgs.push('--faketime', FAKETIME);
}
return spawn(command, [...wrapperArgs.get(), 'python', '--', ...pythonArgs]);
const pythonVersion = process.env.PYTHON_VERSION;
if (pythonVersion !== '2' && pythonVersion !== '3') {
throw new Error("PYTHON_VERSION must be set to 2 or 3");
}
return spawn(command, [...wrapperArgs.get(), `python${pythonVersion}`, '--', ...pythonArgs]);
}
/**