cpl 1.2.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/check_cpln_links.yml +19 -0
  3. data/.overcommit.yml +3 -0
  4. data/CHANGELOG.md +43 -1
  5. data/Gemfile.lock +9 -5
  6. data/README.md +43 -7
  7. data/cpl.gemspec +1 -0
  8. data/docs/commands.md +30 -23
  9. data/docs/dns.md +9 -0
  10. data/docs/tips.md +11 -1
  11. data/examples/controlplane.yml +22 -1
  12. data/lib/command/apply_template.rb +58 -10
  13. data/lib/command/base.rb +79 -2
  14. data/lib/command/build_image.rb +5 -1
  15. data/lib/command/cleanup_stale_apps.rb +0 -2
  16. data/lib/command/copy_image_from_upstream.rb +5 -4
  17. data/lib/command/deploy_image.rb +20 -2
  18. data/lib/command/info.rb +11 -26
  19. data/lib/command/maintenance.rb +8 -4
  20. data/lib/command/maintenance_off.rb +8 -4
  21. data/lib/command/maintenance_on.rb +8 -4
  22. data/lib/command/promote_app_from_upstream.rb +5 -25
  23. data/lib/command/run.rb +20 -22
  24. data/lib/command/run_detached.rb +38 -30
  25. data/lib/command/setup_app.rb +19 -2
  26. data/lib/core/config.rb +36 -14
  27. data/lib/core/controlplane.rb +34 -7
  28. data/lib/core/controlplane_api.rb +12 -0
  29. data/lib/core/controlplane_api_direct.rb +33 -5
  30. data/lib/core/helpers.rb +6 -0
  31. data/lib/cpl/version.rb +1 -1
  32. data/lib/cpl.rb +6 -1
  33. data/lib/generator_templates/controlplane.yml +5 -0
  34. data/lib/generator_templates/templates/gvc.yml +4 -4
  35. data/lib/generator_templates/templates/postgres.yml +1 -1
  36. data/lib/generator_templates/templates/rails.yml +1 -1
  37. data/script/check_cpln_links +45 -0
  38. data/templates/daily-task.yml +3 -2
  39. data/templates/gvc.yml +5 -5
  40. data/templates/identity.yml +2 -1
  41. data/templates/rails.yml +3 -2
  42. data/templates/secrets-policy.yml +4 -0
  43. data/templates/secrets.yml +3 -0
  44. data/templates/sidekiq.yml +3 -2
  45. metadata +21 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 711286ef49686f6c51df2a94c533b3df94f4d71d3fb6018b6ed61c210593dd47
4
- data.tar.gz: '085357faac6b5b27e493049b34c27debab21fa19950af21548fe11889140b557'
3
+ metadata.gz: 0e67b960593def42983c0f333119e9edffe55434751769cb1ca25dd8333c1489
4
+ data.tar.gz: 3f201ff14fe51d451c5ab1fd8705e5e544d5e99c87b83e53c54464841a835a1d
5
5
  SHA512:
6
- metadata.gz: ac229234f4919d8e1b3485095476ef0fddac04573d8dd03aba6a3737fd5e90b319538e04c51d98e5f33f244fe304c519d949a624a377bbc9ee9067754a0c71dd
7
- data.tar.gz: 0ba5203d4f8539dde89a2eb5a52dc92c2098d11bb1914002cd57628081465d08e9842f47546da563bc18edda17fbf12101bfefca8fdcee4088825c0e56ee0fa0
6
+ metadata.gz: cb075c69a7fa151bdd800186594ef481999075c8377eabf7dcb886c0b30e246fcb5e3ccd6396ff0e8487ac5a8b50c24d01b3dade658cd7c2b4ebfa82cb6546c9
7
+ data.tar.gz: 2a7c0782f57fd543f79fdeb985221dc72bfdba830bbfda81dc966e432007ad314ccd28ba299d0084d446993201f05cabaec40a133c0a2edf7b16af70f3e38348
@@ -0,0 +1,19 @@
1
+ name: Check Links
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ pull_request:
8
+
9
+ jobs:
10
+ check_cpln_links:
11
+ runs-on: ubuntu-latest
12
+ name: Check Links
13
+ steps:
14
+ - name: Checkout repository
15
+ uses: actions/checkout@v3
16
+ - name: Validate outgoing links to Control Plane
17
+ run: |
18
+ TERM=xterm-color ./script/check_cpln_links
19
+ shell: bash
data/.overcommit.yml CHANGED
@@ -1,4 +1,7 @@
1
1
  PreCommit:
2
+ ValidateLinks:
3
+ enabled: true
4
+ command: ["bash", "./script/check_cpln_links"]
2
5
  CommandDocs:
