Skip to content

Commit

Permalink
Merge pull request #8 from scientist-softserv/ia-to-s3-migrator-script
Browse files Browse the repository at this point in the history
IA to S3 migrator script
  • Loading branch information
bkiahstroud authored Oct 1, 2024
2 parents 3a7dfa0 + 2a8b62b commit 143460f
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 4 deletions.
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')))
else
Aws::SQS::Client.new(region: 'us-east-2')
end
end

def ocr_queue_url
Expand Down

0 comments on commit 143460f

Please sign in to comment.