Class: Ufo::Docker::State::S3
Instance Method Summary collapse
-
#app ⇒ Object
ufo docker base is called before Ufo.config is loaded.
-
#current_data ⇒ Object
TODO: edge cases: no bucket, no permission.
- #ensure_s3_bucket_exist ⇒ Object
- #read ⇒ Object
- #s3_bucket ⇒ Object
- #s3_key ⇒ Object
- #update ⇒ Object
Methods included from AwsServices
#acm, #applicationautoscaling, #aws_options, #cfn, #cloudwatchlogs, #ec2, #ecr, #ecs, #elb, #s3, #ssm_client, #waf_client
Methods included from AwsServices::Concerns
#find_stack, #find_stack_resources, #stack_resources, #status, #task_definition_arns
Methods inherited from Base
Methods included from Utils::Pretty
#pretty_home, #pretty_path, #pretty_time
Methods included from Utils::Logging
Constructor Details
This class inherits a constructor from Ufo::Docker::State::Base
Instance Method Details
#app ⇒ Object
ufo docker base is called before Ufo.config is loaded. This ensures it is loaded
48 49 50 51 |
# File 'lib/ufo/docker/state/s3.rb', line 48 def app Ufo.config Ufo.app end |
#current_data ⇒ Object
TODO: edge cases: no bucket, no permission
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ufo/docker/state/s3.rb', line 26 def current_data resp = s3.get_object(bucket: s3_bucket, key: s3_key) YAML.load(resp.body) rescue Aws::S3::Errors::NoSuchKey logger.debug "WARN: s3 key does not exist: #{s3_key}" {} rescue Aws::S3::Errors::NoSuchBucket logger.error "ERROR: S3 bucket does not exist to store state: #{s3_bucket}".color(:red) logger.error <<~EOL Please double check the config. See: http://ufoships.com/docs/config/state/ EOL exit 1 end |
#ensure_s3_bucket_exist ⇒ Object
73 74 75 76 77 |
# File 'lib/ufo/docker/state/s3.rb', line 73 def ensure_s3_bucket_exist bucket = Ufo::S3::Bucket.new return if bucket.exist? bucket.deploy end |
#read ⇒ Object
6 7 8 |
# File 'lib/ufo/docker/state/s3.rb', line 6 def read current_data end |
#s3_bucket ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/ufo/docker/state/s3.rb', line 53 def s3_bucket state = Ufo.config.state if state.bucket state.bucket elsif state.managed ensure_s3_bucket_exist Ufo::S3::Bucket.name else logger.error "ERROR: No s3 bucket to store state".color(:red) logger.error <<~EOL UFO needs a bucket to store the built docker base image. Configure an existing bucket or enable UFO to create a bucket. See: http://ufoships.com/docs/config/state/ EOL exit 1 end end |
#s3_key ⇒ Object
43 44 45 |
# File 'lib/ufo/docker/state/s3.rb', line 43 def s3_key "ufo/state/#{app}/#{Ufo.env}/data.yml" end |
#update ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/ufo/docker/state/s3.rb', line 10 def update data = current_data data["base_image"] = @base_image # write data to s3 body = YAML.dump(data) s3.put_object( body: body, bucket: s3_bucket, key: s3_key, ) logger.info "Updated base image in s3://#{s3_bucket}/#{s3_key}" logger.info " #{@base_image}".color(:green) end |