cpl 1.1.2 → 1.2.0

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: 89a038d31fb497bfc6c0d34451ace68fe554d700f4686413a1919cf6d9bceb09
4
- data.tar.gz: 3c733b43e703ad7b7798cf599b71f59ea1758ce2c71babd4486670c5ed5f12a3
3
+ metadata.gz: 711286ef49686f6c51df2a94c533b3df94f4d71d3fb6018b6ed61c210593dd47
4
+ data.tar.gz: '085357faac6b5b27e493049b34c27debab21fa19950af21548fe11889140b557'
5
5
  SHA512:
6
- metadata.gz: 325eecc73176b362c4b898632e45040544ecfdda14ecfbbd655caf92d0912aa3e431fbd8ac90c2681d4a2bcff68db0a71f80813601c1cf3b3ca32d44c9ef033f
7
- data.tar.gz: 0c0c04c6f1d4d57114d50d603fabfbd3470da4f373f48b091991e228306080f47bd3643e5c5c706fe9e3992e661b656b4634c881ee0861b79fbfa1f63a60d8e5
6
+ metadata.gz: ac229234f4919d8e1b3485095476ef0fddac04573d8dd03aba6a3737fd5e90b319538e04c51d98e5f33f244fe304c519d949a624a377bbc9ee9067754a0c71dd
7
+ data.tar.gz: 0ba5203d4f8539dde89a2eb5a52dc92c2098d11bb1914002cd57628081465d08e9842f47546da563bc18edda17fbf12101bfefca8fdcee4088825c0e56ee0fa0
@@ -36,5 +36,5 @@ jobs:
36
36
  uses: actions/upload-artifact@master
37
37
  if: always()
38
38
  with:
39
- name: coverage-report
39
+ name: coverage-report-${{ github.run_id }}-${{ matrix.os }}-${{ matrix.ruby }}
40
40
  path: coverage
data/CHANGELOG.md CHANGED
@@ -14,6 +14,28 @@ Changes since the last non-beta release.
14
14
 
15
15
  _Please add entries here for your pull requests that are not yet released._
16
16
 
