shiplane 0.2.3 → 0.2.7

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a65c39ac05e2fac9eb88f9e80706577318ce04fe04f782d2a9730bc24000b218
4
- data.tar.gz: adf16d46271c06b14f320ffe00bcdbb98d83dca3bcd3f5127bdbf3089b348b0c
3
+ metadata.gz: 7b5ceb3e3ec92da5d153b204c2f3d8e8d9108bc354c2690f6d9de39b69ee1893
4
+ data.tar.gz: f4e5b7340fa59249d4a3ffdfc2ce0f612a6c3faaf49208feebfb12fa0853f099
5
5
  SHA512:
6
- metadata.gz: '08be86c9d7d83f8df85d111ab1f623d0c34683bbff17f50ef7e1139aee5a27862c078cb649b9256f4912f8139b1a3afde7358f7561d410f566a572bc49c5316c'
7
- data.tar.gz: 5d65f4e2c62243105f865fe47deeb12e3a3b2fcd62e0e02842ae29ed086db883a28748ec497976faa37317d70d32dbd1d90f98fe32d8f046ff22983a6d7d1a97
6
+ metadata.gz: 74ce1231080dca4313fa9ed5c37c3197c2fd7e3d05ce275c13e1c0a4aac0a1a8c1f4d0a224b423141cdfc5633c57ad490c46834a8045395948ff9f082ff351dd
7
+ data.tar.gz: f627396ec65b1f5cba4215567d7b0559b91501e5336a3d03a560877d589b0eb452b8380bac1602931be97c7f98c978c53d2fe7713eb080b7600f558429ce6f87
data/README.md CHANGED
@@ -131,6 +131,12 @@ You can run a deployment like so:
131
131
  bundle exec cap production deploy
132
132
  ```
133
133
 
134
+ You can also deploy a specific Git SHA using the following syntax:
135
+
136
+ ```sh
137
+ bundle exec cap production deploy[<sha>]
138
+ ```
139
+
134
140
  ### Troubleshooting
135
141
  This is as much a reminder to me as anyone else. If a new version of the gem has just been released and you are trying to pull it, make sure to run the following if bundler fails:
136
142
  ```
@@ -12,6 +12,22 @@ namespace :deploy do
12
12
  end
13
13
  end
14
14
 
15
+ Rake::Task["deploy"].clear
16
+ task :deploy, :sha do |t, args|
17
+ sha = args[:sha] || fetch(:sha) || `git rev-parse HEAD`.chomp
18
+ set :sha, sha
19
+
20
+ set(:deploying, true)
21
+ %w{ starting started
22
+ updating updated
23
+ publishing published
24
+ finishing finished }.each do |task|
25
+ invoke "deploy:#{task}"
26
+ end
27
+ end
28
+ Rake::Task["default"].clear
29
+ task default: :deploy
30
+
15
31
 
16
32
  # deploy
17
33
  # deploy:check
@@ -11,6 +11,6 @@ namespace :shiplane do
11
11
  end
12
12
 
13
13
  task :build, :sha do |t, args|
14
- Shiplane::Build.build_latest!(args['sha'], fetch(:stage))
14
+ Shiplane::Build.build_latest!(args['sha'], postfix: fetch(:stage), stage: fetch(:stage))
15
15
  end
16
16
  end
@@ -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, build_config.fetch('environment_file', '.env'))
22
+ Dotenv.overload File.join(Dir.pwd, build_environment_filepath)
22
23
 
23
24
  # Add any ENV variable overrides from the capistrano configuration
24
- environment_variable_overrides = fetch(:shiplane_build_environment_variables, {})
25
- environment_variable_overrides.each do |key, value|
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 = nil)
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 = nil)
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 build_directory
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 = true
53
- FileUtils.cd app_directory do
54
- success = success && system("echo 'Downloading #{git_url}/archive/#{sha}.tar.gz --output #{appname}-#{sha}.tar.gz'")
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 = nil)
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
- end
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
@@ -44,7 +44,11 @@ module Shiplane
44
44
  end
45
45
 
46
46
  def virtual_host
47
- @virtual_host ||= options[:virtual_host]
47
+ return @virtual_host if defined?(@virtual_host) && @virtual_host
48
+
49
+ if options[:virtual_host]
50
+ @virtual_host = options[:virtual_host].is_a?(Proc) ? options[:virtual_host].call : options[:virtual_host]
51
+ end
48
52
  end
49
53
 
50
54
  def letsencrypt_host
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Shiplane
4
- VERSION = "0.2.3"
4
+ VERSION = "0.2.7"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shiplane
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Epperson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-02 00:00:00.000000000 Z
11
+ date: 2021-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: shiplane_bootstrappers_chef
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.2.3
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.3
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.3
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.3
40
+ version: 0.2.7
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: dotenv
43
43
  requirement: !ruby/object:Gem::Requirement