Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
224 views
in Technique[技术] by (71.8m points)

GCP: how to make sure that gcp project is set in Cloud Shell Editor

I am toying around a bit with GCP cloud shell editor which I start by visiting https://shell.cloud.google.com/?show=ide (which I installed as an PWA) and would like to debug a simple Flask AppEngine app. The app is using Cloud Logging. It runs fine in the terminal window when I first do:

gcloud config set project myproject

However if I want to use the builtin debugging I get errors because gcloud config set project myproject has not been set in that new window. So my question is how do I make sure that gcloud config set project myproject is run at startup of each console? I already tried running a preLaunchTask but since that is run in a separate console it does not help

Update (26 Jan 2021) Also toyed around with trying to change the .bashrc automatically when opening a project by using a task that is triggered by folderOpen and then writes the relevant gcloud command to a script which is called by .bashrcas shown below

{
    "version": "2.0.0",
    "tasks": [
      {
          "label": "Set GCP Project",
          "type": "shell",
          "command": "echo "set -x; gcloud config set project [MYPROJECT]" > $HOME/set_gcp_project",
          "runOptions": {
              "runOn": "folderOpen"
          },
          "presentation": {
              "reveal": "never",
              "panel": "shared"
          },
          "problemMatcher": []
      }
    ]
}

However Cloud Shell does not support these automated tasks. It works fine in VSCode. However it is still a nuisance because if in the GCP console I open a terminal or it opens it when you click on a run in cloud shell it sets the project to whatever project I had last opened in the Cloud Shell Editor

question from:https://stackoverflow.com/questions/65863297/gcp-how-to-make-sure-that-gcp-project-is-set-in-cloud-shell-editor

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you are interested in customizing your Cloud Shell experience you can always refer to the following section of the documentation.

I guess the must straightforward to always guarantee that the gcloud config set project myproject is always run when a new window is opened will be to append that gcloud command at the end of the .bashrc file located at your $HOME directory.

Just open the Cloud Shell (make sure you are located at the $HOME directory, which is the default directory that opens up when you open your Cloud Shell) and append the gcloud command by running the following command:


[YOUR-USERNAME]@cloudshell:~ (myproject)$ echo "gcloud config set project myproject" >> .bashrc

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...