Top Level Namespace

Defined Under Namespace

Modules: CommitMetadataPersistable, Minitest, NdrDevSupport

Instance Method Summary collapse

Instance Method Details

#add_secret(repo:, repo_path:, shared_dest:) ⇒ Object

Add a secret to be deployed by ndr_dev_support:deploy_secrets



13
14
15
16
17
18
19
# File 'lib/ndr_dev_support/capistrano/deploy_secrets.rb', line 13

def add_secret(repo:, repo_path:, shared_dest:)
  secrets = fetch(:secrets, [])
  raise "Unknown repo #{repo}" unless fetch(:secrets_repositories, {}).key?(repo)

  secrets << { repo: repo, repo_path: repo_path, shared_dest: shared_dest }
  set :secrets, secrets
end

#add_secrets_repo(name:, url:, scm:, branch: nil) ⇒ Object

Add a git or svn secrets respository for ndr_dev_support:deploy_secrets



2
3
4
5
6
7
8
9
10
# File 'lib/ndr_dev_support/capistrano/deploy_secrets.rb', line 2

def add_secrets_repo(name:, url:, scm:, branch: nil)
  raise "Invalid repo name #{name}" unless /\A[A-Z0-9_-]+\z/i.match?(name)
  raise "Unknown scm #{scm}" unless %w[svn git].include?(scm)
  raise "Expected branch for repo #{name}" if scm == 'git' && branch.to_s.empty?

  secrets_repositories = fetch(:secrets_repositories, {})
  secrets_repositories[name] = { url: url, scm: scm, branch: branch }
  set :secrets_repositories, secrets_repositories
end

#add_target(env, name, app, port, app_user, is_web_server) ⇒ Object



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/ndr_dev_support/capistrano/ndr_model.rb', line 188

def add_target(env, name, app, port, app_user, is_web_server)
  desc "Deploy to #{env} service #{app_user || 'you'}@#{app}:#{port}"
  task(name) do
    set :name, name

    set :application_user, app_user

    role :app, app
    set :port, port

    set :webapp_deployment, is_web_server
    set :daemon_deployment, !is_web_server

    set :branch, release_config_for(env).fetch('branch')
    if exists?(:repository_branches)
      set :repository, fetch(:repository_branches) + fetch(:branch)
    end

    # Extract Ruby configuration if available:
    ruby_version = target_ruby_version_for(env)
    set :ruby, ruby_version if ruby_version
  end
  after name, 'ndr_dev_support:prepare'
end

#release_config_for(env) ⇒ Object



176
177
178
179
# File 'lib/ndr_dev_support/capistrano/ndr_model.rb', line 176

def release_config_for(env)
  branches = YAML.safe_load_file('config/deployments.yml', permitted_classes: [Date])
  branches.fetch(env.to_s) { raise 'Unknown release branch!' }
end

#target_ruby_version_for(env) ⇒ Object



181
182
183
184
185
186
# File 'lib/ndr_dev_support/capistrano/ndr_model.rb', line 181

def target_ruby_version_for(env)
  raw   = release_config_for(env).fetch('ruby')
  match = raw.match(/\A(?<version>\d+\.\d+\.\d+)\z/)

  match ? match[:version] : raise('Unrecognized Ruby version!')
end