Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blueprint accepting OS-level environment variable #2011

Open
zaerl opened this issue Nov 21, 2024 · 3 comments
Open

Blueprint accepting OS-level environment variable #2011

zaerl opened this issue Nov 21, 2024 · 3 comments

Comments

@zaerl
Copy link
Collaborator

zaerl commented Nov 21, 2024

This blueprint:

{
  "login": true,
  "steps": [
    {
      "step": "runPHP",
      "code": "<?php require_once 'wordpress/wp-load.php'; wp_insert_post( [ 'post_title' => 'env', 'post_content' => print_r( $_ENV, true ) ] );"
    }
  ]
}

Generates a post with this content:

Array
(
  [USER] => web_user
  [LOGNAME] => web_user
  [PATH] => /
  [PWD] => /
  [HOME] => /home/web_user
  [LANG] => C.UTF-8
  [_] => cli.ts
  [USE_ZEND_ALLOC] => 0
)

It can be a useful addition for blueprints started using the CLI in this way:

TEST="test" bun cli.ts server --blueprint=./test.json

To inherit the TEST environment var. This is a quite advanced option so it should be available only to PHPRunOptions. The env record should be open to be overwritten by the caller. Such as:

```json
{
  "login": true,
  "steps": [
    {
      "step": "runPHPWithOptions",
      "options": {
        "env": {
          "TEST": "false"
        },
        "code": "<?php require_once 'wordpress/wp-load.php'; wp_insert_post( [ 'post_title' => 'env', 'post_content' => print_r( $_ENV, true ) ] );"
      }
    }
  ]
}

So that it will be possible to write this for rapid prototyping:

TEST="true" bun cli.ts server --blueprint=./test.json

The CLI should have a list of env vars to exclude, such as other security measures.

Addendum: Apparently, $_ENV does not have the values passed if used in the code entry. This may be a bug.

@adamziel adamziel transferred this issue from WordPress/blueprints-library Nov 21, 2024
@adamziel adamziel closed this as not planned Won't fix, can't repro, duplicate, stale Dec 18, 2024
@github-project-automation github-project-automation bot moved this from Inbox to Done in Playground Board Dec 18, 2024
@adamziel adamziel reopened this Dec 18, 2024
@github-project-automation github-project-automation bot moved this from Done to Inbox in Playground Board Dec 18, 2024
@adamziel
Copy link
Collaborator

adamziel commented Dec 18, 2024

$ENV being empty does sound like a bug. getenv() works, though:

{
  "steps": [
    {
      "step": "runPHPWithOptions",
      "options": {
        "code": "<?php file_put_contents('/wordpress/index.php', getenv('IS_PRODUCTION')); ?>",
        "env": {
          "IS_PRODUCTION": "yes"
        }
      }
    }
  ]
}

It would indeed be nice if the CLI had an option to accept the OS-level env variables, or if there was something in Blueprints to define env variables for the entire Playground server. I'm hesitant of just loading all the env variables by default as that would breach the OS isolation we're getting from WASM AND some variables might actually introduce problems, e.g. $PATH or $HOME won't match any WASM filesystem paths.

@adamziel
Copy link
Collaborator

Out of curiosity – how would you use this?

@zaerl
Copy link
Collaborator Author

zaerl commented Dec 18, 2024

Out of curiosity – how would you use this?

For quick tests like this:

{
  "steps": [
    {
      "step": "runPHPWithOptions",
      "options": {
        "code": "<?php do_something( getenv( 'VALUE_TO_TEST' ) );",
        "env": {
          "VALUE_TO_TEST": "The default value"
        }
      }
    }
  ]
}

VALUE_TO_TEST="Another value" bun cli.ts server --blueprint=./test.json. So, you can force an environment variable without rewriting the blueprint if you want to check what happens.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants