DEV Community

Cover image for Deploying Google Cloud Platform Credentials to Koyeb
Kyle Welsby
Kyle Welsby

Posted on

Deploying Google Cloud Platform Credentials to Koyeb

Let's say you have an administration application you're deploying to Koyeb and you store assets on Google Cloud Storage.
You're going to need to get GOOGLE_APPLICATION_CREDENTIALS to your deployment somehow while keeping your credentials, secret.

Here is a quick guide to that I hope helps you get your awesome application interfacing with Google Cloud Platform in no time.

Assuming you've already gotten a JSON file containing your credentials the following steps make use of Base64 encoding and decoding to store and transfer the contents of the credentials.

1. Encode your key to Base64

base64 --input gcloud-key.json
Enter fullscreen mode Exit fullscreen mode

You'll have the contents of the file encoded as a Base64 string. You can now add this to your Koyeb environment variables as a secret value.

Koyeb Settings

2. Add the encoded Base64 as a secret variable

GCP_SA_KEY="aGkga295ZWI="
Enter fullscreen mode Exit fullscreen mode

We're saving it as this variable for later use.

4. Add plain text env variable

GOOGLE_APPLICATION_CREDENTIALS="./gcloud-key.json"
Enter fullscreen mode Exit fullscreen mode

While we're in the the environment variable settings, we'll need to add a plain text variable to tell our application what file to look for that contains the Google Application Credentials.

3. Update your build command

echo -n $GCP_SA_KEY | base64 --decode > gcloud-key.json | yarn build
Enter fullscreen mode Exit fullscreen mode

We'll update the build command to echo the base64 string and pipe the string to the base64 command to be decoded and written to the file gcloud-key.json.

Then we'll run our normal build command yarn build.

Thats it, the next time your application builds the Google Application Credentials will be available to your application and you can happily interface with your Google Cloud Platform account.

Hope this helped, happy hacking.

Latest comments (0)