-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
76 lines (61 loc) · 1.98 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# frozen_string_literal: true
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require File.expand_path('config/application', __dir__)
require 'lanalytics/s3'
Lanalytics::Application.load_tasks
namespace :ci do
desc 'Setup service for CI'
task setup: %w[ci:env db:drop:all db:create:all db:schema:load]
desc 'Run specs for CI'
task spec: %w[^spec]
task env: :environment do
ENV['DISABLE_DATABASE_ENVIRONMENT_CHECK'] = '1'
end
end
namespace :s3 do
desc 'Create necessary S3 bucket(s) for reports (if it does not exist already)'
task setup: :environment do
reports = Lanalytics::S3.resource.bucket(
Lanalytics.config.reports['s3_bucket'],
)
if reports.exists?
puts 'Bucket already exists. Done.'
else
reports.create
puts 'Bucket created.'
end
end
end
namespace :elastic do
desc 'Create elasticsearch indexes and mappings (index must not exist)'
task setup: :environment do
interfaces = [
Elasticsearch::ExpEventsInterface,
Elasticsearch::LinkTrackingEventsInterface,
]
interfaces.each do |interface|
client = interface.client
index = interface.index
mapping = interface.mapping
mapping_json = ActiveSupport::JSON.encode mapping
client.perform_request 'PUT', index, {}, mapping_json
puts "Created Elasticsearch index #{index}"
end
end
desc 'Deletes elasticsearch indexes and mappings'
task delete: :environment do
interfaces = [
Elasticsearch::ExpEventsInterface,
Elasticsearch::LinkTrackingEventsInterface,
]
interfaces.each do |interface|
client = interface.client
index = interface.index
client.perform_request 'DELETE', index
puts "Deleted Elasticsearch index #{index}"
end
end
desc 'Deletes and creates elasticsearch indexes and mappings'
task reset: %i[delete setup]
end