-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
280 lines (241 loc) · 9.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
# Define the default task when running "rake" without arguments
task default: %w[deploy]
# VoicePassport
namespace :voicepassport do
# Deploy task: Deploys Architecture and launches services and daemons.
desc "Deploys Architecture and launches all services and daemons needed to work properly."
task :deploy => [
:clean_environment,
:start,
:status
] do
puts "Deploying services..."
end
# Undeploy task: Undeploys Architecture
desc "Undeploys Architecture"
task :undeploy => [:status] do
puts "Undeploy Services"
puts `docker-compose down -v 2>&1`
end
# Start task: Start Containers
desc "Start Containers"
task :start => [ :check_docker, :login, :check_deployment_file ] do
puts "Start Containers"
puts `docker-compose up -d --remove-orphans`
end
# Stop task: Stop Containers
desc "Stop Containers"
task :stop => [ :check_docker ] do
puts "Stop Containers"
puts `docker-compose stop 2>&1`
puts `docker-compose rm -f 2>&1`
end
# Status task: Show Containers Status
desc "Show Containers Status"
task :status do
puts "Show Containers Status"
puts `docker-compose ps 2>&1`
end
desc "Create Apache Airflow Users"
task :create_apache_airflow_users do
# Container name
container_name = "voice-passport-airflow-webserver"
# Commands to create users
create_admin_user_cmd = "docker exec #{container_name} airflow users create -r Admin -u dreamsoftware -e [email protected] -f Sergio -l Sánchez -p dreamsoftware00"
create_executor_user_cmd = "docker exec #{container_name} airflow users create -r User -u api_executor -e [email protected] -f API -l Executor -p dreamsoftware00"
# Create Admin user
puts "Creating Admin user..."
`#{create_admin_user_cmd}`
puts "Admin user created successfully."
# Create API Executor user
puts "Creating API Executor user..."
`#{create_executor_user_cmd}`
puts "API Executor user created successfully."
end
# Build and push Apache Airflow Docker image
desc "Build and push Apache Airflow Docker image"
task :build_and_push_airflow_image do
image_name = "ssanchez11/voice_passport_apache_airflow:0.0.1"
puts "Building Apache Airflow Docker image..."
build_command = "docker build -t #{image_name} ./airflow"
system(build_command)
puts "Pushing Apache Airflow Docker image to DockerHub..."
push_command = "docker push #{image_name}"
system(push_command)
puts "Apache Airflow image built and pushed successfully."
end
# Build and push VoicePassport API Docker image
desc "Build and push VoicePassport API Docker image"
task :build_and_push_voice_passport_api_image do
api_image_name = "ssanchez11/voice_passport_api_service:0.0.1"
api_directory = "./api"
puts "Building VoicePassport API Docker image..."
build_command = "docker build -t #{api_image_name} #{api_directory}"
system(build_command)
puts "Pushing VoicePassport API Docker image to DockerHub..."
push_command = "docker push #{api_image_name}"
system(push_command)
puts "VoicePassport API image built and pushed successfully."
end
desc "Upload contract ABI JSON file to MinIO"
task :upload_contract_abi_to_minio do
require 'aws-sdk-s3'
require 'dotenv/load'
s3_client = Aws::S3::Client.new(
endpoint: "http://127.0.0.1:9000",
access_key_id: ENV["MINIO_ACCESS_KEY"],
secret_access_key: ENV["MINIO_SECRET_KEY"],
force_path_style: true,
region: 'us-east-1'
)
# Path to the contract ABI JSON file
abi_json_file_path = "./abis/VoiceIDVerifier.json"
bucket_name = ENV["MINIO_BUCKET_NAME"]
# Check if the bucket exists
bucket_exists = s3_client.head_bucket(bucket: bucket_name) rescue false
# If the bucket doesn't exist, create it
unless bucket_exists
begin
s3_client.create_bucket(bucket: bucket_name)
puts "Bucket '#{bucket_name}' created successfully."
rescue StandardError => e
puts "Error creating bucket '#{bucket_name}': #{e.message}"
end
end
# Upload the contract ABI JSON file to MinIO bucket
puts "Uploading contract ABI JSON file to MinIO..."
begin
File.open(abi_json_file_path, 'rb') do |file|
s3_client.put_object(
key: ENV["VOICE_ID_VERIFIER_CONTRACT_ABI_NAME"],
body: file,
bucket: bucket_name,
content_type: 'application/json'
)
end
puts "Contract ABI JSON file uploaded successfully."
rescue StandardError => e
puts "Error uploading contract ABI JSON file to MinIO: #{e.message}"
end
end
desc "Delete contract ABI JSON file from MinIO"
task :delete_contract_abi_from_minio do
require 'aws-sdk-s3'
require 'dotenv/load'
s3_client = Aws::S3::Client.new(
endpoint: "http://127.0.0.1:9000",
access_key_id: ENV["MINIO_ACCESS_KEY"],
secret_access_key: ENV["MINIO_SECRET_KEY"],
force_path_style: true,
region: 'us-east-1'
)
bucket_name = ENV["MINIO_BUCKET_NAME"]
abi_json_file_name = ENV["VOICE_ID_VERIFIER_CONTRACT_ABI_NAME"]
# Check if the bucket exists
bucket_exists = s3_client.head_bucket(bucket: bucket_name) rescue false
if bucket_exists
begin
# Delete the ABI JSON file from the bucket
response = s3_client.delete_object(bucket: bucket_name, key: abi_json_file_name)
puts "Contract ABI JSON file '#{abi_json_file_name}' deleted from MinIO bucket '#{bucket_name}'."
rescue Aws::S3::Errors::NoSuchKey
puts "Contract ABI JSON file '#{abi_json_file_name}' does not exist in MinIO bucket '#{bucket_name}'."
rescue StandardError => e
puts "Error deleting contract ABI JSON file from MinIO bucket '#{bucket_name}': #{e.message}"
end
else
puts "MinIO bucket '#{bucket_name}' does not exist."
end
end
desc "Check if contract ABI JSON file exists in MinIO"
task :check_contract_abi_in_minio do
require 'aws-sdk-s3'
require 'dotenv/load'
s3_client = Aws::S3::Client.new(
endpoint: "http://127.0.0.1:9000",
access_key_id: ENV["MINIO_ACCESS_KEY"],
secret_access_key: ENV["MINIO_SECRET_KEY"],
force_path_style: true,
region: 'us-east-1'
)
bucket_name = ENV["MINIO_BUCKET_NAME"]
abi_json_file_name = ENV["VOICE_ID_VERIFIER_CONTRACT_ABI_NAME"]
# Check if the bucket exists
bucket_exists = s3_client.head_bucket(bucket: bucket_name) rescue false
if bucket_exists
begin
# Check if the ABI JSON file exists in the bucket
response = s3_client.head_object(bucket: bucket_name, key: abi_json_file_name)
puts "Contract ABI JSON file '#{abi_json_file_name}' exists in MinIO bucket '#{bucket_name}'."
rescue Aws::S3::Errors::NotFound
puts "Contract ABI JSON file '#{abi_json_file_name}' does not exist in MinIO bucket '#{bucket_name}'."
rescue StandardError => e
puts "Error checking contract ABI JSON file in MinIO bucket '#{bucket_name}': #{e.message}"
end
else
puts "MinIO bucket '#{bucket_name}' does not exist."
end
end
namespace :dapp do
desc "Install dependencies for VoiceIdVerifierDapp"
task :install_dependencies do
sh "cd VoiceIdVerifierDapp && npm install"
end
desc "Run tests for VoiceIdVerifierDapp using Hardhat"
task :run_tests do
sh "cd VoiceIdVerifierDapp && npx hardhat test"
end
desc "Deploy contracts for VoiceIdVerifierDapp on the amoy network"
task :deploy_contracts do
sh "cd VoiceIdVerifierDapp && npx hardhat run --network amoy scripts/deploy.ts"
end
end
# Cleaning Environment task
desc "Cleaning Environment task"
task :clean_environment do
puts "Cleaning Environment"
puts `docker image prune -af`
puts `docker volume prune -f 2>&1`
end
# Check Docker and Docker Compose task
desc "Check Docker and Docker Compose task"
task :check_docker do
puts "Check Docker and Docker Compose ..."
if which('docker') && which('docker-compose')
show_docker_version
show_docker_compose_version
else
raise "Please check that Docker and Docker Compose are visible and accessible in the PATH"
end
end
# Authenticating with existing credentials task
desc "Authenticating with existing credentials task"
task :login do
puts `docker login 2>&1`
end
# Check Deployment File task
desc "Check Deployment File task"
task :check_deployment_file do
puts "Check Deployment File ..."
raise "Deployment file not found, please check availability" unless File.file?("docker-compose.yml")
puts "Deployment File OK"
end
end
# Utility functions
def show_docker_version
puts `docker version 2>&1`
end
def show_docker_compose_version
puts `docker-compose version 2>&1`
end
# Cross-platform way of finding an executable in the $PATH.
def which(cmd)
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
exts.each { |ext|
exe = File.join(path, "#{cmd}#{ext}")
return exe if File.executable?(exe) && !File.directory?(exe)
}
end
return nil
end