dapp 0.0.24 → 0.1.0

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.
Files changed (78) hide show
  1. checksums.yaml +13 -5
  2. data/bin/dapp +17 -1
  3. data/config/en/common.yml +23 -0
  4. data/config/en/net_status.yml +24 -0
  5. data/lib/dapp.rb +68 -12
  6. data/lib/dapp/application.rb +57 -0
  7. data/lib/dapp/application/git_artifact.rb +26 -0
  8. data/lib/dapp/application/logging.rb +120 -0
  9. data/lib/dapp/application/path.rb +31 -0
  10. data/lib/dapp/application/tags.rb +65 -0
  11. data/lib/dapp/build/stage/app_install.rb +19 -0
  12. data/lib/dapp/build/stage/app_setup.rb +19 -0
  13. data/lib/dapp/build/stage/base.rb +106 -0
  14. data/lib/dapp/build/stage/from.rb +40 -0
  15. data/lib/dapp/build/stage/infra_install.rb +23 -0
  16. data/lib/dapp/build/stage/infra_setup.rb +19 -0
  17. data/lib/dapp/build/stage/source_1.rb +31 -0
  18. data/lib/dapp/build/stage/source_1_archive.rb +31 -0
  19. data/lib/dapp/build/stage/source_2.rb +20 -0
  20. data/lib/dapp/build/stage/source_3.rb +27 -0
  21. data/lib/dapp/build/stage/source_4.rb +31 -0
  22. data/lib/dapp/build/stage/source_5.rb +51 -0
  23. data/lib/dapp/build/stage/source_base.rb +109 -0
  24. data/lib/dapp/builder/base.rb +44 -0
  25. data/lib/dapp/builder/chef.rb +242 -0
  26. data/lib/dapp/builder/chef/berksfile.rb +54 -0
  27. data/lib/dapp/builder/shell.rb +16 -0
  28. data/lib/dapp/cli.rb +10 -44
  29. data/lib/dapp/cli/base.rb +55 -0
  30. data/lib/dapp/cli/build.rb +6 -140
  31. data/lib/dapp/cli/flush.rb +19 -0
  32. data/lib/dapp/cli/flush/build_cache.rb +26 -0
  33. data/lib/dapp/cli/flush/stage_cache.rb +23 -0
  34. data/lib/dapp/cli/list.rb +19 -0
  35. data/lib/dapp/cli/push.rb +59 -0
  36. data/lib/dapp/cli/smartpush.rb +19 -0
  37. data/lib/dapp/config/application.rb +98 -0
  38. data/lib/dapp/config/chef.rb +20 -0
  39. data/lib/dapp/config/docker.rb +39 -0
  40. data/lib/dapp/config/git_artifact.rb +78 -0
  41. data/lib/dapp/config/main.rb +23 -0
  42. data/lib/dapp/config/shell.rb +40 -0
  43. data/lib/dapp/controller.rb +103 -0
  44. data/lib/dapp/docker_image.rb +51 -0
  45. data/lib/dapp/error/application.rb +6 -0
  46. data/lib/dapp/error/base.rb +10 -0
  47. data/lib/dapp/error/build.rb +6 -0
  48. data/lib/dapp/error/config.rb +6 -0
  49. data/lib/dapp/error/controller.rb +6 -0
  50. data/lib/dapp/error/shellout.rb +6 -0
  51. data/lib/dapp/filelock.rb +1 -1
  52. data/lib/dapp/git_artifact.rb +43 -272
  53. data/lib/dapp/git_repo/base.rb +10 -12
  54. data/lib/dapp/git_repo/own.rb +7 -3
  55. data/lib/dapp/git_repo/remote.rb +14 -20
  56. data/lib/dapp/helper/cli.rb +66 -0
  57. data/lib/dapp/helper/i18n.rb +20 -0
  58. data/lib/dapp/helper/log.rb +72 -0
  59. data/lib/dapp/helper/paint.rb +27 -0
  60. data/lib/dapp/helper/sha256.rb +14 -0
  61. data/lib/dapp/helper/shellout.rb +41 -0
  62. data/lib/dapp/helper/streaming.rb +49 -0
  63. data/lib/dapp/helper/trivia.rb +27 -0
  64. data/lib/dapp/stage_image.rb +98 -0
  65. data/lib/dapp/version.rb +3 -1
  66. metadata +207 -51
  67. data/lib/dapp/atomizer.rb +0 -56
  68. data/lib/dapp/builder.rb +0 -230
  69. data/lib/dapp/builder/cascade_tagging.rb +0 -48
  70. data/lib/dapp/builder/centos7.rb +0 -47
  71. data/lib/dapp/builder/chefify.rb +0 -107
  72. data/lib/dapp/builder/ci_tagging.rb +0 -53
  73. data/lib/dapp/builder/git_tagging.rb +0 -21
  74. data/lib/dapp/builder/manual_tagging.rb +0 -22
  75. data/lib/dapp/builder/ubuntu1404.rb +0 -20
  76. data/lib/dapp/builder/ubuntu1604.rb +0 -20
  77. data/lib/dapp/docker.rb +0 -207
  78. data/lib/dapp/git_repo/chronicler.rb +0 -44
