<commit_before>REPOSITORY = ENV['REPOSITORY'] || 'grounds'
DOCKER_URL = ENV['DOCKER_URL'] || 'http://127.0.0.1:2375'
RAILS_PORT = ENV['RAILS_PORT'] || 3000
EXEC_PORT  = ENV['EXEC_PORT']  || 8080

IMAGE = "#{REPOSITORY}/grounds.io"

redis = 'grounds-redis'
exec  = 'grounds-exec-latest'

task :build do
  sh "docker build -t #{IMAGE} ."
end

task :test => [:build] do
  sh "docker run -t #{IMAGE} rake test"
end

task :run => [:build, 'detach:redis', 'detach:exec'] do
sh <<-EOF
docker run \
-e WEBSOCKET_URL=#{DOCKER_URL.gsub(/:\d{4}/, ":#{EXEC_PORT}")} \
-e RAILS_PORT=#{RAILS_PORT} \
-p #{RAILS_PORT}:#{RAILS_PORT} \
--link #{redis}:redis \
-t #{IMAGE} \
rake run
EOF

Rake::Task['clean:redis'].execute
Rake::Task['clean:exec'].execute
end

namespace :detach do
  task :redis => ['clean:redis'] do
  sh <<-EOF
  docker run -d \
  --name #{redis} \
  dockerfiles/redis
  EOF
  end

  task :exec => ['clean:exec'] do
  sh <<-EOF
  docker run \
  --name #{exec} \
  -p #{EXEC_PORT}:#{EXEC_PORT} \
  -d #{REPOSITORY}/grounds-exec \
  server \
  -e #{DOCKER_URL} \
  -p #{EXEC_PORT} \
  -r #{REPOSITORY}
  EOF
  end
end

namespace :clean do
  task :redis do
    if container_exist?(redis)
      sh "docker rm -f #{redis}"
    end
  end

  task :exec do
    if container_exist?(exec)
      sh "docker rm -f #{exec}"
    end
  end
end

def container_exist?(name)
  !`docker inspect --format={{.Created}} #{name} 2>/dev/null`.empty?
end<commit_msg>add branch to master task build (docker build)<commit_after>REPOSITORY = ENV['REPOSITORY'] || 'grounds'
DOCKER_URL = ENV['DOCKER_URL'] || 'http://127.0.0.1:2375'
RAILS_PORT = ENV['RAILS_PORT'] || 3000
EXEC_PORT  = ENV['EXEC_PORT']  || 8080

BRANCH = `git rev-parse --abbrev-ref HEAD 2>/dev/null`.gsub("\n", '')
IMAGE  = "#{REPOSITORY}/grounds.io:#{BRANCH}"

redis = 'grounds-redis'
exec  = 'grounds-exec-latest'

task :build do
  sh "docker build -t #{IMAGE} ."
end

task :test => [:build] do
  sh "docker run -t #{IMAGE} rake test"
end

task :run => [:build, 'detach:redis', 'detach:exec'] do
sh <<-EOF
docker run \
-e WEBSOCKET_URL=#{DOCKER_URL.gsub(/:\d{4}/, ":#{EXEC_PORT}")} \
-e RAILS_PORT=#{RAILS_PORT} \
-p #{RAILS_PORT}:#{RAILS_PORT} \
--link #{redis}:redis \
-t #{IMAGE} \
rake run
EOF

Rake::Task['clean:redis'].execute
Rake::Task['clean:exec'].execute
end

namespace :detach do
  task :redis => ['clean:redis'] do
  sh <<-EOF
  docker run -d \
  --name #{redis} \
  dockerfiles/redis
  EOF
  end

  task :exec => ['clean:exec'] do
  sh <<-EOF
  docker run \
  --name #{exec} \
  -p #{EXEC_PORT}:#{EXEC_PORT} \
  -d #{REPOSITORY}/grounds-exec \
  server \
  -e #{DOCKER_URL} \
  -p #{EXEC_PORT} \
  -r #{REPOSITORY}
  EOF
  end
end

namespace :clean do
  task :redis do
    container_delete(redis)
  end

  task :exec do
    container_delete(exec)
  end
end

def container_delete(name)
  if container_exist?(name)
    sh "docker rm -f #{name}"
  end
end

def container_exist?(name)
  !`docker inspect --format={{.Created}} #{name} 2>/dev/null`.empty?
end
{'fraction_non_alphanumeric': 0.1902228134353176, 'fraction_numerical': 0.013634852011972065, 'mean_word_length': 3.4761904761904763, 'pattern_counts': {'":': 2, '<': 15, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '3464141', 'n_tokens_mistral': 1300, 'n_tokens_neox': 1250, 'n_words': 295}