17
+ ### Fixed
18
+
19
+ - Fixed issue where `info` command does not respect `CPLN_ORG` env var. [PR 88](https://github.com/shakacode/heroku-to-control-plane/pull/88) by [Rafael Gomes](https://github.com/rafaelgomesxyz).
20
+ - Fixed issues with running `cpl --version` and `cpl --help` where no configuration file exists. [PR 100](https://github.com/shakacode/heroku-to-control-plane/pull/100) by [Mostafa Ahangarha](https://github.com/ahangarha).
21
+ - Fixed issue where `delete` command fails to delete apps with volumesets. [PR 123](https://github.com/shakacode/heroku-to-control-plane/pull/123) by [Rafael Gomes](https://github.com/rafaelgomesxyz).
22
+
23
+ ### Added
24
+
25
+ - Added `--org` option to all commands. [PR 88](https://github.com/shakacode/heroku-to-control-plane/pull/88) by [Rafael Gomes](https://github.com/rafaelgomesxyz).
26
+ - Added option to set the app with a `CPLN_APP` env var. [PR 88](https://github.com/shakacode/heroku-to-control-plane/pull/88) by [Rafael Gomes](https://github.com/rafaelgomesxyz).
27
+ - Show `org` and `app` on every command excluding `info`, `version`, `maintenance`, `env`, `ps`, and `latest_image`. [PR 94](https://github.com/shakacode/heroku-to-control-plane/pull/94) by [Mostafa Ahangarha](https://github.com/ahangarha).
28
+ - Added option to only use `CPLN_ORG` and `CPLN_APP` env vars if `allow_org_override_by_env` and `allow_app_override_by_env` configs are set to `true` in `controlplane.yml`. [PR 109](https://github.com/shakacode/heroku-to-control-plane/pull/109) by [Rafael Gomes](https://github.com/rafaelgomesxyz).
29
+ - Added `CPLN_LOCATION` env variable and `--location` option for `apply-template`, `ps`, `run`, `run:detached`. [PR 105](https://github.com/shakacode/heroku-to-control-plane/pull/105) by [Mostafa Ahangarha](https://github.com/ahangarha).
30
+ - Added `generate` command for creating basic Control Plane configuration directory. [PR 116](https://github.com/shakacode/heroku-to-control-plane/pull/116) by [Mostafa Ahangarhga](https://github.com/ahangarha).
31
+ - Added `--trace` option to all commands for more detailed logs. [PR 124](https://github.com/shakacode/heroku-to-control-plane/pull/124) by [justin808](https://github.com/justin808)
32
+ - Added better error message to check the org name in case of a 403 error. [PR 124](https://github.com/justin808) by [justin808](https://github.com/justin808)
33
+
34
+ ### Changed
35
+
36
+ - `--org` option now takes precedence over `CPLN_ORG` env var, which takes precedence over `cpln_org` from `controlplane.yml`. [PR 88](https://github.com/shakacode/heroku-to-control-plane/pull/88) by [Rafael Gomes](https://github.com/rafaelgomesxyz).
37
+ - Renamed `setup` config into `setup_app_templates`. [PR 112](https://github.com/shakacode/heroku-to-control-plane/pull/112) by [Mostafa Ahangarha](https://github.com/ahangarha).
38
+
17
39
  ## [1.1.2] - 2023-10-17
18
40
 
19
41
  ### Fixed
@@ -23,7 +45,7 @@ _Please add entries here for your pull requests that are not yet released._
23
45
  ### Added
24
46
 
25
47
  - Added `open-console` command to open the app console on Control Plane. [PR 83](https://github.com/shakacode/heroku-to-control-plane/pull/83) by [Rafael Gomes](https://github.com/rafaelgomesxyz).
26
- - Added option to set the org with a `CPLN_ORG` env var. [PR 83](https://github.com/shakacode/heroku-to-control-plane/pull/83) by [Rafael Gomes](https://github.com/rafaelgomesxyz).
48
+ - Added option to set the org with a `CPLN_ORG`/`CPLN_ORG_UPSTREAM` env var. [PR 83](https://github.com/shakacode/heroku-to-control-plane/pull/83) by [Rafael Gomes](https://github.com/rafaelgomesxyz).
27
49
  - Added `--verbose` option to all commands for more detailed logs. [PR 83](https://github.com/shakacode/heroku-to-control-plane/pull/83) by [Rafael Gomes](https://github.com/rafaelgomesxyz).
28
50
 
29
51
  ### Changed
data/CONTRIBUTING.md CHANGED
@@ -12,12 +12,6 @@ git clone https://github.com/shakacode/heroku-to-control-plane
12
12
  alias cpl="~/projects/heroku-to-control-plane/bin/cpl"
13
13
  ```
14
14
 
15
- Or set the path of the Ruby gem in your Gemfile.
16
-
17
- ```ruby
18
- gem 'cpl', path: '~/projects/heroku-to-control-plane'
19
- ```
20
-
21
15
  ## Linting/Testing
22
16
 
23
17
  Before committing or pushing code, be sure to:
@@ -36,6 +30,8 @@ overcommit --install
36
30
 
37
31
  ## Debugging
38
32
 
33
+ 1. Use the `--verbose` option to see more detailed logs.
34
+ 2. Use the `--trace` option to see full logging of HTTP requests. Warning, this will display keys to your logs or console.
39
35
  1. Add a breakpoint (`debugger`) to any line of code you want to debug.
40
36
  2. Modify the `lib/command/test.rb` file to trigger the code you want to test. To simulate a command, you can use
41
37
  `Cpl::Cli.start` (e.g., `Cpl::Cli.start(["deploy-image", "-a", "my-app-name"])` would be the same as running
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cpl (1.1.2)
4
+ cpl (1.2.0)
5
5
  debug (~> 1.7.1)
6
6
  dotenv (~> 2.8.1)
7
7
  psych (~> 5.1.0)
@@ -24,8 +24,8 @@ GEM
24
24
  dotenv (2.8.1)
25
25
  hashdiff (1.0.1)
26
26
  iniparse (1.5.0)
27
- io-console (0.6.0)
28
- irb (1.8.3)
27
+ io-console (0.7.1)
28
+ irb (1.11.0)
29
29
  rdoc
30
30
  reline (>= 0.3.8)
31
31
  json (2.6.3)
@@ -36,15 +36,15 @@ GEM
36
36
  parallel (1.22.1)
37
37
  parser (3.2.0.0)
38
38
  ast (~> 2.4.1)
39
- psych (5.1.1.1)
39
+ psych (5.1.2)
40
40
  stringio
41
41
  public_suffix (5.0.1)
42
42
  rainbow (3.1.1)
43
43
  rake (13.0.6)
44
- rdoc (6.5.0)
44
+ rdoc (6.6.2)
45
45
  psych (>= 4.0.0)
46
46
  regexp_parser (2.6.2)
47
- reline (0.3.9)
47
+ reline (0.4.1)
48
48
  io-console (~> 0.5)
49
49
  rexml (3.2.5)
50
50
  rspec (3.12.0)
@@ -86,7 +86,7 @@ GEM
86
86
  simplecov_json_formatter (~> 0.1)
87
87
  simplecov-html (0.12.3)
88
88
  simplecov_json_formatter (0.1.4)
89
- stringio (3.0.8)
89
+ stringio (3.1.0)
90
90
  thor (1.2.2)
91
91
  timecop (0.9.6)
92
92
  unicode-display_width (2.4.2)
data/README.md CHANGED
@@ -6,13 +6,19 @@
6
6
  <meta name="keywords" content="Control Plane, Heroku, Kubernetes, K8, Infrastructure">
7
7
  <meta name="google-site-verification" content="dIV4nMplcYl6YOKOaZMqgvdKXhLJ4cdYY6pS6e_YrPU" />
8
8
 
9
- _A gem that provides **Heroku Flow** functionality on Control Plane, including docs for migrating from [Heroku](https://heroku.com) to [Control Plane](https://controlplane.com)_
9
+ _A gem that provides **Heroku Flow** functionality on Control Plane, including docs for migrating from [Heroku](https://heroku.com) to [Control Plane](https://shakacode.controlplane.com/)._
10
10
 
11
11
  [![RSpec](https://github.com/shakacode/heroku-to-control-plane/actions/workflows/rspec.yml/badge.svg)](https://github.com/shakacode/heroku-to-control-plane/actions/workflows/rspec.yml)
12
12
  [![Rubocop](https://github.com/shakacode/heroku-to-control-plane/actions/workflows/rubocop.yml/badge.svg)](https://github.com/shakacode/heroku-to-control-plane/actions/workflows/rubocop.yml)
13
13
 
14
14
  [![Gem](https://badge.fury.io/rb/cpl.svg)](https://badge.fury.io/rb/cpl)
15
15
 
16
+ ---
17
+
18
+ _If you need a free demo account for Control Plane (no CC required), you can contact [controlplane@shakacode.com](mailto:controlplane@shakacode.com)._
19
+
20
+ ---
21
+
16
22
  This playbook shows how to move "Heroku apps" to "Control Plane workloads" via an open-source `cpl` CLI on top of
17
23
  Control Plane's `cpln` CLI.
18
24
 
@@ -90,7 +96,7 @@ For the typical Rails app, this means:
90
96
 
91
97
  ## Installation
92
98
 
93
- 1. Ensure your [Control Plane](https://controlplane.com) account is set up. Set up an `organization` <your-org> for testing in that account and modify the value for `aliases.common.cpln_org` in `.controlplane/controlplane.yml`, or you can also set it with the `CPLN_ORG` environment variable. If you need an organization, please [contact Shakacode](mailto:controlplane@shakacode.com).
99
+ 1. Ensure your [Control Plane](https://shakacode.controlplane.com/) account is set up. Set up an `organization` `<your-org>` for testing in that account and modify the value for `aliases.common.cpln_org` in `.controlplane/controlplane.yml`, or you can also set it with the `CPLN_ORG` environment variable. If you need an organization, please [contact Shakacode](mailto:controlplane@shakacode.com).
94
100
 
95
101
  2. Install [Node.js](https://nodejs.org/en) (required for Control Plane CLI).
96
102
 
@@ -111,8 +117,7 @@ npm update -g @controlplane/cli
111
117
 
112
118
  5. Run `cpln image docker-login --org <your-org>` to ensure that you have access to the Control Plane Docker registry.
113
119
 
114
- 6. Install Heroku to Control Plane `cpl` CLI, either as a [Ruby gem](https://rubygems.org/gems/cpl) or a local clone.
115
- For information on the latter, see [CONTRIBUTING.md](CONTRIBUTING.md). You may also install `cpl` in your project's Gemfile.
120
+ 6. Install Heroku to Control Plane `cpl` CLI as a [Ruby gem](https://rubygems.org/gems/cpl): `gem install cpl`. If you want to hack on the source code, see [CONTRIBUTING.md](CONTRIBUTING.md).
116
121
 
117
122
  7. You can use [this Dockerfile](https://github.com/shakacode/react-webpack-rails-tutorial/blob/master/.controlplane/Dockerfile) as an example for your project. Ensure that you have Docker running.
118
123
 
@@ -138,7 +143,7 @@ The `cpl` gem is based on several configuration files within a `/.controlplane`
138
143
  ├─ entrypoint.sh
139
144
  ```
140
145
 
141
- 1. `controlplane.yml` describes the overall application. Be sure to have <your-org> as the value for `aliases.common.cpln_org`, or set it with the `CPLN_ORG` environment variable.
146
+ 1. `controlplane.yml` describes the overall application. Be sure to have `<your-org>` as the value for `aliases.common.cpln_org`, or set it with the `CPLN_ORG` environment variable.
142
147
  2. `Dockerfile` builds the production application. `entrypoint.sh` is an _example_ entrypoint script for the production application, referenced in your Dockerfile.
143
148
  3. `templates` directory contains the templates for the various workloads, such as `rails.yml` and `postgres.yml`.
144
149
  4. `templates/gvc.yml` defines your project's GVC (like a Heroku app). More importantly, it contains ENV values for the app.
@@ -153,18 +158,31 @@ Here's a complete example of all supported config keys explained for the `contro
153
158
  ```yaml
154
159
  # Keys beginning with "cpln_" correspond to your settings in Control Plane.
155
160
 
161
+ # Global settings that apply to `cpl` usage.
162
+ # You can opt out of allowing the use of CPLN_ORG and CPLN_APP env vars
163
+ # to avoid any accidents with the wrong org / app.
164
+ allow_org_override_by_env: true
165
+ allow_app_override_by_env: true
166
+
156
167
  aliases:
157
168
  common: &common
158
- # Organization name for staging (customize to your needs).
159
- # Production apps will use a different organization, specified below, for security.
169
+ # Organization for staging and QA apps is typically set as an alias.
170
+ # Production apps will use a different organization, specified in `apps`, for security.
171
+ # Change this value to your organization name
172
+ # or set the CPLN_ORG env var and it will override this for all `cpl` commands
173
+ # (provided that `allow_org_override_by_env` is set to `true`).
160
174
  cpln_org: my-org-staging
161
175
 
162
- # Example apps use only one location. Control Plane offers the ability to use multiple locations.
176
+ # Control Plane offers the ability to use multiple locations.
177
+ # default_location is used for commands that require a location
178
+ # including `ps`, `run`, `run:detached`, `apply-template`.
179
+ # This can be overridden with option --location=<location> and
180
+ # CPLN_LOCATION environment variable.
163
181
  default_location: aws-us-east-2
164
182
 
165
183
  # Allows running the command `cpl setup-app`
166
184
  # instead of `cpl apply-template gvc redis postgres memcached rails sidekiq`.
167
- setup:
185
+ setup_app_templates:
168
186
  - gvc
169
187
  - redis
170
188
  - postgres
@@ -224,6 +242,11 @@ apps:
224
242
  my-app-production:
225
243
  <<: *common
226
244
 
245
+ # You can also opt out of allowing the use of CPLN_ORG and CPLN_APP env vars per app.
246
+ # It's recommended to leave this off for production, to avoid any accidents.
247
+ allow_org_override_by_env: false
248
+ allow_app_override_by_env: false
249
+
227
250
  # Use a different organization for production.
228
251
  cpln_org: my-org-production
229
252
 
@@ -255,7 +278,7 @@ Suppose your app is called `tutorial-app`. You can run the following commands.
255
278
  ```sh
256
279
  # Provision all infrastructure on Control Plane.
257
280
  # `tutorial-app` will be created per definition in .controlplane/controlplane.yml.
258
- cpl apply-template gvc postgres redis rails -a tutorial-app
281
+ cpl apply-template gvc postgres redis rails daily-task -a tutorial-app
259
282
 
260
283
  # Build and push the Docker image to the Control Plane repository.
261
284
  # Note, it may take many minutes. Be patient.
@@ -405,7 +428,7 @@ spec:
405
428
  type: cron
406
429
  job:
407
430
  # Run daily job at 2am.
408
- schedule: 0 2 * * *
431
+ schedule: "0 2 * * *"
409
432
  # "Never" or "OnFailure"
410
433
  restartPolicy: Never
411
434
  containers:
data/docs/commands.md CHANGED
@@ -100,7 +100,7 @@ cpl copy-image-from-upstream -a $APP_NAME --upstream-token $UPSTREAM_TOKEN --ima
100
100
 
101
101
  ### `delete`
102
102
 
103
- - Deletes the whole app (GVC with all workloads and all images)
103
+ - Deletes the whole app (GVC with all workloads, all volumesets and all images)
104
104
  - Will ask for explicit user confirmation
105
105
 
106
106
  ```sh
@@ -131,6 +131,15 @@ cpl env -a $APP_NAME
131
131
  if [ cpl exists -a $APP_NAME ]; ...
132
132
  ```
133
133
 
134
+ ### `generate`
135
+
136
+ Creates base Control Plane config and template files
137
+
138
+ ```sh
139
+ # Creates .controlplane directory with Control Plane config and other templates
140
+ cpl generate
141
+ ```
142
+
134
143
  ### `info`
135
144
 
136
145
  - Displays the diff between defined/available apps/workloads (apps equal GVCs)
@@ -140,7 +149,7 @@ if [ cpl exists -a $APP_NAME ]; ...
140
149
  - The diff is based on what's defined in the `.controlplane/controlplane.yml` file
141
150
 
142
151
  ```sh
143
- # Shows diff for all apps in all orgs.
152
+ # Shows diff for all apps in all orgs (based on `.controlplane/controlplane.yml`).
144
153
  cpl info
145
154
 
146
155
  # Shows diff for all apps in a specific org.
@@ -312,7 +321,6 @@ cpl ps:swait -a $APP_NAME -w $WORKLOAD_NAME
312
321
 
313
322
  - Runs one-off **_interactive_** replicas (analog of `heroku run`)
314
323
  - Uses `Standard` workload type and `cpln exec` as the execution method, with CLI streaming
315
- - May not work correctly with tasks that last over 5 minutes (there's a Control Plane scaling bug at the moment)
316
324
  - If `fix_terminal_size` is `true` in the `.controlplane/controlplane.yml` file, the remote terminal size will be fixed to match the local terminal size (may also be overriden through `--terminal-size`)
317
325
 
318
326
  > **IMPORTANT:** Useful for development where it's needed for interaction, and where network connection drops and
@@ -391,8 +399,8 @@ cpl run:detached rails db:migrate:status -a $APP_NAME --use-local-token
391
399
  ### `setup-app`
392
400
 
393
401
  - Creates an app and all its workloads
394
- - Specify the templates for the app and workloads through `setup` in the `.controlplane/controlplane.yml` file
395
- - This should should only be used for temporary apps like review apps, never for persistent apps like production (to update workloads for those, use 'cpl apply-template' instead)
402
+ - Specify the templates for the app and workloads through `setup_app_templates` in the `.controlplane/controlplane.yml` file
403
+ - This should only be used for temporary apps like review apps, never for persistent apps like production (to update workloads for those, use 'cpl apply-template' instead)
396
404
 
397
405
  ```sh
398
406
  cpl setup-app -a $APP_NAME
data/docs/migrating.md CHANGED
@@ -29,13 +29,13 @@ Edit the `.controlplane/controlplane.yml` file as needed. Note that the `my-app-
29
29
  is defined in this file. See
30
30
  [this example](https://github.com/shakacode/react-webpack-rails-tutorial/blob/master/.controlplane/controlplane.yml).
31
31
 
32
- Before the initial setup, add the templates for the app to the `.controlplane/controlplane.yml` file, using the `setup`
32
+ Before the initial setup, add the templates for the app to the `.controlplane/controlplane.yml` file, using the `setup_app_templates`
33
33
  key, e.g.:
34
34
 
35
35
  ```yaml
36
36
  my-app-staging:
37
37
  <<: *common
38
- setup:
38
+ setup_app_templates:
39
39
  - gvc
40
40
  - redis
41
41
  - memcached
@@ -191,7 +191,7 @@ configure an entry for, e.g., `my-app-review`, and then create review apps start
191
191
  my-app-review:
192
192
  <<: *common
193
193
  match_if_app_name_starts_with: true
194
- setup:
194
+ setup_app_templates:
195
195
  - gvc
196
196
  - redis
197
197
  - memcached
@@ -1,15 +1,38 @@
1
1
  # Keys beginning with "cpln_" correspond to your settings in Control Plane.
2
2
 
3
+ # Global settings that apply to `cpl` usage.
4
+ # You can opt out of allowing the use of CPLN_ORG and CPLN_APP env vars
5
+ # to avoid any accidents with the wrong org / app.
6
+ allow_org_override_by_env: true
7
+ allow_app_override_by_env: true
8
+
3
9
  aliases:
4
10
  common: &common
5
- # Organization name for staging (customize to your needs).
6
- # Production apps will use a different organization, specified below, for security.
11
+ # Organization for staging and QA apps is typically set as an alias.
12
+ # Production apps will use a different organization, specified in `apps`, for security.
13
+ # Change this value to your organization name
14
+ # or set the CPLN_ORG env var and it will override this for all `cpl` commands
15
+ # (provided that `allow_org_override_by_env` is set to `true`).
7
16
  cpln_org: my-org-staging
8
17
 
9
- # Example apps use only one location. Control Plane offers the ability to use multiple locations.
18
+ # Control Plane offers the ability to use multiple locations.
19
+ # default_location is used for commands that require a location
20
+ # including `ps`, `run`, `run:detached`, `apply-template`.
21
+ # This can be overridden with option --location=<location> and
22
+ # CPLN_LOCATION environment variable.
10
23
  # TODO: Allow specification of multiple locations.
11
24
  default_location: aws-us-east-2
12
25
 
26
+ # Allows running the command `cpl setup-app`
27
+ # instead of `cpl apply-template gvc redis postgres memcached rails sidekiq`.
28
+ setup:
29
+ - gvc
30
+ - redis
31
+ - postgres
32
+ - memcached
33
+ - rails
34
+ - sidekiq
35
+
13
36
  # Configure the workload name used as a template for one-off scripts, like a Heroku one-off dyno.
14
37
  one_off_workload: rails
15
38
 
@@ -24,26 +47,62 @@ aliases:
24
47
  - postgres
25
48
  - memcached
26
49
 
27
- # Configure the workload name used when maintenance mode is on (defaults to "maintenance")
50
+ # Configure the workload name used when maintenance mode is on (defaults to "maintenance").
28
51
  maintenance_workload: maintenance
29
52
 
53
+ # Fixes the remote terminal size to match the local terminal size
54
+ # when running the commands `cpl run` or `cpl run:detached`.
55
+ fix_terminal_size: true
56
+
57
+ # Apps with a deployed image created before this amount of days will be listed for deletion
58
+ # when running the command `cpl cleanup-stale-apps`.
59
+ stale_app_image_deployed_days: 5
60
+
61
+ # Images that exceed this quantity will be listed for deletion
62
+ # when running the command `cpl cleanup-images`.
63
+ image_retention_max_qty: 20
64
+
65
+ # Images created before this amount of days will be listed for deletion
66
+ # when running the command `cpl cleanup-images` (`image_retention_max_qty` takes precedence).
67
+ image_retention_days: 5
68
+
69
+ # Run workloads created before this amount of days will be listed for deletion
70
+ # when running the command `cpl run:cleanup`.
71
+ stale_run_workload_created_days: 2
72
+
30
73
  apps:
31
74
  my-app-staging:
32
75
  # Use the values from the common section above.
33
76
  <<: *common
77
+
34
78
  my-app-review:
35
79
  <<: *common
80
+
36
81
  # If `match_if_app_name_starts_with` is `true`, then use this config for app names starting with this name,
37
82
  # e.g., "my-app-review-pr123", "my-app-review-anything-goes", etc.
38
83
  match_if_app_name_starts_with: true
84
+
39
85
  my-app-production:
40
86
  <<: *common
87
+
88
+ # You can also opt out of allowing the use of CPLN_ORG and CPLN_APP env vars per app.
89
+ # It's recommended to leave this off for production, to avoid any accidents.
90
+ allow_org_override_by_env: false
91
+ allow_app_override_by_env: false
92
+
41
93
  # Use a different organization for production.
42
94
  cpln_org: my-org-production
95
+
43
96
  # Allows running the command `cpl promote-app-from-upstream -a my-app-production`
44
97
  # to promote the staging app to production.
45
98
  upstream: my-app-staging
99
+
100
+ # Used by the command `cpl promote-app-from-upstream` to run a release script before deploying.
101
+ # This is relative to the `.controlplane/` directory.
102
+ release_script: release_script
103
+
46
104
  my-app-other:
47
105
  <<: *common
106
+
48
107
  # You can specify a different `Dockerfile` relative to the `.controlplane/` directory (defaults to "Dockerfile").
49
108
  dockerfile: ../some_other/Dockerfile
@@ -7,6 +7,7 @@ module Command
7
7
  REQUIRES_ARGS = true
8
8
  OPTIONS = [
9
9
  app_option(required: true),
10
+ location_option,
10
11
  skip_confirm_option
11
12
  ].freeze
12
13
  DESCRIPTION = "Applies application-specific configs from templates"
@@ -126,7 +127,7 @@ module Command
126
127
  def apply_template(filename)
127
128
  data = File.read(filename)
128
129
  .gsub("APP_GVC", config.app)
129
- .gsub("APP_LOCATION", config[:default_location])
130
+ .gsub("APP_LOCATION", config.location)
130
131
  .gsub("APP_ORG", config.org)
131
132
  .gsub("APP_IMAGE", latest_image)
132
133
 
data/lib/command/base.rb CHANGED
@@ -23,6 +23,8 @@ module Command
23
23
  EXAMPLES = ""
24
24
  # If `true`, hides the command from `cpl help`
25
25
  HIDE = false
26
+ # Whether or not to show key information like ORG and APP name in commands
27
+ WITH_INFO_HEADER = true
26
28
 
27
29
  NO_IMAGE_AVAILABLE = "NO_IMAGE_AVAILABLE"
28
30
 
@@ -38,6 +40,10 @@ module Command
38
40
  end
39
41
  end
40
42
 
43
+ def self.common_options
44
+ [org_option, verbose_option, trace_option]
45
+ end
46
+
41
47
  def self.org_option(required: false)
42
48
  {
43
49
  name: :org,
@@ -103,6 +109,19 @@ module Command
103
109
  }
104
110
  end
105
111
 
112
+ def self.location_option(required: false)
113
+ {
114
+ name: :location,
115
+ params: {
116
+ aliases: ["-l"],
117
+ banner: "LOCATION_NAME",
118
+ desc: "Location name",
119
+ type: :string,
120
+ required: required
121
+ }
122
+ }
123
+ end
124
+
106
125
  def self.upstream_token_option(required: false)
107
126
  {
108
127
  name: :upstream_token,
@@ -188,6 +207,17 @@ module Command
188
207
  }
189
208
  end
190
209
 
210
+ def self.trace_option(required: false)
211
+ {
212
+ name: :trace,
213
+ params: {
214
+ desc: "Shows trace of API calls. WARNING: may contain sensitive data",
215
+ type: :boolean,
216
+ required: required
217
+ }
218
+ }
219
+ end
220
+
191
221
  def self.all_options
192
222
  methods.grep(/_option$/).map { |method| send(method.to_s) }
193
223
  end
@@ -239,6 +269,7 @@ module Command
239
269
  end
240
270
 
241
271
  def latest_image_next(app = config.app, org = config.org, commit: nil)
272
+ # debugger
242
273
  commit ||= config.options[:commit]
243
274
 
244
275
  @latest_image_next ||= {}
@@ -21,11 +21,6 @@ module Command
21
21
  EX
22
22
 
23
23
  def call # rubocop:disable Metrics/MethodLength
24
- if config.org_comes_from_env
25
- puts Shell.color("Org comes from CPLN_ORG env var", :yellow)
26
- puts
27
- end
28
-
29
24
  if config.app
30
25
  puts "#{Shell.color("Current config (app '#{config.app}')", :blue)}:"
31
26
  puts pretty_print(config.current)
@@ -7,21 +7,45 @@ module Command
7
7
  app_option(required: true),
8
8
  skip_confirm_option
9
9
  ].freeze
10
- DESCRIPTION = "Deletes the whole app (GVC with all workloads and all images)"
10
+ DESCRIPTION = "Deletes the whole app (GVC with all workloads, all volumesets and all images)"
11
11
  LONG_DESCRIPTION = <<~DESC
12
- - Deletes the whole app (GVC with all workloads and all images)
12
+ - Deletes the whole app (GVC with all workloads, all volumesets and all images)
13
13
  - Will ask for explicit user confirmation
14
14
  DESC
15
15
 
16
16
  def call
17
+ return progress.puts("App '#{config.app}' does not exist.") if cp.fetch_gvc.nil?
18
+
19
+ check_volumesets
20
+ check_images
17
21
  return unless confirm_delete
18
22
 
23
+ delete_volumesets
19
24
  delete_gvc
20
25
  delete_images
21
26
  end
22
27
 
23
28
  private
24
29
 
30
+ def check_volumesets
31
+ @volumesets = cp.fetch_volumesets["items"]
32
+ return progress.puts("No volumesets to delete.") unless @volumesets.any?
33
+
34
+ message = "The following volumesets will be deleted along with the app:"
35
+ volumesets_list = @volumesets.map { |volumeset| "- #{volumeset['name']}" }.join("\n")
36
+ progress.puts("#{Shell.color(message, :red)}\n#{volumesets_list}\n\n")
37
+ end
38
+
39
+ def check_images
40
+ @images = cp.query_images["items"]
41
+ .select { |image| image["name"].start_with?("#{config.app}:") }
42
+ return progress.puts("No images to delete.") unless @images.any?
43
+
44
+ message = "The following images will be deleted along with the app:"
45
+ images_list = @images.map { |image| "- #{image['name']}" }.join("\n")
46
+ progress.puts("#{Shell.color(message, :red)}\n#{images_list}\n\n")
47
+ end
48
+
25
49
  def confirm_delete
26
50
  return true if config.options[:yes]
27
51
 
@@ -33,22 +57,27 @@ module Command
33
57
  end
34
58
 
35
59
  def delete_gvc
36
- return progress.puts("App '#{config.app}' does not exist.") if cp.fetch_gvc.nil?
37
-
38
60
  step("Deleting app '#{config.app}'") do
39
61
  cp.gvc_delete
40
62
  end
41
63
  end
42
64
 
43
- def delete_images
44
- images = cp.query_images["items"]
45
- .filter_map { |item| item["name"] if item["name"].start_with?("#{config.app}:") }
65
+ def delete_volumesets
66
+ @volumesets.each do |volumeset|
67
+ step("Deleting volumeset '#{volumeset['name']}'") do
68
+ # If the volumeset is attached to a workload, we need to delete the workload first
69
+ workload = volumeset.dig("status", "usedByWorkload")&.split("/")&.last
70
+ cp.delete_workload(workload) if workload
46
71
 
47
- return progress.puts("No images to delete.") unless images.any?
72
+ cp.delete_volumeset(volumeset["name"])
73
+ end
74
+ end
75
+ end
48
76
 
49
- images.each do |image|
50
- step("Deleting image '#{image}'") do
51
- cp.image_delete(image)
77
+ def delete_images
78
+ @images.each do |image|
79
+ step("Deleting image '#{image['name']}'") do
80
+ cp.image_delete(image["name"])
52
81
  end
53
82
  end
54
83
  end
data/lib/command/env.rb CHANGED
@@ -10,6 +10,7 @@ module Command
10
10
  LONG_DESCRIPTION = <<~DESC
11
11
  - Displays app-specific environment variables
12
12
  DESC
13
+ WITH_INFO_HEADER = false
13
14
 
14
15
  def call
15
16
  cp.fetch_gvc!.dig("spec", "env").map do |prop|
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Command
4
+ class Generator < Thor::Group
5
+ include Thor::Actions
6
+
7
+ def copy_files
8
+ directory("generator_templates", ".controlplane")
9
+ end
10
+
11
+ def self.source_root
12
+ File.expand_path("../", __dir__)
13
+ end
14
+ end
15
+
16
+ class Generate < Base
17
+ NAME = "generate"
18
+ DESCRIPTION = "Creates base Control Plane config and template files"
19
+ LONG_DESCRIPTION = <<~DESC
20
+ Creates base Control Plane config and template files
21
+ DESC
22
+ EXAMPLES = <<~EX
23
+ ```sh
24
+ # Creates .controlplane directory with Control Plane config and other templates
25
+ cpl generate
26
+ ```
27
+ EX
28
+ WITH_INFO_HEADER = false
29
+
30
+ def call
31
+ if controlplane_directory_exists?
32
+ Shell.warn("The directory '.controlplane' already exists!")
33
+ return
34
+ end
35
+
36
+ Generator.start
37
+ end
38
+
39
+ private
40
+
41
+ def controlplane_directory_exists?
42
+ Dir.exist? ".controlplane"
43
+ end
44
+ end
45
+ end