Skip to content

Commit

Permalink
Add services::settings to change ZDD options (#353)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdelaossa authored Sep 19, 2024
1 parent 25ffcff commit 70bb3d2
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 31 deletions.
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ PATH
specs:
aptible-cli (0.21.0)
activesupport (>= 4.0, < 6.0)
aptible-api (~> 1.6.2)
aptible-api (~> 1.6.5)
aptible-auth (~> 1.2.5)
aptible-billing (~> 1.0)
aptible-resource (~> 1.1)
Expand All @@ -28,7 +28,7 @@ GEM
tzinfo (~> 1.1)
addressable (2.8.0)
public_suffix (>= 2.0.2, < 5.0)
aptible-api (1.6.2)
aptible-api (1.6.5)
aptible-auth
aptible-resource
gem_config
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ Commands:
aptible rebuild # Rebuild an app, and restart its services
aptible restart # Restart all services associated with an app
aptible services # List Services for an App
aptible services:settings SERVICE [--force-zero-downtime|--no-force-zero-downtime] [--simple-health-check|--no-simple-health-check] # Modifies the zero-downtime deploy setting for a service
aptible ssh [COMMAND] # Run a command against an app
aptible version # Print Aptible CLI version
```
Expand Down
2 changes: 1 addition & 1 deletion aptible-cli.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
spec.require_paths = ['lib']

spec.add_dependency 'activesupport', '>= 4.0', '< 6.0'
spec.add_dependency 'aptible-api', '~> 1.6.2'
spec.add_dependency 'aptible-api', '~> 1.6.5'
spec.add_dependency 'aptible-auth', '~> 1.2.5'
spec.add_dependency 'aptible-billing', '~> 1.0'
spec.add_dependency 'aptible-resource', '~> 1.1'
Expand Down
23 changes: 23 additions & 0 deletions lib/aptible/cli/subcommands/services.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,29 @@ def services
end
end
end

desc 'services:settings SERVICE'\
' [--force-zero-downtime|--no-force-zero-downtime]'\
' [--simple-health-check|--no-simple-health-check]',
'Modifies the zero-downtime deploy setting for a service'
app_options
option :force_zero_downtime,
type: :boolean, default: false,
desc: 'Force zero downtime deployments.'\
' Has no effect if service has an associated Endpoint'
option :simple_health_check,
type: :boolean, default: false,
desc: 'Use a simple uptime healthcheck during deployments'
define_method 'services:settings' do |service|
service = ensure_service(options, service)
updates = {}
updates[:force_zero_downtime] =
options[:force_zero_downtime] if options[:force_zero_downtime]
updates[:naive_health_check] =
options[:simple_health_check] if options[:simple_health_check]

service.update!(**updates) if updates.any?
end
end
end
end
Expand Down
89 changes: 61 additions & 28 deletions spec/aptible/cli/subcommands/services_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,78 @@
allow(subject).to receive(:fetch_token) { token }
allow(Aptible::Api::App).to receive(:all).with(token: token)
.and_return([app])
allow(subject).to receive(:options).and_return(app: app.handle)
end

it 'lists a CMD service' do
Fabricate(:service, app: app, process_type: 'cmd', command: nil)
subject.send('services')
describe '#services' do
before do
allow(subject).to receive(:options).and_return(app: app.handle)
end

expect(captured_output_text.split("\n")).to include('Service: cmd')
expect(captured_output_text.split("\n")).to include('Command: CMD')
end
it 'lists a CMD service' do
Fabricate(:service, app: app, process_type: 'cmd', command: nil)
subject.send('services')

it 'lists a service with command' do
Fabricate(:service, app: app, process_type: 'cmd', command: 'foobar')
subject.send('services')
expect(captured_output_text.split("\n")).to include('Service: cmd')
expect(captured_output_text.split("\n")).to include('Command: CMD')
end

expect(captured_output_text.split("\n")).to include('Service: cmd')
expect(captured_output_text.split("\n")).to include('Command: foobar')
end
it 'lists a service with command' do
Fabricate(:service, app: app, process_type: 'cmd', command: 'foobar')
subject.send('services')

it 'lists container size' do
Fabricate(:service, app: app, container_memory_limit_mb: 1024)
subject.send('services')
expect(captured_output_text.split("\n")).to include('Service: cmd')
expect(captured_output_text.split("\n")).to include('Command: foobar')
end

expect(captured_output_text.split("\n")).to include('Container Size: 1024')
end
it 'lists container size' do
Fabricate(:service, app: app, container_memory_limit_mb: 1024)
subject.send('services')

expect(captured_output_text.split("\n"))
.to include('Container Size: 1024')
end

it 'lists container count' do
Fabricate(:service, app: app, container_count: 3)
subject.send('services')
it 'lists container count' do
Fabricate(:service, app: app, container_count: 3)
subject.send('services')

expect(captured_output_text.split("\n")).to include('Container Count: 3')
expect(captured_output_text.split("\n")).to include('Container Count: 3')
end

it 'lists multiple services' do
Fabricate(:service, app: app, process_type: 'foo')
Fabricate(:service, app: app, process_type: 'bar')
subject.send('services')

expect(captured_output_text.split("\n")).to include('Service: foo')
expect(captured_output_text.split("\n")).to include('Service: bar')
end
end

it 'lists multiple services' do
Fabricate(:service, app: app, process_type: 'foo')
Fabricate(:service, app: app, process_type: 'bar')
subject.send('services')
describe '#services:settings' do
let(:base_options) { { app: app.handle } }

it 'allows changing zero_downtime_deployment settings' do
stub_options(force_zero_downtime: true, simple_health_check: true)
service = Fabricate(:service, app: app, process_type: 'foo')

expect(service).to receive(:update!)
.with(force_zero_downtime: true, naive_health_check: true)

subject.send('services:settings', 'foo')
end

it 'allows changing only one of the options' do
stub_options(simple_health_check: true)
service = Fabricate(:service, app: app, process_type: 'foo')

expect(service).to receive(:update!).with(naive_health_check: true)

subject.send('services:settings', 'foo')
end
end

expect(captured_output_text.split("\n")).to include('Service: foo')
expect(captured_output_text.split("\n")).to include('Service: bar')
def stub_options(**opts)
allow(subject).to receive(:options).and_return(base_options.merge(opts))
end
end

0 comments on commit 70bb3d2

Please sign in to comment.