Separate Dockerrun.aws.json files for staging and production
Asked Answered
P

2

12

What is the best way to handle deployment to staging and production for the Dockerrun.aws.json file? Is there a way to pass variables to the image value, etc or have multiple Dockerrun.aws.json files one for each environment? Currently my staging env gets the image tagged as staging and production gets the images tagged as production but I need the Dockerrun.aws.json different for each env? I either want to do something like:

"image": "${IMAGE}",

where IMAGE is defined in the configs for each environment or separate each file out. So I can setup each container differently based on staging or production.

Philomel answered 3/5, 2018 at 19:10 Comment(1)
Could you find a way?Allistir
E
5

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.

Effort answered 12/1, 2020 at 22:23 Comment(0)
V
0

One way could be having a Makefile and have separate commands for deploying in separate environments e.g "make deploy-staging" or "make deploy-prod". Internally, the command would generate Dockerrun.aws.json dynamically by interpolating env specific values to a template Dockerrun.aws file.

Vacillatory answered 18/3, 2019 at 9:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.