Report this

What is the reason for this report?

Apps: how to copy environment data to a file

Posted on December 29, 2021

Our Go application, previously built as a docker repo, uses NATS and requires a credentials file to load. Their libraries do no support anything else (as far as I can tell.)

I can set the credential file’s contents in an encrypted environment variable, but I have been unable to copy it into place using the “Run Command” configuration option. Setting the command to the following for example just gives back [] during deployment in the logs, which I’m assuming is some kind of security mechanism:

sh -c 'echo $NATS_CREDS_FILE > /app/config/nats.creds'
./app serve

Is there any other way to achieve this? Thanks.



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hey there!

I assume you are building this as a Dockerfile build. If not please let me know.

Environment variables are only available as build-args for Dockerfile builds in App Platform. So you should declare them in the Dockerfile as an ARG and then set the ENV variable in the Dockerfile from the build-arg.

Something like this may work:

ARG TEST_VARIABLE
ENV NATS_CREDS_FILE=${TEST_VARIABLE}

TEST_VARIABLE would be the encrypted variable you set in the UI. You could then set the value to a file the same as you have it in your run command.

Hope it helps! Nate

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.