diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..9e90a9ee --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM ruby:2.7.8 + +WORKDIR /app +COPY . /app + +RUN ./cleanup_bundler +RUN gem install bundler -v '< 2' +RUN bundle install + +CMD ["/app/bin/aptible"] diff --git a/README.md b/README.md index 706131ae..9992d32a 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ Commands: aptible backup:restore BACKUP_ID [--environment ENVIRONMENT_HANDLE] [--handle HANDLE] [--container-size SIZE_MB] [--disk-size SIZE_GB] [--key-arn KEY_ARN] # Restore a backup aptible config # Print an app's current configuration aptible config:add [VAR1=VAL1] [VAR2=VAL2] [...] # Add an ENV variable to an app + aptible config:get [VAR1] # Print a specific key within an app's current configuration aptible config:rm [VAR1] [VAR2] [...] # Remove an ENV variable from an app aptible config:set [VAR1=VAL1] [VAR2=VAL2] [...] # Add an ENV variable to an app aptible config:unset [VAR1] [VAR2] [...] # Remove an ENV variable from an app diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..6a6a7726 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,10 @@ +services: + # docker compose run cli bash + # export APTIBLE_ACCESS_TOKEN=xxx + # bundle exec ./bin/aptible help + cli: + build: . + volumes: + - type: bind + source: . + target: /app diff --git a/lib/aptible/cli/subcommands/config.rb b/lib/aptible/cli/subcommands/config.rb index 0f384885..f1b1bae9 100644 --- a/lib/aptible/cli/subcommands/config.rb +++ b/lib/aptible/cli/subcommands/config.rb @@ -29,6 +29,23 @@ def config end end + desc 'config:get [VAR1]', + "Print a specific key within an app's current configuration" + app_options + define_method 'config:get' do |*args| + app = ensure_app(options) + config = app.current_configuration + env = config ? config.env : {} + + Formatter.render(Renderer.current) do |root| + key = args[0] + value = env + .select { |k| k == key } + .map { |_, v| v } + root.value(value) + end + end + desc 'config:add [VAR1=VAL1] [VAR2=VAL2] [...]', 'Add an ENV variable to an app' app_options diff --git a/spec/aptible/cli/subcommands/config_spec.rb b/spec/aptible/cli/subcommands/config_spec.rb index f59117d7..2af99a86 100644 --- a/spec/aptible/cli/subcommands/config_spec.rb +++ b/spec/aptible/cli/subcommands/config_spec.rb @@ -57,6 +57,28 @@ end end + describe '#config:get' do + it 'should show single environment variable specified' do + app.current_configuration = Fabricate( + :configuration, app: app, env: { 'FOO' => 'BAR', 'QUX' => 'two words' } + ) + subject.send('config:get', 'FOO') + + expect(captured_output_text).to match(/BAR/) + expect(captured_output_text).not_to match(/two\\ words/) + expect(captured_output_json).to match_array(['BAR']) + end + + it 'should show empty line when env var not found' do + app.current_configuration = Fabricate( + :configuration, app: app, env: { 'FOO' => 'BAR', 'QUX' => 'two words' } + ) + subject.send('config:get', 'MIZ') + + expect(captured_output_text).to eq('') + end + end + describe '#config:set' do it 'sets environment variables' do expect(app).to receive(:create_operation!)