go-deploy 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c5e7e9730a45edefb5dca3888e984b9c4c57520be8d488b412325540dd8fbbf
4
- data.tar.gz: 431652eb8564fb76a5ae0adf1c6db5310853003b1180f2a86e7e33b263b5537e
3
+ metadata.gz: 22417099867eb15aa41105057edb556f0432097f6895efcaf17145db8d6c5823
4
+ data.tar.gz: e7b8ee57f98af129a7fd195e7bd9c21a72e53604dfc8a6174fc4f43312b7a5fa
5
5
  SHA512:
6
- metadata.gz: 8bbff13e4e0c60685b93fdffb2fd9a3d35dc82da49e7aa7e031461dc7a5499d07d23582dbe1d1ac3b70a79fb304128fd2fc672fc3da5747ccb41c413333def5a
7
- data.tar.gz: cad8f6abc2e2f45103ada5a6465df95320e7c53b655fb1c9309d5b8c72bcb5c9b995242d2ca9003b895b8fc83790e1c428a540c4d3485b0bd67c62880d136a77
6
+ metadata.gz: de3be640d4dbaca465d639045c1ca589d263951c87ed0b00ea5d86dffdfc159324f511af7ad368c2b860214f7fc0da5b2157f6852fe1bba6ab4b959bccbfd87c
7
+ data.tar.gz: bf4d50df18a2284759181afabcaa5e3b5646445cb127552d5f6fd9a88baae35932d37e517ebbc9420e48673ed7bb5b7ca4da895b9d6c77360afd224c20b86627
@@ -30,7 +30,7 @@ module GoDeploy
30
30
  results.all?
31
31
  end
32
32
 
33
- def sudo(ssh:, command:, password: '', is_show_color: true)
33
+ def sudo_exec(ssh:, command:, is_show_color: true)
34
34
  ssh.open_channel do |channel|
35
35
  channel.request_pty do |_c, success|
36
36
  raise 'Could not request pty' unless success
@@ -39,7 +39,7 @@ module GoDeploy
39
39
  channel.on_data do |_c, cmd|
40
40
  log(command: cmd, is_show_remote_name: false) if is_show_color
41
41
 
42
- channel.send_data "#{password}\n" if cmd[/\[sudo\]|Password/i]
42
+ channel.send_data "#{@config['password']}\n" if cmd[/\[sudo\]|Password/i]
43
43
  end
44
44
  end
45
45
  end
@@ -15,17 +15,48 @@ module GoDeploy
15
15
  def initialize
16
16
  super
17
17
  begin
18
- file_name = ARGV[0] || 'production'
19
- self.config = YAML.load_file(File.join(__dir__, "#{file_name}.yaml"))
20
- @console = Console.new config
18
+ error_message = 'Please specify an order e.g.go-deploy production deploy or go-deploy production logs'
19
+ @file_name = ARGV[0]
20
+ @action = ARGV[1]
21
+ puts error_message.red and exit if @file_name.nil? && @action.nil?
22
+
23
+ yaml_file = File.join(Dir.pwd, "#{@file_name}.yaml")
24
+
25
+ self.config = YAML.load_file(yaml_file)
26
+ @console = Console.new(config)
21
27
  @service = config['service']
22
28
  rescue StandardError => e
23
29
  puts e.message.red
24
- raise
30
+ exit
25
31
  end
26
32
  end
27
33
 
28
34
  def run
35
+ case @action.upcase
36
+ when 'DEPLOY'
37
+ deploy_go
38
+ when 'LOGS'
39
+ logs
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ def ssh
46
+ return @ssh if defined? @ssh
47
+
48
+ @ssh = Net::SSH.start(config['host'], config['user'], ssh_options)
49
+ end
50
+
51
+ def ssh_options
52
+ {
53
+ keys: [config['passphrase']],
54
+ forward_agent: true,
55
+ paranoid: true
56
+ }
57
+ end
58
+
59
+ def deploy_go
29
60
  # Step 1
30
61
  wrapper
31
62
  # Step 2
@@ -41,23 +72,12 @@ module GoDeploy
41
72
  # Stop 7
42
73
  remove_files
43
74
  # Stop 8
44
- start_go_service
45
- end
46
-
47
- private
48
-
49
- def ssh
50
- return @ssh if defined? @ssh
51
-
52
- @ssh = Net::SSH.start(config['host'], config['user'], ssh_options)
75
+ start_go_service if @is_restart
53
76
  end
54
77
 
55
- def ssh_options
56
- {
57
- keys: [config['passphrase']],
58
- forward_agent: true,
59
- paranoid: true
60
- }
78
+ def logs
79
+ @service_name = @service['name']
80
+ @console.sudo_exec(ssh: ssh, command: "sudo journalctl -u #{@service_name}.service -f", is_show_color: false)
61
81
  end
62
82
 
63
83
  def wrapper
@@ -102,8 +122,9 @@ module GoDeploy
102
122
 
103
123
  def stop_go_service_and_copy_files
104
124
  @service_name = @service['name']
105
- puts "Step 6 systemctl:stop:#{@service_name}".green
106
- @console.exec(ssh: ssh, command: "cd #{@deploy_to}/repo && sudo systemctl stop #{@service_name}.service")
125
+ @is_restart = @service['is_restart']
126
+ puts "Step 6 systemctl:stop:#{@service_name}".green if @is_restart
127
+ @console.sudo_exec(ssh: ssh, command: "sudo systemctl stop #{@service_name}.service")
107
128
  @console.exec(ssh: ssh, command: "cd #{@deploy_to}/repo && mv #{@env_file} #{@deploy_to}")
108
129
 
109
130
  @service['copy_files'].each do |file_name|
@@ -123,7 +144,7 @@ module GoDeploy
123
144
 
124
145
  def start_go_service
125
146
  puts "Step 8 systemctl:start#{@service_name}".green
126
- @console.exec(ssh: ssh, command: "sudo systemctl start #{@service_name}.service")
147
+ @console.sudo_exec(ssh: ssh, command: "sudo systemctl start #{@service_name}.service")
127
148
  end
128
149
  end
129
150
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: go-deploy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Saharak Manoo
@@ -79,7 +79,7 @@ files:
79
79
  - lib/go_deploy/console.rb
80
80
  - lib/go_deploy/deploy.rb
81
81
  - lib/go_deploy/string.rb
82
- homepage: http://rubygems.org/gems/go-deploy
82
+ homepage: https://rubygems.org/gems/go-deploy
83
83
  licenses:
84
84
  - MIT
85
85
  metadata: {}