app_builder 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: cf31788f50e6273be39db53433a0d796a48aae60
4
- data.tar.gz: a990d3dc8a725b46e7735e27cfaed6ef44152f78
2
+ SHA256:
3
+ metadata.gz: 90d50fefbbf304f1583a317d7e75d2a7b76522f3a3853afc4f10a5a7d317e782
4
+ data.tar.gz: 6f435137c829b1f7e5228c2c773262ade74ca48afb6a8c397eb05d440d379ffd
5
5
  SHA512:
6
- metadata.gz: c55a495fcac30f0c8f9621326cdb1ee22191d60c2d14592fca38ea674d36a996cc25ed18866d9c374633e9e347ff9ffb37319d58ba2fd442e16fc38c6a6a81d6
7
- data.tar.gz: bd2be65308005e49811120eb513fac67ffc6e5585ed973b3a6a926c041a0cbdefd3c746c11a2ead24934c208d271130603fc83801407b30c6e4522051601a4be
6
+ metadata.gz: 31819cb8c80f1ff2ba9c1b6bc9f7488f67635ac310350741f7fe640846349aa489d7d5a1a08da30e1138e5b21230408d6d7e924c8bf1f9c295f7480f0ca0c63b
7
+ data.tar.gz: dccdc528227c9dae120e398dbe30a2ae48952292c825c7e1a83038f912c9189c491c1cc49d9ae81c8198c6ea57aee85704b062979dc6891f1554ad1941bed3a1
data/lib/app_builder.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require "erb"
1
2
  require "forwardable"
2
3
  require "logger"
3
4
  require "open3"
@@ -8,3 +9,4 @@ require "app_builder/config"
8
9
  require "app_builder/base"
9
10
  require "app_builder/archiver"
10
11
  require "app_builder/builder"
12
+ require "app_builder/uploader"
@@ -3,7 +3,7 @@ module AppBuilder
3
3
  extend Forwardable
4
4
 
5
5
  attr_accessor :config
6
- ::AppBuilder::Config::VALID_OPTIONS.each do |name|
6
+ ::AppBuilder::Config::PARAMETERS.each do |name|
7
7
  def_delegator :config, name
8
8
  end
9
9
 
@@ -2,7 +2,7 @@ module AppBuilder
2
2
  class Builder < Base
3
3
  def build
4
4
  archiver.archive
5
- execute("tar zcf #{File.join(build_path, 'app.tar.gz')} .", chdir: archive_path)
5
+ execute("tar zcf #{builded_src_path} .", chdir: archive_path)
6
6
  end
7
7
 
8
8
  def archiver
@@ -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
- :logger,
15
- ].freeze
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
- self.build_id = Time.now.strftime("%Y%m%d%H%M%S")
32
- self.project_name = File.basename(`git rev-parse --show-toplevel`.chomp)
33
- self.remote_repository = `git remote get-url origin`.chomp
34
- self.branch = ENV.fetch("TARGET_BRANCH", "master")
35
- self.revision = `git rev-parse #{branch}`.chomp
36
- self.working_path = File.join("/var/tmp", project_name)
37
- self.repo_path = File.join(working_path, "repo")
38
- self.archive_path = File.join(working_path, "archive", build_id)
39
- self.build_path = File.join(working_path, "build", build_id)
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
@@ -1,3 +1,3 @@
1
1
  module AppBuilder
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
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.0
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-08 00:00:00.000000000 Z
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.11
112
+ rubygems_version: 2.7.6
111
113
  signing_key:
112
114
  specification_version: 4
113
115
  summary: Application build utilities.