docs: def deploy_sandbox_shared_setup(log, verbose=True, app=None, exp_config=None):
      """Set up Git, push to Heroku, and launch the app."""
      if verbose:
          out = None
      else:
          out = open(os.devnull, "w")
  
      config = get_config()
      if not config.ready:
          config.load()
      heroku.sanity_check(config)
  
      (id, tmp) = setup_experiment(log, debug=False, app=app, exp_config=exp_config)
  
      # Register the experiment using all configured registration services.
      if config.get("mode") == "live":
          log("Registering the experiment on configured services...")
          registration.register(id, snapshot=None)
  
      # Log in to Heroku if we aren't already.
      log("Making sure that you are logged in to Heroku.")
      heroku.log_in()
      config.set("heroku_auth_token", heroku.auth_token())
      log("", chevrons=False)
  
      # Change to temporary directory.
      cwd = os.getcwd()
      os.chdir(tmp)
  
      # Commit Heroku-specific files to tmp folder's git repo.
      git = GitClient(output=out)
      git.init()
      git.add("--all")
      git.commit('"Experiment {}"'.format(id))
  
      # Initialize the app on Heroku.
      log("Initializing app on Heroku...")
      team = config.get("heroku_team", None)
      heroku_app = HerokuApp(dallinger_uid=id, output=out, team=team)
      heroku_app.bootstrap()
      heroku_app.buildpack("https://github.com/stomita/heroku-buildpack-phantomjs")
  
      # Set up add-ons and AWS environment variables.
      database_size = config.get("database_size")
      redis_size = config.get("redis_size")
      addons = [
          "heroku-postgresql:{}".format(quote(database_size)),
          "heroku-redis:{}".format(quote(redis_size)),
          "papertrail",
      ]
      if config.get("sentry"):
          addons.append("sentry")
  
      for name in addons:
          heroku_app.addon(name)
  
      heroku_config = {
          "aws_access_key_id": config["aws_access_key_id"],
          "aws_secret_access_key": config["aws_secret_access_key"],
          "aws_region": config["aws_region"],
          "auto_recruit": config["auto_recruit"],
          "smtp_username": config["smtp_username"],
          "smtp_password": config["smtp_password"],
          "whimsical": config["whimsical"],
      }
  
      heroku_app.set_multiple(**heroku_config)
  
      # Wait for Redis database to be ready.
      log("Waiting for Redis...")
      ready = False
      while not ready:
          try:
              r = redis.from_url(heroku_app.redis_url)
              r.set("foo", "bar")
              ready = True
          except (ValueError, redis.exceptions.ConnectionError):
              time.sleep(2)
  
      log("Saving the URL of the postgres database...")
      # Set the notification URL and database URL in the config file.
      config.extend(
          {
              "notification_url": heroku_app.url + "/notifications",
              "database_url": heroku_app.db_url,
          }
      )
      config.write()
      git.add("config.txt")
      time.sleep(0.25)
      git.commit("Save URLs for database and notifications")
      time.sleep(0.25)
  
      # Launch the Heroku app.
      log("Pushing code to Heroku...")
      git.push(remote="heroku", branch="HEAD:master")
  
      log("Scaling up the dynos...")
      size = config.get("dyno_type")
      for process in ["web", "worker"]:
          qty = config.get("num_dynos_" + process)
          heroku_app.scale_up_dyno(process, qty, size)
      if config.get("clock_on"):
          heroku_app.scale_up_dyno("clock", 1, size)
  
      time.sleep(8)
  
      # Launch the experiment.
      log("Launching the experiment on the remote server and starting recruitment...")
      launch_data = _handle_launch_data("{}/launch".format(heroku_app.url), error=log)
      result = {
          "app_name": heroku_app.name,
          "app_home": heroku_app.url,
          "recruitment_msg": launch_data.get("recruitment_msg", None),
      }
      log("Experiment details:")
      log("App home: {}".format(result["app_home"]), chevrons=False)
      log("Recruiter info:")
      log(result["recruitment_msg"], chevrons=False)
  
      # Return to the branch whence we came.
      os.chdir(cwd)
  
      log("Completed deployment of experiment " + id + ".")
      return result