shiplane 0.2.6 → 0.2.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5b5acdecf601b6e3dcc169a7034ba182339401e432a4ede3a718f0fce112f400
4
- data.tar.gz: 311b91b9388650ccdf260dca0a92f99c776019e182a05044b31fb352a0a5a51b
3
+ metadata.gz: 6bbe97524b9b82e6b2582798b437608cff1824a7c03f5551c5de8fed3d4693c1
4
+ data.tar.gz: 8e0b79ded64782d46a625c23bc7d093e6e6e7f38fca3306711bb71374b10816c
5
5
  SHA512:
6
- metadata.gz: 3fd03c6026a3a18cbcbdf974830f826c4c766712b7859de225a86b50c15e45970e9ac03a531204af708a5e81ffa8e79f3fbe39b8640f7e9443b2b68c19c0a7eb
7
- data.tar.gz: dda7a3732b07058709461b24deccf24a9c471381af8667e915344e0ee1dcb9f7ac3b4e969e7e9d93ef1f541eeb064c491858aa104733e7485258f838bc90b926
6
+ metadata.gz: 7834ebda28494d3a6b99315bb841f22bb11fe45aee07fabd652d2e2e5e684082169d1c4abcc362e431d9f4c1cd269724b6c198c1cc272286ad5508211267a42d
7
+ data.tar.gz: 802840623b6b1d23147bc59b8b9e6adad23e74eff89cb2b12a13768faceaca6b249061888365302694c5bf10242cec02dd29947f3dbd5b2740e6653a4007b989
data/README.md CHANGED
@@ -118,6 +118,33 @@ You can build a docker container based on the HEAD of your current branch like s
118
118
  bundle exec cap production shiplane
