From e05e19c266e7fc95f059bc1a6c1cee491aae44bf Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sun, 12 Jan 2025 16:06:13 -0800 Subject: [PATCH] Create deploy.rake This task is to be run as a post-deploy script. It checks for new unimported data, imports it, then downloads the relevant images to S3 or local disk depending on the parameters provided. --- lib/tasks/deploy.rake | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 lib/tasks/deploy.rake diff --git a/lib/tasks/deploy.rake b/lib/tasks/deploy.rake new file mode 100644 index 0000000..fa09d22 --- /dev/null +++ b/lib/tasks/deploy.rake @@ -0,0 +1,37 @@ +namespace :deploy do + desc 'Post-deployment tasks: Import new data and download related images. Options: TEST=true for test mode, VERBOSE=true for verbose output, STORAGE=local|s3|both' + task post_deployment: :environment do + require_relative '../granblue/downloaders/base_downloader' + Dir[Rails.root.join('lib', 'granblue', '**', '*.rb')].each { |file| require file } + + # Ensure Rails environment is loaded + Rails.application.eager_load! + + # Parse and validate storage option + storage = (ENV['STORAGE'] || 'both').to_sym + unless [:local, :s3, :both].include?(storage) + puts 'Invalid STORAGE option. Must be one of: local, s3, both' + exit 1 + end + + options = { + test_mode: ENV['TEST'] == 'true', + verbose: ENV['VERBOSE'] == 'true', + storage: storage + } + + if options[:test_mode] + puts 'Test mode enabled' + end + + if options[:verbose] + puts 'Verbose output enabled' + end + + puts "Storage mode: #{storage}" + + # Execute the task + manager = PostDeploymentManager.new(options) + manager.run + end +end