go-deploy 1.0.0 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c5e7e9730a45edefb5dca3888e984b9c4c57520be8d488b412325540dd8fbbf
4
- data.tar.gz: 431652eb8564fb76a5ae0adf1c6db5310853003b1180f2a86e7e33b263b5537e
3
+ metadata.gz: 9c385399badbee84ad7c506aa7b4655d4a8dbd24cd48a430e5942162b6ff27ae
4
+ data.tar.gz: e564f308ced04af90337ea9c1d8cb70745bb45afc9fbcf0fdd9bb8afc9683354
5
5
  SHA512:
6
- metadata.gz: 8bbff13e4e0c60685b93fdffb2fd9a3d35dc82da49e7aa7e031461dc7a5499d07d23582dbe1d1ac3b70a79fb304128fd2fc672fc3da5747ccb41c413333def5a
7
- data.tar.gz: cad8f6abc2e2f45103ada5a6465df95320e7c53b655fb1c9309d5b8c72bcb5c9b995242d2ca9003b895b8fc83790e1c428a540c4d3485b0bd67c62880d136a77
6
+ metadata.gz: 2219a8c491e77b8160b5185100c1fb9450f1f1ae8b78201fba5cc0e6811f1340c0b8cc9b957a8239d96fbb96bb120a604193e381c50dcc5968666cf95c0e616f
7
+ data.tar.gz: '08b60e0511abd792efb684c3c988a8137111b771153238df31dd0a9d1b9889a8dbbd93188da54d4198674d27eb9b69d6312ec6072b6561e9ee204d1658f7681f'
@@ -7,8 +7,8 @@ module GoDeploy
7
7
  @config = config
8
8
  end
9
9
 
10
- def log(command:, is_show_remote_name: true)
11
- puts "\t#{command}".yellow
10
+ def log(command:, is_show_remote_name: true, is_show_color: true)
11
+ puts is_show_color ? "\t#{command}".yellow : "\t#{command}"
12
12
  show_remote_name if is_show_remote_name
13
13
  end
14
14
 
@@ -30,16 +30,16 @@ 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
37
37
 
38
38
  channel.exec(command)
39
39
  channel.on_data do |_c, cmd|
40
- log(command: cmd, is_show_remote_name: false) if is_show_color
40
+ log(command: cmd, is_show_remote_name: false, is_show_color: 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,33 +15,29 @@ 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
29
- # Step 1
30
- wrapper
31
- # Step 2
32
- git_check
33
- # Step 3
34
- git_clone
35
- # Step 4
36
- set_env
37
- # Step 5
38
- build_go
39
- # Stop 6
40
- stop_go_service_and_copy_files
41
- # Stop 7
42
- remove_files
43
- # Stop 8
44
- start_go_service
35
+ case @action.upcase
36
+ when 'DEPLOY'
37
+ deploy_go
38
+ when 'LOGS'
39
+ logs
40
+ end
45
41
  end
46
42
 
47
43
  private
@@ -60,6 +56,30 @@ module GoDeploy
60
56
  }
61
57
  end
62
58
 
59
+ def deploy_go
60
+ # Step 1
61
+ wrapper
62
+ # Step 2
63
+ git_check
64
+ # Step 3
65
+ git_clone
66
+ # Step 4
67
+ set_env
68
+ # Step 5
69
+ build_go
70
+ # Stop 6
71
+ copy_files
72
+ # Stop 7
73
+ remove_files
74
+ # Stop 8
75
+ start_go_service if @is_restart
76
+ end
77
+
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)
81
+ end
82
+
63
83
  def wrapper
64
84
  puts 'Step 1 git:wrapper'.green
65
85
  @git_ssh_name = "git-ssh-#{SecureRandom.hex(10)}.sh"
@@ -92,19 +112,26 @@ module GoDeploy
92
112
  project_env_file = "#{@deploy_to}/repo/.env"
93
113
  @env_file = @service['env_file']
94
114
  puts 'Step 4 set:env'.green
95
- show("Uploading #{project_env_file}") if ssh.scp.upload!(@env_file, project_env_file)
115
+ @console.log(command: "Uploading #{project_env_file}") if ssh.scp.upload!(@env_file, project_env_file)
96
116
  end
97
117
 
98
118
  def build_go
119
+ @service_name = @service['name']
99
120
  puts 'Step 5 build:go'.green
100
- @console.exec(ssh: ssh, command: "cd #{@service['deploy_to']}/repo && go build -o #{@service['name']}")
121
+ @is_restart = @service['is_restart']
122
+
123
+ if @is_restart
124
+ @console.sudo_exec(ssh: ssh, command: "sudo systemctl stop #{@service_name}.service")
125
+ puts "\tStop #{@service_name} service".green
126
+ end
127
+
128
+ @console.exec(ssh: ssh, command: "cd #{@service['deploy_to']}/repo && go build -o #{@service_name}")
101
129
  end
102
130
 
103
- def stop_go_service_and_copy_files
131
+ def copy_files
132
+ puts 'Step 6 copy files'.green
104
133
  @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")
107
- @console.exec(ssh: ssh, command: "cd #{@deploy_to}/repo && mv #{@env_file} #{@deploy_to}")
134
+ @console.exec(ssh: ssh, command: "cd #{@deploy_to}/repo && mv .env #{@deploy_to}")
108
135
 
109
136
  @service['copy_files'].each do |file_name|
110
137
  @console.exec(ssh: ssh, command: "cd #{@deploy_to}/repo && mv #{file_name} #{@deploy_to}")
@@ -122,10 +149,9 @@ module GoDeploy
122
149
  end
123
150
 
124
151
  def start_go_service
125
- puts "Step 8 systemctl:start#{@service_name}".green
126
- @console.exec(ssh: ssh, command: "sudo systemctl start #{@service_name}.service")
152
+ puts "Step 8 systemctl:start:#{@service_name}".green
153
+ @console.sudo_exec(ssh: ssh, command: "sudo systemctl start #{@service_name}.service")
154
+ puts "\tStart #{@service_name} service".green
127
155
  end
128
156
  end
129
157
  end
130
-
131
- GoDeploy::Deploy.new.run
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.5
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: {}