119
119
  ```
120
120
 
121
+ ### Environment Variables
122
+ Shiplane uses specific .env files to make sure that a given build environment contains the appropriate environment variables. These are used for 3 separate purposes:
123
+ - The environment that the Shiplane process is running in. For example, if you want to authenticate with a Github private repo, you will need to set the GITHUB_TOKEN environment variable in your .env file so that Shiplane can authenticate.
124
+ - The buildtime step of building the container. If your container needs environment variables to be set during buildtime so that the container can be built, you will need these builtime env variables. Examples might include a Github Token used to pull dependencies from private repositories on Github during buildtime. These variables will not be stored in your container, but you may need to remove any traces of these variables that might be stored in your container as side effects if your dependency ecosystem does this. For example, Ruby Gems downloaded during buildtime using an Github Token will result in that token being stored in the Gemfile.lock file. The [examples folder](examples/rails_app/.shiplane/production_dockerfile_stages) provide an example of a means of removing this after bundling. You may consider a similar step during your build process.
125
+ - The runtime environment may require some environment variables. For example, you might have a bunch of ENVIRONMENT VARIABLES necessary for your application to run (less secure, but simpler), or, you might need an environment variable to access a vault somewhere containing other runtime ENVIRONMENT VARIABLES (more secure, slightly more difficult), or, you may have none at all and use another mechanism to inject appropriate settings (you have more control over this, but the most difficult).
126
+
127
+ ## Important ENVIRONMENT VARIABLES for the Shiplane Process
128
+ ```sh
129
+ GITHUB_TOKEN=XXXXXXXXXX # required if pulling from a private Github Repository
130
+ BITBUCKET_TOKEN=XXXXXXXXXX # required if pulling from a private Bitbucket Repository
131
+ BITBUCKET_USERNAME=XXXXXXXXXX # required if pulling from a private Bitbucket Repository
132
+ ```
133
+
134
+ ## Important ENVIRONMENT VARIABLES for buildtime
135
+ ```sh
136
+ DOCKERHUB_PASSWORD=XXXXXXXXXX # deprecated but still supported token/password specifically for DOCKERHUB
137
+ DOCKERHUB_USERNAME=XXXXXXXXXX # deprecated but still supported username specifically for DOCKERHUB
138
+ SHIPLANE_CONTAINER_REGISTRY_TOKEN=XXXXXXXXXX # Token for container registry authentication
139
+ SHIPLANE_CONTAINER_REGISTRY_USERNAME=XXXXXXXXXX # Username for container registry authentication
140
+ RAISE_EXCEPTIONS_ON_FAILED_BUILD=true # Tells Shiplane to stop on a failed build and raise an exception. Defaults to 'false'
141
+ ```
142
+ ## Important ENVIRONMENT VARIABLES for runtime
143
+ # Rails Environment Variable sample
144
+ ```sh
145
+ RAILS_MASTER_KEY=XXXXXXXXXX
146
+ ```
147
+
121
148
  #### Deploying
122
149
  Shiplane provides tasks to help you deploy your code. These tasks depend on your deployment framework, but each task appropriately launches your docker containers on your selected framework.
123
150
 
@@ -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
@@ -1,17 +1,18 @@
1
1
  project:
2
2
  appname: <%= app_name %>
3
3
  version_control: git
4
- # The origin url on Github
5
- # origin: username/repo_title
4
+ version_control_host: github # alternately, use `bitbucket` if your application is hosted on BitBucket
5
+ # The origin url on Github or Bitbucket
6
+ origin: #username/<%= app_name %>
6
7
  bootstrap:
7
8
  env_file: .env.production
8
9
  chef-bootstrapper:
9
- package_name: chefdk_3.13.1-1_amd64.deb
10
- package_url: https://packages.chef.io/files/stable/chefdk/3.13.1/ubuntu/16.04/chefdk_3.13.1-1_amd64.deb
10
+ package_name: chefdk_3.6.57-1_amd64.deb
11
+ package_url: https://packages.chef.io/files/stable/chefdk/3.6.57/ubuntu/18.04/chefdk_3.6.57-1_amd64.deb
11
12
  build:
12
13
  registry:
13
14
  # url: ghcr.io # for Github Container Service. Should work for similar services such as Gitlab
14
- # url: :dockerhub # for default Dockerhub Service
15
+ # url: dockerhub # for default Dockerhub Service
15
16
  settings_folder: .shiplane
16
17
  environment_file: .env.production
17
18
  compose_filepath: docker-compose.yml
@@ -20,7 +21,7 @@ build:
20
21
  artifacts:
21
22
  container-name:
22
23
  tag: <%= app_name %>-base:latest
23
- repo: kirillian2/<%= app_name %>
24
+ repo: #username/<%= app_name %>
24
25
  ports:
25
26
  - "3000:3000"
26
27
  compose:
@@ -40,8 +41,8 @@ deploy:
40
41
  requires_sudo: false
41
42
  # Put SSH options here
42
43
  # ssh_options:
43
- # user: a_user
44
- # keys: "path/to/ssh/keys"
44
+ # user: <%= ENV['SSH_USERNAME_ENV_VARIABLE_HERE'] %>
45
+ # keys: <%= ENV['PATH_TO_SSH_KEYS_HERE'] %>
45
46
  # forward_agent: true
46
47
  # auth_methods:
47
48
  # - publickey
@@ -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|
@@ -52,7 +53,7 @@ module Shiplane
52
53
  end
53
54
  rescue StepFailureException => e
54
55
  puts e.message
55
- raise if ENV['RAISE_EXCEPTIONS_ON_FAILED_BUILD']
56
+ raise if ENV['RAISE_EXCEPTIONS_ON_FAILED_BUILD'] == 'true'
56
57
  end
57
58
 
58
59
  def steps(artifact_name, attributes)
@@ -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
@@ -144,7 +147,7 @@ module Shiplane
144
147
  end
145
148
 
146
149
  def dockerhub?
147
- registry_configuration['url'] == :dockerhub
150
+ registry_configuration['url'].to_s == 'dockerhub'
148
151
  end
149
152
 
150
153
  def token_auth?
@@ -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,31 +4,54 @@ 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
+ def bitbucket_origin?
25
+ project_config['version_control_host'] == 'bitbucket'
26
+ end
27
+
28
+ def github_origin?
29
+ project_config['version_control_host'] == 'github'
24
30
  end
25
31
 
26
32
  def github_token
27
33
  @github_token ||= ENV['GITHUB_TOKEN']
28
34
  end
29
35
 
36
+ def bitbucket_token
37
+ @bitbucket_token ||= ENV['BITBUCKET_APP_PASSWORD']
38
+ end
39
+
40
+ def bitbucket_username
41
+ @bitbucket_username ||= ENV['BITBUCKET_APP_USERNAME']
42
+ end
43
+
30
44
  def git_url
31
- "https://#{github_token ? "#{github_token}@" : ''}github.com/#{project_config['origin']}"
45
+ return github_url if github_origin?
46
+ return bitbucket_url if bitbucket_origin?
47
+ end
48
+
49
+ def github_url
50
+ "https://#{github_token ? "#{github_token}@" : ''}github.com/#{project_config['origin']}/archive/#{sha}.tar.gz"
51
+ end
52
+
53
+ def bitbucket_url
54
+ "https://#{bitbucket_token ? "#{bitbucket_username}:#{bitbucket_token}@" : ''}bitbucket.org/#{project_config['origin']}/get/#{sha}.tar.gz"
32
55
  end
33
56
 
34
57
  def app_directory
@@ -40,7 +63,7 @@ module Shiplane
40
63
  end
41
64
 
42
65
  def make_directory
43
- FileUtils.mkdir_p build_directory
66
+ FileUtils.mkdir_p app_directory
44
67
  end
45
68
 
46
69
  def checkout!
@@ -49,18 +72,40 @@ module Shiplane
49
72
  puts "Checking out Application #{appname}[#{sha}]..."
50
73
  make_directory
51
74
 
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
75
+ success = system("echo 'Downloading #{git_url}/archive/#{sha}.tar.gz --output #{archive_filename}'")
76
+ success = success && download_archive
77
+ success = success && unpack_archive
58
78
 
59
79
  raise "Errors encountered while downloading archive" unless success
60
80
  puts "Finished checking out Application"
61
81
  tasks.each(&method(:send))
62
82
  end
63
83
 
84
+ def archive_filename
85
+ @archive_filename ||= "#{appname}-#{sha}.tar.gz"
86
+ end
87
+
88
+ def archive_path
89
+ @archive_path ||= File.join(app_directory, archive_filename)
90
+ end
91
+
92
+ def download_archive
93
+ return true if File.exist? archive_path
94
+
95
+ system("curl -L #{git_url} --output #{archive_path}")
96
+ end
97
+
98
+ def unpack_archive
99
+ FileUtils.rm_rf(build_directory) if File.directory?(build_directory)
100
+ FileUtils.mkdir_p build_directory
101
+
102
+ success = true
103
+ FileUtils.cd app_directory do
104
+ success = success && system("tar -xzf #{appname}-#{sha}.tar.gz -C .")
105
+ end
106
+ success
107
+ end
108
+
64
109
  def tasks
65
110
  [:make_directories, :copy_env_files, :copy_insert_on_build_files, :unignore_required_directories]
66
111
  end
@@ -115,8 +160,8 @@ module Shiplane
115
160
  ['vendor']
116
161
  end
117
162
 
118
- def self.checkout!(sha)
119
- new(sha).checkout!
163
+ def self.checkout!(sha, config: nil)
164
+ new(sha, config: config).checkout!
120
165
  end
121
166
  end
122
167
  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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Shiplane
4
- VERSION = "0.2.6"
4
+ VERSION = "0.2.9"
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.6
4
+ version: 0.2.9
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-10-25 00:00:00.000000000 Z
11
+ date: 2022-05-29 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.6
19
+ version: 0.2.9
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.6
26
+ version: 0.2.9
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.6
33
+ version: 0.2.9
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.6
40
+ version: 0.2.9
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: dotenv
43
43
  requirement: !ruby/object:Gem::Requirement