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
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.
2. Add the encoded Base64 as a secret variable
GCP_SA_KEY="aGkga295ZWI="
We're saving it as this variable for later use.
4. Add plain text env variable
GOOGLE_APPLICATION_CREDENTIALS="./gcloud-key.json"
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
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.
Top comments (0)