app_builder 0.1.4 → 0.1.5

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
2
  SHA256:
3
- metadata.gz: 17ce5dd23729388a0087da20a784ff3b816f8c57fba31ca57f3e721e1a7ffdcf
4
- data.tar.gz: a88df3a875b6a397cc1c1035628bea75ae59712130f6b952c57a173408c92387
3
+ metadata.gz: 149fe7ac668f0ea948e2af2e8b9aae387ac6ef1cac4592bf1177ff4e0f2ecf61
4
+ data.tar.gz: 67988388e57e2ec2497b4af7afbdde4461286ba380393f8c670cacd534839c4f
5
5
  SHA512:
6
- metadata.gz: 7bfc464fb1677988dc93858de377d3497fdf4cb470e6adfbf4ca20ba8d0586100f162e70c4b28579a35280215b9cf5f78cfdd96c6c3a4c584dbecdecf02bd121
7
- data.tar.gz: 211e70acaf02d62d8e4077f158f2952b57a89a3e6a4d66fa10e9f0ab763d6bc18b522442c65bef511dc6d5c1e3365764b20b5076369303352fd8738953fde193
6
+ metadata.gz: 3f235767dd93845ffd8c14ea5de871bc40c6015e283fad6853f823fd4c9039dde72e8c5db52995f33bbea08c3726ca7d2a468d7ddb65f8f0b3c0a5851cb26976
7
+ data.tar.gz: 43f9111c90199bdbabbf2d7bd3862ed58f254be6864bc1052e12e4e6680bbb22627836c4d1852d9402f7afc253c8e467684d1dbbbeb1769b5e7fba4a78833c27
@@ -7,18 +7,12 @@ module AppBuilder
7
7
  end
8
8
 
9
9
  def archive
10
- execute("mkdir -p #{working_path} #{archive_path} #{build_path}")
11
- if File.exist?("#{repo_path}/HEAD")
12
- execute("git remote update", chdir: repo_path)
13
- else
14
- execute("git clone --mirror #{remote_repository} #{repo_path}")
10
+ create_base_directories
11
+ update_repository
12
+ execute_with_hooks(:archive) do
13
+ execute("git archive #{branch} | tar -x -C #{archive_path}", chdir: repo_path)
14
+ create_revision_to(revision_path)
15
15
  end
16
-
17
- execute("git archive #{branch} | tar -x -C #{archive_path}", chdir: repo_path)
18
-
19
- rev_hash = { "branch" => branch, "revision" => revision }
20
- File.open(revision_path, "w") { |f| f.write(rev_hash.to_yaml) }
21
- log(:info, "Create revision: #{rev_hash.inspect}")
22
16
  end
23
17
  end
24
18
  end
@@ -13,6 +13,31 @@ module AppBuilder
13
13
 
14
14
  private
15
15
 
16
+ def execute_with_hooks(type)
17
+ raise ArgumentError unless block_given?
18
+ Array(send("before_#{type}")).each { |hook| hook.call(self) }
19
+ yield
20
+ Array(send("after_#{type}")).each { |hook| hook.call(self) }
21
+ end
22
+
23
+ def create_base_directories
24
+ execute("mkdir -p #{working_path} #{archive_path} #{build_path}")
25
+ end
26
+
27
+ def update_repository
28
+ if File.exist?("#{repo_path}/HEAD")
29
+ execute("git remote update", chdir: repo_path)
30
+ else
31
+ execute("git clone --mirror #{remote_repository} #{repo_path}")
32
+ end
33
+ end
34
+
35
+ def create_revision_to(path)
36
+ rev_hash = { "branch" => branch, "revision" => revision }
37
+ File.open(path, "w") { |f| f.write(rev_hash.to_yaml) }
38
+ log(:info, "Create revision: #{rev_hash.inspect}")
39
+ end
40
+
16
41
  def log(level, message)
17
42
  logger&.send(level, message)
18
43
  end
@@ -19,7 +19,9 @@ module AppBuilder
19
19
 
20
20
  def build
21
21
  archiver.archive
22
- execute("tar zcf #{builded_src_path} .", chdir: archive_path)
22
+ execute_with_hooks(:build) do
23
+ execute("tar zcf #{builded_src_path} .", chdir: archive_path)
24
+ end
23
25
  end
24
26
  end
25
27
  end
@@ -1,23 +1,29 @@
1
1
  module AppBuilder
2
2
  class Config
