netlify / cli

Netlify Command Line Interface
http://cli.netlify.com
MIT License
1.58k stars 358 forks source link

Environment variables not available in `onPreDev` plugin event #5612

Open eduardoboucas opened 1 year ago

eduardoboucas commented 1 year ago

Describe the bug

@biilmann has reported that he's not seeing the URL environment variable in the onPreDev event of a build plugin when running netlify dev --live. We should do a review of the environment variables we're exposing and ensure they're consistent with what's available to functions.

https://github.com/netlify/cli/pull/5607

Steps to reproduce

  1. Create a build plugin with a onPreDev that prints process.env
  2. Create a function that prints process.env
  3. Run netlify dev --live
  4. Compare the output of the two sources
biruwon commented 1 year ago

I have created a plugin following the template, and this is what I have for process.env in the onPreDev:

{
    "FORCE_COLOR": "1",
    "PIPENV_VENV_IN_PROJECT": "1",
    "NETLIFY_BUILD_BASE": "/opt/build",
    "NVM_INC": "/opt/buildhome/.nvm/versions/node/v16.20.0/include/node",
    "rvm_prefix": "/opt/buildhome",
    "LANGUAGE": "en_US:en",
    "rvm_stored_umask": "0022",
    "MY_RUBY_HOME": "/opt/buildhome/.rvm/rubies/ruby-2.7.2",
    "GIMME_NO_ENV_ALIAS": "true",
    "YARN_VERSION": "1.22.19",
    "RUBY_VERSION": "ruby-2.7.2",
    "PWD": "/opt/build/repo",
    "rvm_version": "1.29.12 (latest)",
    "rvm_user_install_flag": "1",
    "CONTEXT": "production",
    "GIMME_CGO_ENABLED": "true",
    "HOME": "/opt/buildhome",
    "LANG": "en_US.UTF-8",
    "VIRTUAL_ENV": "/opt/buildhome/python3.8",
    "DEPLOY_URL": "https://64353c4a97266a0008a1ed56--transcendent-pasca-c4bb76.netlify.app/",
    "COMMIT_REF": "95b5a06ef9015d6811d78ee502e9de6999c8e911",
    "DATADOG_HOST": "10.65.138.50",
    "HEAD": "master",
    "DEPLOY_ID": "64353c4a97266a0008a1ed56",
    "GOROOT": "/opt/buildhome/.gimme/versions/go1.19.5.linux.amd64",
    "URL": "https://transcendent-pasca-c4bb76.netlify.app/",
    "CACHED_COMMIT_REF": "95b5a06ef9015d6811d78ee502e9de6999c8e911",
    "INTEGRATION_TEST": "",
    "GIMME_TYPE": "binary",
    "NVM_DIR": "/opt/buildhome/.nvm",
    "NETLIFY": "true",
    "rvm_bin_path": "/opt/buildhome/.rvm/bin",
    "GO_VERSION": "1.19.x",
    "GEM_PATH": "/opt/buildhome/.rvm/gems/ruby-2.7.2:/opt/buildhome/.rvm/gems/ruby-2.7.2@global",
    "GIMME_ENV_PREFIX": "/opt/buildhome/.gimme/env",
    "GEM_HOME": "/opt/buildhome/.rvm/gems/ruby-2.7.2",
    "NETLIFY_IMAGES_CDN_DOMAIN": "d33wubrfki0l68.cloudfront.net",
    "CYPRESS_CACHE_FOLDER": "./node_modules/.cache/CypressBinary",
    "BRANCH": "master",
    "RVM_DIR": "/opt/buildhome/.rvm",
    "rvm_loaded_flag": "1",
    "SHLVL": "1",
    "NVM_CD_FLAGS": "",
    "BUGSNAG_KEY_BUILD_INFO": "8b2ab336661bf29d58011117d9c997d3",
    "PULL_REQUEST": "false",
    "REPOSITORY_URL": "https://github.com/biruwon/netlify-plugin-repro-env-vars",
    "NETLIFY_SUBSTAGE_TIMES": "/tmp/substage_times.txt",
    "GIMME_GO_VERSION": "1.19.x",
    "GOCACHE": "/opt/buildhome/.gimme_cache/gocache",
    "PIPENV_DEFAULT_PYTHON_VERSION": "3.8",
    "SITE_ID": "72b90d06-dd52-462a-9e8b-7cb17639ed98",
    "SWIFTENV_ROOT": "/opt/buildhome/.swiftenv",
    "DEPLOY_PRIME_URL": "https://master--transcendent-pasca-c4bb76.netlify.app/",
    "PS1": "(python3.8) ",
    "GATSBY_TELEMETRY_DISABLED": "1",
    "LC_ALL": "en_US.UTF-8",
    "SITE_NAME": "transcendent-pasca-c4bb76",
    "PIPENV_RUNTIME": "3.8",
    "PATH": "/opt/build/repo/src/node_modules/.bin:/opt/build/repo/node_modules/.bin:/opt/build/node_modules/.bin:/opt/node_modules/.bin:/node_modules/.bin:/opt/buildhome/.nvm/versions/node/v14.14.0/bin:/opt/build/repo/node_modules/.bin:/opt/buildhome/.nvm/versions/node/v14.14.0/bin:/opt/buildhome/.gimme/versions/go1.19.5.linux.amd64/bin:/opt/buildhome/.rvm/gems/ruby-2.7.2/bin:/opt/buildhome/.rvm/gems/ruby-2.7.2@global/bin:/opt/buildhome/.rvm/rubies/ruby-2.7.2/bin:/opt/buildhome/python3.8/bin:/home/linuxbrew/.linuxbrew/bin:/opt/buildhome/.swiftenv/bin:/opt/buildhome/.swiftenv/shims:/opt/buildhome/.php:/opt/buildhome/.binrc/bin:/opt/buildhome/.deno/bin:/usr/local/rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/buildhome/.cask/bin:/opt/buildhome/.gimme/bin:/opt/buildhome/.dotnet/tools:/opt/buildhome/.dotnet:/opt/buildhome/.cargo/bin:/opt/buildhome/.rvm/bin",
    "CI": "true",
    "NVM_BIN": "/opt/buildhome/.nvm/versions/node/v16.20.0/bin",
    "NEXT_TELEMETRY_DISABLED": "1",
    "NODE_VERSION": "14.14.0",
    "IRBRC": "/opt/buildhome/.rvm/rubies/ruby-2.7.2/.irbrc",
    "BUILD_ID": "64353c4a97266a0008a1ed54",
    "rvm_path": "/opt/buildhome/.rvm",
    "OLDPWD": "/opt/build/repo",
    "GOPATH": "/opt/buildhome/.gimme_cache/gopath",
    "_": "/opt/buildhome/node-deps/node"
}

