rails_deploy 0.1.1
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 +7 -0
- data/README.md +1 -0
- data/lib/deploy.rb +113 -0
- metadata +73 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 92931eebe8d0a513ad0d5238770eb47b75ed29a52e0057ccd00de5403b15dcb6
|
4
|
+
data.tar.gz: ef94e8d3cdb8814e5d6a1208388220fd63be1d9ac4b1eb69068b3be42f792345
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bbfa75b58508249217e6a70d1daae6d993cb74b2a7cda625b2ffb11ad1513f31e97b3591ba9110648001a67fb8cb26210c58b76387c8018c82f1fc5414a0fd88
|
7
|
+
data.tar.gz: d56ea4f405da35a81e35556155a0c0ca5087b6db88f0670e5bd78af40f3bdff54fb49b304f8b539dca53cf821723ad3adcca2740298bcf77226a4c15dc4bb73a
|
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# 快速部署工具
|
data/lib/deploy.rb
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'open3'
|
4
|
+
require 'optparse'
|
5
|
+
require 'pathname'
|
6
|
+
require 'logger'
|
7
|
+
|
8
|
+
module Deploy
|
9
|
+
MOVED_DIRS = [
|
10
|
+
'log',
|
11
|
+
'tmp',
|
12
|
+
]
|
13
|
+
SHARED_DIRS = [
|
14
|
+
'public/assets',
|
15
|
+
'public/fonts',
|
16
|
+
'vendor/bundle'
|
17
|
+
].freeze
|
18
|
+
SHARED_FILES = [
|
19
|
+
'config/credentials/production.key'
|
20
|
+
].freeze
|
21
|
+
INIT_DIRS = [
|
22
|
+
'tmp/sockets',
|
23
|
+
'tmp/pids',
|
24
|
+
'config/credentials'
|
25
|
+
].freeze
|
26
|
+
extend self
|
27
|
+
|
28
|
+
def restart
|
29
|
+
exec_cmd('bundle exec pumactl restart')
|
30
|
+
end
|
31
|
+
|
32
|
+
def github_hmac(data)
|
33
|
+
OpenSSL::HMAC.hexdigest('sha1', RailsCom.config.github_hmac_key, data)
|
34
|
+
end
|
35
|
+
|
36
|
+
def init_shared_paths(root = Pathname.pwd.join('../shared'))
|
37
|
+
dirs = []
|
38
|
+
dirs += MOVED_DIRS.map { |dir| root.join(dir) }
|
39
|
+
dirs += SHARED_DIRS.map { |dir| root.join(dir) }
|
40
|
+
dirs += INIT_DIRS.map { |dir| root.join(dir) }
|
41
|
+
FileUtils.mkdir_p dirs
|
42
|
+
|
43
|
+
SHARED_FILES.map do |path|
|
44
|
+
`touch #{root.join(path)}`
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def ln_shared_paths(root = Pathname.pwd)
|
49
|
+
cmds = []
|
50
|
+
cmds << 'bundle config set --local deployment true'
|
51
|
+
cmds << 'bundle config set --local path vendor/bundle'
|
52
|
+
cmds << 'bundle config set --local without development test'
|
53
|
+
cmds += MOVED_DIRS.map do |path|
|
54
|
+
"rm -rf #{root.join(path)}"
|
55
|
+
end
|
56
|
+
cmds += (MOVED_DIRS + SHARED_DIRS).map do |path|
|
57
|
+
"ln -Tsfv #{root.join('../shared', path)} #{root.join(path)}"
|
58
|
+
end
|
59
|
+
cmds += SHARED_FILES.map do |path|
|
60
|
+
"ln -Tsfv #{root.join('../shared', path)} #{root.join(path)}"
|
61
|
+
end
|
62
|
+
cmds.each do |cmd|
|
63
|
+
exec_cmd(cmd)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def exec_cmds(env = 'production', added_cmds: [])
|
68
|
+
start_at = Time.now
|
69
|
+
logger.debug "Deploy at #{start_at}"
|
70
|
+
cmds = [
|
71
|
+
'whoami',
|
72
|
+
'git pull',# --recurse-submodules
|
73
|
+
'bundle install'
|
74
|
+
]
|
75
|
+
cmds << "RAILS_ENV=#{env} bundle exec rake db:migrate"
|
76
|
+
cmds << 'bundle exec pumactl restart'
|
77
|
+
cmds += Array(added_cmds)
|
78
|
+
cmds.each do |cmd|
|
79
|
+
exec_cmd(cmd)
|
80
|
+
end
|
81
|
+
finish_at = Time.now
|
82
|
+
logger.debug "Deploy finished at #{finish_at}, used: #{finish_at - start_at}s"
|
83
|
+
end
|
84
|
+
|
85
|
+
def exec_cmd(cmd)
|
86
|
+
Open3.popen2e(cmd) do |_, output, thread|
|
87
|
+
logger.debug "\e[35m #{cmd} (PID: #{thread.pid}) \e[0m"
|
88
|
+
output.each_line do |line|
|
89
|
+
logger.debug " #{line.chomp}"
|
90
|
+
end
|
91
|
+
puts "\n"
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def logger
|
96
|
+
if defined? Rails
|
97
|
+
Rails.logger
|
98
|
+
else
|
99
|
+
Logger.new $stdout
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
options = { env: 'production' }
|
106
|
+
OptionParser.new do |opts|
|
107
|
+
opts.on('-e ENV') do |v|
|
108
|
+
options[:env] = v
|
109
|
+
end
|
110
|
+
opts.on('-C') do |v|
|
111
|
+
puts "--------->#{v}"
|
112
|
+
end
|
113
|
+
end.parse!
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails_deploy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- qinmingyuan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-07-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Deploy from server
|
42
|
+
email:
|
43
|
+
- mingyuan0715@foxmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- README.md
|
49
|
+
- lib/deploy.rb
|
50
|
+
homepage: https://github.com/work-design/rails_deploy
|
51
|
+
licenses:
|
52
|
+
- MIT
|
53
|
+
metadata: {}
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
requirements: []
|
69
|
+
rubygems_version: 3.4.10
|
70
|
+
signing_key:
|
71
|
+
specification_version: 4
|
72
|
+
summary: Deploy from server
|
73
|
+
test_files: []
|