2016-02-01 17:37:37 +01:00
|
|
|
namespace :dev do
|
|
|
|
desc 'Initialise dev environment'
|
2017-06-12 16:12:03 +02:00
|
|
|
task :init do
|
2016-02-01 17:37:37 +01:00
|
|
|
puts 'start initialisation'
|
2016-02-02 10:24:36 +01:00
|
|
|
Rake::Task['dev:generate_token_file'].invoke
|
|
|
|
Rake::Task['dev:generate_franceconnect_file'].invoke
|
2016-05-20 16:27:32 +02:00
|
|
|
Rake::Task['dev:generate_fog_credentials_file'].invoke
|
2016-05-13 16:08:51 +02:00
|
|
|
Rake::Task['dev:generate_features_file'].invoke
|
2016-02-02 10:24:36 +01:00
|
|
|
|
2016-02-01 17:37:37 +01:00
|
|
|
puts 'end initialisation'
|
|
|
|
end
|
|
|
|
|
2017-06-12 16:12:03 +02:00
|
|
|
task :generate_token_file do
|
2016-02-02 10:24:36 +01:00
|
|
|
puts 'creating token.rb file'
|
2017-11-20 18:55:59 +01:00
|
|
|
res = `rake secret`.delete("\n")
|
2017-06-12 16:12:03 +02:00
|
|
|
file = File.new('config/initializers/token.rb', 'w+')
|
2016-02-02 10:24:36 +01:00
|
|
|
file.write("TPS::Application.config.SIADETOKEN = '#{res}'")
|
2016-02-01 17:37:37 +01:00
|
|
|
file.close
|
|
|
|
end
|
|
|
|
|
2016-02-02 10:24:36 +01:00
|
|
|
task :generate_franceconnect_file do
|
2017-06-12 16:12:03 +02:00
|
|
|
file = File.new('config/france_connect.yml', 'w+')
|
2018-01-15 19:09:08 +01:00
|
|
|
comment = <<~EOF
|
|
|
|
particulier_identifier: plop
|
|
|
|
particulier_secret: plip
|
2016-02-01 17:37:37 +01:00
|
|
|
|
2018-01-15 19:09:08 +01:00
|
|
|
particulier_redirect_uri: 'http://localhost:3000/france_connect/particulier/callback'
|
2016-02-01 17:37:37 +01:00
|
|
|
|
2018-01-15 19:09:08 +01:00
|
|
|
particulier_authorization_endpoint: 'https://fcp.integ01.dev-franceconnect.fr/api/v1/authorize'
|
|
|
|
particulier_token_endpoint: 'https://fcp.integ01.dev-franceconnect.fr/api/v1/token'
|
|
|
|
particulier_userinfo_endpoint: 'https://fcp.integ01.dev-franceconnect.fr/api/v1/userinfo'
|
|
|
|
particulier_logout_endpoint: 'https://fcp.integ01.dev-franceconnect.fr/api/v1/logout'
|
|
|
|
EOF
|
2016-02-01 17:37:37 +01:00
|
|
|
file.write(comment)
|
|
|
|
file.close
|
|
|
|
end
|
2016-05-13 16:08:51 +02:00
|
|
|
|
2016-05-20 16:27:32 +02:00
|
|
|
task :generate_fog_credentials_file do
|
|
|
|
puts 'creating fog_credentials.test.yml file'
|
2018-01-15 19:09:08 +01:00
|
|
|
content = <<~EOF
|
|
|
|
default:
|
|
|
|
openstack_tenant: "ovh_fake_tenant_name"
|
|
|
|
openstack_api_key: "ovh_fake_password"
|
|
|
|
openstack_username: "ovh_fake_username"
|
|
|
|
openstack_auth_url: "https://auth.cloud.ovh.net/v2.0/tokens"
|
|
|
|
openstack_region: "SBG1"
|
|
|
|
EOF
|
2017-06-12 16:12:03 +02:00
|
|
|
file = File.new("config/fog_credentials.test.yml", "w+")
|
2016-05-13 16:08:51 +02:00
|
|
|
file.write(content)
|
|
|
|
file.close
|
|
|
|
end
|
|
|
|
|
|
|
|
task :generate_features_file do
|
|
|
|
puts 'creating features.yml file'
|
2018-01-15 19:09:08 +01:00
|
|
|
content = <<~EOF
|
|
|
|
remote_storage: true
|
|
|
|
EOF
|
2017-06-12 16:12:03 +02:00
|
|
|
file = File.new("config/initializers/features.yml", "w+")
|
2016-05-13 16:08:51 +02:00
|
|
|
file.write(content)
|
|
|
|
file.close
|
|
|
|
end
|
2017-10-11 21:26:09 +02:00
|
|
|
|
|
|
|
def run_and_stop_if_error(cmd)
|
|
|
|
sh cmd do |ok, res|
|
|
|
|
if !ok
|
|
|
|
abort "#{cmd} failed with result : #{res.exitstatus}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
task :import_db do
|
|
|
|
filename = "tps_prod_#{1.day.ago.strftime("%d-%m-%Y")}.sql"
|
|
|
|
local_file = "/tmp/#{filename}"
|
2018-05-29 16:52:30 +02:00
|
|
|
|
|
|
|
if !File.exist?(local_file)
|
|
|
|
run_and_stop_if_error "scp -C deploy@sgmap_backup:/var/backup/production1/db/#{filename} #{local_file}"
|
|
|
|
end
|
2017-10-11 21:26:09 +02:00
|
|
|
|
2017-10-19 16:15:34 +02:00
|
|
|
dev_env_param = "RAILS_ENV=development"
|
|
|
|
|
|
|
|
Rake::Task["db:drop"].invoke(dev_env_param)
|
|
|
|
Rake::Task["db:create"].invoke(dev_env_param)
|
2017-10-11 21:26:09 +02:00
|
|
|
run_and_stop_if_error "psql tps_development -f #{local_file}"
|
|
|
|
|
2017-10-19 16:15:34 +02:00
|
|
|
Rake::Task["db:migrate"].invoke(dev_env_param)
|
|
|
|
Rake::Task["db:environment:set"].invoke(dev_env_param)
|
2017-10-18 10:48:35 +02:00
|
|
|
Rake::Task["db:test:prepare"].invoke
|
2017-10-11 21:26:09 +02:00
|
|
|
end
|
2017-10-09 18:17:40 +02:00
|
|
|
|
|
|
|
task :console do
|
|
|
|
exec("ssh tps@sgmap_production1 -t 'source /etc/profile && cd current && bundle exec rails c production'")
|
|
|
|
end
|
2016-02-01 17:37:37 +01:00
|
|
|
end
|