I want to have a custom Procfile that is only used for some environments of my application but not all of them. The point of an application is to deploy the same codebase, and I don't want to have perpetually different code branches just to maintain a different Procfile.
How do I have a Procfile be conditionally applied to some environments based on an environment variable (which I can then set differently on different environments)?
Just to give a concrete example of this, let's say I want DataDog to only be included on some of my environments but not all of them. DataDog requires a custom Procfile, where you prepend ddtrace-run
to the actual command you want to run. So I want some of my environments to be running ddtrace-run gunicorn ...
and I want others to just be running gunicorn ...
.
One solution is to make a Procfile that has a conditional bash command, such as test $ENV_VAR && command_a || command_b
. To do this in a Procfile using the DataDog example would look like this:
web: test $DD_ENABLED && ddtrace-run gunicorn --bind :8000 --workers 2 --threads 15 config.wsgi:application || gunicorn --bind :8000 --workers 2 --threads 15 config.wsgi:application
While you can create a Procfile with a container_command
, this is dangerous to do because Elastic Beanstalk will delete it on config changes: Elastic Beanstalk deleting generated files on config changes