title: Using separate Dockerrun.aws.json files for separate branch deployments with Travis CI
body: <p>So I'm trying to setup a simple Multicontainer Elastic Beanstalk application that deploys automatically through Travis CI.</p>
  
  <p>Additionally, I have two environments set up on Elastic Beanstalk, a production environment and a staging environment, and I have my .travis.yml file setup to deploy to the production environment on master and staging on the stage branch, like so:</p>
  
  <pre><code>sudo: required
  services:
    - docker
  before_install: docker build -t web:ci -f web/Dockerfile.dev web
  script: docker run web:ci npm run test -- --coverage
  before_deploy:
    - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_ID" --password-stdin
    - bash .build/image_maker.sh
    - bash .build/environment_initializer.sh
  deployments:
    elasticbeanstalkdeploy: &amp;elastic_beanstalk_deploy
      skip_cleanup: true
      provider: elasticbeanstalk
      app: "MySuperCoolApp"
      region: "us-east-2"
      bucket_name: "elasticbeanstalk-us-east-2-012345678910"
      bucket_path: "MySuperCoolApp"
      access_key_id: $ELASTIC_BEANSTALK_ACCESS_KEY
      secret_access_key:
        secure: $ELASTIC_BEANSTALK_SECRET_KEY
  deploy:
    - &lt;&lt;: *elastic_beanstalk_deploy
      env: "MySuperCoolApp-ProductionEnv"
      on:
        branch: master
    - &lt;&lt;: *elastic_beanstalk_deploy
      env: "MySuperCoolApp-StagingEnv"
      on:
        branch: stage
  </code></pre>
  
  <p>You'll notice on the 'before_deploy' phase of the build I call bash on two separate files. </p>
  
  <p>The first is image_maker.sh, which is responsible for building all of the images required for the EB app and pushing them to Docker hub.</p>
  
  <p>I won't show you any code from the image_maker.sh file since I am certain it's working and isn't relevant to the problem, but you should know that it tags the images based on the current branch being pushed to. </p>
  
  <p>When being pushed to master, each image will be tagged with production.latest (eg: image_name:production.latest), and when being pushed to the stage branch, each image will be tagged with staging.latest (eg: image_name:staging.latest.)</p>
  
  <p>This is important to know because it explains why I'm trying to do this next step (which is what I'm struggling with.)</p>
  
  <p>Basically I have two Dockerrun.aws.json files, each stored in the .build directory under a production or staging subdirectory (so I have one file at '.build/production/Dockerrun.aws.json' and the other at '.build/staging/Dockerrun.aws.json.')</p>
  
  <p>Here's the basic file structure:</p>
  
  <pre><code>root
    .travis.yml
    .build
      image_maker.sh
      environment_initializer.sh
      production
        - Dockerrun.aws.json
      staging 
        - Dockerrun.aws.json
  </code></pre>
  
  <p>The ONLY difference between each of the Dockerrun.aws.json files is which image tag they use in the container definitions, the staging Dockerrun file looks for images tagged with staging.latest, and the production Dockerrun file looks for images tagged with production.latest</p>
  
  <p>Seems easy enough.</p>
  
  <p>The obvious next step is to move the Dockerrun file to the root directory based on which branch is being pushed to so that when Elastic Beanstalk receives the code it knows what to do.</p>
  
  <p>This is the sole purpose of the second bash script from the 'before_deploy' command: .build/environment_initializer.sh. </p>
  
  <p>Here is the code:</p>
  
  <pre class="lang-sh prettyprint-override"><code>#!/bin/bash
  
  if [[ "$TRAVIS_PULL_REQUEST" = false ]]; then
  
    if [ "$TRAVIS_BRANCH" = 'master' ]; then
      echo Moving production Dockerrun.aws.json to root
      mv ./.build/production/Dockerrun.aws.json ./
    fi
  
    if [ "$TRAVIS_BRANCH" = 'stage' ]; then
      echo Moving staging Dockerrun.aws.json to root
      mv ./.build/staging/Dockerrun.aws.json ./
    fi
  
  fi
  </code></pre>
  
  <p>Ideally, I would expect this to do exactly what I want, and work seamlessly. The problem is, no matter what I try, I always get the same error on the Elastic Beanstalk logs:</p>
  
  <pre><code>No ecs task definition (or empty definition file) found in environment
  </code></pre>
  
  <p>Which basically means the code that gets passed to Elastic Beanstalk doesn't have the changes I made in the .build/environment_initializer.sh, which sucks because from what I understand using skip_cleanup inside of the deploy command is supposed to stop Travis from undoing the changes you've made to the code. </p>
  
  <p>I'm at a loss for what to try next, so far I've tried about a thousand different small tweaks to the code above, including:</p>
  
  <ol>
  <li>Adding a 'git stash -all' at the end of the environment_initializer.sh file.</li>
  <li>About a hundred variations on the 'mv ./.build/production/Dockerrun.aws.json ./'</li>
  <li>Using cp instead of mv.</li>
  </ol>
  
  <p>But no matter what I do, nothing seems to work. So now, I'm leaving it in your hands. Any help would be much appreciated!</p>