缺少Git钩子环境变量
我正在为Digital Ocean上的node应用程序创建一个自定义构建系统,其中涉及git钩子来安装依赖项并启动应用程序。应用程序配置的一部分从环境变量读取敏感数据(无法签入repo)。在我的git钩子中,我使用外部脚本停止应用程序,将repo文件(从缺少Git钩子环境变量,git,bash,digital-ocean,githooks,pm2,Git,Bash,Digital Ocean,Githooks,Pm2,我正在为Digital Ocean上的node应用程序创建一个自定义构建系统,其中涉及git钩子来安装依赖项并启动应用程序。应用程序配置的一部分从环境变量读取敏感数据(无法签入repo)。在我的git钩子中,我使用外部脚本停止应用程序,将repo文件(从SOURCE\u repo复制到SOURCE\u DIR(应该更好地命名变量)并重新启动应用程序: # hooks/post-receive # go to the www repo and stop the app cd $SOURCE_DIR
SOURCE\u repo
复制到SOURCE\u DIR
(应该更好地命名变量)并重新启动应用程序:
# hooks/post-receive
# go to the www repo and stop the app
cd $SOURCE_DIR
if [ -f tools/staging-stop.sh ]; then
echo "Stopping the staging app..."
tools/staging-stop.sh
fi
cd $SOURCE_REPO
git --work-tree=${SOURCE_DIR} checkout --force
cd $SOURCE_DIR
if [ -f tools/staging-start.sh ]; then
echo "Starting the staging app..."
tools/staging-start.sh
fi
# tools/staging-stop.sh
node_modules/.bin/pm2 stop staging
# updates env vars
node_modules/.bin/pm2 delete staging
# tools/stating-start.sh
source /etc/profile.d/my_env_vars.sh
yarn install --production=true
NODE_ENV=staging node_modules/.bin/pm2 start build/index.js --name staging
但是,由于一个原因,我无法精确指出/etc/profile.d/my_env_vars.sh
中的环境变量(我认为这些变量应该在没有来源的情况下可用)在git钩子启动应用程序时不存在。但是,如果我ssh
进入服务器并使用pm2手动启动应用程序,则环境变量可用,因此我猜这与git钩子本身及其启动的shell类型有关
我非常感谢你在这方面的帮助