@@ -1,53 +0,0 @@
1
- module Dapp
2
- class Builder
3
- # CI tagging strategy
4
- module CiTagging
5
- def tag_ci(image_id)
6
- return unless opts[:tag_ci] || opts[:tag_build_id]
7
-
8
- raise 'CI environment required (Travis or GitLab CI)' unless ENV['GITLAB_CI'] || ENV['TRAVIS']
9
-
10
- spec = {
11
- name: name,
12
- repo: opts[:docker_repo]
13
- }
14
-
15
- tag_ci_branch_and_tag image_id, spec
16
- tag_ci_build_id image_id, spec
17
- end
18
-
19
- private
20
-
21
- def tag_ci_branch_and_tag(image_id, spec)
22
- return unless opts[:tag_ci]
23
-
24
- log 'Applying CI tagging strategy'
25
-
26
- if ENV['GITLAB_CI']
27
- branch = ENV['CI_BUILD_REF_NAME']
28
- tag = ENV['CI_BUILD_TAG']
29
- elsif ENV['TRAVIS']
30
- branch = ENV['TRAVIS_BRANCH']
31
- tag = ENV['TRAVIS_TAG']
32
- end
33
-
34
- docker.tag image_id, spec.merge(tag: branch) if branch
35
- [tag, 'latest'].each { |t| docker.tag image_id, spec.merge(tag: t) } if tag
36
- end
37
-
38
- def tag_ci_build_id(image_id, spec)
39
- return unless opts[:tag_build_id]
40
-
41
- log 'Applying CI build id tag'
42
-
43
- if ENV['GITLAB_CI']
44
- build_id = ENV['CI_BUILD_ID']
45
- elsif ENV['TRAVIS']
46
- build_id = ENV['TRAVIS_BUILD_NUMBER']
47
- end
48
-
49
- docker.tag image_id, spec.merge(tag: build_id) if build_id
50
- end
51
- end
52
- end
53
- end
@@ -1,21 +0,0 @@
1
- module Dapp
2
- class Builder
3
- # Git tagging strategy
4
- module GitTagging
5
- def tag_git(image_id)
6
- spec = {
7
- name: name,
8
- repo: opts[:docker_repo]
9
- }
10
-
11
- { commit: 'rev-parse HEAD', branch: 'rev-parse --abbrev-ref HEAD' }.each do |tag_type, git_command|
12
- next unless opts[:"tag_#{tag_type}"]
13
-
14
- log "Applying git #{tag_type} tag"
15
-
16
- docker.tag image_id, spec.merge(tag: shellout("git -C #{home_path} #{git_command}").stdout.strip)
17
- end
18
- end
19
- end
20
- end
21
- end
@@ -1,22 +0,0 @@
1
- module Dapp
2
- class Builder
3
- # Manual tagging strategy
4
- module ManualTagging
5
- def tag_manual(image_id)
6
- return unless opts[:tags]
7
-
8
- log 'Applying manual tags'
9
-
10
- opts[:tags].each do |tag|
11
- spec = {
12
- name: name,
13
- tag: tag,
14
- repo: opts[:docker_repo]
15
- }
16
-
17
- docker.tag image_id, spec
18
- end
19
- end
20
- end
21
- end
22
- end
@@ -1,20 +0,0 @@
1
- module Dapp
2
- class Builder
3
- # Ubuntu 16.04 support
4
- module Ubuntu1404
5
- def from_ubuntu1404
6
- # use ubuntu 14.04
7
- docker.from 'ubuntu:14.04'
8
- docker.run(
9
- 'apt-get update',
10
- 'apt-get -y dist-upgrade',
11
- 'apt-get -y install apt-utils git curl apt-transport-https',
12
- step: :begining
13
- )
14
-
15
- # TERM & utf8
16
- docker.env TERM: 'xterm', LANG: 'C.UTF-8', step: :begining
17
- end
18
- end
19
- end
20
- end
@@ -1,20 +0,0 @@
1
- module Dapp
2
- class Builder
3
- # Ubuntu 16.04 support
4
- module Ubuntu1604
5
- def from_ubuntu1604
6
- # use ubuntu 16.04
7
- docker.from 'ubuntu:16.04'
8
- docker.run(
9
- 'apt-get update',
10
- 'apt-get -y dist-upgrade',
11
- 'apt-get -y install apt-utils git curl apt-transport-https',
12
- step: :begining
13
- )
14
-
15
- # TERM & utf8
16
- docker.env TERM: 'xterm', LANG: 'C.UTF-8', step: :begining
17
- end
18
- end
19
- end
20
- end
data/lib/dapp/docker.rb DELETED
@@ -1,207 +0,0 @@
1
- module Dapp
2
- # Dockerfile builder and docker binary wrapper
3
- class Docker
4
- def initialize(builder)
5
- @builder = builder
6
- end
7
-
8
- def name(name = nil)
9
- @name = name || @name
10
- end
11
-
12
- def from(from = nil)
13
- @from = from || @from
14
- end
15
-
16
- def build_path(*path)
17
- builder.build_path(builder.home_branch, [name, 'docker'].compact.join('.'), *path)
18
- end
19
-
20
- def run(*command, step: :build)
21
- add_instruction step, :run, command.join(' && ')
22
- end
23
-
24
- def workdir(directory, step: :build)
25
- add_instruction step, :workdir, directory
26
- end
27
-
28
- def copy(what, where, step: :build)
29
- add_instruction step, :copy, what, where
30
- end
31
-
32
- def add(what, where, step: :build)
33
- add_instruction step, :add, what, where
34
- end
35
-
36
- def add_artifact(file_path, filename, where, step: :build)
37
- add_instruction step, :add_artifact, file_path, filename, where
38
- end
39
-
40
- def expose(*ports, step: :build)
41
- add_instruction step, :expose, ports
42
- end
43
-
44
- def env(step: :build, **env)
45
- add_instruction step, :env, env
46
- end
47
-
48
- def volume(*paths, step: :build)
49
- add_instruction step, :volume, paths
50
- end
51
-
52
- def cmd(*commands, step: :build)
53
- add_instruction step, :cmd, commands
54
- end
55
-
56
- def initialize_dup(other)
57
- super
58
-
59
- @name = @name.dup if @name
60
- @from = @from.dup if @from
61
-
62
- @instructions = @instructions.dup
63
- @instructions.each do |step, step_instructions|
64
- @instructions[step] = step_instructions.dup
65
- end
66
- end
67
-
68
- def build
69
- # prepare
70
- generate_dockerfile
71
-
72
- # build
73
- res = docker("build --force-rm=true --rm=true #{build_path}", log_verbose: true)
74
-
75
- # return image id
76
- res.stdout.lines.grep(/^Successfully built ([0-9a-f]+)\n$/).first.strip.split.last
77
- end
78
-
79
- def image_exist?(**kwargs)
80
- !image_id(**kwargs).nil?
81
- end
82
-
83
- def image_id(**kwargs)
84
- image = images(**kwargs).first
85
- image ? image[:id] : nil
86
- end
87
-
88
- def images(name:, tag: nil, repo: nil)
89
- all_images.select { |i| i[:name] == pad_image_name(name: name, repo: repo) && (!tag || i[:tag] == tag) }
90
- end
91
-
92
- def all_images
93
- docker('images').stdout.lines.drop(1).map(&:strip)
94
- .map { |line| Hash[[:name, :tag, :id].zip(line.strip.split(/\s{2,}/)[0..3])] }
95
- end
96
-
97
- # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
98
- def tag(origin, new, force: true)
99
- # FIXME -f flag was removed since docker v 1.10
100
- # cmd = "tag#{' -f' if force} "
101
- cmd = "tag "
102
-
103
- if origin.is_a?(String)
104
- origin_image_id = origin
105
- cmd += origin
106
- else
107
- origin_image_id = image_id(origin)
108
- cmd += pad_image_name(origin)
109
- end
110
-
111
- # auto rmi
112
- if force && origin_image_id && (new_image_id = image_id(new))
113
- rmi new if new_image_id != origin_image_id
114
- end
115
-
116
- docker cmd + ' ' + pad_image_name(**new)
117
- end
118
- # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
119
-
120
- def rmi(**kwargs)
121
- docker "rmi #{pad_image_name(**kwargs)}"
122
- end
123
-
124
- def push(name:, tag: nil, repo: nil)
125
- docker "push #{pad_image_name name: name, tag: tag, repo: repo}", log_verbose: true
126
- end
127
-
128
- protected
129
-
130
- def pad_image_name(name:, tag: nil, repo: nil)
131
- name = "#{repo}/#{name}" if repo
132
- name = "#{name}:#{tag}" if tag
133
- name
134
- end
135
-
136
- attr_reader :builder
137
-
138
- def instructions(step)
139
- (@instructions ||= {})[step] ||= []
140
- end
141
-
142
- def add_instruction(step, *args)
143
- instructions(step) << args
144
- end
145
-
146
- def docker(command, **kwargs)
147
- builder.shellout "docker #{command}", **kwargs
148
- end
149
-
150
- def dockerfile_path
151
- build_path 'Dockerfile'
152
- end
153
-
154
- def generate_dockerfile_run(dockerfile, *params)
155
- dockerfile.puts 'RUN ' + params[0]
156
- end
157
-
158
- def generate_dockerfile_copy(dockerfile, *params)
159
- dockerfile.puts "COPY #{params[0]} #{params[1]}"
160
- end
161
-
162
- def generate_dockerfile_add(dockerfile, *params)
163
- dockerfile.puts "ADD #{params[0]} #{params[1]}"
164
- end
165
-
166
- def generate_dockerfile_add_artifact(dockerfile, *params)
167
- FileUtils.link params[0], build_path(params[1]), force: true
168
- dockerfile.puts "ADD #{params[1]} #{params[2]}"
169
- end
170
-
171
- def generate_dockerfile_expose(dockerfile, *params)
172
- dockerfile.puts 'EXPOSE ' + params[0].map(&:to_s).join(' ')
173
- end
174
-
175
- def generate_dockerfile_env(dockerfile, *params)
176
- dockerfile.puts 'ENV ' + params[0].map { |k, v| %(#{k}="#{v}") }.join(' ')
177
- end
178
-
179
- def generate_dockerfile_volume(dockerfile, *params)
180
- dockerfile.puts 'VOLUME ' + params[0].join(' ')
181
- end
182
-
183
- def generate_dockerfile_workdir(dockerfile, *params)
184
- dockerfile.puts "WORKDIR #{params[0]}"
185
- end
186
-
187
- def generate_dockerfile_cmd(dockerfile, *params)
188
- dockerfile.puts 'CMD ' + params[0].join(' ')
189
- end
190
-
191
- def generate_dockerfile_step(dockerfile, step)
192
- instructions(step).each do |directive, *params|
193
- send :"generate_dockerfile_#{directive}", dockerfile, *params
194
- end
195
- end
196
-
197
- def generate_dockerfile
198
- File.open dockerfile_path, 'w' do |dockerfile|
199
- dockerfile.puts 'FROM ' + from
200
-
201
- [:begining, :prepare, :build, :setup].each do |step|
202
- generate_dockerfile_step(dockerfile, step)
203
- end
204
- end
205
- end
206
- end
207
- end
@@ -1,44 +0,0 @@
1
- module Dapp
2
- module GitRepo
3
- # Gitkeeper for autogenerated and external data
4
- class Chronicler < Base
5
- def initialize(builder, name, **kwargs)
6
- super
7
-
8
- lock do
9
- unless File.directory? chronodir_path
10
- git "init --separate-git-dir=#{dir_path} #{chronodir_path}"
11
- git_chrono 'commit --allow-empty -m init'
12
- end
13
- end
14
- end
15
-
16
- def chronodir_path(*path)
17
- build_path name, *path
18
- end
19
-
20
- def commit!(comment = '+')
21
- lock do
22
- git_chrono 'add --all'
23
- unless git_chrono('diff --cached --quiet', returns: [0, 1]).status.success?
24
- git_chrono "commit -m #{comment}"
25
- end
26
- end
27
- end
28
-
29
- def cleanup!
30
- lock do
31
- super
32
- FileUtils.rm_rf dir_path
33
- FileUtils.rm_rf chronodir_path
34
- end
35
- end
36
-
37
- protected
38
-
39
- def git_chrono(command, **kwargs)
40
- git "-C #{chronodir_path} #{command}", **kwargs
41
- end
42
- end
43
- end
44
- end