popito 0.0.1.alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.byebug_history +247 -0
- data/.gitignore +9 -0
- data/.gitlab-ci.yml +20 -0
- data/.rubocop.yml +25 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +49 -0
- data/README.md +2 -0
- data/Rakefile +3 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/exe/popito +52 -0
- data/lib/popito/deployer/build/build_executor.rb +54 -0
- data/lib/popito/deployer/build/builders/docker.rb +50 -0
- data/lib/popito/deployer/client/archive_downloading.rb +15 -0
- data/lib/popito/deployer/client/client_base.rb +29 -0
- data/lib/popito/deployer/client/included_files.rb +13 -0
- data/lib/popito/deployer/config/config_payload.rb +22 -0
- data/lib/popito/deployer/deploy/deploy_executor.rb +20 -0
- data/lib/popito/deployer/deployer.rb +15 -0
- data/lib/popito/deployer/stage/stage_preparing.rb +27 -0
- data/lib/popito/deployer/version.rb +5 -0
- data/popito.gemspec +41 -0
- metadata +153 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3e56e16a84c3bf667dab3e304d6d83581bebfcdeceeae420efb78d27af8f08f9
|
4
|
+
data.tar.gz: 1312c4cc5388d955f3c871cbedf267c6ff07d554ebe9e21555ded7957ca4334b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f87b027418d1663b04f489cf6dcd20aa6894901c3f14d366fcc9657f5b8e6276eb8ae9fd8f648d7554a6533d1da11e7166e624117f802f4a759236c043837bf5
|
7
|
+
data.tar.gz: 51a241c5d4ac3f04572d20df75e593dcf80b5b6760769297e97e1a208854072594dd7038f720cd148a725da730b84599a69c63ca9b983512f539b6ee8fb708c3
|
data/.byebug_history
ADDED
@@ -0,0 +1,247 @@
|
|
1
|
+
q
|
2
|
+
params
|
3
|
+
q
|
4
|
+
params
|
5
|
+
q
|
6
|
+
params
|
7
|
+
q
|
8
|
+
params
|
9
|
+
q
|
10
|
+
params[:token]
|
11
|
+
params
|
12
|
+
q
|
13
|
+
params
|
14
|
+
c
|
15
|
+
JSON.parse(err.response.body)["message"]
|
16
|
+
err
|
17
|
+
q
|
18
|
+
err
|
19
|
+
q
|
20
|
+
n
|
21
|
+
y
|
22
|
+
q
|
23
|
+
err.response.body
|
24
|
+
err
|
25
|
+
q
|
26
|
+
puts caller()
|
27
|
+
caller()
|
28
|
+
call()
|
29
|
+
call
|
30
|
+
err
|
31
|
+
err.class
|
32
|
+
err
|
33
|
+
err.response
|
34
|
+
JSON.parse(err.response.body)
|
35
|
+
JSON.parse(err.response.body)["message"]
|
36
|
+
err
|
37
|
+
c
|
38
|
+
JSON.parse(response.body).class
|
39
|
+
JSON.parse(response.body)
|
40
|
+
response.body
|
41
|
+
n
|
42
|
+
q
|
43
|
+
default_headers
|
44
|
+
q
|
45
|
+
headers
|
46
|
+
q
|
47
|
+
config_payload
|
48
|
+
continue
|
49
|
+
x["build"][0]["dockerfile"]
|
50
|
+
x["build"][0]["targets"]
|
51
|
+
x["build"][0]
|
52
|
+
x["build"]
|
53
|
+
x=YAML.load(File.read("#{config_payload.build_path}/build.yaml"))
|
54
|
+
x["build"]
|
55
|
+
x=YAML.load(File.read("#{config_payload.build_path}/build.yaml")).class
|
56
|
+
x
|
57
|
+
x["build"]
|
58
|
+
x=YAML.load(File.read("#{config_payload.build_path}/build.yaml")).class
|
59
|
+
x[0]
|
60
|
+
x=YAML.load(File.read("#{config_payload.build_path}/build.yaml")).class
|
61
|
+
YAML.load(File.read("#{config_payload.build_path}/build.yaml")).class
|
62
|
+
YAML.load(File.read("#{config_payload.build_path}/build.yaml"))
|
63
|
+
q
|
64
|
+
YAML.load(File.read("#{config_payload.project_path}/build.yaml"))
|
65
|
+
c
|
66
|
+
continue
|
67
|
+
z.read
|
68
|
+
x.read
|
69
|
+
z = Zlib::GzipReader.new(StringIO.new(body))
|
70
|
+
body
|
71
|
+
z = Zlib::GzipReader.new(body)
|
72
|
+
z = Zlib::GzipReader.new(body)
|
73
|
+
unzipped = StringIO.new(z.read)
|
74
|
+
body
|
75
|
+
c
|
76
|
+
q
|
77
|
+
body
|
78
|
+
c
|
79
|
+
q
|
80
|
+
body.size
|
81
|
+
body
|
82
|
+
c
|
83
|
+
q
|
84
|
+
JSON.parse(err.response.body)["code"]
|
85
|
+
JSON.parse(err.response.body)
|
86
|
+
JSON.parse(err.response.body)["codigo"]
|
87
|
+
JSON.parse(err.response.body)["codigo"] + ""
|
88
|
+
JSON.parse(err.response.body)["code"] + ""
|
89
|
+
JSON.parse(err.response.body)["message"]
|
90
|
+
TypeError.kind_of?(RuntimeError)
|
91
|
+
JSON.parse('{}')
|
92
|
+
JSON.parse({})
|
93
|
+
JSON.parse("")
|
94
|
+
JSON.parse(nil)
|
95
|
+
JSON.parse(err.response.body)["message"]
|
96
|
+
JSON.parse(err.response.body)
|
97
|
+
::JSON.parse(err.response.body)
|
98
|
+
require 'json'
|
99
|
+
::JSON.parse(err.response.body)
|
100
|
+
JSON.parse(err.response.body)
|
101
|
+
JSON(err.response.body)
|
102
|
+
err.response.body
|
103
|
+
err.response
|
104
|
+
c
|
105
|
+
q
|
106
|
+
response
|
107
|
+
c
|
108
|
+
q
|
109
|
+
ARGV[0]
|
110
|
+
ARGV[1]
|
111
|
+
continue
|
112
|
+
y
|
113
|
+
q
|
114
|
+
config_payload.project_path
|
115
|
+
File.expand_path(config_payload.project_path)
|
116
|
+
q
|
117
|
+
config_payload.project_path
|
118
|
+
config_payload
|
119
|
+
q
|
120
|
+
c
|
121
|
+
q
|
122
|
+
current_scope&.config.nil?
|
123
|
+
context
|
124
|
+
current_scope
|
125
|
+
q
|
126
|
+
default
|
127
|
+
context.config
|
128
|
+
context
|
129
|
+
current_scope
|
130
|
+
c
|
131
|
+
q
|
132
|
+
config_payload.get_value(key: 'RAILS_RUN_MIGRATES', default: 'false')
|
133
|
+
q
|
134
|
+
config_payload.get_value(key: 'ENVIRONMENT')
|
135
|
+
config_payload.get_value(key: :ENVIRONMENT)
|
136
|
+
config_payload.get_value(:ENVIRONMENTconfig_payload.get_value(key: :ENVIRONMENT))
|
137
|
+
config_payload.get_value(:ENVIRONMENT)
|
138
|
+
q
|
139
|
+
container[:env]
|
140
|
+
c
|
141
|
+
container[:env]
|
142
|
+
c
|
143
|
+
container[:env]
|
144
|
+
c
|
145
|
+
container[:env]
|
146
|
+
c
|
147
|
+
container[:env]
|
148
|
+
c
|
149
|
+
container[:env]
|
150
|
+
c
|
151
|
+
container[:env]
|
152
|
+
c
|
153
|
+
container[:env]
|
154
|
+
q
|
155
|
+
continue
|
156
|
+
q
|
157
|
+
container[:env]
|
158
|
+
c
|
159
|
+
container[:env]
|
160
|
+
byebug
|
161
|
+
q
|
162
|
+
container[:env]
|
163
|
+
c
|
164
|
+
container[:env]
|
165
|
+
c
|
166
|
+
container[:env]
|
167
|
+
c
|
168
|
+
container[:env]
|
169
|
+
q
|
170
|
+
continue
|
171
|
+
config_payload.context.config.ENV
|
172
|
+
config_payload.context.config.env
|
173
|
+
config_payload.context.config
|
174
|
+
container[:env][0]config_payload.context.config
|
175
|
+
container[:env]
|
176
|
+
c
|
177
|
+
container[:env]
|
178
|
+
c
|
179
|
+
container[:env]
|
180
|
+
c
|
181
|
+
container[:env]
|
182
|
+
container[:name]
|
183
|
+
container
|
184
|
+
config_payload.current_scope.config
|
185
|
+
q
|
186
|
+
config_payload.current_scope.config
|
187
|
+
config_payload.current_scope.name
|
188
|
+
config_payload.current_scope
|
189
|
+
c
|
190
|
+
config_payload.current_scope.config
|
191
|
+
c
|
192
|
+
config_payload.current_scope.config
|
193
|
+
c
|
194
|
+
config_payload.current_scope.config
|
195
|
+
c
|
196
|
+
config_payload.current_scope.config
|
197
|
+
c
|
198
|
+
config_payload.current_scope.config
|
199
|
+
c
|
200
|
+
config_payload.current_scope.config
|
201
|
+
c
|
202
|
+
config_payload.current_scope.config
|
203
|
+
c
|
204
|
+
config_payload.current_scope.config
|
205
|
+
c
|
206
|
+
config_payload.current_scope.config
|
207
|
+
q
|
208
|
+
config_payload.current_scope.config
|
209
|
+
current_context
|
210
|
+
current_scope
|
211
|
+
config_payload
|
212
|
+
container
|
213
|
+
container["type"]
|
214
|
+
container[:type]
|
215
|
+
c
|
216
|
+
container[:type]
|
217
|
+
container["config"]
|
218
|
+
c
|
219
|
+
container["config"]
|
220
|
+
c
|
221
|
+
container["config"]
|
222
|
+
c
|
223
|
+
container["config"]
|
224
|
+
c
|
225
|
+
container["config"]
|
226
|
+
c
|
227
|
+
container["config"]
|
228
|
+
q
|
229
|
+
container["config"]
|
230
|
+
c
|
231
|
+
container["config"]
|
232
|
+
c
|
233
|
+
container["config"]
|
234
|
+
c
|
235
|
+
container["config"]
|
236
|
+
container.config
|
237
|
+
container
|
238
|
+
c
|
239
|
+
container
|
240
|
+
container.config
|
241
|
+
c
|
242
|
+
container.config
|
243
|
+
c
|
244
|
+
container.config
|
245
|
+
c
|
246
|
+
container.config
|
247
|
+
container
|
data/.gitignore
ADDED
data/.gitlab-ci.yml
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
variables:
|
2
|
+
CONTAINER_IMAGE: docker-registry.baladapp.com.br/$CI_PROJECT_PATH
|
3
|
+
DOCKER_DRIVER: overlay2
|
4
|
+
|
5
|
+
build:gem:
|
6
|
+
stage: build
|
7
|
+
image: docker-registry.baladapp.com.br/docker/baladapp-ruby/mina:latest
|
8
|
+
script:
|
9
|
+
- rake build
|
10
|
+
- rake release
|
11
|
+
|
12
|
+
build:docker-image:
|
13
|
+
stage: build
|
14
|
+
image: docker:stable
|
15
|
+
script:
|
16
|
+
- TAG=v$(cat lib/popito/deployer/version.rb | grep VERSION | egrep -o '[0-9]+\.[0-9]+\.[0-9]+[\.a-z]*')
|
17
|
+
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN docker-registry.baladapp.com.br
|
18
|
+
- docker build -f docker/Dockerfile --tag $CONTAINER_IMAGE:latest --tag $CONTAINER_IMAGE:${TAG} .
|
19
|
+
- docker push $CONTAINER_IMAGE:latest
|
20
|
+
- docker push $CONTAINER_IMAGE:${TAG}
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
Lint/UselessAssignment:
|
2
|
+
Exclude:
|
3
|
+
- 'lib/popito/deployer/client/archive_downloading.rb'
|
4
|
+
- 'lib/popito/deployer/client/included_files.rb'
|
5
|
+
Layout/LineLength:
|
6
|
+
Max: 130
|
7
|
+
Metrics/CyclomaticComplexity:
|
8
|
+
Max: 8
|
9
|
+
Style/FrozenStringLiteralComment:
|
10
|
+
Enabled: false
|
11
|
+
Style/StringLiterals:
|
12
|
+
Enabled: false
|
13
|
+
Style/Documentation:
|
14
|
+
Enabled: false
|
15
|
+
Metrics/AbcSize:
|
16
|
+
Max: 25
|
17
|
+
Metrics/MethodLength:
|
18
|
+
Max: 20
|
19
|
+
AllCops:
|
20
|
+
NewCops: enable
|
21
|
+
Exclude:
|
22
|
+
- 'bin/bundle'
|
23
|
+
- 'db/schema.rb'
|
24
|
+
- 'db/migrate/*'
|
25
|
+
- 'db/seeds.rb'
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
popito (0.0.1.alpha)
|
5
|
+
deep_merge (~> 1.2)
|
6
|
+
erb (~> 2.2)
|
7
|
+
json (~> 2.5)
|
8
|
+
minitar (~> 0.9)
|
9
|
+
rest-client (~> 2.1)
|
10
|
+
yaml (~> 0.1)
|
11
|
+
|
12
|
+
GEM
|
13
|
+
remote: https://rubygems.org/
|
14
|
+
specs:
|
15
|
+
cgi (0.2.0)
|
16
|
+
deep_merge (1.2.1)
|
17
|
+
domain_name (0.5.20190701)
|
18
|
+
unf (>= 0.0.5, < 1.0.0)
|
19
|
+
erb (2.2.3)
|
20
|
+
cgi
|
21
|
+
http-accept (1.7.0)
|
22
|
+
http-cookie (1.0.4)
|
23
|
+
domain_name (~> 0.5)
|
24
|
+
json (2.5.1)
|
25
|
+
mime-types (3.3.1)
|
26
|
+
mime-types-data (~> 3.2015)
|
27
|
+
mime-types-data (3.2021.0704)
|
28
|
+
minitar (0.9)
|
29
|
+
netrc (0.11.0)
|
30
|
+
rake (13.0.3)
|
31
|
+
rest-client (2.1.0)
|
32
|
+
http-accept (>= 1.7.0, < 2.0)
|
33
|
+
http-cookie (>= 1.0.2, < 2.0)
|
34
|
+
mime-types (>= 1.16, < 4.0)
|
35
|
+
netrc (~> 0.8)
|
36
|
+
unf (0.1.4)
|
37
|
+
unf_ext
|
38
|
+
unf_ext (0.0.7.7)
|
39
|
+
yaml (0.1.1)
|
40
|
+
|
41
|
+
PLATFORMS
|
42
|
+
x86_64-darwin-20
|
43
|
+
|
44
|
+
DEPENDENCIES
|
45
|
+
popito!
|
46
|
+
rake (~> 13.0)
|
47
|
+
|
48
|
+
BUNDLED WITH
|
49
|
+
2.2.24
|
data/README.md
ADDED
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require_relative '../lib/popito/deployer/deployer'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/popito
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'optparse'
|
5
|
+
require_relative '../lib/popito/deployer/deployer'
|
6
|
+
|
7
|
+
params = {}
|
8
|
+
OptionParser.new do |opts|
|
9
|
+
opts.on('--build', 'Generate docker images.')
|
10
|
+
opts.on('--release', 'Push docker images to registry (must run after or together with build).')
|
11
|
+
opts.on('--deploy', 'Run kubectl apply against deploy files.')
|
12
|
+
opts.on('--check', 'Run kubectl apply --dry-run against generated yaml files.')
|
13
|
+
opts.on('--tag IMAGE_TAG', 'This tag will used to build docker images and deploy.')
|
14
|
+
opts.on('--tag-alt IMAGE_TAG_ALT', 'This tag will used to build docker images.')
|
15
|
+
opts.on('--env ENVIRONMENT', 'It define environment used to build images and deploy files.')
|
16
|
+
opts.on('--endpoint https://popito.mydomain.com', 'It defines popito endpoint.')
|
17
|
+
opts.on('--token POPITO_TOKEN', 'This popito token used to auth this client in a specific project.')
|
18
|
+
opts.on('--path ./project_path', 'Root folder of the app.')
|
19
|
+
end.parse!(into: params)
|
20
|
+
|
21
|
+
raise ArgumentError, 'You can choose --deploy and --check together.' if params[:check] && params[:deploy]
|
22
|
+
|
23
|
+
stages = []
|
24
|
+
stages.push('build') if params[:build]
|
25
|
+
stages.push('release') if params[:release]
|
26
|
+
stages.push('check') if params[:check]
|
27
|
+
stages.push('deploy') if params[:deploy]
|
28
|
+
|
29
|
+
config_payload = Popito::ConfigPayload.new(
|
30
|
+
project_path: params[:path],
|
31
|
+
stages: stages,
|
32
|
+
project_token: params[:token],
|
33
|
+
build_config: {
|
34
|
+
IMAGE_TAG: params[:tag],
|
35
|
+
IMAGE_TAG_ALT: params[:tag_alt],
|
36
|
+
ENVIRONMENT: params[:env]
|
37
|
+
}
|
38
|
+
)
|
39
|
+
|
40
|
+
if params[:build] || params[:release]
|
41
|
+
Popito::StagePreparing.new(config_payload).create_deployer_folder(stage: 'build')
|
42
|
+
builder = Popito::BuildExecutor.new(config_payload)
|
43
|
+
builder.build if params[:build]
|
44
|
+
builder.release if params[:release]
|
45
|
+
end
|
46
|
+
|
47
|
+
if params[:check] || params[:deploy]
|
48
|
+
Popito::StagePreparing.new(config_payload).create_deployer_folder(stage: 'deploy')
|
49
|
+
deployer = Popito::DeployExecutor.new(config_payload)
|
50
|
+
deployer.check if params[:check]
|
51
|
+
deployer.deploy if params[:deploy]
|
52
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require_relative './builders/docker'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
module Popito
|
5
|
+
class BuildExecutor
|
6
|
+
attr_accessor :config_payload
|
7
|
+
|
8
|
+
def initialize(config_payload)
|
9
|
+
self.config_payload = config_payload
|
10
|
+
end
|
11
|
+
|
12
|
+
def yaml_config
|
13
|
+
@yaml_config ||= load_yaml
|
14
|
+
end
|
15
|
+
|
16
|
+
def build
|
17
|
+
yaml_config["build"].each do |build|
|
18
|
+
build["tags"].each do |tag|
|
19
|
+
builder = Popito::BuildExecutor::Builders::Docker.new(
|
20
|
+
root_path: config_payload.project_path,
|
21
|
+
dockerfile: "#{config_payload.build_path}/#{build['dockerfile']}",
|
22
|
+
image: build["image"],
|
23
|
+
tag: tag
|
24
|
+
)
|
25
|
+
builder.build
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def release
|
31
|
+
yaml_config["build"].each do |build|
|
32
|
+
build["tags"].each do |tag|
|
33
|
+
builder = Popito::BuildExecutor::Builders::Docker.new(
|
34
|
+
root_path: config_payload.project_path,
|
35
|
+
dockerfile: "#{config_payload.build_path}/#{build['dockerfile']}",
|
36
|
+
image: build["image"],
|
37
|
+
tag: tag
|
38
|
+
)
|
39
|
+
builder.push
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def camelize(value)
|
47
|
+
value.to_s.capitalize.gsub(/_(\w)/) { Regexp.last_match(1).upcase }
|
48
|
+
end
|
49
|
+
|
50
|
+
def load_yaml
|
51
|
+
YAML.safe_load(File.read("#{config_payload.build_path}/build.yaml"))
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'erb'
|
2
|
+
module Popito
|
3
|
+
class BuildExecutor
|
4
|
+
module Builders
|
5
|
+
class Docker
|
6
|
+
attr_accessor :dockerfile, :image, :tag, :root_path
|
7
|
+
|
8
|
+
def initialize(root_path:, dockerfile:, image:, tag:)
|
9
|
+
self.dockerfile = dockerfile
|
10
|
+
self.image = image
|
11
|
+
self.tag = tag
|
12
|
+
self.root_path = root_path
|
13
|
+
end
|
14
|
+
|
15
|
+
def build
|
16
|
+
puts "Building ..."
|
17
|
+
puts "Dockerfile: #{dockerfile}"
|
18
|
+
puts "Image: #{image}"
|
19
|
+
puts "Tag: #{tag}"
|
20
|
+
Dir.chdir(root_path)
|
21
|
+
docker_build
|
22
|
+
end
|
23
|
+
|
24
|
+
def push
|
25
|
+
puts "Pushing ..."
|
26
|
+
puts "Dockerfile: #{dockerfile}"
|
27
|
+
puts "Image: #{image}"
|
28
|
+
puts "Tag: #{tag}"
|
29
|
+
docker_push
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def docker_push
|
35
|
+
puts "#{self.class.name}: docker push #{image_full_name}"
|
36
|
+
system "docker push #{image_full_name}", exception: true
|
37
|
+
end
|
38
|
+
|
39
|
+
def docker_build
|
40
|
+
puts "#{self.class.name}: docker build #{image_full_name}"
|
41
|
+
system "docker build -f #{dockerfile} --tag #{image_full_name} .", exception: true
|
42
|
+
end
|
43
|
+
|
44
|
+
def image_full_name
|
45
|
+
"#{image}:#{tag}"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
require 'json'
|
3
|
+
require 'minitar'
|
4
|
+
module Popito
|
5
|
+
class ArchiveDownloading < Popito::ClientBase
|
6
|
+
def download_and_extract(stage:)
|
7
|
+
payload = { stage: stage, build_config: config_payload.build_config,
|
8
|
+
included_files: config_payload.included_files_payload }
|
9
|
+
response = RestClient.post("#{API_HOST}/api/v1/archive", payload, headers = default_headers)
|
10
|
+
extract_tgz(response.body)
|
11
|
+
rescue RestClient::UnprocessableEntity => e
|
12
|
+
raise parse_error(e)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
require 'json'
|
3
|
+
require 'minitar'
|
4
|
+
module Popito
|
5
|
+
class ClientBase
|
6
|
+
API_HOST = 'http://localhost:3000'.freeze
|
7
|
+
attr_accessor :config_payload
|
8
|
+
|
9
|
+
def initialize(config_payload:)
|
10
|
+
self.config_payload = config_payload
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def parse_error(err)
|
16
|
+
JSON.parse(err.response.body)["message"]
|
17
|
+
rescue StandardError
|
18
|
+
"An error has been occurred."
|
19
|
+
end
|
20
|
+
|
21
|
+
def extract_tgz(body)
|
22
|
+
Minitar.unpack(Zlib::GzipReader.new(StringIO.new(body)), config_payload.project_path)
|
23
|
+
end
|
24
|
+
|
25
|
+
def default_headers
|
26
|
+
{ 'X-Client-Version': Popito::VERSION, 'X-Project-Token': config_payload.project_token }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
require 'json'
|
3
|
+
require 'minitar'
|
4
|
+
module Popito
|
5
|
+
class IncludedFiles < Popito::ClientBase
|
6
|
+
def included_files_list
|
7
|
+
response = RestClient.get("#{API_HOST}/api/v1/included-files", headers = default_headers)
|
8
|
+
JSON.parse(response.body)
|
9
|
+
rescue RestClient::UnprocessableEntity => e
|
10
|
+
raise parse_error(e)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'base64'
|
2
|
+
module Popito
|
3
|
+
class ConfigPayload
|
4
|
+
attr_accessor :project_path, :build_path, :deploy_path, :stages, :build_config, :project_token, :included_files
|
5
|
+
|
6
|
+
def initialize(project_path:, project_token:, stages: [], build_config: {}, included_files: [])
|
7
|
+
self.project_path = File.expand_path(project_path)
|
8
|
+
self.build_path = File.expand_path("#{project_path}/#{Popito::BUILD_DIR_NAME}")
|
9
|
+
self.deploy_path = File.expand_path("#{project_path}/#{Popito::DEPLOY_DIR_NAME}")
|
10
|
+
self.stages = stages
|
11
|
+
self.project_token = project_token
|
12
|
+
self.build_config = build_config
|
13
|
+
self.included_files = included_files
|
14
|
+
end
|
15
|
+
|
16
|
+
def included_files_payload
|
17
|
+
included_files.map do |file|
|
18
|
+
{ encoding: 'base64', path: file, content: Base64.encode64(File.read("#{project_path}/#{file}")) }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Popito
|
2
|
+
class DeployExecutor
|
3
|
+
attr_accessor :config_payload
|
4
|
+
|
5
|
+
def initialize(config_payload)
|
6
|
+
self.config_payload = config_payload
|
7
|
+
@deploy_files_dir = "#{config_payload.deploy_path}/deploy"
|
8
|
+
end
|
9
|
+
|
10
|
+
def check
|
11
|
+
puts 'Validating generated files...'
|
12
|
+
system "kubectl apply --validate=true --dry-run=client -f #{@deploy_files_dir}", exception: true
|
13
|
+
end
|
14
|
+
|
15
|
+
def deploy
|
16
|
+
puts 'Applying generated files...'
|
17
|
+
system "kubectl apply -f #{@deploy_files_dir}", exception: true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Popito
|
4
|
+
BUILD_DIR_NAME = '_popito/build'
|
5
|
+
DEPLOY_DIR_NAME = '_popito/deploy'
|
6
|
+
end
|
7
|
+
|
8
|
+
require_relative "version"
|
9
|
+
require_relative 'config/config_payload'
|
10
|
+
require_relative 'client/client_base'
|
11
|
+
require_relative 'client/included_files'
|
12
|
+
require_relative 'client/archive_downloading'
|
13
|
+
require_relative 'stage/stage_preparing'
|
14
|
+
require_relative 'build/build_executor'
|
15
|
+
require_relative 'deploy/deploy_executor'
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module Popito
|
4
|
+
class StagePreparing
|
5
|
+
attr_accessor :config_payload
|
6
|
+
|
7
|
+
def initialize(config_payload)
|
8
|
+
self.config_payload = config_payload
|
9
|
+
end
|
10
|
+
|
11
|
+
def create_deployer_folder(stage:)
|
12
|
+
config_payload.included_files = Popito::IncludedFiles.new(config_payload: config_payload).included_files_list
|
13
|
+
Popito::ArchiveDownloading.new(config_payload: config_payload).download_and_extract(stage: stage)
|
14
|
+
docker_ajusts if config_payload.stages.include?('build')
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def docker_ajusts
|
20
|
+
return unless File.exist?("#{config_payload.build_path}/.dockerignore")
|
21
|
+
|
22
|
+
File.open("#{config_payload.project_path}/.dockerignore", 'a') do |file|
|
23
|
+
file.write File.read("#{config_payload.build_path}/.dockerignore")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/popito.gemspec
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/popito/deployer/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "popito"
|
7
|
+
spec.version = Popito::VERSION
|
8
|
+
spec.authors = ["Wagner Caixeta"]
|
9
|
+
spec.email = ["wagner.caixeta@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "WIP: Build docker images for Rails Projects and deploy it on K8S using a Popito Server."
|
12
|
+
spec.description = "WIP: This gem is not ready yet."
|
13
|
+
spec.homepage = "http://github.com/platbr/popito"
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
|
15
|
+
|
16
|
+
# spec.metadata["allowed_push_host"] = "https://gems.baladapp.com.br"
|
17
|
+
|
18
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
19
|
+
spec.metadata["source_code_uri"] = "http://github.com/platbr/popito"
|
20
|
+
spec.metadata["changelog_uri"] = "http://github.com/platbr/popito/blob/master/CHANGELOG.md"
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
25
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features|docker)/}) }
|
26
|
+
end
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
# Uncomment to register a new dependency of your gem
|
32
|
+
spec.add_dependency "deep_merge", '~> 1.2'
|
33
|
+
spec.add_dependency "erb", '~> 2.2'
|
34
|
+
spec.add_dependency "json", '~> 2.5'
|
35
|
+
spec.add_dependency "minitar", '~> 0.9'
|
36
|
+
spec.add_dependency "rest-client", '~> 2.1'
|
37
|
+
spec.add_dependency "yaml", '~> 0.1'
|
38
|
+
|
39
|
+
# For more information and examples about making a new gem, checkout our
|
40
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
41
|
+
end
|
metadata
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: popito
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1.alpha
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Wagner Caixeta
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-09-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: deep_merge
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: erb
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: json
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.5'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.5'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitar
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.9'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.9'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rest-client
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.1'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.1'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: yaml
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.1'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.1'
|
97
|
+
description: 'WIP: This gem is not ready yet.'
|
98
|
+
email:
|
99
|
+
- wagner.caixeta@gmail.com
|
100
|
+
executables:
|
101
|
+
- popito
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".byebug_history"
|
106
|
+
- ".gitignore"
|
107
|
+
- ".gitlab-ci.yml"
|
108
|
+
- ".rubocop.yml"
|
109
|
+
- Gemfile
|
110
|
+
- Gemfile.lock
|
111
|
+
- README.md
|
112
|
+
- Rakefile
|
113
|
+
- bin/console
|
114
|
+
- bin/setup
|
115
|
+
- exe/popito
|
116
|
+
- lib/popito/deployer/build/build_executor.rb
|
117
|
+
- lib/popito/deployer/build/builders/docker.rb
|
118
|
+
- lib/popito/deployer/client/archive_downloading.rb
|
119
|
+
- lib/popito/deployer/client/client_base.rb
|
120
|
+
- lib/popito/deployer/client/included_files.rb
|
121
|
+
- lib/popito/deployer/config/config_payload.rb
|
122
|
+
- lib/popito/deployer/deploy/deploy_executor.rb
|
123
|
+
- lib/popito/deployer/deployer.rb
|
124
|
+
- lib/popito/deployer/stage/stage_preparing.rb
|
125
|
+
- lib/popito/deployer/version.rb
|
126
|
+
- popito.gemspec
|
127
|
+
homepage: http://github.com/platbr/popito
|
128
|
+
licenses: []
|
129
|
+
metadata:
|
130
|
+
homepage_uri: http://github.com/platbr/popito
|
131
|
+
source_code_uri: http://github.com/platbr/popito
|
132
|
+
changelog_uri: http://github.com/platbr/popito/blob/master/CHANGELOG.md
|
133
|
+
post_install_message:
|
134
|
+
rdoc_options: []
|
135
|
+
require_paths:
|
136
|
+
- lib
|
137
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: 2.5.0
|
142
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">"
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: 1.3.1
|
147
|
+
requirements: []
|
148
|
+
rubygems_version: 3.1.4
|
149
|
+
signing_key:
|
150
|
+
specification_version: 4
|
151
|
+
summary: 'WIP: Build docker images for Rails Projects and deploy it on K8S using a
|
152
|
+
Popito Server.'
|
153
|
+
test_files: []
|