Question

Apps: how to copy environment data to a file

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.


Submit an answer

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!

Sign In or Sign Up to Answer

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