Class: Capistrano::DataPlaneApi::Deploy::Args
- Inherits:
-
Object
- Object
- Capistrano::DataPlaneApi::Deploy::Args
- Defined in:
- lib/capistrano/data_plane_api/deploy/args.rb
Overview
Class which parses all provided command-line arguments passed to the deployment script and saves them in an object.
Constant Summary collapse
- PRINTABLE_ENV_VARS =
%w[BRANCH NO_MIGRATIONS NO_ASSET_PRECOMPILATION].freeze
Instance Attribute Summary collapse
-
#branch ⇒ Object
Git branch that the code will be deployed to.
-
#check ⇒ Object
Checks deployment dependencies.
- #force_haproxy ⇒ Object
-
#group ⇒ Object
Name of the HAProxy server group/backend.
- #no_haproxy ⇒ Object
- #no_migrations ⇒ Object
-
#only ⇒ Object
Ordered list of servers to which the app will be deployed.
-
#rake ⇒ Object
Rake command that will be called remotely (
deployby default). -
#stage ⇒ Object
Name of the deployment stage/server.
-
#test ⇒ Object
(also: #test?)
Runs in test mode if true, only prints commands without executing them.
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, val) ⇒ Object
- #deploy_command(stage = nil) ⇒ Object
- #humanized_deploy_command(stage = nil) ⇒ Object
-
#initialize ⇒ Args
constructor
A new instance of Args.
- #one_server? ⇒ Boolean
- #only? ⇒ Boolean
- #prepare_if_one_server ⇒ Object
Constructor Details
#initialize ⇒ Args
Returns a new instance of Args.
221 222 223 |
# File 'lib/capistrano/data_plane_api/deploy/args.rb', line 221 def initialize @rake = 'deploy' end |
Instance Attribute Details
#branch ⇒ Object
Git branch that the code will be deployed to
178 179 180 |
# File 'lib/capistrano/data_plane_api/deploy/args.rb', line 178 def branch @branch end |
#check ⇒ Object
Checks deployment dependencies
216 217 218 |
# File 'lib/capistrano/data_plane_api/deploy/args.rb', line 216 def check @check end |
#force_haproxy ⇒ Object
197 198 199 |
# File 'lib/capistrano/data_plane_api/deploy/args.rb', line 197 def force_haproxy @force_haproxy end |
#group ⇒ Object
Name of the HAProxy server group/backend
188 189 190 |
# File 'lib/capistrano/data_plane_api/deploy/args.rb', line 188 def group @group end |
#no_haproxy ⇒ Object
191 192 193 |
# File 'lib/capistrano/data_plane_api/deploy/args.rb', line 191 def no_haproxy @no_haproxy end |
#no_migrations ⇒ Object
194 195 196 |
# File 'lib/capistrano/data_plane_api/deploy/args.rb', line 194 def no_migrations @no_migrations end |
#only ⇒ Object
Ordered list of servers to which the app will be deployed
202 203 204 |
# File 'lib/capistrano/data_plane_api/deploy/args.rb', line 202 def only @only end |
#rake ⇒ Object
Rake command that will be called remotely (deploy by default)
207 208 209 |
# File 'lib/capistrano/data_plane_api/deploy/args.rb', line 207 def rake @rake end |
#stage ⇒ Object
Name of the deployment stage/server
212 213 214 |
# File 'lib/capistrano/data_plane_api/deploy/args.rb', line 212 def stage @stage end |
#test ⇒ Object Also known as: test?
Runs in test mode if true, only prints commands without executing them
183 184 185 |
# File 'lib/capistrano/data_plane_api/deploy/args.rb', line 183 def test @test end |
Class Method Details
.parse(options = nil) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/capistrano/data_plane_api/deploy/args.rb', line 17 def self.parse( = nil) # rubocop:disable Metrics/MethodLength, Style/ClassMethodsDefinitions args = new opt_parser = ::OptionParser.new do |parser| # rubocop:disable Metrics/BlockLength parser. = <<~BANNER Usage: bin/deploy [options] This script can be used to deploy this app to remote servers. BANNER parser.on( '-c', '--current', 'Deploy from the currently checked out branch', ) do |_val| args.branch = `git branch --show-current`.strip ::ENV['BRANCH'] = args.branch end parser.on( '-t', '--test', 'Show the commands that would be executed but do not carry out the deployment', ) do |val| args.test = val end parser.on( '-C', '--check', 'Test deployment dependencies. ' \ 'Checks things like directory permissions, necessary utilities, ' \ 'HaProxy backends and servers', ) do |val| args.check = val args.rake = 'deploy:check' if val end parser.on( '-g GROUP', '--group=GROUP', 'Deploy the code to every server in the passed HAProxy backend/group', ) do |val| args.group = val end parser.on( '--no-haproxy', 'Do not modify the state of any server in HAProxy', ) do |val| args.no_haproxy = val ::ENV['NO_HAPROXY'] = 'true' end parser.on( '--force-haproxy', 'Ignore the current state of servers in HAProxy', ) do |val| args.force_haproxy = val ::ENV['FORCE_HAPROXY'] = 'true' end parser.on( '-o ONLY', '--only=ONLY', 'Deploy the code only to the passed servers in the same order', ) do |val| next unless val args.only = val.split(',').map(&:strip).uniq end parser.on( '-H', '--haproxy-config', 'Show the current HAProxy configuration', ) do |val| next unless val ::Signal.trap('INT') { exit } ::Capistrano::DataPlaneApi.show_config exit end parser.on( '-S', '--haproxy-state', 'Show the current HAProxy state', ) do |val| next unless val ::Signal.trap('INT') { exit } ::Capistrano::DataPlaneApi.show_state exit end parser.on( '-T', '--tasks', 'Print a list of all available deployment Rake tasks', ) do |val| next unless val puts COLORS.bold.blue('Available Rake Tasks') `cap -T`.each_line do |line| puts line.delete_prefix('cap ') end exit end parser.on( '-r RAKE', '--rake=RAKE', 'Carry out a particular Rake task on the server', ) do |val| next unless val args.rake = val end parser.on('-h', '--help', 'Prints this help') do puts parser exit end parser.on( '-b BRANCH', '--branch=BRANCH', 'Deploy the code from the passed Git branch', ) do |val| args.branch = val ::ENV['BRANCH'] = val end parser.on( '--no-migrations', 'Do not carry out migrations', ) do |val| args.no_migrations = val ::ENV['NO_MIGRATIONS'] = 'true' end parser.on( '-A', '--no-asset-precompilation', 'Skip asset precompilation during deployment', ) do ::ENV['NO_ASSET_PRECOMPILATION'] = 'true' end end opt_parser.parse!( || ::ARGV) args.stage = ::ARGV.first&.start_with?('-') ? nil : ::ARGV.first args.prepare_if_one_server args end |
Instance Method Details
#[](key) ⇒ Object
261 262 263 |
# File 'lib/capistrano/data_plane_api/deploy/args.rb', line 261 def [](key) public_send(key) end |
#[]=(key, val) ⇒ Object
266 267 268 |
# File 'lib/capistrano/data_plane_api/deploy/args.rb', line 266 def []=(key, val) public_send("#{key}=", val) end |
#deploy_command(stage = nil) ⇒ Object
242 243 244 245 |
# File 'lib/capistrano/data_plane_api/deploy/args.rb', line 242 def deploy_command(stage = nil) used_stage = stage || self.stage "cap #{used_stage} #{rake}" end |
#humanized_deploy_command(stage = nil) ⇒ Object
248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/capistrano/data_plane_api/deploy/args.rb', line 248 def humanized_deploy_command(stage = nil) result = ::String.new PRINTABLE_ENV_VARS.each do |env_var_name| next unless (value = ::ENV[env_var_name]) result << "#{env_var_name}=#{value} " end result << deploy_command(stage) result end |
#one_server? ⇒ Boolean
271 272 273 |
# File 'lib/capistrano/data_plane_api/deploy/args.rb', line 271 def one_server? Boolean(@stage && @group.nil?) end |
#only? ⇒ Boolean
226 227 228 229 230 |
# File 'lib/capistrano/data_plane_api/deploy/args.rb', line 226 def only? return false if @only.nil? @only.any? end |
#prepare_if_one_server ⇒ Object
233 234 235 236 237 238 239 |
# File 'lib/capistrano/data_plane_api/deploy/args.rb', line 233 def prepare_if_one_server return unless one_server? server, backend = ::Capistrano::DataPlaneApi.find_server_and_backend(T.must(@stage)) @only = [T.must(server.name)] @group = backend.name end |