Old question but in case it can help others, I wanted to do pretty much the same thing and automate it, so as a quick way to do it I came up with a simple shell script.
The idea was to have a Dockerrun.aws.json template file that would hold a dynamic ENV property, then depending on the desired environment, the script would use this template and generate the appropriate Dockerrun.aws.json file.
Example:
Create a shell script with the following content:
#!/bin/bash
# current script directory path
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# $1 will be the environement name passed to the script : it can only be dev or prod
# if empty, we ask for user input for convenience
if [ "$1" == "" ]; then
echo -n "Enter your the environment (either 'dev' or 'prod') and press [ENTER]:"
read ENV
else
ENV=$1
fi
# check if environment name is valid
if [ "$ENV" == "dev" ] || [ "$ENV" == "prod" ] ; then
# move to shell script directory
cd $DIR
# generate Dockerfile from template by replacing the ENV property by the input
echo "Generating Dockerrun.aws.json..."
sed -e "s/\${ENV}/$ENV/g" Dockerrun.aws.json.template > Dockerrun.aws.json
# do other things here if necessary
else
echo "$ENV is not a valid environment name, accepted values : env & prod"
exit 0
fi
Then create your Dockerrun.aws.json.template file:
{
"AWSEBDockerrunVersion": 2,
"containerDefinitions": [
{
"name": "php-app",
"image": "phpfpm-image-${ENV}",
#...
},
{
"name": "nginx-proxy",
"image": "nginx-image-${ENV}",
#...
}
]
}
Now, just put the shell script where your Dockerrun.aws.jon.template file resides, and run it like so:
sh yourscript.sh dev
It will generate a valid file for you to use for the given environment.
This is a simple example that gives you a basic idea of what do to, then you can build something much more complex from it. I personally use it to pick all the right config files (.ebextensions, etc.) and then zip the whole thing to upload on beanstalk.