shiplane 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/capistrano/tasks/shiplane.rake +1 -1
- data/lib/shiplane/build.rb +17 -14
- data/lib/shiplane/checkout_artifact.rb +35 -15
- data/lib/shiplane/configuration.rb +12 -2
- data/lib/shiplane/convert_compose_file.rb +5 -7
- data/lib/shiplane/convert_dockerfile.rb +5 -7
- data/lib/shiplane/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b5ceb3e3ec92da5d153b204c2f3d8e8d9108bc354c2690f6d9de39b69ee1893
|
4
|
+
data.tar.gz: f4e5b7340fa59249d4a3ffdfc2ce0f612a6c3faaf49208feebfb12fa0853f099
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74ce1231080dca4313fa9ed5c37c3197c2fd7e3d05ce275c13e1c0a4aac0a1a8c1f4d0a224b423141cdfc5633c57ad490c46834a8045395948ff9f082ff351dd
|
7
|
+
data.tar.gz: f627396ec65b1f5cba4215567d7b0559b91501e5336a3d03a560877d589b0eb452b8380bac1602931be97c7f98c978c53d2fe7713eb080b7600f558429ce6f87
|
data/lib/shiplane/build.rb
CHANGED
@@ -9,20 +9,21 @@ require_relative 'configuration'
|
|
9
9
|
module Shiplane
|
10
10
|
class Build
|
11
11
|
extend Forwardable
|
12
|
-
attr_accessor :sha, :postfix, :tag_latest
|
12
|
+
attr_accessor :sha, :postfix, :tag_latest, :stage, :build_environment_variables
|
13
13
|
|
14
|
-
delegate %i(build_config project_config) => :shiplane_config
|
14
|
+
delegate %i(build_config project_config build_environment_filepath) => :shiplane_config
|
15
15
|
|
16
|
-
def initialize(sha, postfix:, tag_latest: false)
|
16
|
+
def initialize(sha, postfix:, tag_latest: false, stage: nil)
|
17
17
|
@sha = sha
|
18
18
|
@tag_latest = tag_latest
|
19
19
|
@postfix = postfix
|
20
|
+
@stage = stage
|
20
21
|
|
21
|
-
Dotenv.overload File.join(Dir.pwd,
|
22
|
+
Dotenv.overload File.join(Dir.pwd, build_environment_filepath)
|
22
23
|
|
23
24
|
# Add any ENV variable overrides from the capistrano configuration
|
24
|
-
|
25
|
-
|
25
|
+
build_environment_variables = fetch(:shiplane_build_environment_variables, {})
|
26
|
+
build_environment_variables.each do |key, value|
|
26
27
|
if value.is_a? Proc
|
27
28
|
ENV[key.to_s] = value.call
|
28
29
|
else
|
@@ -33,13 +34,13 @@ module Shiplane
|
|
33
34
|
|
34
35
|
def build!
|
35
36
|
unless File.exist?(File.join(project_folder, Shiplane::SHIPLANE_CONFIG_FILENAME))
|
36
|
-
Shiplane::CheckoutArtifact.checkout!(sha)
|
37
|
-
Shiplane::ConvertComposeFile.convert_output!(project_folder, sha)
|
37
|
+
Shiplane::CheckoutArtifact.checkout!(sha, config: shiplane_config)
|
38
|
+
Shiplane::ConvertComposeFile.convert_output!(project_folder, sha, config: shiplane_config)
|
38
39
|
end
|
39
40
|
|
40
41
|
buildable_artifacts.each do |(artifact_name, attributes)|
|
41
42
|
compose_context = docker_config.fetch('services', {}).fetch(artifact_name.to_s, {})
|
42
|
-
Shiplane::ConvertDockerfile.convert_output!(project_folder, attributes, compose_context)
|
43
|
+
Shiplane::ConvertDockerfile.convert_output!(project_folder, attributes, compose_context, config: shiplane_config)
|
43
44
|
|
44
45
|
FileUtils.cd project_folder do
|
45
46
|
steps(artifact_name, attributes).select{|step| step.fetch(:condition, true) }.each do |step|
|
@@ -74,6 +75,8 @@ module Shiplane
|
|
74
75
|
def build_command(artifact_name)
|
75
76
|
[
|
76
77
|
'docker-compose',
|
78
|
+
'--env-file',
|
79
|
+
build_environment_filepath,
|
77
80
|
'build',
|
78
81
|
build_cache_option,
|
79
82
|
artifact_name,
|
@@ -125,7 +128,7 @@ module Shiplane
|
|
125
128
|
end
|
126
129
|
|
127
130
|
def shiplane_config
|
128
|
-
@shiplane_config ||= Shiplane::Configuration.new
|
131
|
+
@shiplane_config ||= Shiplane::Configuration.new(stage: stage)
|
129
132
|
end
|
130
133
|
|
131
134
|
def docker_config
|
@@ -187,12 +190,12 @@ module Shiplane
|
|
187
190
|
end
|
188
191
|
|
189
192
|
# API Helper Methods
|
190
|
-
def self.build!(sha, postfix
|
191
|
-
new(sha, postfix: postfix).build!
|
193
|
+
def self.build!(sha, postfix: nil, stage: nil)
|
194
|
+
new(sha, postfix: postfix, stage: stage).build!
|
192
195
|
end
|
193
196
|
|
194
|
-
def self.build_latest!(sha, postfix
|
195
|
-
new(sha, postfix: postfix, tag_latest: true).build!
|
197
|
+
def self.build_latest!(sha, postfix: nil, stage: nil)
|
198
|
+
new(sha, postfix: postfix, tag_latest: true, stage: stage).build!
|
196
199
|
end
|
197
200
|
end
|
198
201
|
end
|
@@ -4,25 +4,23 @@ module Shiplane
|
|
4
4
|
class CheckoutArtifact
|
5
5
|
extend Forwardable
|
6
6
|
attr_accessor :sha
|
7
|
+
attr_reader :shiplane_config
|
7
8
|
|
8
9
|
delegate %i(build_config project_config) => :shiplane_config
|
9
10
|
|
10
|
-
def initialize(sha)
|
11
|
+
def initialize(sha, config: nil)
|
11
12
|
@sha = sha
|
13
|
+
@shiplane_config = config || Shiplane::Configuration.new
|
12
14
|
|
13
15
|
# call this before changing directories.
|
14
16
|
# This prevents race conditions where the config file is accessed before being downloaded
|
15
|
-
shiplane_config
|
17
|
+
@shiplane_config
|
16
18
|
end
|
17
19
|
|
18
20
|
def appname
|
19
21
|
@appname ||= project_config['appname']
|
20
22
|
end
|
21
23
|
|
22
|
-
def shiplane_config
|
23
|
-
@shiplane_config ||= Shiplane::Configuration.new
|
24
|
-
end
|
25
|
-
|
26
24
|
def github_token
|
27
25
|
@github_token ||= ENV['GITHUB_TOKEN']
|
28
26
|
end
|
@@ -40,7 +38,7 @@ module Shiplane
|
|
40
38
|
end
|
41
39
|
|
42
40
|
def make_directory
|
43
|
-
FileUtils.mkdir_p
|
41
|
+
FileUtils.mkdir_p app_directory
|
44
42
|
end
|
45
43
|
|
46
44
|
def checkout!
|
@@ -49,18 +47,40 @@ module Shiplane
|
|
49
47
|
puts "Checking out Application #{appname}[#{sha}]..."
|
50
48
|
make_directory
|
51
49
|
|
52
|
-
success =
|
53
|
-
|
54
|
-
|
55
|
-
success = success && system("curl -L #{git_url}/archive/#{sha}.tar.gz --output #{appname}-#{sha}.tar.gz")
|
56
|
-
success = success && system("tar -xzf #{appname}-#{sha}.tar.gz -C .")
|
57
|
-
end
|
50
|
+
success = system("echo 'Downloading #{git_url}/archive/#{sha}.tar.gz --output #{archive_filename}'")
|
51
|
+
success = success && download_archive
|
52
|
+
success = success && unpack_archive
|
58
53
|
|
59
54
|
raise "Errors encountered while downloading archive" unless success
|
60
55
|
puts "Finished checking out Application"
|
61
56
|
tasks.each(&method(:send))
|
62
57
|
end
|
63
58
|
|
59
|
+
def archive_filename
|
60
|
+
@archive_filename ||= "#{appname}-#{sha}.tar.gz"
|
61
|
+
end
|
62
|
+
|
63
|
+
def archive_path
|
64
|
+
@archive_path ||= File.join(app_directory, archive_filename)
|
65
|
+
end
|
66
|
+
|
67
|
+
def download_archive
|
68
|
+
return true if File.exist? archive_path
|
69
|
+
|
70
|
+
system("curl -L #{git_url}/archive/#{sha}.tar.gz --output #{archive_path}")
|
71
|
+
end
|
72
|
+
|
73
|
+
def unpack_archive
|
74
|
+
FileUtils.rm_rf(build_directory) if File.directory?(build_directory)
|
75
|
+
FileUtils.mkdir_p build_directory
|
76
|
+
|
77
|
+
success = true
|
78
|
+
FileUtils.cd app_directory do
|
79
|
+
success = success && system("tar -xzf #{appname}-#{sha}.tar.gz -C .")
|
80
|
+
end
|
81
|
+
success
|
82
|
+
end
|
83
|
+
|
64
84
|
def tasks
|
65
85
|
[:make_directories, :copy_env_files, :copy_insert_on_build_files, :unignore_required_directories]
|
66
86
|
end
|
@@ -115,8 +135,8 @@ module Shiplane
|
|
115
135
|
['vendor']
|
116
136
|
end
|
117
137
|
|
118
|
-
def self.checkout!(sha)
|
119
|
-
new(sha).checkout!
|
138
|
+
def self.checkout!(sha, config: nil)
|
139
|
+
new(sha, config: config).checkout!
|
120
140
|
end
|
121
141
|
end
|
122
142
|
end
|
@@ -1,9 +1,10 @@
|
|
1
1
|
module Shiplane
|
2
2
|
class Configuration
|
3
|
-
attr_accessor :project_folder
|
3
|
+
attr_accessor :project_folder, :stage
|
4
4
|
|
5
|
-
def initialize(project_folder
|
5
|
+
def initialize(project_folder: nil, stage: stage)
|
6
6
|
@project_folder = project_folder || Dir.pwd
|
7
|
+
@stage = stage
|
7
8
|
end
|
8
9
|
|
9
10
|
def shiplane_config_file
|
@@ -30,6 +31,15 @@ module Shiplane
|
|
30
31
|
@project_config ||= config.fetch('project', {})
|
31
32
|
end
|
32
33
|
|
34
|
+
def build_environment_filepath
|
35
|
+
return @build_environment_filepath if defined? @build_environment_filepath
|
36
|
+
|
37
|
+
@build_environment_filepath = build_config.fetch('environment_file', '.env')
|
38
|
+
@build_environment_filepath = File.join(project_folder, "#{@build_environment_filepath}.#{stage}") if File.exist?(File.join(project_folder, "#{@build_environment_filepath}.#{stage}"))
|
39
|
+
|
40
|
+
@build_environment_filepath
|
41
|
+
end
|
42
|
+
|
33
43
|
def self.config(project_folder = nil)
|
34
44
|
new(project_folder).config
|
35
45
|
end
|
@@ -6,16 +6,14 @@ module Shiplane
|
|
6
6
|
class ConvertComposeFile
|
7
7
|
extend Forwardable
|
8
8
|
attr_accessor :project_folder, :sha
|
9
|
+
attr_reader :shiplane_config
|
9
10
|
|
10
11
|
delegate %i(build_config) => :shiplane_config
|
11
12
|
|
12
|
-
def initialize(project_folder, sha)
|
13
|
+
def initialize(project_folder, sha, config: nil)
|
13
14
|
@project_folder = project_folder
|
14
15
|
@sha = sha
|
15
|
-
|
16
|
-
|
17
|
-
def shiplane_config
|
18
|
-
@shiplane_config ||= Shiplane::Configuration.new
|
16
|
+
@shiplane_config = config || Shiplane::Configuration.new
|
19
17
|
end
|
20
18
|
|
21
19
|
def compose_config
|
@@ -48,8 +46,8 @@ module Shiplane
|
|
48
46
|
puts "Compose File Converted..."
|
49
47
|
end
|
50
48
|
|
51
|
-
def self.convert_output!(project_folder, sha)
|
52
|
-
new(project_folder, sha).convert_output!
|
49
|
+
def self.convert_output!(project_folder, sha, config: nil)
|
50
|
+
new(project_folder, sha, config: config).convert_output!
|
53
51
|
end
|
54
52
|
end
|
55
53
|
end
|
@@ -4,23 +4,21 @@ module Shiplane
|
|
4
4
|
class ConvertDockerfile
|
5
5
|
extend Forwardable
|
6
6
|
attr_accessor :artifact_context, :compose_context, :project_folder
|
7
|
+
attr_reader :shiplane_config
|
7
8
|
|
8
9
|
delegate %i(build_config project_config) => :shiplane_config
|
9
10
|
|
10
|
-
def initialize(project_folder, artifact_context, compose_context)
|
11
|
+
def initialize(project_folder, artifact_context, compose_context, config: nil)
|
11
12
|
@project_folder = project_folder
|
12
13
|
@artifact_context = artifact_context
|
13
14
|
@compose_context = compose_context
|
15
|
+
@shiplane_config = config || Shiplane::Configuration.new
|
14
16
|
end
|
15
17
|
|
16
18
|
def appname
|
17
19
|
@appname ||= project_config['appname']
|
18
20
|
end
|
19
21
|
|
20
|
-
def shiplane_config
|
21
|
-
@shiplane_config ||= Shiplane::Configuration.new
|
22
|
-
end
|
23
|
-
|
24
22
|
def dockerfile_name
|
25
23
|
@dockerfile_name ||= compose_context.fetch('build', {}).fetch('context', '.').tap do |filename|
|
26
24
|
filename.gsub!(/^\.$/, 'Dockerfile')
|
@@ -53,8 +51,8 @@ module Shiplane
|
|
53
51
|
puts "Dockerfile Converted..."
|
54
52
|
end
|
55
53
|
|
56
|
-
def self.convert_output!(project_folder, artifact_context, compose_context)
|
57
|
-
new(project_folder, artifact_context, compose_context).convert_output!
|
54
|
+
def self.convert_output!(project_folder, artifact_context, compose_context, config: nil)
|
55
|
+
new(project_folder, artifact_context, compose_context, config: config).convert_output!
|
58
56
|
end
|
59
57
|
end
|
60
58
|
end
|
data/lib/shiplane/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shiplane
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Epperson
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.2.
|
19
|
+
version: 0.2.7
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.2.
|
26
|
+
version: 0.2.7
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: shiplane_deployers_capistrano_docker
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - '='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.2.
|
33
|
+
version: 0.2.7
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - '='
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.2.
|
40
|
+
version: 0.2.7
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: dotenv
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|