go-deploy 1.0.1 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/go_deploy/console.rb +3 -3
- data/lib/go_deploy/deploy.rb +29 -18
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50058ed1eb8d11ed5de965b64fe7199f393f39d92e0d727ce5a11b35846dd29f
|
4
|
+
data.tar.gz: 72cd1cc0ed9a164c397cceb3914da8fcf0e0200a6ced4fa195561f68adfbab2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca05a668523babc01f6165e53027b519ac478b441c37fdc374babf32108e993ce7df9d91926922effb265b36a1cbe50217997e1dde88d17a4f3bdfc221a4740b
|
7
|
+
data.tar.gz: bc63fa11fbb69a17009e4f63724d244687adf6bfdc322473278dbff8919a2fb88b9284ce6a4b29a5ca1f42b15cf1961635a35b556bd40272559c9a7c4edc537d
|
data/lib/go_deploy/console.rb
CHANGED
@@ -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
|
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
|
data/lib/go_deploy/deploy.rb
CHANGED
@@ -68,7 +68,7 @@ module GoDeploy
|
|
68
68
|
# Step 5
|
69
69
|
build_go
|
70
70
|
# Stop 6
|
71
|
-
|
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 #{@
|
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 #{@
|
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
|
-
|
119
|
+
@deploy_env_file = "#{@deploy_to}/repo/.env"
|
113
120
|
@env_file = @service['env_file']
|
114
|
-
puts 'Step
|
115
|
-
|
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
|
-
|
127
|
-
|
128
|
-
|
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
|
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
|
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
|