go-deploy 1.0.1 → 1.0.6

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: 22417099867eb15aa41105057edb556f0432097f6895efcaf17145db8d6c5823
4
- data.tar.gz: e7b8ee57f98af129a7fd195e7bd9c21a72e53604dfc8a6174fc4f43312b7a5fa
3
+ metadata.gz: 50058ed1eb8d11ed5de965b64fe7199f393f39d92e0d727ce5a11b35846dd29f
4
+ data.tar.gz: 72cd1cc0ed9a164c397cceb3914da8fcf0e0200a6ced4fa195561f68adfbab2d
5
5
  SHA512:
6
- metadata.gz: de3be640d4dbaca465d639045c1ca589d263951c87ed0b00ea5d86dffdfc159324f511af7ad368c2b860214f7fc0da5b2157f6852fe1bba6ab4b959bccbfd87c
7
- data.tar.gz: bf4d50df18a2284759181afabcaa5e3b5646445cb127552d5f6fd9a88baae35932d37e517ebbc9420e48673ed7bb5b7ca4da895b9d6c77360afd224c20b86627
6
+ metadata.gz: ca05a668523babc01f6165e53027b519ac478b441c37fdc374babf32108e993ce7df9d91926922effb265b36a1cbe50217997e1dde88d17a4f3bdfc221a4740b
7
+ data.tar.gz: bc63fa11fbb69a17009e4f63724d244687adf6bfdc322473278dbff8919a2fb88b9284ce6a4b29a5ca1f42b15cf1961635a35b556bd40272559c9a7c4edc537d
@@ -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
 
@@ -37,7 +37,7 @@ module GoDeploy
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
42
  channel.send_data "#{@config['password']}\n" if cmd[/\[sudo\]|Password/i]
43
43
  end
@@ -68,7 +68,7 @@ module GoDeploy
68
68
  # Step 5
69
69
  build_go
70
70
  # Stop 6
71
- stop_go_service_and_copy_files
71
+ copy_files
72
72
  # Stop 7
73
73
  remove_files
74
74
  # Stop 8
@@ -93,39 +93,51 @@ module GoDeploy
93
93
  end
94
94
 
95
95
  def git_check
96
+ @git_repo_url = @service['git_repo_url']
96
97
  puts 'Step 2 git:check'.green
97
- @console.exec(ssh: ssh, command: "git ls-remote #{@service['git_repo_url']} HEAD")
98
+ @console.exec(ssh: ssh, command: "git ls-remote #{@git_repo_url} HEAD")
98
99
  end
99
100
 
100
101
  def git_clone
101
102
  @deploy_to = @service['deploy_to']
102
103
  puts 'Step 3 git:clone'.green
103
104
  @console.exec(ssh: ssh, command: "mkdir -p #{@deploy_to}")
104
- @console.exec(ssh: ssh, command: "git clone #{@service['git_repo_url']} #{@deploy_to}/repo")
105
+ @console.exec(ssh: ssh, command: "git clone #{@git_repo_url} #{@deploy_to}/repo")
105
106
  # clean up files
106
107
  @service['copy_files'].each do |file_name|
107
108
  @console.exec(ssh: ssh, command: "rm -rf #{@deploy_to}/#{file_name}")
108
109
  end
109
110
  end
110
111
 
112
+ def git_update
113
+ puts 'Step 4 git:clone'.green
114
+ @console.exec(ssh: ssh, command: "cd #{@deploy_to}/repo && git remote set-url origin #{git_repo_url}")
115
+ @console.exec(ssh: ssh, command: "cd #{@deploy_to}/repo && git remote update --prune")
116
+ end
117
+
111
118
  def set_env
112
- project_env_file = "#{@deploy_to}/repo/.env"
119
+ @deploy_env_file = "#{@deploy_to}/repo/.env"
113
120
  @env_file = @service['env_file']
114
- puts 'Step 4 set:env'.green
115
- show("Uploading #{project_env_file}") if ssh.scp.upload!(@env_file, project_env_file)
121
+ puts 'Step 5 set:env'.green
122
+ @console.log(command: "Uploading #{project_env_file}") if ssh.scp.upload!(@env_file, @deploy_env_file)
116
123
  end
117
124
 
118
125
  def build_go
119
- puts 'Step 5 build:go'.green
120
- @console.exec(ssh: ssh, command: "cd #{@service['deploy_to']}/repo && go build -o #{@service['name']}")
121
- end
122
-
123
- def stop_go_service_and_copy_files
124
126
  @service_name = @service['name']
127
+ puts 'Step 6 build:go'.green
125
128
  @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")
128
- @console.exec(ssh: ssh, command: "cd #{@deploy_to}/repo && mv #{@env_file} #{@deploy_to}")
129
+
130
+ if @is_restart
131
+ @console.sudo_exec(ssh: ssh, command: "sudo systemctl stop #{@service_name}.service")
132
+ puts "\tStop #{@service_name} service".green
133
+ end
134
+
135
+ @console.exec(ssh: ssh, command: "cd #{@service['deploy_to']}/repo && go build -o #{@service_name}")
136
+ end
137
+
138
+ def copy_files
139
+ puts 'Step 7 copy files'.green
140
+ @console.exec(ssh: ssh, command: "cd #{@deploy_to}/repo && mv #{@deploy_env_file} #{@deploy_to}")
129
141
 
130
142
  @service['copy_files'].each do |file_name|
131
143
  @console.exec(ssh: ssh, command: "cd #{@deploy_to}/repo && mv #{file_name} #{@deploy_to}")
@@ -135,7 +147,7 @@ module GoDeploy
135
147
  end
136
148
 
137
149
  def remove_files
138
- puts 'Step 7 removed:files'.green
150
+ puts 'Step 8 removed:files'.green
139
151
  @console.exec(ssh: ssh, command: "cd #{@deploy_to}/repo && mv #{@service_name} #{@deploy_to}")
140
152
  @console.exec(ssh: ssh, command: "rm -rf #{@deploy_to}/repo")
141
153
  @console.exec(ssh: ssh, command: "rm -rf #{@git_wrapper_path}")
@@ -143,10 +155,9 @@ module GoDeploy
143
155
  end
144
156
 
145
157
  def start_go_service
146
- puts "Step 8 systemctl:start#{@service_name}".green
158
+ puts "Step 9 systemctl:start:#{@service_name}".green
147
159
  @console.sudo_exec(ssh: ssh, command: "sudo systemctl start #{@service_name}.service")
160
+ puts "\tStart #{@service_name} service".green
148
161
  end
149
162
  end
150
163
  end
151
-
152
- 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.1
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Saharak Manoo