<commit_before>require 'capistrano/ext/multistage'

set :stages, %w(staging production)
set :default_stage, "production"

require "bundler/capistrano"

default_run_options[:pty] = true

set :application, 'cartodb'

set :scm, :git
# set :git_enable_submodules, 1
set :git_shallow_clone, 1
set :scm_user, 'ubuntu'
set :use_sudo, false
set :repository, "<EMAIL>:Vizzuality/cartodb.git"
ssh_options[:forward_agent] = true
ssh_options[:keys] = [File.join(ENV["HOME"], ".ec2", "id-vizzuality")]
set :keep_releases, 5

set :appserver_staging, '172.16.17.32'
set :appserver_production, '172.16.17.32'
set :user,  'ubuntu'

set(:deploy_to){
  "/home/ubuntu/www/#{stage}.#{application}.com"
}

after  "deploy:update_code", :symlinks, :run_migrations, :set_staging_flag

desc "Restart Application"
deploy.task :restart, :roles => [:app] do
  run "touch #{current_path}/tmp/restart.txt"
end

desc "Migraciones"
task :run_migrations, :roles => [:app] do
  run <<-CMD
    export RAILS_ENV=#{stage} &&
    cd #{release_path} &&
    rake db:migrate --trace
  CMD
end

task :symlinks, :roles => [:app] do
  run <<-CMD
    ln -s #{shared_path}/system #{release_path}/public/system;
    ln -s #{shared_path}/pdfs #{release_path}/public/;
    ln -s #{shared_path}/cache #{release_path}/public/;
    ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml;
    ln -nfs #{shared_path}/config/app_config.yml #{release_path}/config/app_config.yml;
  CMD
end

desc 'Create asset packages'
task :asset_packages, :roles => [:app] do
 run <<-CMD
   export RAILS_ENV=#{stage} &&
   cd #{release_path} &&
   rake asset:packager:build_all
 CMD
end

desc "Uploads config yml files to app server's shared config folder"
task :upload_yml_files, :roles => :app do
  run "mkdir #{deploy_to}/shared/config ; true"
  upload("config/database.yml", "#{deploy_to}/shared/config/database.yml")
  upload("config/app_config.yml", "#{deploy_to}/shared/config/app_config.yml")
end

namespace :db do

  desc "Run rake:seed on remote app server"
  task :seed, :roles => :app do
    run "cd #{current_release} && RAILS_ENV=#{stage} rake db:seed"
  end

  desc "Setup the database"<commit_msg>Creates a symbolic link in public to the uploads folder at deploy<commit_after>require 'capistrano/ext/multistage'

set :stages, %w(staging production)
set :default_stage, "production"

require "bundler/capistrano"

default_run_options[:pty] = true

set :application, 'cartodb'

set :scm, :git
# set :git_enable_submodules, 1
set :git_shallow_clone, 1
set :scm_user, 'ubuntu'
set :use_sudo, false
set :repository, "git@github.com:Vizzuality/cartodb.git"
ssh_options[:forward_agent] = true
ssh_options[:keys] = [File.join(ENV["HOME"], ".ec2", "id-vizzuality")]
set :keep_releases, 5

set :appserver_staging, '172.16.17.32'
set :appserver_production, '172.16.17.32'
set :user,  'ubuntu'

set(:deploy_to){
  "/home/ubuntu/www/#{stage}.#{application}.com"
}

after  "deploy:update_code", :symlinks, :run_migrations, :set_staging_flag

desc "Restart Application"
deploy.task :restart, :roles => [:app] do
  run "touch #{current_path}/tmp/restart.txt"
end

desc "Migraciones"
task :run_migrations, :roles => [:app] do
  run <<-CMD
    export RAILS_ENV=#{stage} &&
    cd #{release_path} &&
    rake db:migrate --trace
  CMD
end

task :symlinks, :roles => [:app] do
  run <<-CMD
    ln -s #{shared_path}/system #{release_path}/public/system;
    ln -s #{shared_path}/pdfs #{release_path}/public/;
    ln -s #{shared_path}/cache #{release_path}/public/;
    ln -s #{shared_path}/uploads #{release_path}/public/;
    ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml;
    ln -nfs #{shared_path}/config/app_config.yml #{release_path}/config/app_config.yml;
  CMD
end

desc 'Create asset packages'
task :asset_packages, :roles => [:app] do
 run <<-CMD
   export RAILS_ENV=#{stage} &&
   cd #{release_path} &&
   rake asset:packager:build_all
 CMD
end

desc "Uploads config yml files to app server's shared config folder"
task :upload_yml_files, :roles => :app do
  run "mkdir #{deploy_to}/shared/config ; true"
  upload("config/database.yml", "#{deploy_to}/shared/config/database.yml")
  upload("config/app_config.yml", "#{deploy_to}/shared/config/app_config.yml")
end

namespace :db do

  desc "Run rake:seed on remote app server"
  task :seed, :roles => :app do
    run "cd #{current_release} && RAILS_ENV=#{stage} rake db:seed"
  end

  desc "Setup the database"
{'fraction_non_alphanumeric': 0.15531580130366374, 'fraction_numerical': 0.009889862890537199, 'mean_word_length': 4.909694555112882, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 5, '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': '4285462', 'n_tokens_mistral': 1729, 'n_tokens_neox': 1623, 'n_words': 390}