Class: AwsDockerUtils::Controllers::S3

Inherits:
Object
  • Object
show all
Defined in:
lib/aws_docker_utils/controllers/s3.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ S3

Returns a new instance of S3.



11
12
13
14
15
16
17
# File 'lib/aws_docker_utils/controllers/s3.rb', line 11

def initialize(opts={})
  @bucket_name    = opts.fetch('<s3_bucket_name>')
  @task_name      = opts.fetch('<as_task>', "file")
  @container_name = opts.fetch('<container_name>')
  @cmd            = opts.fetch('<cmd>')
  @file_name      = Tempfile.new("#{`date '+#{@task_name}_%y-%m-%d_%H-%M'`.chop}.sql")
end

Instance Method Details

#activateObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/aws_docker_utils/controllers/s3.rb', line 19

def activate
  Docker::Client.new(container_name: @container_name, cmd: "#{@cmd} > #{@file_name.path}").exec
  s3 = Providers::S3.new(bucket_name: @bucket_name)
  if s3.put(Compressor.new(@file_name.path).compress)
    puts "Pushed to S3."
  else
    puts "Unable to do the job."
  end
  @file_name.close
end