GoogleCloudPlatform / berglas

A tool for managing secrets on Google Cloud
https://cloud.google.com/secret-manager
Apache License 2.0
1.24k stars 96 forks source link

Running locally #57

Closed gad2103 closed 5 years ago

gad2103 commented 5 years ago

hello! thanks for this library. I'm trying to speed up my development cycles and obviously its slow to rebuild/re-deploy to make sure everything works.

i was hoping to run locally before deploying to Cloud Run. However i get this error when i try

  1. running locally with golang
  2. running locally with docker + env variables
2019/08/30 20:48:52 failed to detect environment: unknown runtime
panic: failed to detect environment: unknown runtime

goroutine 1 [running]:
github.com/GoogleCloudPlatform/berglas/pkg/auto.handleError(...)
    /src/vendor/github.com/GoogleCloudPlatform/berglas/pkg/auto/importer.go:108
github.com/GoogleCloudPlatform/berglas/pkg/auto.init.0()
    /src/vendor/github.com/GoogleCloudPlatform/berglas/pkg/auto/importer.go:44 +0x64e

its the same error whether i run using a container or locally and it's the auto package. If i comment that import out everything works locally (sort of).

there isn't any documentation about local run vs deployed run. would be awesome to have that. for now i'm going to just do the wrong thing with env vars in a cloud function...

i am running on macOS with docker for Mac and go 1.12 otherwise. thanks again!

sethvargo commented 5 years ago

To run locally, edit your entrypoint to pass --local and don't use auto detection. You can't fake being on GCE locally 😄

wieringen commented 5 years ago

We solved this in our project by ditching the auto importer and loading all env vars we need in a struct. After that we loop through them and resolve every value using something like the code below. Seems to be working well on every env (locally, gke and cloud functions)

import (
    "context"

    "github.com/GoogleCloudPlatform/berglas/pkg/berglas"
)

func berglasParser(ctx context.Context, v string) (string, error) {
    if berglas.IsReference(v) {
        s, err := berglas.Resolve(ctx, v)
        return string(s), err
    }
    return v, nil
}
sethvargo commented 5 years ago

Yea - that's a good approach. The "auto" is supposed to be magic, but that does make it difficult to test.