admin管理员组文章数量:1221303
I've set up a devcontainer in a VSCode Ruby project, and the launch configurations don't seem to be able to override environment variables from the devcontainer. I set up the devcontainer to launch from docker compose, with one environment variable set in the .env
file, and another set in compose.yml
.
services:
active_sinatra:
restart: unless-stopped
image: donkirkby/active-sinatra-devcontainer:v0.2.2
environment:
- EXAMPLE_VALUE
- EXAMPLE_VALUE2=from-compose-file
volumes:
- .:/opt/active_sinatra
I wrote example_script.rb
to display the environment variables, plus a third that isn't set yet.
value = ENV.fetch('EXAMPLE_VALUE', 'not set')
puts "example value is #{value.inspect}."
value2 = ENV.fetch('EXAMPLE_VALUE2', 'not set')
puts "example value 2 is #{value2.inspect}."
value3 = ENV.fetch('EXAMPLE_VALUE3', 'not set')
puts "example value 3 is #{value3.inspect}."
I set up a launch configuration that overrides all three environment variables.
{
"type": "ruby_lsp",
"name": "Debug example",
"request": "launch",
"program": "ruby /opt/active_sinatra/example_script.rb",
"env": {
"EXAMPLE_VALUE": "1 from launch",
"EXAMPLE_VALUE2": "2 from launch",
"EXAMPLE_VALUE3": "3 from launch"
}
},
Unfortunately, my Ruby script only sees the third environment variable when I debug it with the launch configuration.
Ruby REPL: You can run any Ruby expression here.
Note that output to the STDOUT/ERR printed on the TERMINAL.
[experimental]
`,COMMAND` runs `COMMAND` debug command (ex: `,info`).
`,help` to list all debug commands.
DEBUGGER: Disconnected.
example value is "from-env-file".
example value 2 is "from-compose-file".
example value 3 is "3 from launch".
Is there any way to change one of the existing environment variables using the launch configuration, or do I have to change the docker compose configuration, relaunch the container, and then launch my debugger?
If you want to play around with my example code, you can see it on GitHub, then open a codespace on the docker-compose
branch.
本文标签: rubyCan VSCode override environment variablesStack Overflow
版权声明:本文标题:ruby - Can VSCode override environment variables - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739354886a2159554.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论