linux - 我的计算引擎 VM 没有从我的存储库中获取更改

标签 linux git shell google-compute-engine google-cloud-source-repos

我有一个计算引擎实例,它的启动脚本包括以下几行。

# Get the application source code from the Google Cloud Repository.
# git requires $HOME and it's not set during the startup script.
export HOME=/root
git config --global credential.helper gcloud.sh
git clone https://source.developers.google.com/p/$PROJECTID /opt/app

此代码告诉 VM 从云存储库获取源代码,即我的应用程序代码。每当我修改我的源代码并将更改推送到存储库并重新启动我的虚拟机时,虚拟机都不会执行新代码。如何在不删除实例和创建新实例的情况下让虚拟机运行新代码?

最佳答案

GCE VM 启动脚本在每次 启动时运行,而不仅仅是第一次启动,因此您应该只在第一次克隆 repo,然后每隔一次更新一次,例如,

# Note: this script is untested but should work.

export HOME=/root
git config --global credential.helper gcloud.sh

declare -r LOCAL_GIT_REPO="/opt/app"
if ! [[ -e "${LOCAL_GIT_REPO}" ]]; then
  git clone https://source.developers.google.com/p/$PROJECTID "${LOCAL_GIT_REPO}"
else
  cd "${LOCAL_GIT_REPO}"
  git pull
fi

然后,您可以随时手动重新运行此脚本以在您的实例运行时更新您的存储库。如果您想让实例自动更新自己的代码,请从 cron 调用此脚本。您可以通过 man cronman crontab 了解如何设置定期命令运行.

关于linux - 我的计算引擎 VM 没有从我的存储库中获取更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32908055/

相关文章:

php - 使用特定版本的 PHP 进行 xDebug

linux - awk 在单列上完全连接 2 个文件

android - 如何使用 Google Services Gradle 插件在 Circle CI 上测试 android 应用程序

git - Visual Studio Code 无法检测到已安装的 git

git - 当我将 mercurial 导出到 git 时,为什么结果这么大?

java - 如何将shell脚本输出重定向到java控制台

python - 如何使用 python 进行 shell 导航

linux - 这里的字符串是否进行分词?

Python:获取 shell 命令的输出 'history'

linux - 如何在包debuild中包含一个目录