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 +4 -4
- data/lib/go_deploy/console.rb +5 -5
- data/lib/go_deploy/deploy.rb +56 -30
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c385399badbee84ad7c506aa7b4655d4a8dbd24cd48a430e5942162b6ff27ae
|
4
|
+
data.tar.gz: e564f308ced04af90337ea9c1d8cb70745bb45afc9fbcf0fdd9bb8afc9683354
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2219a8c491e77b8160b5185100c1fb9450f1f1ae8b78201fba5cc0e6811f1340c0b8cc9b957a8239d96fbb96bb120a604193e381c50dcc5968666cf95c0e616f
|
7
|
+
data.tar.gz: '08b60e0511abd792efb684c3c988a8137111b771153238df31dd0a9d1b9889a8dbbd93188da54d4198674d27eb9b69d6312ec6072b6561e9ee204d1658f7681f'
|
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
|
|
@@ -30,16 +30,16 @@ module GoDeploy
|
|
30
30
|
results.all?
|
31
31
|
end
|
32
32
|
|
33
|
-
def
|
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
|
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
|
data/lib/go_deploy/deploy.rb
CHANGED
@@ -15,33 +15,29 @@ module GoDeploy
|
|
15
15
|
def initialize
|
16
16
|
super
|
17
17
|
begin
|
18
|
-
|
19
|
-
|
20
|
-
@
|
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
|
-
|
30
|
+
exit
|
25
31
|
end
|
26
32
|
end
|
27
33
|
|
28
34
|
def run
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
-
|
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
|
-
@
|
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
|
131
|
+
def copy_files
|
132
|
+
puts 'Step 6 copy files'.green
|
104
133
|
@service_name = @service['name']
|
105
|
-
|
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
|
126
|
-
@console.
|
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.
|
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:
|
82
|
+
homepage: https://rubygems.org/gems/go-deploy
|
83
83
|
licenses:
|
84
84
|
- MIT
|
85
85
|
metadata: {}
|