3
6
  enabled: true
4
7
  command: ["bundle", "exec", "rake", "check_command_docs"]
data/CHANGELOG.md CHANGED
@@ -14,6 +14,45 @@ 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
+ ## [1.4.0] - 2024-03-20
18
+
19
+ ### Added
20
+
21
+ - Added new template substitution variables (used by `apply-template` and `setup-app` commands): `{{APP_LOCATION_LINK}}`, `{{APP_IMAGE_LINK}}`, `{{APP_IDENTITY}}`, `{{APP_IDENTITY_LINK}}`, `{{APP_SECRETS}}` and `{{APP_SECRETS_POLICY}}`. [PR 146](https://github.com/shakacode/heroku-to-control-plane/pull/146) by [Rafael Gomes](https://github.com/rafaelgomesxyz).
22
+ - Added `--run-release-phase` option to `deploy-image` command to run release script before deploying (same step as in `promote-app-from-upstream` command). [PR 146](https://github.com/shakacode/heroku-to-control-plane/pull/146) by [Rafael Gomes](https://github.com/rafaelgomesxyz).
23
+
24
+ ### Changed
25
+
26
+ - Template substitution (used by `apply-template` and `setup-app` commands) now uses double braces (e.g., `APP_ORG` -> `{{APP_ORG}}`). This change is backwards compatible. [PR 146](https://github.com/shakacode/heroku-to-control-plane/pull/146) by [Rafael Gomes](https://github.com/rafaelgomesxyz).
27
+ - Renamed template substitution variable `APP_GVC` to `{{APP_NAME}}` (used by `apply-template` and `setup-app` commands). This change is backwards compatible. [PR 146](https://github.com/shakacode/heroku-to-control-plane/pull/146) by [Rafael Gomes](https://github.com/rafaelgomesxyz).
28
+ - `setup-app` command now automatically binds the app to the secrets policy, as long as both the identity and the policy exist. Added `--skip-secret-access-binding` option to prevent this behavior. [PR 146](https://github.com/shakacode/heroku-to-control-plane/pull/146) by [Rafael Gomes](https://github.com/rafaelgomesxyz).
29
+ - Local API token is now refreshed when it is about to expire. [PR 146](https://github.com/shakacode/heroku-to-control-plane/pull/146) by [Rafael Gomes](https://github.com/rafaelgomesxyz).
30
+ - `apply-template` command now exits with non-zero code if failed to apply any templates. [PR 146](https://github.com/shakacode/heroku-to-control-plane/pull/146) by [Rafael Gomes](https://github.com/rafaelgomesxyz).
31
+
32
+ ## [1.3.0] - 2024-03-19
33
+
34
+ ### Fixed
35
+
36
+ - Fixed issue where cpln profile was not switched back to `default` if an error happened while running `copy-image-from-upstream` command. [PR 135](https://github.com/shakacode/heroku-to-control-plane/pull/135) by [Rafael Gomes](https://github.com/rafaelgomesxyz).
37
+ - Fixed issue that didn't allow using upstream with `match_if_app_name_starts_with` set to `true` in `copy-image-from-upstream` command. [PR 136](https://github.com/shakacode/heroku-to-control-plane/pull/136) by [Rafael Gomes](https://github.com/rafaelgomesxyz).
38
+
39
+ ### Added
40
+
41
+ - Added `--no-clean-on-failure` option to `run:detached` command to skip deletion of failed workload run. [PR 133](https://github.com/shakacode/heroku-to-control-plane/pull/133) by [Justin Gordon](https://github.com/justin808) and [Rafael Gomes](https://github.com/rafaelgomesxyz).
42
+ - Added `--domain` option to `maintenance`, `maintenance:on` and `maintenance:off` commands. [PR 131](https://github.com/shakacode/heroku-to-control-plane/pull/131) by [Rafael Gomes](https://github.com/rafaelgomesxyz).
43
+ - Added `default_domain` config to specify domain for `maintenance`, `maintenance:on` and `maintenance:off` commands. [PR 131](https://github.com/shakacode/heroku-to-control-plane/pull/131) by [Rafael Gomes](https://github.com/rafaelgomesxyz).
44
+ - Added option to specify upstream for `copy-image-from-upstream` command through `CPLN_UPSTREAM` env var. [PR 138](https://github.com/shakacode/heroku-to-control-plane/pull/138) by [Rafael Gomes](https://github.com/rafaelgomesxyz).
45
+
46
+ ### Changed
47
+
48
+ - `build-image` command now accepts extra options and passes them to `docker build`. [PR 126](https://github.com/shakacode/heroku-to-control-plane/pull/126) by [Rafael Gomes](https://github.com/rafaelgomesxyz).
49
+ - `CPLN_ORG_UPSTREAM` env var now takes precedence over config from `controlplane.yml` in `copy-image-from-upstream` command. [PR 137](https://github.com/shakacode/heroku-to-control-plane/pull/137) by [Rafael Gomes](https://github.com/rafaelgomesxyz).
50
+ - `info` command now works properly for apps with `match_if_app_name_starts_with` set to `true`.[PR 139](https://github.com/shakacode/heroku-to-control-plane/pull/139) by [Rafael Gomes](https://github.com/rafaelgomesxyz).
51
+ - `info` command now lists workloads in the same order as `controlplane.yml`. [PR 139](https://github.com/shakacode/heroku-to-control-plane/pull/139) by [Rafael Gomes](https://github.com/rafaelgomesxyz).
52
+ - Improved domain workload matching for `maintenance`, `maintenance:on` and `maintenance:off` commands (instead of matching only by workload, it now matches by org + app + workload, which is more accurate). [PR 140](https://github.com/shakacode/heroku-to-control-plane/pull/140) by [Rafael Gomes](https://github.com/rafaelgomesxyz).
53
+
54
+ ## [1.2.0] - 2024-01-03
55
+
17
56
  ### Fixed
18
57
 
19
58
  - 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).
@@ -117,7 +156,10 @@ _Please add entries here for your pull requests that are not yet released._
117
156
 
118
157
  - Initial release
119
158
 
120
- [Unreleased]: https://github.com/shakacode/heroku-to-control-plane/compare/v1.1.2...HEAD
159
+ [Unreleased]: https://github.com/shakacode/heroku-to-control-plane/compare/v1.4.0...HEAD
160
+ [1.4.0]: https://github.com/shakacode/heroku-to-control-plane/compare/v1.3.0...v1.4.0
161
+ [1.3.0]: https://github.com/shakacode/heroku-to-control-plane/compare/v1.2.0...v1.3.0
162
+ [1.2.0]: https://github.com/shakacode/heroku-to-control-plane/compare/v1.1.2...v1.2.0
121
163
  [1.1.2]: https://github.com/shakacode/heroku-to-control-plane/compare/v1.1.1...v1.1.2
122
164
  [1.1.1]: https://github.com/shakacode/heroku-to-control-plane/compare/v1.1.0...v1.1.1
123
165
  [1.1.0]: https://github.com/shakacode/heroku-to-control-plane/compare/v1.0.4...v1.1.0
data/Gemfile.lock CHANGED
@@ -1,9 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cpl (1.2.0)
4
+ cpl (1.4.0)
5
5
  debug (~> 1.7.1)
6
6
  dotenv (~> 2.8.1)
7
+ jwt (~> 2.8.1)
7
8
  psych (~> 5.1.0)
8
9
  thor (~> 1.2.1)
9
10
 
@@ -13,6 +14,7 @@ GEM
13
14
  addressable (2.8.4)
14
15
  public_suffix (>= 2.0.2, < 6.0)
15
16
  ast (2.4.2)
17
+ base64 (0.2.0)
16
18
  childprocess (4.1.0)
17
19
  crack (0.4.5)
18
20
  rexml
@@ -24,11 +26,13 @@ GEM
24
26
  dotenv (2.8.1)
25
27
  hashdiff (1.0.1)
26
28
  iniparse (1.5.0)
27
- io-console (0.7.1)
28
- irb (1.11.0)
29
+ io-console (0.7.2)
30
+ irb (1.12.0)
29
31
  rdoc
30
- reline (>= 0.3.8)
32
+ reline (>= 0.4.2)
31
33
  json (2.6.3)
34
+ jwt (2.8.1)
35
+ base64
32
36
  overcommit (0.60.0)
33
37
  childprocess (>= 0.6.3, < 5)
34
38
  iniparse (~> 1.4)
@@ -44,7 +48,7 @@ GEM
44
48
  rdoc (6.6.2)
45
49
  psych (>= 4.0.0)
46
50
  regexp_parser (2.6.2)
47
- reline (0.4.1)
51
+ reline (0.4.3)
48
52
  io-console (~> 0.5)
49
53
  rexml (3.2.5)
50
54
  rspec (3.12.0)
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Heroku to Control Plane `cpl` CLI
1
+ # The power of Kubernetes with the ease of Heroku!
2
2
 
3
3
  <meta name="author" content="Justin Gordon and Sergey Tarasov">
4
4
  <meta name="description" content="Instructions on how to migrate from Heroku to Control Plane and a CLI called cpl to make it easier.">
@@ -6,16 +6,24 @@
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://shakacode.controlplane.com/)._
10
-
11
9
  [![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
10
  [![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
11
 
14
12
  [![Gem](https://badge.fury.io/rb/cpl.svg)](https://badge.fury.io/rb/cpl)
15
13
 
14
+
15
+ Here's a playbook for migrating from [Heroku Flow](https://www.heroku.com/flow) to [Control Plane](https://shakacode.controlplane.com) with our `cpl` gem source code.
16
+
17
+ ----
18
+
19
+ _If you need a free demo account for Control Plane (no CC required), you can contact [Justin Gordon, CEO of ShakaCode](mailto:justin@shakacode.com)._
20
+
16
21
  ---
17
22
 
18
- _If you need a free demo account for Control Plane (no CC required), you can contact [controlplane@shakacode.com](mailto:controlplane@shakacode.com)._
23
+ Be sure to see the [demo app](https://github.com/shakacode/react-webpack-rails-tutorial/tree/master/.controlplane)
24
+ If you would like to see the simple YAML configuration and setup,
25
+ Also, check [how the `cpl` gem (this project) is used in the Github actions](https://github.com/shakacode/react-webpack-rails-tutorial/blob/master/.github/actions/deploy-to-control-plane/action.yml).
26
+ Here is a brief [video overview](https://www.youtube.com/watch?v=llaQoAV_6Iw).
19
27
 
20
28
  ---
21
29
 
@@ -117,7 +125,7 @@ npm update -g @controlplane/cli
117
125
 
118
126
  5. Run `cpln image docker-login --org <your-org>` to ensure that you have access to the Control Plane Docker registry.
119
127
 
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).
128
+ 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).
121
129
 
122
130
  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.
123
131
 
@@ -182,8 +190,20 @@ aliases:
182
190
 
183
191
  # Allows running the command `cpl setup-app`
184
192
  # instead of `cpl apply-template gvc redis postgres memcached rails sidekiq`.
193
+ #
194
+ # Note:
195
+ # 1. These names correspond to files in the `./controlplane/templates` directory.
196
+ # 2. Each file can contain many objects, such as in the case of templates that create a resource, like `postgres`.
197
+ # 3. While the naming often corresponds to a workload or other object name, the naming is arbitrary.
198
+ # Naming does not need to match anything other than the file name without the `.yml` extension.
185
199
  setup_app_templates:
186
200
  - gvc
201
+
202
+ # These templates are only required if using secrets.
203
+ - identity
204
+ - secrets
205
+ - secrets-policy
206
+
187
207
  - redis
188
208
  - postgres
189
209
  - memcached
@@ -194,11 +214,16 @@ aliases:
194
214
  one_off_workload: rails
195
215
 
196
216
  # Workloads that are for the application itself and are using application Docker images.
217
+ # These are updated with the new image when running the `deploy-image` command,
218
+ # and are also used by the `info`, `ps:`, and `run:cleanup` commands in order to get all of the defined workloads.
219
+ # On the other hand, if you have a workload for Redis, that would NOT use the application Docker image
220
+ # and not be listed here.
197
221
  app_workloads:
198
222
  - rails
199
223
  - sidekiq
200
224
 
201
225
  # Additional "service type" workloads, using non-application Docker images.
226
+ # These are only used by the `info`, `ps:` and `run:cleanup` commands in order to get all of the defined workloads.
202
227
  additional_workloads:
203
228
  - redis
204
229
  - postgres
@@ -258,6 +283,10 @@ apps:
258
283
  # This is relative to the `.controlplane/` directory.
259
284
  release_script: release_script
260
285
 
286
+ # default_domain is used for commands that require a domain
287
+ # including `maintenance`, `maintenance:on`, `maintenance:off`.
288
+ default_domain: domain.com
289
+
261
290
  my-app-other:
262
291
  <<: *common
263
292
 
@@ -475,6 +504,13 @@ cpl --help
475
504
 
476
505
  ## Examples
477
506
 
478
- - See the `examples/` and `templates/` directories of this repository.
507
+ - See this repository's `examples/` and `templates/` directories.
479
508
  - See the `.controlplane/` directory of this live example:
480
- [react-webpack-rails-tutorial](https://github.com/shakacode/react-webpack-rails-tutorial/tree/master/.controlplane)
509
+ [react-webpack-rails-tutorial](https://github.com/shakacode/react-webpack-rails-tutorial/tree/master/.controlplane).
510
+ - See [how the `cpl` gem is used in the Github actions](https://github.com/shakacode/react-webpack-rails-tutorial/blob/master/.github/actions/deploy-to-control-plane/action.yml).
511
+ - Here is a brief [video overview](https://www.youtube.com/watch?v=llaQoAV_6Iw).
512
+
513
+ ## Resources
514
+ * If you need a free demo account for Control Plane (no CC required), you can contact [Justin Gordon, CEO of ShakaCode](mailto:justin@shakacode.com).
515
+ * [Control Plane Site](https://shakacode.controlplane.com)
516
+ * [Join our Slack to Discuss Heroku to Control Plane](https://reactrails.slack.com/join/shared_invite/enQtNjY3NTczMjczNzYxLTlmYjdiZmY3MTVlMzU2YWE0OWM0MzNiZDI0MzdkZGFiZTFkYTFkOGVjODBmOWEyYWQ3MzA2NGE1YWJjNmVlMGE)
data/cpl.gemspec CHANGED
@@ -17,6 +17,7 @@ Gem::Specification.new do |spec|
17
17
 
18
18
  spec.add_dependency "debug", "~> 1.7.1"
19
19
  spec.add_dependency "dotenv", "~> 2.8.1"
20
+ spec.add_dependency "jwt", "~> 2.8.1"
20
21
  spec.add_dependency "psych", "~> 5.1.0"
21
22
  spec.add_dependency "thor", "~> 1.2.1"
22
23
 
data/docs/commands.md CHANGED
@@ -21,10 +21,14 @@ This `-a` option is used in most of the commands and will pick all other app con
21
21
  **Preprocessed template variables:**
22
22
 
23
23
  ```
24
- APP_GVC - basically GVC or app name
25
- APP_LOCATION - default location
26
- APP_ORG - organization
27
- APP_IMAGE - will use latest app image
24
+ {{APP_ORG}} - organization name
25
+ {{APP_NAME}} - GVC/app name
26
+ {{APP_LOCATION}} - location, per YML file, ENV, or command line arg
27
+ {{APP_LOCATION_LINK}} - full link for location, ready to be used for the value of `staticPlacement.locationLinks` in the templates
28
+ {{APP_IMAGE}} - latest app image
29
+ {{APP_IMAGE_LINK}} - full link for latest app image, ready to be used for the value of `containers[].image` in the templates
30
+ {{APP_IDENTITY}} - default identity
31
+ {{APP_IDENTITY_LINK}} - full link for identity, ready to be used for the value of `identityLink` in the templates
28
32
  ```
29
33
 
30
34
  ```sh
@@ -41,6 +45,7 @@ cpl apply-template gvc postgres redis rails -a $APP_NAME
41
45
  - Automatically assigns image numbers, e.g., `app:1`, `app:2`, etc.
42
46
  - Uses `.controlplane/Dockerfile` or a different Dockerfile specified through `dockerfile` in the `.controlplane/controlplane.yml` file
43
47
  - If a commit is provided through `--commit` or `-c`, it will be set as the runtime env var `GIT_COMMIT`
48
+ - Accepts extra options that are passed to `docker build`
44
49
 
45
50
  ```sh
46
51
  cpl build-image -a $APP_NAME
@@ -86,7 +91,7 @@ cpl config -a $APP_NAME
86
91
  ### `copy-image-from-upstream`
87
92
 
88
93
  - Copies an image (by default the latest) from a source org to the current org
89
- - The source org must be specified through `upstream` in the `.controlplane/controlplane.yml` file
94
+ - The source app must be specified either through the `CPLN_UPSTREAM` env var or `upstream` in the `.controlplane/controlplane.yml` file
90
95
  - Additionally, the token for the source org must be provided through `--upstream-token` or `-t`
91
96
  - A `cpln` profile will be temporarily created to pull the image from the source org
92
97
 
@@ -110,6 +115,8 @@ cpl delete -a $APP_NAME
110
115
  ### `deploy-image`
111
116
 
112
117
  - Deploys the latest image to app workloads
118
+ - Optionally runs a release script before deploying if specified through `release_script` in the `.controlplane/controlplane.yml` file and `--run-release-phase` is provided
119
+ - The deploy will fail if the release script exits with a non-zero code or doesn't exist
113
120
 
114
121
  ```sh
115
122
  cpl deploy-image -a $APP_NAME
@@ -250,8 +257,9 @@ cpl open-console -a $APP_NAME
250
257
  - Copies the latest image from upstream, runs a release script (optional), and deploys the image
251
258
  - It performs the following steps:
252
259
  - Runs `cpl copy-image-from-upstream` to copy the latest image from upstream
253
- - Runs a release script if specified through `release_script` in the `.controlplane/controlplane.yml` file
254
260
  - Runs `cpl deploy-image` to deploy the image
261
+ - If `.controlplane/controlplane.yml` includes the `release_script`, `cpl deploy-image` will use the `--run-release-phase` option
262
+ - The deploy will fail if the release script exits with a non-zero code
255
263
 
256
264
  ```sh
257
265
  cpl promote-app-from-upstream -a $APP_NAME -t $UPSTREAM_TOKEN
@@ -331,28 +339,25 @@ cpl ps:swait -a $APP_NAME -w $WORKLOAD_NAME
331
339
  cpl run -a $APP_NAME
332
340
 
333
341
  # Need to quote COMMAND if setting ENV value or passing args.
334
- cpl run 'LOG_LEVEL=warn rails db:migrate' -a $APP_NAME
335
-
336
- # COMMAND may also be passed at the end.
337
342
  cpl run -a $APP_NAME -- 'LOG_LEVEL=warn rails db:migrate'
338
343
 
339
344
  # Runs command, displays output, and exits shell.
340
- cpl run ls / -a $APP_NAME
341
- cpl run rails db:migrate:status -a $APP_NAME
345
+ cpl run -a $APP_NAME -- ls /
346
+ cpl run -a $APP_NAME -- rails db:migrate:status
342
347
 
343
348
  # Runs command and keeps shell open.
344
- cpl run rails c -a $APP_NAME
349
+ cpl run -a $APP_NAME -- rails c
345
350
 
346
351
  # Uses a different image (which may not be promoted yet).
347
- cpl run rails db:migrate -a $APP_NAME --image appimage:123 # Exact image name
348
- cpl run rails db:migrate -a $APP_NAME --image latest # Latest sequential image
352
+ cpl run -a $APP_NAME --image appimage:123 -- rails db:migrate # Exact image name
353
+ cpl run -a $APP_NAME --image latest -- rails db:migrate # Latest sequential image
349
354
 
350
355
  # Uses a different workload than `one_off_workload` from `.controlplane/controlplane.yml`.
351
- cpl run bash -a $APP_NAME -w other-workload
356
+ cpl run -a $APP_NAME -w other-workload -- bash
352
357
 
353
358
  # Overrides remote CPLN_TOKEN env variable with local token.
354
359
  # Useful when superuser rights are needed in remote container.
355
- cpl run bash -a $APP_NAME --use-local-token
360
+ cpl run -a $APP_NAME --use-local-token -- bash
356
361
  ```
357
362
 
358
363
  ### `run:cleanup`
@@ -374,26 +379,26 @@ cpl run:cleanup -a $APP_NAME
374
379
  - Implemented with only async execution methods, more suitable for production tasks
375
380
  - Has alternative log fetch implementation with only JSON-polling and no WebSockets
376
381
  - Less responsive but more stable, useful for CI tasks
382
+ - Deletes the workload whenever finished with success
383
+ - Deletes the workload whenever finished with failure by default
384
+ - Use `--no-clean-on-failure` to disable cleanup to help with debugging failed runs
377
385
 
378
386
  ```sh
379
387
  cpl run:detached rails db:prepare -a $APP_NAME
380
388
 
381
389
  # Need to quote COMMAND if setting ENV value or passing args.
382
- cpl run:detached 'LOG_LEVEL=warn rails db:migrate' -a $APP_NAME
383
-
384
- # COMMAND may also be passed at the end.
385
390
  cpl run:detached -a $APP_NAME -- 'LOG_LEVEL=warn rails db:migrate'
386
391
 
387
392
  # Uses a different image (which may not be promoted yet).
388
- cpl run:detached rails db:migrate -a $APP_NAME --image appimage:123 # Exact image name
389
- cpl run:detached rails db:migrate -a $APP_NAME --image latest # Latest sequential image
393
+ cpl run:detached -a $APP_NAME --image appimage:123 -- rails db:migrate # Exact image name
394
+ cpl run:detached -a $APP_NAME --image latest -- rails db:migrate # Latest sequential image
390
395
 
391
396
  # Uses a different workload than `one_off_workload` from `.controlplane/controlplane.yml`.
392
- cpl run:detached rails db:migrate:status -a $APP_NAME -w other-workload
397
+ cpl run:detached -a $APP_NAME -w other-workload -- rails db:migrate:status
393
398
 
394
399
  # Overrides remote CPLN_TOKEN env variable with local token.
395
400
  # Useful when superuser rights are needed in remote container.
396
- cpl run:detached rails db:migrate:status -a $APP_NAME --use-local-token
401
+ cpl run:detached -a $APP_NAME --use-local-token -- rails db:migrate:status
397
402
  ```
398
403
 
399
404
  ### `setup-app`
@@ -401,6 +406,8 @@ cpl run:detached rails db:migrate:status -a $APP_NAME --use-local-token
401
406
  - Creates an app and all its workloads
402
407
  - Specify the templates for the app and workloads through `setup_app_templates` in the `.controlplane/controlplane.yml` file
403
408
  - 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)
409
+ - Automatically binds the app to the secrets policy, as long as both the identity and the policy exist
410
+ - Use `--skip-secret-access-binding` to prevent the automatic bind
404
411
 
405
412
  ```sh
406
413
  cpl setup-app -a $APP_NAME
data/docs/dns.md ADDED
@@ -0,0 +1,9 @@
1
+ # DNS Setup Example
2
+
3
+ About reactrails.com DNS, steps:
4
+ 1. create CNAME or ALIAS record pointing to rails-xxxx.cpln.app
5
+ 1. go to CPLN Domains -> create
6
+ 1. add reactrails.com copy code from there
7
+ 1. add TXT record with code as _cpln.reactrails.com
8
+ 1. hit ok on CPLN, route to rails workload when asked
9
+ 1. wait domain check and certificates created
data/docs/tips.md CHANGED
@@ -85,7 +85,17 @@ For storing ENVs in the source code, we can use a level of indirection so that y
85
85
  code like `cpln://secret/my-app-review-env-secrets.SECRET_KEY_BASE` and then have the secret value stored at the org
86
86
  level, which applies to your GVCs mapped to that org.
87
87
 
88
- Here is how you do this:
88
+ You can do this during the initial app setup, like this:
89
+
90
+ 1. Add the templates for `identity`, `secrets` and `secrets-policy` to `.controlplane/templates`
91
+ 2. Ensure that the templates are listed in `setup_app_templates` for the app in `.controlplane/controlplane.yml`
92
+ 3. Run `cpl setup-app -a $APP_NAME`
93
+ 4. The identity, secrets and secrets policy will be automatically created, along with the proper binding
94
+ 5. In the upper left "Manage Org" menu, click on "Secrets"
95
+ 6. Find the created secret (it will be in the `$APP_PREFIX-secrets` format) and add the secret env vars there
96
+ 7. Use `cpln://secret/...` in the app to access the secret env vars (e.g., `cpln://secret/$APP_PREFIX-secrets.SOME_VAR`)
97
+
98
+ You can also do it manually after. Here is how you do this:
89
99
 
90
100
  1. In the upper left "Manage Org" menu, click on "Secrets"
91
101
  2. Create a secret with `Secret Type: Dictionary` (e.g., `my-secrets`) and add the secret env vars there
@@ -25,8 +25,20 @@ aliases:
25
25
 
26
26
  # Allows running the command `cpl setup-app`
27
27
  # instead of `cpl apply-template gvc redis postgres memcached rails sidekiq`.
28
- setup:
28
+ #
29
+ # Note:
30
+ # 1. These names correspond to files in the `./controlplane/templates` directory.
31
+ # 2. Each file can contain many objects, such as in the case of templates that create a resource, like `postgres`.
32
+ # 3. While the naming often corresponds to a workload or other object name, the naming is arbitrary.
33
+ # Naming does not need to match anything other than the file name without the `.yml` extension.
34
+ setup_app_templates:
29
35
  - gvc
36
+
37
+ # These templates are only required if using secrets.
38
+ - identity
39
+ - secrets
40
+ - secrets-policy
41
+
30
42
  - redis
31
43
  - postgres
32
44
  - memcached
@@ -37,11 +49,16 @@ aliases:
37
49
  one_off_workload: rails
38
50
 
39
51
  # Workloads that are for the application itself and are using application Docker images.
52
+ # These are updated with the new image when running the `deploy-image` command,
53
+ # and are also used by the `info`, `ps:`, and `run:cleanup` commands in order to get all of the defined workloads.
54
+ # On the other hand, if you have a workload for Redis, that would NOT use the application Docker image
55
+ # and not be listed here.
40
56
  app_workloads:
41
57
  - rails
42
58
  - sidekiq
43
59
 
44
60
  # Additional "service type" workloads, using non-application Docker images.
61
+ # These are only used by the `info`, `ps:` and `run:cleanup` commands in order to get all of the defined workloads.
45
62
  additional_workloads:
46
63
  - redis
47
64
  - postgres
@@ -101,6 +118,10 @@ apps:
101
118
  # This is relative to the `.controlplane/` directory.
102
119
  release_script: release_script
103
120
 
121
+ # default_domain is used for commands that require a domain
122
+ # including `maintenance`, `maintenance:on`, `maintenance:off`.
123
+ default_domain: domain.com
124
+
104
125
  my-app-other:
105
126
  <<: *common
106
127
 
@@ -20,10 +20,14 @@ module Command
20
20
  **Preprocessed template variables:**
21
21
 
22
22
  ```
23
- APP_GVC - basically GVC or app name
24
- APP_LOCATION - default location
25
- APP_ORG - organization
26
- APP_IMAGE - will use latest app image
23
+ {{APP_ORG}} - organization name
24
+ {{APP_NAME}} - GVC/app name
25
+ {{APP_LOCATION}} - location, per YML file, ENV, or command line arg
26
+ {{APP_LOCATION_LINK}} - full link for location, ready to be used for the value of `staticPlacement.locationLinks` in the templates
27
+ {{APP_IMAGE}} - latest app image
28
+ {{APP_IMAGE_LINK}} - full link for latest app image, ready to be used for the value of `containers[].image` in the templates
29
+ {{APP_IDENTITY}} - default identity
30
+ {{APP_IDENTITY_LINK}} - full link for identity, ready to be used for the value of `identityLink` in the templates
27
31
  ```
28
32
  DESC
29
33
  EXAMPLES = <<~EX
@@ -36,7 +40,7 @@ module Command
36
40
  ```
37
41
  EX
38
42
 
39
- def call # rubocop:disable Metrics/MethodLength, Metrics/PerceivedComplexity
43
+ def call # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
40
44
  ensure_templates!
41
45
 
42
46
  @created_items = []
@@ -55,6 +59,8 @@ module Command
55
59
 
56
60
  progress.puts if @asked_for_confirmation
57
61
 
62
+ @deprecated_variables = []
63
+
58
64
  pending_templates.each do |template, filename|
59
65
  step("Applying template '#{template}'", abort_on_error: false) do
60
66
  items = apply_template(filename)
@@ -70,9 +76,13 @@ module Command
70
76
  end
71
77
  end
72
78
 
79
+ warn_deprecated_variables
80
+
73
81
  print_created_items
74
82
  print_failed_templates
75
83
  print_skipped_templates
84
+
85
+ exit(1) if @failed_templates.any?
76
86
  end
77
87
 
78
88
  private
@@ -124,17 +134,55 @@ module Command
124
134
  false
125
135
  end
126
136
 
127
- def apply_template(filename)
137
+ def apply_template(filename) # rubocop:disable Metrics/MethodLength
128
138
  data = File.read(filename)
129
- .gsub("APP_GVC", config.app)
130
- .gsub("APP_LOCATION", config.location)
131
- .gsub("APP_ORG", config.org)
132
- .gsub("APP_IMAGE", latest_image)
139
+ .gsub("{{APP_ORG}}", config.org)
140
+ .gsub("{{APP_NAME}}", config.app)
141
+ .gsub("{{APP_LOCATION}}", config.location)
142
+ .gsub("{{APP_LOCATION_LINK}}", app_location_link)
143
+ .gsub("{{APP_IMAGE}}", latest_image)
144
+ .gsub("{{APP_IMAGE_LINK}}", app_image_link)
145
+ .gsub("{{APP_IDENTITY}}", app_identity)
146
+ .gsub("{{APP_IDENTITY_LINK}}", app_identity_link)
147
+ .gsub("{{APP_SECRETS}}", app_secrets)
148
+ .gsub("{{APP_SECRETS_POLICY}}", app_secrets_policy)
149
+
150
+ find_deprecated_variables(data)
151
+
152
+ # Kept for backwards compatibility
153
+ data = data
154
+ .gsub("APP_ORG", config.org)
155
+ .gsub("APP_GVC", config.app)
156
+ .gsub("APP_LOCATION", config.location)
157
+ .gsub("APP_IMAGE", latest_image)
133
158
 
134
159
  # Don't read in YAML.safe_load as that doesn't handle multiple documents
135
160
  cp.apply_template(data)
136
161
  end
137
162
 
163
+ def new_variables
164
+ {
165
+ "APP_ORG" => "{{APP_ORG}}",
166
+ "APP_GVC" => "{{APP_NAME}}",
167
+ "APP_LOCATION" => "{{APP_LOCATION}}",
168
+ "APP_IMAGE" => "{{APP_IMAGE}}"
169
+ }
170
+ end
171
+
172
+ def find_deprecated_variables(data)
173
+ @deprecated_variables.push(*new_variables.keys.select { |old_key| data.include?(old_key) })
174
+ @deprecated_variables = @deprecated_variables.uniq.sort
175
+ end
176
+
177
+ def warn_deprecated_variables
178
+ return unless @deprecated_variables.any?
179
+
180
+ message = "Please replace these variables in the templates, " \
181
+ "as support for them will be removed in a future major version bump:"
182
+ deprecated = @deprecated_variables.map { |old_key| " - #{old_key} -> #{new_variables[old_key]}" }.join("\n")
183
+ progress.puts("\n#{Shell.color("DEPRECATED: #{message}", :yellow)}\n#{deprecated}")
184
+ end
185
+
138
186
  def report_success(item)
139
187
  @created_items.push(item)
140
188
  end