Class: Deploy::Deployer

Inherits:
Thor
  • Object
show all
Includes:
Output
Defined in:
lib/deploy/deployer.rb

Instance Method Summary collapse

Methods included from Output

#colorize, #green, #pink, #red, #shout, #yellow

Instance Method Details

#deployObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/deploy/deployer.rb', line 26

def deploy
  check_setup

  environment = options[:environment]
  build = options[:build]

  version = options[:version]
  (shout('You must pass a version with -v'); exit(1)) unless version

  repo = ENV['DOCKER_REPO']

  if build
    announce({ color: '#6080C0', title: "Deployment started with build", text: "Deploying version #{version} to #{environment || 'stage'}" })
    build_image(repo, version)

    tag_image_as_latest(repo, version)

    push_image(repo, version)
    push_image(repo, 'latest')
  else
    announce({ color: '#6080C0', title: "Deployment started without build", text: "Deploying version #{version} to #{environment || 'stage'}" })
  end

  run_deploy(version, environment)
  announce({ color: 'good', title: 'Deployment Succeeded!!', text: "The current version of #{environment || 'stage'} is #{version}" })
end

#rollbackObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/deploy/deployer.rb', line 56

def rollback
  check_setup

  environment = options[:environment]
  version = options[:version]
  (shout('You must pass a version with -v'); exit(1)) unless version

  repo = ENV['DOCKER_REPO']

  announce({ color: '#6080C0', title: "Rollback started", text: "Rolling back to #{version} on #{environment || 'stage'}" })

  pull_image(repo, version)

  tag_image_as_latest(repo, version)

  push_image(repo, 'latest')

  run_rollback(version, environment)
  announce({ color: 'good', title: 'Rollback Succeeded!!', text: "The current version of #{environment || 'stage'} is #{version}" })
end

#setupObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/deploy/deployer.rb', line 6

def setup
  (shout('AWS creds already configured at ~/.aws/config.'); exit(1)) if File.exist?(File.expand_path('~/.aws/config'))

  key = ask('Enter AWS Key:')
  secret = ask('Enter AWS Secret:')

  Dir.mkdir(File.expand_path('~/.aws'))

  File.open(File.expand_path('~/.aws/config'), 'w') do |f|
    f.puts '[default]'
    f.puts "aws_access_key_id = #{key}"
    f.puts "aws_secret_access_key = #{secret}"
  end
  shout('AWS creds successfully configured at ~/.aws/config.') if File.exist?(File.expand_path('~/.aws/config'))
end

#test_slackObject



78
79
80
# File 'lib/deploy/deployer.rb', line 78

def test_slack
  notifier('', { color: 'good', title: 'This is a test notification from eb-docker-deploy.' })
end