vs the output when running netlify dev --live in the same function:

{
    "TERM_SESSION_ID": "w0t11p0:CEF8E2A9-75CD-4148-A2A4-407DC3D76D8D",
    "SSH_AUTH_SOCK": "/private/tmp/com.apple.launchd.TOJ22j0vbN/Listeners",
    "LC_TERMINAL_VERSION": "3.4.16",
    "COLORFGBG": "7;0",
    "ITERM_PROFILE": "Default",
    "SQLITE_EXEMPT_PATH_FROM_VNODE_GUARDS": "/Users/antoniojesus/Library/WebKit/Databases",
    "XPC_FLAGS": "0x0",
    "PWD": "/Users/antoniojesus/projects/compute/netlify-plugin-repro-env-vars",
    "SHELL": "/bin/zsh",
    "__CFBundleIdentifier": "com.googlecode.iterm2",
    "SECURITYSESSIONID": "186b3",
    "LC_CTYPE": "UTF-8",
    "TERM_PROGRAM_VERSION": "3.4.16",
    "TERM_PROGRAM": "iTerm.app",
    "PATH": "/Users/antoniojesus/.rvm/gems/ruby-3.0.4/bin:/Users/antoniojesus/.rvm/gems/ruby-3.0.4@global/bin:/Users/antoniojesus/.rvm/rubies/ruby-3.0.4/bin:/usr/local/opt/mysql-client/bin:/opt/homebrew/opt/openssl@3/bin:/Users/antoniojesus/Downloads/google-cloud-sdk/bin:/opt/homebrew/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Users/antoniojesus/.rvm/bin:/usr/local/go/bin",
    "LC_TERMINAL": "iTerm2",
    "COLORTERM": "truecolor",
    "COMMAND_MODE": "unix2003",
    "TERM": "xterm-256color",
    "HOME": "/Users/antoniojesus",
    "TMPDIR": "/var/folders/ch/fp_2xspn7cs_8tj65y9m80jw0000gn/T/",
    "USER": "antoniojesus",
    "XPC_SERVICE_NAME": "0",
    "LOGNAME": "antoniojesus",
    "LaunchInstanceID": "5D584670-87B4-406C-8237-398511DEA11D",
    "__CF_USER_TEXT_ENCODING": "0x1F5:0x0:0x0",
    "ITERM_SESSION_ID": "w0t11p0:CEF8E2A9-75CD-4148-A2A4-407DC3D76D8D",
    "SHLVL": "1",
    "OLDPWD": "/Users/antoniojesus/projects/compute/netlify-plugin-repro-env-vars",
    "rvm_prefix": "/Users/antoniojesus",
    "rvm_path": "/Users/antoniojesus/.rvm",
    "rvm_bin_path": "/Users/antoniojesus/.rvm/bin",
    "rvm_version": "1.29.12 (latest)",
    "GEM_HOME": "/Users/antoniojesus/.rvm/gems/ruby-3.0.4",
    "GEM_PATH": "/Users/antoniojesus/.rvm/gems/ruby-3.0.4:/Users/antoniojesus/.rvm/gems/ruby-3.0.4@global",
    "MY_RUBY_HOME": "/Users/antoniojesus/.rvm/rubies/ruby-3.0.4",
    "IRBRC": "/Users/antoniojesus/.rvm/rubies/ruby-3.0.4/.irbrc",
    "RUBY_VERSION": "ruby-3.0.4",
    "_": "/usr/local/bin/netlify",
    "SITE_ID": "72b90d06-dd52-462a-9e8b-7cb17639ed98",
    "SITE_NAME": "transcendent-pasca-c4bb76",
    "DEPLOY_ID": "0",
    "BUILD_ID": "0",
    "URL": "https://transcendent-pasca-c4bb76-c4749c.netlify.live",
    "REPOSITORY_URL": "https://github.com/biruwon/netlify-plugin-repro-env-vars",
    "DEPLOY_PRIME_URL": "https://master--transcendent-pasca-c4bb76.netlify.app",
    "DEPLOY_URL": "https://transcendent-pasca-c4bb76-c4749c.netlify.live",
    "CONTEXT": "dev",
    "NETLIFY_LOCAL": "true",
    "BRANCH": "master",
    "HEAD": "master",
    "COMMIT_REF": "95b5a06ef9015d6811d78ee502e9de6999c8e911",
    "CACHED_COMMIT_REF": "89b67a40814baa9cc0cd795e56831441354834d0",
    "PULL_REQUEST": "false",
    "LANG": "en_US.UTF-8",
    "LANGUAGE": "en_US:en",
    "LC_ALL": "en_US.UTF-8",
    "GATSBY_TELEMETRY_DISABLED": "1",
    "NEXT_TELEMETRY_DISABLED": "1",
    "NODE_VERSION": "14.14.0",
    "NETLIFY_DEV": "true",
    "BASE_URL": "https://transcendent-pasca-c4bb76-c4749c.netlify.live",
    "AWS_LAMBDA_FUNCTION_NAME": "handler",
    "AWS_LAMBDA_FUNCTION_MEMORY_SIZE": "176",
    "AWS_LAMBDA_FUNCTION_VERSION": "1.0",
    "AWS_EXECUTION_ENV": "AWS_Lambda_nodejs16.14.2",
    "LAMBDA_CONSOLE_SOCKET": "14",
    "LAMBDA_CONTROL_SOCKET": "11",
    "LAMBDA_RUNTIME_DIR": "/Users/antoniojesus/projects/compute/netlify-plugin-repro-env-vars",
    "NODE_PATH": "/Users/antoniojesus/projects/compute/netlify-plugin-repro-env-vars/node_modules",
    "TZ": "Europe/Madrid",
    "LAMBDA_TASK_ROOT": "/Users/antoniojesus/projects/compute/netlify-plugin-repro-env-vars/.netlify/functions-serve/hello-world",
    "_HANDLER": "hello-world.handler",
    "AWS_REGION": "us-east-1",
    "AWS_DEFAULT_REGION": "us-east-1"
}

I see in the original issue the problem was the URL? I can see it in both, but with a slightly difference, the live deploy it's adding another hash to it

biruwon commented 1 year ago

@eduardoboucas is this still a problem? As I see the related PR merged

sarahetter commented 1 year ago

@eduardoboucas bump on the above :)