英文:
Are exported environment variables set in .profile.d scripts persistent in cloudfoundry container?
问题
我是在开发自定义构建包方面相当新手。我想设置一些容器级别的环境变量。我在/bin/supply
目录下创建的脚本中添加了导出命令。
# 设置默认值
mkdir -p "${BUILD_PATH}/.profile.d/"
cat > "${BUILD_PATH}/.profile.d/defaults.sh" <<SH
export TEST_VARIABLE="hello"
SH
我了解到添加到.profile.d
的脚本将在构建包启动期间被调用。我的容器按预期启动。我通过SSH连接到容器并验证了脚本位于/app/.profile.d/
中。我还可以在应用程序启动日志中看到引用了该变量。但是当我尝试在容器内部echo该变量时,它为空。
我知道我可以使用cf set-env
来设置这个变量,但我只是想知道在构建包中是否可能实现这一点。
英文:
I am quite new in developing a custom buildpack. I want to set some container level environment variables. I added the export commands in a created script under /bin/supply
.
# setup defaults
mkdir -p "${BUILD_PATH}/.profile.d/"
cat > "${BUILD_PATH}/.profile.d/defaults.sh" <<SH
export TEST_VARIABLE="hello"
SH
I read that the scripts added to .profile.d
will be sourced during buildpack launch. My container starts as expected. I ssh to the container and verified that the script was inside /app/.profile.d/
. I can also see in app start logs that the variable was referenced. But when I tried to echo the variable inside the container, it was empty.
I know that I can setup the variable using cf set-env
but I just want to know if it is possible in buildpack.
答案1
得分: 1
以下是要翻译的内容:
"Believe it or not, things are working. Your buildpack is writing to the correct location, and the environment variable is being set for your application.
The issue is with cf ssh
. When you cf ssh
into an application it does not source the .profile.d/
scripts. Those are only sourced before the application starts.
The reason for this is that the system cannot know what is in those scripts, and it is possible that sourcing them when you cf ssh
into the container could be harmful or cause side effects. Most of the time, that's not the case, and those scripts just set up the environment.
As such, if you want to enter the container and have the environment setup for you then you can run cf ssh <app> -t -c "/tmp/lifecycle/launcher /home/vcap/app bash ‘’”
. This will execute the launcher, which will source all those files.
Alternatively, you can cf ssh
like normal and then specifically source
the .profile.d
scripts you require."
英文:
Believe it or not, things are working. Your buildpack is writing to the correct location, and the environment variable is being set for your application.
The issue is with cf ssh
. When you cf ssh
into an application it does not source the .profile.d/
scripts. Those are only sourced before the application starts.
The reason for this is that the system cannot know what is in those scripts, and it is possible that sourcing them when you cf ssh
into the container could be harmful or cause side effects. Most of the time, that's not the case, and those scripts just set up the environment.
As such, if you want to enter the container and have the environment setup for you then you can run cf ssh <app> -t -c "/tmp/lifecycle/launcher /home/vcap/app bash ‘’”
. This will execute the launcher, which will source all those files.
Alternatively, you can cf ssh
like normal and then specifically source
the .profile.d
scripts you require.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论