app_builder 0.1.0 → 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 +5 -5
- data/lib/app_builder.rb +2 -0
- data/lib/app_builder/base.rb +1 -1
- data/lib/app_builder/builder.rb +1 -1
- data/lib/app_builder/config.rb +75 -13
- data/lib/app_builder/template/manifest.yml.erb +21 -0
- data/lib/app_builder/uploader.rb +43 -0
- data/lib/app_builder/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 90d50fefbbf304f1583a317d7e75d2a7b76522f3a3853afc4f10a5a7d317e782
|
4
|
+
data.tar.gz: 6f435137c829b1f7e5228c2c773262ade74ca48afb6a8c397eb05d440d379ffd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31819cb8c80f1ff2ba9c1b6bc9f7488f67635ac310350741f7fe640846349aa489d7d5a1a08da30e1138e5b21230408d6d7e924c8bf1f9c295f7480f0ca0c63b
|
7
|
+
data.tar.gz: dccdc528227c9dae120e398dbe30a2ae48952292c825c7e1a83038f912c9189c491c1cc49d9ae81c8198c6ea57aee85704b062979dc6891f1554ad1941bed3a1
|
data/lib/app_builder.rb
CHANGED
data/lib/app_builder/base.rb
CHANGED
data/lib/app_builder/builder.rb
CHANGED
data/lib/app_builder/config.rb
CHANGED
@@ -6,13 +6,29 @@ module AppBuilder
|
|
6
6
|
:remote_repository,
|
7
7
|
:branch,
|
8
8
|
:revision,
|
9
|
+
:src_base_url,
|
10
|
+
:manifest_base_url,
|
11
|
+
:remote_src_path,
|
12
|
+
:remote_manifest_path,
|
13
|
+
:manifest_template_path,
|
14
|
+
:resource_host,
|
15
|
+
:ssh_user,
|
16
|
+
:identity_file,
|
17
|
+
:logger,
|
18
|
+
].freeze
|
19
|
+
|
20
|
+
PARAMETERS = [
|
9
21
|
:working_path,
|
10
22
|
:repo_path,
|
11
23
|
:archive_path,
|
12
24
|
:build_path,
|
25
|
+
:builded_src_path,
|
26
|
+
:builded_manifest_path,
|
13
27
|
:revision_path,
|
14
|
-
:
|
15
|
-
|
28
|
+
:src_url,
|
29
|
+
:manifest_url,
|
30
|
+
:remote_app_home,
|
31
|
+
].concat(VALID_OPTIONS).freeze
|
16
32
|
|
17
33
|
attr_accessor *VALID_OPTIONS
|
18
34
|
|
@@ -27,18 +43,64 @@ module AppBuilder
|
|
27
43
|
self
|
28
44
|
end
|
29
45
|
|
46
|
+
def build_name
|
47
|
+
"#{build_id}.tar.gz"
|
48
|
+
end
|
49
|
+
|
50
|
+
def manifest_name
|
51
|
+
"#{build_id}.yml"
|
52
|
+
end
|
53
|
+
|
54
|
+
def working_path
|
55
|
+
File.join("/var/tmp", project_name)
|
56
|
+
end
|
57
|
+
|
58
|
+
def repo_path
|
59
|
+
File.join(working_path, "repo")
|
60
|
+
end
|
61
|
+
|
62
|
+
def archive_path
|
63
|
+
File.join(working_path, "archive", build_id)
|
64
|
+
end
|
65
|
+
|
66
|
+
def build_path
|
67
|
+
File.join(working_path, "build", build_id)
|
68
|
+
end
|
69
|
+
|
70
|
+
def builded_src_path
|
71
|
+
File.join(build_path, build_name)
|
72
|
+
end
|
73
|
+
|
74
|
+
def builded_manifest_path
|
75
|
+
File.join(build_path, manifest_name)
|
76
|
+
end
|
77
|
+
|
78
|
+
def revision_path
|
79
|
+
File.join(archive_path, "revision.yml")
|
80
|
+
end
|
81
|
+
|
82
|
+
def src_url
|
83
|
+
File.join(src_base_url, build_name)
|
84
|
+
end
|
85
|
+
|
86
|
+
def manifest_url
|
87
|
+
File.join(manifest_base_url, build_name)
|
88
|
+
end
|
89
|
+
|
90
|
+
def remote_app_home
|
91
|
+
File.join("/var/www", project_name)
|
92
|
+
end
|
93
|
+
|
30
94
|
def reset
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
self.revision_path = File.join(archive_path, "revision.yml")
|
41
|
-
self.logger = Logger.new(STDOUT)
|
95
|
+
@build_id = Time.now.strftime("%Y%m%d%H%M%S")
|
96
|
+
@project_name = File.basename(`git rev-parse --show-toplevel`.chomp)
|
97
|
+
@remote_repository = `git remote get-url origin`.chomp
|
98
|
+
@branch = ENV.fetch("TARGET_BRANCH", "master")
|
99
|
+
@revision = `git rev-parse #{branch}`.chomp
|
100
|
+
@manifest_template_path = File.expand_path("template/manifest.yml.erb", __dir__)
|
101
|
+
@ssh_user = ENV.fetch("USER", nil)
|
102
|
+
@identity_file = "~/.ssh/id_rsa"
|
103
|
+
@logger = Logger.new(STDOUT)
|
42
104
|
end
|
43
105
|
end
|
44
106
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
src: <%= src_url %>
|
2
|
+
checksum: <%= checksum %>
|
3
|
+
dest: <%= remote_app_home %>/releases/<%= build_id %>
|
4
|
+
commands:
|
5
|
+
pre:
|
6
|
+
- echo 'staring deploy'
|
7
|
+
post:
|
8
|
+
- ln -nfs <%= remote_app_home %>/releases/<%= build_id %> <%= remote_app_home %>/current
|
9
|
+
- rm -rf <%= remote_app_home %>/current/log
|
10
|
+
- ln -nfs <%= remote_app_home %>/shared/log <%= remote_app_home %>/current/log
|
11
|
+
- mkdir -p <%= remote_app_home %>/current/tmp
|
12
|
+
- ln -nfs <%= remote_app_home %>/shared/pids <%= remote_app_home %>/current/tmp/pids
|
13
|
+
- echo 'deploy done'
|
14
|
+
success:
|
15
|
+
- echo 'deploy success'
|
16
|
+
failure:
|
17
|
+
- echo 'deploy failed!!'
|
18
|
+
- cat >> /path/to/failure.log
|
19
|
+
excludes:
|
20
|
+
- "*.pid"
|
21
|
+
- "*.socket"
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module AppBuilder
|
2
|
+
class Uploader < Base
|
3
|
+
def upload
|
4
|
+
builder.build
|
5
|
+
if s3?(src_url)
|
6
|
+
upload_to_s3(builded_src_path, src_url)
|
7
|
+
else
|
8
|
+
upload_to_server(builded_src_path, remote_src_path)
|
9
|
+
end
|
10
|
+
|
11
|
+
generate_manifest
|
12
|
+
if s3?(manifest_url)
|
13
|
+
upload_to_s3(builded_manifest_path, manifest_url)
|
14
|
+
else
|
15
|
+
upload_to_server(builded_manifest_path, remote_manifest_path)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def upload_to_s3(local, remote)
|
20
|
+
execute("aws s3 cp #{local} #{remote}")
|
21
|
+
end
|
22
|
+
|
23
|
+
def upload_to_server(local, remote)
|
24
|
+
execute("scp -i #{identity_file} #{local} #{ssh_user}@#{resource_host}:#{remote}")
|
25
|
+
end
|
26
|
+
|
27
|
+
def generate_manifest
|
28
|
+
checksum = `openssl sha256 #{builded_src_path} | awk -F"=" '{ print $2 }'`.strip
|
29
|
+
manifest = ERB.new(File.read(manifest_template_path)).result(binding)
|
30
|
+
File.open(builded_manifest_path, "w") { |f| f.write(manifest) }
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def s3?(url)
|
36
|
+
url.to_s.start_with?("s3://")
|
37
|
+
end
|
38
|
+
|
39
|
+
def builder
|
40
|
+
@builder || Builder.new(config)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/app_builder/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: app_builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- i2bskn
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-07-
|
11
|
+
date: 2018-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -87,6 +87,8 @@ files:
|
|
87
87
|
- lib/app_builder/base.rb
|
88
88
|
- lib/app_builder/builder.rb
|
89
89
|
- lib/app_builder/config.rb
|
90
|
+
- lib/app_builder/template/manifest.yml.erb
|
91
|
+
- lib/app_builder/uploader.rb
|
90
92
|
- lib/app_builder/version.rb
|
91
93
|
homepage: https://github.com/i2bskn/app_builder
|
92
94
|
licenses: []
|
@@ -107,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
109
|
version: '0'
|
108
110
|
requirements: []
|
109
111
|
rubyforge_project:
|
110
|
-
rubygems_version: 2.6
|
112
|
+
rubygems_version: 2.7.6
|
111
113
|
signing_key:
|
112
114
|
specification_version: 4
|
113
115
|
summary: Application build utilities.
|