I am writing a program that speaks with Cloud Spanner in Postgres Dialect. My application is a gin server and I am using pgadapter to connect as mentioned in this doc.
My application runs fine locally. But when I deploy it to cloud run, I get the following log.
The error basically comes from the StartPGAdapterWithCredentials
function.
func StartPGAdapter(ctx context.Context, project, instance string) (port int, cleanup func(), err error) {
credentials, err := google.FindDefaultCredentials(ctx)
fmt.Println("credentials " + (credentials.ProjectID) + "json " + utils.ToString(credentials.JSON) + "ts " + utils.ToString(credentials.TokenSource))
if err != nil {
return 0, func() {}, err
}
return StartPGAdapterWithCredentials(ctx, project, instance, credentials)
}
func StartPGAdapterWithCredentials(ctx context.Context, project, instance string, credentials *google.Credentials) (port int, cleanup func(), err error) {
if credentials == nil {
return 0, func() {}, fmt.Errorf("credentials cannot be nil")
}
if credentials.JSON == nil || len(credentials.JSON) == 0 {
return 0, func() {}, fmt.Errorf("only JSON based credentials are supported")
}
credentialsFile, err := os.CreateTemp(os.TempDir(), "pgadapter-credentials")
if err != nil {
return 0, func() {}, err
}
On my local system, GOOGLE_APPLICATION_CREDENTIALS
is set and hence it is able to get the credentials. However, this is not working in cloud run.
How do I get it to run in cloud run?
Additional Info : followed the example present here.