By Tim Nolte
I’ve tried looking through all of the available documentation on using the environment variables and can’t find anything about using the environment variables in the Run Command for your App/Component. I want to store some encrypted values in the environment variables and pass those in arguments with there run command after deploying an App. I am deploying a Worker, using a Docker image and my run command looks like this:
imapsync --user1 $USER1 --password1 $PASSWORD1 --user2 $USER2 --password2 $PASSWORD2 --subfolder2 $USER1 --gmail1 --gmail2
I want all of those variables to be environment variables that are passed in when run.
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!
Hello,
I have just tested this and it seems to be working.
Are you defining the scope of your environment variables as per the documentation here:
If so, you need to make sure that you’ve also defined the variables to have a RUN_TIME scope so that you could use them for your run commands:
envs:
- key: RUNTIME_ONLY_VAR
scope: RUN_TIME
value: i'm a little teapot
Or alternatively, if you need the environment variables for both the run and the build times, you could use RUN_AND_BUILD_TIME.
I tested this with the following simple deployment:
alerts:
- rule: DEPLOYMENT_FAILED
name: testapp
region: fra
services:
- environment_slug: php
envs:
- key: TEST
scope: RUN_AND_BUILD_TIME
type: SECRET
value: EV[1:jKc4tNWFtX6EE12356DESA9IkSX4W1L:tnxT09rsY+q7aDrUu7P3Z7y5J9E=]
github:
branch: main
repo: myrepo/demo
http_port: 8080
instance_count: 1
testapp: basic-xs
name: guild
routes:
- path: /
run_command: 'echo "test: ${TEST}" > test.txt ; heroku-php-apache2 public/'
source_dir: /
Best,
Bobby
This is what I ultimately ended up with creating: https://github.com/timnolte/imapsync-worker
And my App Spec looks like this:
alerts:
- rule: DEPLOYMENT_FAILED
- rule: DOMAIN_FAILED
name: imapsync-worker
region: nyc
workers:
- dockerfile_path: Dockerfile
envs:
- key: USER1
scope: RUN_TIME
value: <omitted>
- key: PASSWORD1
scope: RUN_TIME
type: SECRET
value: <omitted>
- key: USER2
scope: RUN_TIME
value: <omitted>
- key: PASSWORD2
scope: RUN_TIME
type: SECRET
value: <omitted>
- key: OPTS
scope: RUN_TIME
github:
branch: main
deploy_on_push: true
repo: timnolte/imapsync-worker
instance_count: 1
instance_size_slug: basic-xxs
log_destinations:
- logtail:
token: <omitted>
name: imapsync-worker
name: imapsync-worker
run_command: emailsync gmail2gmail
source_dir: /
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.