无法在 Compute Engine 中克隆 Google 云存储库

Can't clone Google Cloud Repository in Compute Engine

我正在尝试在 Google Compute Engine 中设置一个 Node 项目,遵循以下指南:https://cloud.google.com/nodejs/getting-started/getting-started-on-compute-engine

启动脚本一切正常,直到第 27 行:

git clone https://source.developers.google.com/p/${PROJECTID}/r/${REPOSITORY} /opt/app/new-repo

当脚本尝试克隆 repo 时,我在日志中收到一些错误:

INVALID_ARGUMENT: Request contains an invalid argument

message: "Invalid authentication credentials. Please generate a new identifier: https://source.developers.google.com/new-password"

fatal: unable to access 'https://source.developers.google.com/<path-to-repo>': The requested URL returned error: 400

此错误可能是什么原因造成的,我该如何解决?我试图研究克隆身份验证,但没有发现任何与脚本相关的内容。我访问了新密码 link,并尝试在服务器中执行 gitcookie 命令,但没有帮助。

我使用的启动脚本完全像in guide:

set -v


# Talk to the metadata server to get the project id
PROJECTID=$(curl -s "http://metadata.google.internal/computeMetadata/v1/project/project-id" -H "Metadata-Flavor: Google")
REPOSITORY="new-repo"

# Install logging monitor. The monitor will automatically pick up logs sent to
# syslog.
curl -s "https://storage.googleapis.com/signals-agents/logging/google-fluentd-install.sh" | bash
service google-fluentd restart &

# Install dependencies from apt
apt-get update
apt-get install -yq ca-certificates git build-essential supervisor

# Install nodejs
mkdir /opt/nodejs
curl https://nodejs.org/dist/v8.12.0/node-v8.12.0-linux-x64.tar.gz | tar xvzf - -C /opt/nodejs --strip-components=1
ln -s /opt/nodejs/bin/node /usr/bin/node
ln -s /opt/nodejs/bin/npm /usr/bin/npm

# 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}/r/${REPOSITORY} /opt/app/new-repo

# Install app dependencies
cd /opt/app/new-repo
npm install

# Create a nodeapp user. The application will run as this user.
useradd -m -d /home/nodeapp nodeapp
chown -R nodeapp:nodeapp /opt/app

# Configure supervisor to run the node app.
cat >/etc/supervisor/conf.d/node-app.conf << EOF
[program:nodeapp]
directory=/opt/app/new-repo
command=npm start
autostart=true
autorestart=true
user=nodeapp
environment=HOME="/home/nodeapp",USER="nodeapp",NODE_ENV="production"
stdout_logfile=syslog
stderr_logfile=syslog
EOF

supervisorctl reread
supervisorctl update

# Application should now be running under supervisor

我怀疑这个问题是由于调用者没有对存储库的权限,我建议您检查您正在使用的帐户以运行此命令具有与源存储库交互所需的权限。

如果丢失,我建议将角色 roles/source.admin 添加到您的帐户,使用 these instructions,然后尝试 运行 再次命令。