GoogleCloudPlatform / appengine-ruby

Optional integration library for the Ruby runtime for Google App Engine
Apache License 2.0
53 stars 21 forks source link

Specify project via environment variable #22

Open RSpace opened 5 years ago

RSpace commented 5 years ago

I deploy into multiple GCloud projects, and would like to be able to specify the project id via an environment variable when calling rake appengine:exec, similar to how ie. GAE_SERVICE can be specified.

As far as I can see from the source code, this is not currently possible?

will3216 commented 5 years ago

Yeah, I am running into the same issue. I've found an ugly way to get around it I am SSH'ing to an active instance/container and running within the docker container:

  1. SSH to the server running your container:
    gcloud --project $PROJECT_NAME app instances ssh $(gcloud app instances list --service=$SERVICE_NAME --filter=VM_STATUS:RUNNING --format=json | jq -r '.[0].id') --version $(gcloud app instances list --service=$SERVICE_NAME --filter=VM_STATUS:RUNNING --format=json | jq -r '.[0].version') --service=$SERVICE_NAME
  2. Run your command against the container:
    docker exec -it gaeapp /bin/bash -c "$YOUR_CMD"
    # Examle
    docker exec -it gaeapp /bin/bash -c "bundle exec rake db:migrate"
    # Or, just shell into the container to run whatever you'd like within the environment:
    docker exec -it gaeapp /bin/bash

    Note, if you get an unknown container error using gaeapp in the second step, run sudo docker ps find the name of the correct container and replace gaeapp in the previous command.

Based on: https://gist.github.com/kyptin/e5da270a54abafac2fbfcd9b52cafb61

Alternatively: You can just swap what project you are configured, but this seems like a good way to make a mistake lol

gcloud config set project $TARGET_PROJECT_NAME
bundle exec rake appengine:exec[...]
dazuma commented 5 years ago

Version 0.5 (coming within a week or so) will include the ability to set GAE_PROJECT.