Class: EmDeploy::Deployment
- Inherits:
-
Object
- Object
- EmDeploy::Deployment
- Defined in:
- lib/em-deploy/deployment.rb
Instance Attribute Summary collapse
-
#app_name ⇒ Object
Returns the value of attribute app_name.
-
#config ⇒ Object
Returns the value of attribute config.
-
#revision ⇒ Object
Returns the value of attribute revision.
Instance Method Summary collapse
- #activate_revision ⇒ Object
- #build_application ⇒ Object
-
#initialize(environment = 'development') ⇒ Deployment
constructor
A new instance of Deployment.
- #upload_assets ⇒ Object
Constructor Details
#initialize(environment = 'development') ⇒ Deployment
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/em-deploy/deployment.rb', line 58 def initialize(environment='development') puts %x(tput civis) json = JSON.parse( File.read('./deploy.json') ) custom = {} = {} [:aws] = { region: 'us-east-1' } [:redis] = { host: '127.0.0.1', port: 6379 } [:environment] = environment if json[environment] json[environment].each do |k,v| if v.class == Hash custom[k.to_sym] = {} v.each { |_k,_v| custom[k.to_sym][_k.to_sym] = _v } else custom[k.to_sym] = v end end end self.config = .merge!(custom) self.revision = %x(git rev-parse --short HEAD).chomp! self.app_name = JSON.parse( File.read('./package.json') )['name'].downcase.chomp puts "Preparing to deploy #{app_name.capitalize}. Environment: #{environment} Revision: #{"#{revision}".colorize(:light_blue)}" %x(rm -rf #{}/dist) if File.directory?('./dist') build_application if File.directory?('./dist') upload_assets activate_revision end puts "\nDeployment Successful!".colorize(:light_green) puts %x(tput cnorm) end |
Instance Attribute Details
#app_name ⇒ Object
Returns the value of attribute app_name.
3 4 5 |
# File 'lib/em-deploy/deployment.rb', line 3 def app_name @app_name end |
#config ⇒ Object
Returns the value of attribute config.
3 4 5 |
# File 'lib/em-deploy/deployment.rb', line 3 def config @config end |
#revision ⇒ Object
Returns the value of attribute revision.
3 4 5 |
# File 'lib/em-deploy/deployment.rb', line 3 def revision @revision end |
Instance Method Details
#activate_revision ⇒ Object
35 36 37 38 39 |
# File 'lib/em-deploy/deployment.rb', line 35 def activate_revision redis = Redis.new(config[:redis]) redis.set(revision, File.read('./dist/index.html')) redis.set("#{app_name}:current", revision) end |
#build_application ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/em-deploy/deployment.rb', line 41 def build_application c = %w{ | / - \\ } t = Thread.new { %x(ember build --environment #{config[:environment]}) } print "\n" print "Building #{app_name.capitalize} " while t.alive? print c[0] sleep 0.1 print "\b" c.push(c.shift) end t.join puts "\n" puts "\n" end |
#upload_assets ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/em-deploy/deployment.rb', line 5 def upload_assets = ProgressBar.create(title: 'Uploading Assets', progress_mark: '='.colorize(:light_blue), length: 80) count = 0 threads = [] Dir.glob('./dist/assets/*') do |path| t = Thread.new do p = File.(path) if File.directory?(p) Dir.glob("#{p}/*") { |sub| Uploader.new(sub, config) } else Uploader.new(p, config) end end threads.push(t) end .total = threads.count .progress = count while count < threads.count do count = threads.map { |t| t unless t.alive? }.compact.count .progress = count sleep 0.2 end threads.each(&:join) !threads.map { |t| t.alive? }.compact.include?(true) end |