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 +4 -4
- data/lib/app_builder/archiver.rb +5 -11
- data/lib/app_builder/base.rb +25 -0
- data/lib/app_builder/builder.rb +3 -1
- data/lib/app_builder/config.rb +40 -29
- data/lib/app_builder/uploader.rb +5 -3
- data/lib/app_builder/version.rb +1 -1
- 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: 149fe7ac668f0ea948e2af2e8b9aae387ac6ef1cac4592bf1177ff4e0f2ecf61
|
4
|
+
data.tar.gz: 67988388e57e2ec2497b4af7afbdde4461286ba380393f8c670cacd534839c4f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f235767dd93845ffd8c14ea5de871bc40c6015e283fad6853f823fd4c9039dde72e8c5db52995f33bbea08c3726ca7d2a468d7ddb65f8f0b3c0a5851cb26976
|
7
|
+
data.tar.gz: 43f9111c90199bdbabbf2d7bd3862ed58f254be6864bc1052e12e4e6680bbb22627836c4d1852d9402f7afc253c8e467684d1dbbbeb1769b5e7fba4a78833c27
|
data/lib/app_builder/archiver.rb
CHANGED
@@ -7,18 +7,12 @@ module AppBuilder
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def archive
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
data/lib/app_builder/base.rb
CHANGED
@@ -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
|
data/lib/app_builder/builder.rb
CHANGED
data/lib/app_builder/config.rb
CHANGED
@@ -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,
|
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
|
-
:
|
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
|
-
|
68
|
+
"#{build_id}.tar.gz"
|
68
69
|
end
|
69
70
|
|
70
71
|
def manifest_name
|
71
|
-
|
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
|
-
@
|
128
|
-
@manifest_ext = "yml"
|
125
|
+
@remote_src_path = "assets"
|
129
126
|
@manifest_template_path = File.expand_path("template/manifest.yml.erb", __dir__)
|
130
|
-
@
|
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
|
137
|
-
@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")),
|
data/lib/app_builder/uploader.rb
CHANGED
@@ -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
|
-
|
28
|
-
|
29
|
-
|
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)
|
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.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
|
+
date: 2018-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: net-ssh
|