How to upload a secret credential file to DigitalOcean App Platform
If you are using Firebase or other services that require a secret credential file, you’d face this problem of trying to fit the file into the App Platform’s Environment Variables settings that accepts only text. Here’s a workaround.
— -
First, encode your credential file with base64. You can do it in the terminal as such:
base64 -i firebase_admin_sdk_key.json -o output.txtThis will create a file called output.txt with the encoded strings of your credential file.
— -
Next, copy the encoded string into a Environment Variables field on DigitalOcean like any other text value. I’ve chosen FIREBASE_ADMIN_SDK_KEY as my key, but you can choose any name you like.
— -
Finally, we need to update our Dockerfile to recreate the secret credential file from our Environment Variable .
# inject Firebase Credentials on DigitalOcean
ARG FIREBASE_ADMIN_SDK_KEY
RUN if [ -n "${FIREBASE_ADMIN_SDK_KEY}" ]; then echo ${FIREBASE_ADMIN_SDK_KEY} | base64 --decode > /app/src/firebase_admin_sdk_key.json; fiNote that the ARG FIREBASE_ADMIN_SDK_KEY should match with the Environment Variable key name you added above.
The path /app/src/firebase_admin_sdk_key.json should also be updated to the correct path to your credential file in your app.
— -
And just like that, you are now ready to deploy to App Platforms!
If you do not have an account yet, use this referral link to get $200 free credits when you sign up!
