Google Cloud: How to deploy mirrored Repository

2020-01-27 07:46发布

I am trying to deploy a node app, which is in a repository in GitHub, and mirrored by the Google App Engine.

The steps I took:

  1. Create the app on my local machine

  2. Published the Repository on Github

  3. In the Google Console, I told App Engine to mirror this Repository, which works: If I go to Development, the repository shows up:

enter image description here

  1. Then I open the remote shell Google is providing, and tried to run gcloud app deploy, which gave an error, then I noticed the files are not in the directory. So I browsed through all the folders of this machine via the shell, and I can't find it.

Question: What am I missing here? Does Google mirroring my Repo not imply it is somewhere saved on the instance? Do I need to clone it to there as well?

1条回答
何必那么认真
2楼-- · 2020-01-27 08:13

I'm using as reference the solution pointed to by this answer: https://stackoverflow.com/a/40693455/4495081.

In the web-cached article all the ops are done inside the cloud shell, basically a local repo exists in your cloud shell "homedir". From there it is saved/uploaded to the cloud source repository:

Save your source code in Cloud Source Repositories

  1. Switch to the tab with the open shell pane and go to your app’s directory:

    cd helloworldapp
    
  2. Initialize git and your repo. The first two steps aren't necessary if you've done them before:

    git config --global user.email "you@example.com" 
    git config --global user.name "Your Name" 
    git init 
    git add . -A
    git commit -m "Initial commit"
    
  3. Authorize Git to access GCP:

    git config credential.helper gcloud.sh
    
  4. Add the repository as a remote named ‘google’ to your local Git repository, first replacing [PROJECT_ID] with the name of your Cloud project:

    git remote add google /web/20161119132814/https://source.developers.google.com/p/[PROJECT_ID]/r/default
    
    git push google master
    

In your case you went in the other direction: you created your cloud source repository and linked it to your github one using the Developer Console, but no repo exists in your cloud shell homedir.

All you need to do is to clone your cloud source repository into your cloud shell homedir, which I think can be done in the cloud shell, following the custom steps indicated in the Clone your Cloud Repository to a local Git repository section of the Source Code page, then deploy from there. Something along these lines:

gcloud init
gcloud source repos clone repo_name --project=proj_name
cd repo_name
gcloud app deploy ...
查看更多
登录 后发表回答