Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IA to S3 migrator script #8

Merged
merged 8 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
!.env.development
!.env.test
*~undo-tree~
tmp
log
7 changes: 5 additions & 2 deletions bin/build
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ rm -rf \
test \
tmp \
.ruby-lsp \
log \
vendor/bundle/ruby/3.*/cache
find . -iname "*~undo-tree~" -delete
popd
Expand All @@ -38,7 +39,8 @@ rm -rf \
README.md \
test \
tmp \
.ruby-lsp \
.ruby-lsp \
log \
vendor/bundle/ruby/3.*/cache
find . -iname "*~undo-tree~" -delete
popd
Expand All @@ -54,7 +56,8 @@ rm -rf \
README.md \
test \
tmp \
.ruby-lsp \
.ruby-lsp \
log \
vendor/bundle/ruby/3.*/cache
find . -iname "*~undo-tree~" -delete
popd
25 changes: 25 additions & 0 deletions bin/ia_to_s3_migrator
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env ruby

# Usage: bin/migrate_iaids

require 'ruby-progressbar'
require_relative '../lib/space_stone'

puts '== Tail log/ia_to_s3_migrator.log for logs =='

iaids = File.read('tmp/iaids.txt').split("\n")
logger = Logger.new('log/ia_to_s3_migrator.log')
progressbar = ProgressBar.create(total: iaids.size, format: '%a %e %P% Processed: %c from %C')
s3_bucket = SpaceStone::S3Service.bucket

iaids.each do |iaid|
# WARN: This dumbly checks for any downloads; if some files have been uploaded
# but some haven't, it will skip uploading all of them
if s3_bucket.objects(prefix: "#{iaid}/downloads").any?
logger.warn("== #{iaid} == Files have already been uploaded to S3, skipping")
else
logger.info("== #{iaid} == Downloading files...")
process_ia_id(iaid, '/store/tmp/fast-tmp')
end
progressbar.increment
end
9 changes: 9 additions & 0 deletions bin/migrate_iaids
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
set -e

STAGE_ENV=production docker compose run \
--rm \
--remove-orphans \
--volume /store/tmp/fast-tmp:/store/tmp/fast-tmp \
web \
'bundle exec bin/ia_to_s3_migrator'
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ services:
- .:/var/task:delegated
- /var/run/docker.sock:/var/run/docker.sock
command: "sam local start-api --host '0.0.0.0' --port 3030 --docker-volume-basedir ${PWD}"
entrypoint: /bin/bash
entrypoint: /bin/bash -c
ports:
- 3030:3030
6 changes: 5 additions & 1 deletion lib/space_stone/sqs_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ module SpaceStone
# Service object to add messages to either sqs queue
module SqsService
def client
@client ||= Aws::SQS::Client.new(region: 'us-east-2')
@client ||= if ENV.fetch('AWS_S3_ACCESS_KEY_ID', nil)
Aws::SQS::Client.new(region: 'us-east-2', credentials: Aws::Credentials.new(ENV.fetch('AWS_S3_ACCESS_KEY_ID'), ENV.fetch('AWS_S3_SECRET_ACCESS_KEY')))
bkiahstroud marked this conversation as resolved.
Show resolved Hide resolved
else
Aws::SQS::Client.new(region: 'us-east-2')
end
end

def ocr_queue_url
Expand Down
Loading