<commit_before>node[:deploy].each do |application, deploy|

  # node[:deploy]['appshortname'][:environment_variables][:variable_name]

  environment = deploy[:environment_variables].dup

  if deploy[:application_type] != 'other'
    Chef::Log.debug("Skipping deploy::docker application #{application} as it is not deployed to this layer")
    next
  elsif environment.delete(:APP_TYPE) != 'docker'
    Chef::Log.debug("Skipping deploy::docker application #{application} as it is not of type 'docker'")
    next
  end

  image = environment.delete :IMAGE
  Chef::Log.debug("Going to deploy '#{application}', from '#{image}'")

  containers = environment.delete :CONTAINERS
  containers = containers ? containers.to_i : 1
  
  execute "pulling #{application} image" do
    Chef::Log.info("Pulling '#{image}'...")
    command "docker pull #{image}"
  end

  ##
  # @TODO Here what we should actually be doing is spin up a new container
  #       add it to some kind of load balancing haproxy and after we're done
  #       and we're sure it's running we kill it.
  containers.times do |i|
    execute "kill running #{application}#{i} container" do
      Chef::Log.info("Killing running #{application}#{i} containers...")
      command "docker kill #{application}#{i}"
      only_if "docker ps -f status=running | grep ' #{application}#{i} '"
    end
  end

  containers.times do |i|
    execute "remove stopped #{application}#{i} container" do
      Chef::Log.info("Removing the #{application}#{i} container...")
      command "docker rm  #{application}#{i}"
      only_if "docker ps -a | grep ' #{application}#{i} '"
    end
  end

  { "PG_HOST" => deploy[:database][:host],
    "PG_USER" =>  deploy[:database][:username],
    "PG_PASSWORD" => deploy[:database][:password]
  }.each do |k,v|
    environment[k] = v unless v.nil? || v == ""
  end
  
  env_string = environment.inject("") do |memo, (key, value)|
    memo + "--env \"#{key}=#{value}\" "
  end
  
  volumes_from = deploy["volumes_from"].inject("") do |memo, value|
    memo + "--volumes-from #{value} "
  end if deploy["volumes_from"]
  
  ports = deploy["ports"].inject("") do |memo, value|
    memo + "-p #{value} "
  end if deploy["ports"]
  
  links = deploy["links"].inject("") do |memo, value|
    memo + "--link #{value} "
  end if deploy["links"]

  containers.times do |i|
    execute "launch #{application}#{i} container" do
      Chef::Log.info("Launching #{image}...")
          
      command "docker run -d --name #{application}#{i} #{ports} #{env_string} #{links} #{volumes_from} #{image}"
    end
  end
end<commit_msg>updated the deploy recipe to support new app style<commit_after>node[:deploy].each do |application, deploy|

  if deploy[:application_type] != 'other'
    Chef::Log.debug("Skipping deploy::docker application #{application} as it is not deployed to this layer")
    next
  elsif environment.delete(:APP_TYPE) != 'docker'
    Chef::Log.debug("Skipping deploy::docker application #{application} as it is not of type 'docker'")
    next
  end

  deploy.each do |apps|
    apps.each do |app_name, app_config|
      image = app_config["image"]

      containers = app_config["containers"] || 1

      environment = (app_config["env"] || {}).dup
      volumes_from = app_config["volumes_from"] || []
      ports = app_config["ports"] || []
      links = app_config["links"] || []

      if app_config["database"]
        {
          "DB_ADAPTER" => deploy[:database][:adapter],
          "DB_DATABASE" => deploy[:database][:database],
          "DB_HOST" => deploy[:database][:host],
          "DB_PASSWORD" => deploy[:database][:password],
          "DB_PORT" => deploy[:database][:port],
          "DB_RECONNECT" => deploy[:database][:reconnect],
          "DB_USERNAME" =>  deploy[:database][:username]
        }.each do |k,v|
          environment[k] = v
        end
      end

      env_string = environment.inject("") do |memo, (key, value)|
        memo + "--env \"#{key}=#{value}\" "
      end

      volumes_from = volumes_from.inject("") do |memo, value|
        memo + "--volumes-from #{value} "
      end

      ports = ports.inject("") do |memo, value|
        memo + "-p #{value} "
      end

      links = links.inject("") do |memo, value|
        memo + "--link #{value} "
      end

      Chef::Log.debug("Deploying '#{application}/#{app_name}', from '#{image}'")

      execute "pulling #{image}" do
        Chef::Log.info("Pulling '#{image}'...")
        command "docker pull #{image}"
      end

      ##
      # @TODO Here what we should actually be doing is spin up a new container
      #       add it to some kind of load balancing haproxy and after we're done
      #       and we're sure it's running we kill it.
      containers.times do |i|
        execute "kill running #{app_name}#{i} container" do
          Chef::Log.info("Killing running #{application}/#{app_name}#{i} container...")
          command "docker kill #{app_name}#{i}"
          only_if "docker ps -f status=running | grep ' #{app_name}#{i} '"
        end

        execute "remove stopped #{app_name}#{i} container" do
          Chef::Log.info("Removing the #{application}/#{app_name}#{i} container...")
          command "docker rm  #{app_name}#{i}"
          only_if "docker ps -a | grep ' #{app_name}#{i} '"
        end

        execute "launch #{app_name}#{i} container" do
          Chef::Log.info("Launching #{image}...")
          command "docker run -d -h #{app_name}#{i} --name #{app_name}#{i} #{ports} #{env_string} #{links} #{volumes_from} #{image}"
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.16442772702847933, 'fraction_numerical': 0.0003582303421099767, 'mean_word_length': 3.002867383512545, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4579978', 'n_tokens_mistral': 1768, 'n_tokens_neox': 1750, 'n_words': 480}