3
3
  CHANGEABLE_PARAMETERS = [
4
- :build_id,
5
- :project_name,
6
- :remote_repository,
7
- :branch,
8
- :revision,
9
- :upload_type,
10
- :upload_id, # bucket name or remote host
11
- :logger,
4
+ :build_id, # default: timestamp
5
+ :project_name, # default: repository name
6
+ :remote_repository, # default: remote origin
7
+ :branch, # default: TARGET_BRANCH or master
8
+ :revision, # default: commit hash
9
+ :upload_type, # :s3 or :http or :https (default: :s3)
10
+ :upload_id, # bucket name or remote host (default: none)
11
+ :logger, # default: AppBuilder::Logger
12
+
13
+ # hooks
14
+ :before_archive,
15
+ :after_archive,
16
+ :before_build,
17
+ :after_build,
18
+ :before_upload,
19
+ :after_upload,
12
20
 
13
21
  # source
14
- :builded_src_ext,
15
- :remote_src_path,
22
+ :remote_src_path, # default: assets
16
23
 
17
24
  # manifest
18
- :manifest_template_path,
19
- :remote_manifest_path,
20
- :manifest_ext,
25
+ :manifest_template_path, # default: lib/app_builder/template/manifest.yml.erb in this repository
26
+ :remote_manifest_path, # default: manifests
21
27
 
22
28
  # Only use when upload to S3
23
29
  :region,
@@ -28,11 +34,6 @@ module AppBuilder
28
34
  :resource_host,
29
35
  :resource_user,
30
36
  :resource_ssh_options,
31
-
32
- # Only use when remote build
33
- # :build_host,
34
- # :build_user,
35
- # :build_ssh_options,
36
37
  ].freeze
37
38
 
38
39
  PARAMETERS = [
@@ -64,11 +65,11 @@ module AppBuilder
64
65
  end
65
66
 
66
67
  def build_name
67
- [build_id, builded_src_ext].join(".")
68
+ "#{build_id}.tar.gz"
68
69
  end
69
70
 
70
71
  def manifest_name
71
- [build_id, manifest_ext].join(".")
72
+ "#{build_id}.yml"
72
73
  end
73
74
 
74
75
  def working_path
@@ -116,30 +117,40 @@ module AppBuilder
116
117
  end
117
118
 
118
119
  def reset
119
- @build_host = "localhost"
120
- @build_user = ENV.fetch("USER", nil)
121
- @build_ssh_options = {}
122
120
  @build_id = Time.now.strftime("%Y%m%d%H%M%S")
123
121
  @project_name = File.basename(`git rev-parse --show-toplevel`.chomp)
124
122
  @remote_repository = `git remote get-url origin`.chomp
125
123
  @branch = ENV.fetch("TARGET_BRANCH", "master")
126
124
  @revision = `git rev-parse #{branch}`.chomp
127
- @builded_src_ext = "tar.gz"
128
- @manifest_ext = "yml"
125
+ @remote_src_path = "assets"
129
126
  @manifest_template_path = File.expand_path("template/manifest.yml.erb", __dir__)
130
- @resource_user = @build_user
127
+ @remote_manifest_path = "manifests"
128
+ @resource_user = ENV.fetch("USER", nil)
131
129
  @resource_ssh_options = {}
132
130
  @logger = Logger.new(STDOUT)
133
131
  @upload_type = :s3
134
132
 
135
- # for upload to S3
136
- @region = ENV.fetch("AWS_DEFAULT_REGION", aws_config("region") || "ap-northeast-1")
137
- @access_key_id = ENV.fetch("AWS_ACCESS_KEY_ID", aws_credential("aws_access_key_id"))
133
+ # for upload to S3 (from `.aws/config` and `.aws/credentials`)
134
+ @region = ENV.fetch("AWS_DEFAULT_REGION", aws_config("region") || "ap-northeast-1")
135
+ @access_key_id = ENV.fetch("AWS_ACCESS_KEY_ID", aws_credential("aws_access_key_id"))
138
136
  @secret_access_key = ENV.fetch("AWS_SECRET_ACCESS_KEY", aws_credential("aws_secret_access_key"))
137
+
138
+ initialize_hooks
139
139
  end
140
140
 
141
141
  private
142
142
 
143
+ def initialize_hooks
144
+ [
145
+ :@before_archive,
146
+ :@after_archive,
147
+ :@before_build,
148
+ :@after_build,
149
+ :@before_upload,
150
+ :@after_upload,
151
+ ].each { |hook_name| instance_variable_set(hook_name, []) }
152
+ end
153
+
143
154
  def aws_config(key)
144
155
  find_aws_setting_by(
145
156
  ENV.fetch("AWS_CONFIG_FILE", File.expand_path("~/.aws/config")),
@@ -24,9 +24,11 @@ module AppBuilder
24
24
  def upload
25
25
  upload_proc = s3? ? method(:upload_to_s3) : method(:upload_to_server)
26
26
  builder.build
27
- upload_proc.call(builded_src_path, remote_src_file)
28
- generate_manifest
29
- upload_proc.call(builded_manifest_path, remote_manifest_file)
27
+ execute_with_hooks(:upload) do
28
+ upload_proc.call(builded_src_path, remote_src_file)
29
+ generate_manifest
30
+ upload_proc.call(builded_manifest_path, remote_manifest_file)
31
+ end
30
32
  end
31
33
 
32
34
  def upload_to_s3(local, remote)
@@ -1,3 +1,3 @@
1
1
  module AppBuilder
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
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.4
4
+ version: 0.1.5
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 00:00:00.000000000 Z
11
+ date: 2018-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-ssh