cpl 1.1.1 → 1.1.2.rc.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: ea3952c523b5ee8b9815befa82df1ecaee53a323a37f081344660d27f3003371
4
- data.tar.gz: e346e1f6327ab009d0b801b651350355ad74cb9abbf9d69bb04fa46be00c4ea3
3
+ metadata.gz: bd0eff627240313d5202ff74368af8fff67483bcf0769f52f9c923a0839bfd73
4
+ data.tar.gz: a31c430587ecfce5cc1e7ede82ce31a0c91aec07de401fa849d18f75035dc4f1
5
5
  SHA512:
6
- metadata.gz: d1b0bfc22da8b9209720e8a262739dcbd738722713165370203e471f52e2aedd52087196dd5b476f05d0dc5f744cdbebe861c1840c2aa32f95339cdafa175807
7
- data.tar.gz: c067f243e3aabb72c271e02c7dd937355bf01e98645f4d163982143ad8a5e19cccdb19574dbe799e2eb7ac215a6f9e89db67f26e7e234252d227f5972b122331
6
+ metadata.gz: 770a3ab110f7b5b7049103c50350044805ed74c1ffedf61249d9696c94877fba43cd2bef031f6d9fd2dd70f2e29e2f970cd2d32cecadd6d7a2eaa3048bd493eb
7
+ data.tar.gz: ec006511deb5b41610f9d4780e02c1265eddfde523f95e3c7c373ef787039c3f5cb9a99c0132da020cd649029ea6e355b37f51fb3d4035381b10724c2ac4a4d4
data/CHANGELOG.md CHANGED
@@ -14,6 +14,13 @@ 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.1.2] - 2023-10-17
18
+ ### Fixed
19
+
20
+ - Fixed failed build on MacOS by adding platform flag and fixed multiple files in yaml document for template. [PR 81](https://github.com/shakacode/heroku-to-control-plane/pull/81) by [justin808](https://github.com/justin808).
21
+
22
+ ## [1.1.1] - 2023-09-23
23
+
17
24
  ### Fixed
18
25
 
19
26
  - Fixed issue where API token is not reset when switching profile. [PR 77](https://github.com/shakacode/heroku-to-control-plane/pull/77) by [Rafael Gomes](https://github.com/rafaelgomesxyz).
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cpl (1.1.1)
4
+ cpl (1.1.2.rc.0)
5
5
  debug (~> 1.7.1)
6
6
  dotenv (~> 2.8.1)
7
7
  psych (~> 5.1.0)
@@ -25,7 +25,7 @@ GEM
25
25
  hashdiff (1.0.1)
26
26
  iniparse (1.5.0)
27
27
  io-console (0.6.0)
28
- irb (1.8.1)
28
+ irb (1.8.3)
29
29
  rdoc
30
30
  reline (>= 0.3.8)
31
31
  json (2.6.3)
@@ -36,7 +36,7 @@ GEM
36
36
  parallel (1.22.1)
37
37
  parser (3.2.0.0)
38
38
  ast (~> 2.4.1)
39
- psych (5.1.0)
39
+ psych (5.1.1.1)
40
40
  stringio
41
41
  public_suffix (5.0.1)
42
42
  rainbow (3.1.1)
@@ -44,7 +44,7 @@ GEM
44
44
  rdoc (6.5.0)
45
45
  psych (>= 4.0.0)
46
46
  regexp_parser (2.6.2)
47
- reline (0.3.8)
47
+ reline (0.3.9)
48
48
  io-console (~> 0.5)
49
49
  rexml (3.2.5)
50
50
  rspec (3.12.0)
data/README.md CHANGED
@@ -6,7 +6,7 @@
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 playbook 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://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)
@@ -89,21 +89,23 @@ For the typical Rails app, this means:
89
89
 
90
90
  ## Installation
91
91
 
92
+ 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 value for `aliases.common.cpln_org` in `.controlplane/controlplane.yml`. If you need an organization, please [contact Shakcode](mailto:controlplane@shkacode.com).
92
93
  1. Install [Node.js](https://nodejs.org/en) (required for Control Plane CLI).
93
- 2. Install [Ruby](https://www.ruby-lang.org/en/) (required for these helpers).
94
- 3. Install Control Plane CLI (adds `cpln` command) and configure credentials.
95
94
 
95
+ 1. Install [Ruby](https://www.ruby-lang.org/en/) (required for these helpers).
96
+
97
+ 1. Install Control Plane CLI (and configure access) [docs here](https://docs.controlplane.com/quickstart/quick-start-3-cli#getting-started-with-the-cli), `npm install -g @controlplane/cli`. You can update the `cpln` command line with `npm update -g @controlplane/cli`. Then run `cpln login` to ensure access.
96
98
  ```sh
97
99
  npm install -g @controlplane/cli
98
100
  cpln login
99
101
  ```
100
102
 
101
- 4. Install Heroku to Control Plane `cpl` CLI, either as a [Ruby gem](https://rubygems.org/gems/cpl) or a local clone.
102
- For information on the latter, see [CONTRIBUTING.md](CONTRIBUTING.md).
103
+ 1. Run `cpln image docker-login --org <your-org>` to ensure that you have access to the Control Plane Docker registry.
103
104
 
104
- ```sh
105
- gem install cpl
106
- ```
105
+ 1. Install Heroku to Control Plane `cpl` CLI, either as a [Ruby gem](https://rubygems.org/gems/cpl) or a local clone.
106
+ For information on the latter, see [CONTRIBUTING.md](CONTRIBUTING.md). You may also install `cpl` in your project's Gemfile.
107
+
108
+ 1. This project has a `Dockerfile` for Control Plane in this directory. You can use it as an example for your project. Ensure that you have Docker running.
107
109
 
108
110
  **Note:** Do not confuse the `cpl` CLI with the `cpln` CLI. The `cpl` CLI is the Heroku to Control Plane playbook CLI.
109
111
  The `cpln` CLI is the Control Plane CLI.
@@ -112,10 +114,32 @@ The `cpln` CLI is the Control Plane CLI.
112
114
 
113
115
  Click [here](/docs/migrating.md) to see the steps to migrate.
114
116
 
115
- ## Config
117
+ ## Configuration Files
116
118
 
117
- Here's a complete example of all supported config keys explained:
119
+ The `cpl` gem is based on several configuration files within a `/.controlplane` top-level directory in your Rails project.
118
120
 
121
+ ```
122
+ .controlplane/
123
+ ├─ templates/
124
+ │ ├─ gvc.yml
125
+ │ ├─ postgres.yml
126
+ │ ├─ rails.yml
127
+ ├─ controlplane.yml
128
+ ├─ Dockerfile
129
+ ├─ entrypoint.sh
130
+ ```
131
+
132
+ 1. `controlplane.yml` describes the overall application. Be sure to have <your-org> as the value for `aliases.common.cpln_org`.
133
+ 2. `Dockerfile` builds the production application. `entrypoint.sh` is an _example_ entrypoint script for the production application, referenced in your Dockerfile.
134
+ 3. `templates` directory contains the templates for the various workloads, such as `rails.yml` and `postgres.yml`.
135
+ 4. `templates/gvc.yml` defines your project's GVC (like a Heroku app). Most importantly, it contains ENV values for app.
136
+ 5. `templates/rails.yml` defines your Rails workload. It may inherit ENV values from the parent GVC, which is populated from the `templates/gvc.yml`. This file also configures scaling, sizing, firewalls, and other workload specific values.
137
+ 6. For other workloads (like lines in a Heroku Procfile), you create additional template files. For example, you can base a `templates/sidekiq.yml` on the `templates/rails.yml` file.
138
+ 7. You can have other files in the `templates` directory, such as `redis.yml` and `postgres.yml` which could setup Redis and Postgres for a testing application.
139
+
140
+ Here's a complete example of all supported config keys explained for the `controlplane.yml` file:
141
+
142
+ ### `controlplane.yml`
119
143
  ```yaml
120
144
  # Keys beginning with "cpln_" correspond to your settings in Control Plane.
121
145
 
@@ -208,6 +232,61 @@ apps:
208
232
  dockerfile: ../some_other/Dockerfile
209
233
  ```
210
234
 
235
+ ## Workflow
236
+
237
+ For a live example, see the [react-webpack-rails-tutorial](https://github.com/shakacode/react-webpack-rails-tutorial/blob/master/.controlplane/readme.md).
238
+ This example should closely match the below example.
239
+
240
+ Suppose your app is called `tutorial-app`. You can run the following commands.
241
+
242
+ ### Setup Commands
243
+ ```sh
244
+ # Provision all infrastructure on Control Plane.
245
+ # app tutorial-app will be created per definition in .controlplane/controlplane.yml
246
+ cpl apply-template gvc postgres redis rails -a tutorial-app
247
+
248
+ # Build and push docker image to Control Plane repository
249
+ # Note, may take many minutes. Be patient. Check for error messages, such as forgetting to run `cpln image docker-login --org <your-org>`
250
+ cpl build-image -a tutorial-app
251
+
252
+ # Promote image to app after running `cpl build-image command`
253
+ # Note, the UX of images may not show the image for up to 5 minutes. However, it's ready.
254
+ cpl deploy-image -a tutorial-app
255
+
256
+ # See how app is starting up
257
+ cpl logs -a tutorial-app
258
+
259
+ # Open app in browser (once it has started up)
260
+ cpl open -a tutorial-app
261
+ ```
262
+
263
+ ### Promoting code updates
264
+
265
+ After committing code, you will update your deployment of `tutorial-app` with the following commands:
266
+
267
+ ```sh
268
+ # Build and push new image with sequential image tagging, e.g. 'tutorial-app:1', then 'tutorial-app:2', etc.
269
+ cpl build-image -a tutorial-app
270
+
271
+ # Run database migrations (or other release tasks) with latest image,
272
+ # while app is still running on previous image.
273
+ # This is analogous to the release phase.
274
+ cpl runner rails db:migrate -a tutorial-app --image latest
275
+
276
+ # Pomote latest image to app
277
+ cpl deploy-image -a tutorial-app
278
+ ```
279
+
280
+ If you needed to push a new image with a specific commit SHA, you can run the following command:
281
+
282
+ ```sh
283
+ # Build and push with sequential image tagging and commit SHA, e.g. 'tutorial-app:123_ABCD'
284
+ cpl build-image -a tutorial-app --commit ABCD
285
+ ```
286
+
287
+ ### Real World
288
+ Most companies will configure their CI system to handle the above steps. Please [contact Shakcode](mailto:controlplane@shkacode.com) for examples of how to do this, jump on [**React+Rails Slack channel**] (https://reactrails.slack.com/join/shared_invite/enQtNjY3NTczMjczNzYxLTlmYjdiZmY3MTVlMzU2YWE0OWM0MzNiZDI0MzdkZGFiZTFkYTFkOGVjODBmOWEyYWQ3MzA2NGE1YWJjNmVlMGE).
289
+
211
290
  ## Environment
212
291
 
213
292
  There are two main places where we can set up environment variables in Control Plane:
@@ -227,16 +306,18 @@ It is also possible to set up a Secret store (of type `Dictionary`), which we ca
227
306
  `cpln://secret/MY_SECRET_STORE_NAME/MY_SECRET_VAR_NAME`. In such a case, we must set up an app Identity and proper
228
307
  Policy to access the secret.
229
308
 
309
+ In `templates/gvc.yml`:
230
310
  ```yaml
231
- # In `templates/gvc.yml`:
232
311
  spec:
233
312
  env:
234
313
  - name: MY_GLOBAL_VAR
235
314
  value: 'value'
236
315
  - name: MY_SECRET_GLOBAL_VAR
237
316
  value: 'cpln://secret/MY_SECRET_STORE_NAME/MY_SECRET_GLOBAL_VAR'
317
+ ```
238
318
 
239
- # In `templates/rails.yml`:
319
+ In `templates/rails.yml`:
320
+ ```yaml
240
321
  spec:
241
322
  containers:
242
323
  - name: rails
@@ -130,7 +130,8 @@ module Command
130
130
  .gsub("APP_ORG", config.org)
131
131
  .gsub("APP_IMAGE", latest_image)
132
132
 
133
- cp.apply(YAML.safe_load(data))
133
+ # Don't read in YAML.safe_load as that doesn't handle multiple documents
134
+ cp.apply_template(data)
134
135
  end
135
136
 
136
137
  def report_success(template)
data/lib/command/run.rb CHANGED
@@ -111,7 +111,7 @@ module Command
111
111
  end
112
112
 
113
113
  # Create workload clone
114
- cp.apply("kind" => "workload", "name" => one_off, "spec" => spec)
114
+ cp.apply_hash("kind" => "workload", "name" => one_off, "spec" => spec)
115
115
  end
116
116
 
117
117
  def runner_script # rubocop:disable Metrics/MethodLength
@@ -104,7 +104,7 @@ module Command
104
104
  container_spec["env"] << { "name" => "CONTROLPLANE_RUNNER", "value" => runner_script }
105
105
 
106
106
  # Create workload clone
107
- cp.apply("kind" => "workload", "name" => one_off, "spec" => spec)
107
+ cp.apply_hash("kind" => "workload", "name" => one_off, "spec" => spec)
108
108
  end
109
109
 
110
110
  def runner_script # rubocop:disable Metrics/MethodLength
@@ -44,7 +44,10 @@ class Controlplane # rubocop:disable Metrics/ClassLength
44
44
  end
45
45
 
46
46
  def image_build(image, dockerfile:, build_args: [], push: true)
47
- cmd = "docker build -t #{image} -f #{dockerfile}"
47
+ # https://docs.controlplane.com/guides/push-image#step-2
48
+ # Might need to use `docker buildx build` if compatiblitity issues arise
49
+ cmd = "docker build --platform=linux/amd64 -t #{image} -f #{dockerfile}"
50
+
48
51
  build_args.each { |build_arg| cmd += " --build-arg #{build_arg}" }
49
52
  cmd += " #{config.app_dir}"
50
53
  perform!(cmd)
@@ -273,8 +276,21 @@ class Controlplane # rubocop:disable Metrics/ClassLength
273
276
  end
274
277
 
275
278
  # apply
279
+ def apply_template(data) # rubocop:disable Metrics/MethodLength
280
+ Tempfile.create do |f|
281
+ f.write(data)
282
+ f.rewind
283
+ cmd = "cpln apply #{gvc_org} --file #{f.path} > /dev/null"
284
+ if Shell.tmp_stderr
285
+ cmd += " 2> #{Shell.tmp_stderr.path}"
286
+ perform(cmd)
287
+ else
288
+ perform!(cmd)
289
+ end
290
+ end
291
+ end
276
292
 
277
- def apply(data) # rubocop:disable Metrics/MethodLength
293
+ def apply_hash(data) # rubocop:disable Metrics/MethodLength
278
294
  Tempfile.create do |f|
279
295
  f.write(data.to_yaml)
280
296
  f.rewind
data/lib/cpl/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cpl
4
- VERSION = "1.1.1"
4
+ VERSION = "1.1.2.rc.0"
5
5
  MIN_CPLN_VERSION = "0.0.71"
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cpl
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2.rc.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Gordon
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-09-21 00:00:00.000000000 Z
12
+ date: 2023-10-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: debug
@@ -303,9 +303,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
303
303
  version: 2.7.0
304
304
  required_rubygems_version: !ruby/object:Gem::Requirement
305
305
  requirements:
306
- - - ">="
306
+ - - ">"
307
307
  - !ruby/object:Gem::Version
308
- version: '0'
308
+ version: 1.3.1
309
309
  requirements: []
310
310
  rubygems_version: 3.4.12
311
311
  signing_key: