def build_bundler
    if File.exist?("#{Dir.pwd}/.bundle/config")
      warn(<<~WARNING, inline: true)
        You have the `.bundle/config` file checked into your repository
          It contains local state like the location of the installed bundle
          as well as configured git local gems, and other settings that should
        not be shared between multiple checkouts of a single repo. Please
        remove the `.bundle/` folder from your repo and add it to your `.gitignore` file.

        https://devcenter.heroku.com/articles/bundler-configuration
      WARNING
    end

    bundle_command = String.new("")
    bundle_command << "BUNDLE_WITHOUT='#{ENV["BUNDLE_WITHOUT"]}' "
    bundle_command << "BUNDLE_PATH=#{ENV["BUNDLE_PATH"]} "
    bundle_command << "BUNDLE_BIN=#{ENV["BUNDLE_BIN"]} "
    bundle_command << "BUNDLE_DEPLOYMENT=#{ENV["BUNDLE_DEPLOYMENT"]} " if ENV["BUNDLE_DEPLOYMENT"] # Unset on windows since we delete the Gemfile.lock
    bundle_command << "bundle install -j4"

    topic("Installing dependencies using bundler #{bundler.version}")

    bundler_output = String.new("")
    bundle_time = nil
    env_vars = {}
    pwd = Dir.pwd
    bundler_path = "#{pwd}/#{slug_vendor_base}/gems/#{bundler.dir_name}/lib"

    # we need to set BUNDLE_CONFIG and BUNDLE_GEMFILE for
    # codon since it uses bundler.
    env_vars["BUNDLE_GEMFILE"] = "#{pwd}/Gemfile"
    env_vars["BUNDLE_CONFIG"] = "#{pwd}/.bundle/config"
    env_vars["NOKOGIRI_USE_SYSTEM_LIBRARIES"] = "true"
    env_vars["BUNDLE_DISABLE_VERSION_CHECK"] = "true"

    puts "Running: #{bundle_command}"
    bundle_time = Benchmark.realtime do
      bundler_output << pipe("#{bundle_command} --no-clean", out: "2>&1", env: env_vars, user_env: true)
    end

    if $?.success?
      puts "Bundle completed (#{"%.2f" % bundle_time}s)"
      puts "Cleaning up the bundler cache."
      pipe("bundle clean", out: "2> /dev/null", user_env: true, env: env_vars)
      @bundler_cache.store

      # Keep gem cache out of the slug
      FileUtils.rm_rf("#{slug_vendor_base}/cache")

      bundle_list(
        stream_to_user: !bundler_output.match?(/Installing|Fetching|Using/)
      )
    else
      error_message = "Failed to install gems via Bundler."
      puts "Bundler Output: #{bundler_output}"
      if bundler_output.match(/An error occurred while installing sqlite3/)
        error_message += <<~ERROR

          Detected sqlite3 gem which is not supported on Heroku:
          https://devcenter.heroku.com/articles/sqlite3
        ERROR
      end

      if bundler_output.match(/but your Gemfile specified/)
        error_message += <<~ERROR

          Detected a mismatch between your Ruby version installed and
          Ruby version specified in Gemfile or Gemfile.lock. You can
          correct this by running:

              $ bundle update --ruby
              $ git add Gemfile.lock
              $ git commit -m "update ruby version"

          If this does not solve the issue please see this documentation:

          https://devcenter.heroku.com/articles/ruby-versions#your-ruby-version-is-x-but-your-gemfile-specified-y
        ERROR
      end

      error error_message
    end
  end
runs bundler to install the dependencies