convox_installer 2.0.0 → 3.0.1

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: b9b7140386f111c59db16b8db7429b2fb3a5c1a48372a2559e2e2c5499d59dd2
4
- data.tar.gz: 6e94e2c459c01426f8b6d2adc7d232f630e9711722947d2899b20ea509089c47
3
+ metadata.gz: c08b32666153594de1c3464ab4c8ea4f324952115facc72fc159d75de7d1a85e
4
+ data.tar.gz: 2f162d039ab30ebea6ecd8086bc88b30da9c50234c614594c43725036f75f2cb
5
5
  SHA512:
6
- metadata.gz: 64741ea4bd8a4e03d30172d366976e7d18c99cd2dff1f27ceaf5106d86de56c46fc0302fed774669f5a513d3b5cd8212b3b94e54687a539b235e545b3a9c90cb
7
- data.tar.gz: 67966065258259f0b64c7572895ee884f4e34c55e4f9c1ddbff90cf431e8da78984706955b406655d8f0128f4edd21842559129aa5b7dde73a745a121ad44ce1
6
+ metadata.gz: cdaf7159e5bebdde39ffed648fab4be85c5d2a556818b30ec8587ba52e920de44c09434edd654e894501ecb8a68c756c1c64e9de8939412d320dc753ab156163
7
+ data.tar.gz: 219b697d883f91bd173e214402af2d3f5ec988881a025e894f4e3aafef1970af61a1bb2905b886fac437788a18812f9dbbc1e6307aa2d80f1997fdc0d800f0be
data/.rubocop.yml CHANGED
@@ -8,7 +8,7 @@ Style/MixinUsage:
8
8
  Exclude:
9
9
  - examples/**/*
10
10
 
11
- Metrics/LineLength:
11
+ Layout/LineLength:
12
12
  Max: 100
13
13
 
14
14
  Style/StringLiterals:
@@ -1,4 +1,5 @@
1
1
  {
2
- "editor.formatOnSave": false,
3
- "editor.formatOnSaveTimeout": 5000
2
+ "editor.formatOnSave": true,
3
+ "editor.formatOnSaveTimeout": 5000,
4
+ "ruby.rubocop.executePath": "/usr/local/bin/rubocop-daemon-wrapper/"
4
5
  }
data/Gemfile CHANGED
@@ -9,6 +9,7 @@ group :test do
9
9
  gem 'pry-byebug', require: false
10
10
  gem 'rspec'
11
11
  gem 'rubocop'
12
+ gem 'rubocop-daemon'
12
13
  gem 'rubocop-rspec'
13
14
  gem 'vcr'
14
15
  gem 'webmock'
data/README.md CHANGED
@@ -1,10 +1,22 @@
1
1
  # Convox Installer
2
2
 
3
- A Ruby gem that makes it easier to build a Convox installation script. This is like Chef/Ansible/Terraform for your initial Convox setup.
3
+ A Ruby gem that makes it easier to build a Convox installation script. The main purpose of this gem is to make it easier to set up on-premise installations of your app for enterprise users.
4
4
 
5
- # Requirements: Convox v2
5
+ This gem provides a DSL so that you can write a script that walks your users through setting up Convox and getting your app and running, setting up S3 buckets, etc.
6
+
7
+ ## Requirements
8
+
9
+ - MacOS
10
+ - Convox v3 CLI
11
+
12
+ _Please let us know if you need to run this script on Linux. Linux support should not be too difficult to implement, but unfortunately we probably won't be able to support Windows._
13
+
14
+ ### Requires Convox >= 3
15
+
16
+ This version of `convox_installer` is only designed to work with Convox 3 and later. You can run `convox version` to check your version. Please install the Convox v3 CLI by following the instructions here: https://docs.convox.com/getting-started/introduction/
17
+
18
+ _If you want to set up a Convox v2 rack (deprecated), the last version of `convox_installer` that supports the v2 CLI is `1.0.9`. (Take a look at [the `convox2` branch](https://github.com/DocSpring/convox_installer/tree/convox2).)_
6
19
 
7
- This version of `convox_installer` is only designed to work with Convox v2. Please install the v2 CLI by following the instructions at their old documentation site: https://docsv2.convox.com/introduction/installation
8
20
  ## USE AT YOUR OWN RISK! THIS CODE IS PROVIDED WITHOUT ANY WARRANTIES OR GUARANTEES
9
21
 
10
22
  We have successfully set up a number of test and production deployments using this gem. Everything seems to work very well. The library also facilitates idempotency and crash-resistance, so you can easily re-run your installation script if something goes wrong. However, if anything goes wrong, then you can end up with a large AWS bill if you're not careful. If anything crashes then make sure you double-check everything in your AWS account and shut down any leftover resources. **USE THIS SOFTWARE AT YOUR OWN RISK.**
@@ -14,10 +26,12 @@ We have successfully set up a number of test and production deployments using th
14
26
  - Idempotent. If this script crashes, you can restart it and it will pick up
15
27
  where it left off. Every step looks up the existing state, and only makes a change
16
28
  if things are not yet set up (or out of sync).
17
- - Ensures that the `convox` and `aws` CLI tools are installed
29
+ - Ensures that the `convox` and `terraform` CLI tools are installed
18
30
  - Wraps the `convox` CLI and parses JSON output from API calls
19
- - Add n Docker Repository (e.g. ECR registry)
31
+ - Add a Docker Repository (e.g. ECR registry)
20
32
  - Set up an S3 bucket with an optional CORS policy
33
+ - Set up an RDS database (Postgres)
34
+ - Set up an Elasticache cluster (Redis)
21
35
 
22
36
  ## Introduction
23
37
 
@@ -25,7 +39,7 @@ We have successfully set up a number of test and production deployments using th
25
39
 
26
40
  `convox_installer` is a Ruby gem that makes it much easier to build an installation script for `convox/rack` (the open source PaaS). The Convox CLI is awesome, but it's missing a nice way to script a full deployment. I originally wrote a bash script that made API calls and used [`jq`](https://stedolan.github.io/jq/) and `sed`, but this was very error-prone and it did not have good cross-platform support.
27
41
 
28
- I've rewritten this installation script in Ruby, which provides very good cross-platform support, and also allows me to write tests.
42
+ I've written this installation script in Ruby, which provides very good cross-platform support, and also allows me to write tests.
29
43
 
30
44
  ## Usage
31
45
 
@@ -37,7 +51,7 @@ require 'bundler/inline'
37
51
 
38
52
  gemfile do
39
53
  source 'https://rubygems.org'
40
- gem 'convox_installer'
54
+ gem 'convox_installer', '3.0.0'
41
55
  end
42
56
 
43
57
  require "convox_installer"
@@ -134,17 +148,13 @@ Shows a heading and optional details.
134
148
 
135
149
  #### `ensure_requirements!`
136
150
 
137
- Makes sure that the `convox` and `aws` CLI tools are installed on this system. If not, shows installation instructions and exits.
151
+ Makes sure that the `convox` and `terraform` CLI tools are installed on this system. If not, shows installation instructions and exits.
138
152
 
139
153
  #### `prompt_for_config`
140
154
 
141
155
  Loads config from ENV vars, or from saved config at `./.installer_config.json`.
142
156
  If any config settings are missing, it prompts the user for input. Finally, it shows a summary of the config, and asks the user if they want to proceed with the installation. If the user enters `y` (or `yes`), the `prompt_for_config` method completes. If they enter `n` (or `no`), we loop over every setting and let them press "enter" to keep the current value, or provide a new value to correct any mistakes.
143
157
 
144
- #### `backup_convox_host_and_rack`
145
-
146
- If there are any existing files at `~/.convox/host` or `~/.convox/rack`, this method moves these to `~/.convox/host.bak` and `~/.convox/rack.bak`.
147
-
148
158
  #### `install_convox`
149
159
 
150
160
  - **Required Config:** `aws_region`, `aws_access_key_id`, `aws_secret_access_key`,
@@ -152,13 +162,13 @@ If there are any existing files at `~/.convox/host` or `~/.convox/rack`, this me
152
162
 
153
163
  Runs `convox rack install ...`. Has some validations to ensure that all required settings are present.
154
164
 
155
- #### `validate_convox_auth_and_write_host!`
165
+ #### `validate_convox_rack_and_write_current!`
156
166
 
157
- After running `install_convox`, call this method to ensure that the the `~/.convox/auth` file has been updated with the correct details (checks the rack name and AWS region.) Then it sets the rack host in `~/.convox/host` (if not already set.)
167
+ Ensures that the local machine contains a directory for the rack's terraform config, and sets the current rack for Convox CLI commands.
158
168
 
159
- #### `validate_convox_rack!`
169
+ #### `validate_convox_rack_api!`
160
170
 
161
- Calls `convox api get /system` to get the Rack details, then makes sure that everything is correct.
171
+ Makes an API request (`convox api get /system`) to get the rack details, and makes sure that everything is correct.
162
172
 
163
173
  #### `convox_rack_data`
164
174
 
@@ -174,10 +184,14 @@ Checks if the app already exists. If not, calls `convox apps create ... --wait`
174
184
 
175
185
  Writes the app name into `./.convox/app` (in the current directory.) The `convox` CLI reads this file, so you don't need to specify the `--app` flag for future commands.
176
186
 
177
- #### `create_s3_bucket!`
187
+ #### `add_s3_bucket`
188
+
189
+ Adds an S3 bucket to your Terraform config.
178
190
 
179
191
  - **Required Config:** `s3_bucket_name`
180
192
 
193
+ NOTE: This method just writes a new Terraform configuration file. You must run `apply_terraform_update!` to apply the changes and create the S3 bucket.
194
+
181
195
  Creates an S3 bucket from the `:s3_bucket_name` config setting. This is not a default setting, so you can add something like this to your custom `@prompts`:
182
196
 
183
197
  ```ruby
@@ -190,41 +204,94 @@ Creates an S3 bucket from the `:s3_bucket_name` config setting. This is not a de
190
204
 
191
205
  The `:value` `Proc` will generate a bucket name with a random suffix. (Avoids conflicts when you are setting up multiple deployments for your app.)
192
206
 
193
- `create_s3_bucket!` will also call `set_s3_bucket_cors_policy` automatically, so you don't need to call this manually.
194
-
195
- #### `set_s3_bucket_cors_policy`
207
+ You can also set a CORS policy for your S3 bucket. (`:s3_bucket_name`)
208
+ We set the `cors_rule` option for the `aws_s3_bucket` resource in the Terraform configuration. Example:
196
209
 
197
- - **Required Config:** `s3_bucket_name`
210
+ ```
211
+ cors_rule {
212
+ allowed_headers = ["*"]
213
+ allowed_methods = ["PUT", "POST"]
214
+ allowed_origins = ["https://s3-website-test.hashicorp.com"]
215
+ expose_headers = ["ETag"]
216
+ max_age_seconds = 3000
217
+ }
218
+ ```
198
219
 
199
- Set up a CORS policy for your S3 bucket. (`:s3_bucket_name`)
220
+ See: https://registry.terraform.io/providers/hashicorp/aws/3.33.0/docs/resources/s3_bucket#using-cors
200
221
 
201
- _Note: If the `:s3_bucket_cors_policy` setting is not provided, then this method does nothing._
222
+ _Note: If the `:s3_bucket_cors_rule` setting is not provided, then it is skipped._
202
223
 
203
- You should set `:s3_bucket_cors_policy` to a JSON string. Here's how I set this up in my own `install.rb` script:
224
+ Here's how we set up a CORS policy in our own `install.rb` script:
204
225
 
205
226
  ```ruby
206
- S3_BUCKET_CORS_POLICY = <<-JSON
207
- {
208
- "CORSRules": [
209
- {
210
- "AllowedOrigins": ["*"],
211
- "AllowedHeaders": ["Authorization", "cache-control", "x-requested-with"],
212
- "AllowedMethods": ["PUT", "POST", "GET"],
213
- "MaxAgeSeconds": 3000
214
- }
215
- ]
216
- }
217
- JSON
227
+ xxxxc = <<-TERRAFORM
228
+ cors_rule {
229
+ allowed_headers = ["Authorization", "cache-control", "x-requested-with"]
230
+ allowed_methods = ["PUT", "POST", "GET"]
231
+ allowed_origins = ["*"]
232
+ expose_headers = []
233
+ max_age_seconds = 3000
234
+ }
235
+ TERRAFORM
218
236
 
219
237
  @prompts = [
220
238
  {
221
- key: :s3_bucket_cors_policy,
222
- value: S3_BUCKET_CORS_POLICY,
239
+ key: :s3_bucket_cors_rule,
240
+ value: S3_BUCKET_CORS_RULE,
223
241
  hidden: true,
224
242
  }
225
243
  ]
226
244
  ```
227
245
 
246
+ #### `add_rds_database`
247
+
248
+ Adds an RDS database to your Terraform config.
249
+
250
+ - **Required Config:**
251
+ - `database_username`
252
+ - `database_password`
253
+ - **Optional Config:**
254
+ - `database_allocated_storage` _(default: 30)_
255
+ - `database_engine` _(default: 'postgres')_
256
+ - `database_engine_version` _(default: '14.2')_
257
+ - `database_instance_class` _(default: 'db.t3.medium')_
258
+ - `database_multi_az` _(default: true)_
259
+
260
+ #### `add_elasticache_cluster`
261
+
262
+ Adds an Elasticache cluster to your Terraform config.
263
+
264
+ - **Optional Config:**
265
+ - `engine` _(default: 'redis')_
266
+ - `engine_version` _(default: '6.x')_
267
+ - `node_type` _(default: 'cache.t3.medium')_
268
+ - `num_cache_nodes` _(default: 1)_
269
+ - `port` _(default: 6379)_
270
+
271
+ #### `apply_terraform_update!`
272
+
273
+ Runs `terraform apply -auto-approve` to apply any changes to your Terraform configuration (add new resources, etc.)
274
+
275
+ #### `rds_details`
276
+
277
+ Returns information about the created RDS database resource.
278
+
279
+ ```ruby
280
+ {
281
+ postgres_url: "Full URL for the RDS database (including auth)",
282
+ }
283
+ ```
284
+
285
+ #### `elasticache_details`
286
+
287
+ Returns information about the created RDS database resource.
288
+
289
+ ```ruby
290
+ {
291
+ redis_url: "Full URL for the Redis cluster",
292
+ }
293
+ ```
294
+
228
295
  #### `s3_bucket_details`
229
296
 
230
297
  - **Required Config:** `s3_bucket_name`
@@ -249,13 +316,14 @@ Checks the list of registries to see if `docker_registry_url` has already been a
249
316
 
250
317
  #### `default_service_domain_name`
251
318
 
252
- - **Required Config:** `convox_app_name`, `default_service`
319
+ - **Required Config:** `convox_app_name`
320
+ - **Optional Config:** `default_service`
253
321
 
254
- Parses the rack router ELB name and region, and returns the default `convox.site` domain for your default service. (You can visit this URL in the browser to access your app.)
322
+ Finds the default `*.convox.cloud` URL for the web service. (You can visit this URL in the browser to access your app.)
255
323
 
256
- Example: `myapp-web.rackname-route-abcdfe123456-123456789.us-west-2.convox.site`
324
+ Example: `web.docspring.dc6bae48c2e36366.convox.cloud`
257
325
 
258
- Set a default service in your config prompts (e.g. `web`):
326
+ You can override the default service name in your config (e.g. `web`):
259
327
 
260
328
  ```ruby
261
329
  @prompts = [
@@ -9,6 +9,7 @@
9
9
  # gem "convox_installer"
10
10
  # end
11
11
 
12
+ require 'English'
12
13
  $LOAD_PATH << File.expand_path('../lib', __dir__)
13
14
  require 'pry-byebug'
14
15
 
@@ -20,18 +21,15 @@ include ConvoxInstaller
20
21
  MINIMAL_HEALTH_CHECK_PATH = '/health/site'
21
22
  COMPLETE_HEALTH_CHECK_PATH = '/health'
22
23
 
23
- S3_BUCKET_CORS_POLICY = <<~JSON
24
- {
25
- "CORSRules": [
26
- {
27
- "AllowedOrigins": ["*"],
28
- "AllowedHeaders": ["Authorization", "cache-control", "x-requested-with"],
29
- "AllowedMethods": ["PUT", "POST", "GET"],
30
- "MaxAgeSeconds": 3000
31
- }
32
- ]
24
+ S3_BUCKET_CORS_RULE = <<-TERRAFORM
25
+ cors_rule {
26
+ allowed_headers = ["Authorization", "cache-control", "x-requested-with"]
27
+ allowed_methods = ["PUT", "POST", "GET"]
28
+ allowed_origins = ["*"]
29
+ expose_headers = []
30
+ max_age_seconds = 3000
33
31
  }
34
- JSON
32
+ TERRAFORM
35
33
 
36
34
  @prompts = ConvoxInstaller::Config::DEFAULT_PROMPTS + [
37
35
  {
@@ -81,8 +79,18 @@ JSON
81
79
  value: -> { "app-uploads-#{SecureRandom.hex(4)}" }
82
80
  },
83
81
  {
84
- key: :s3_bucket_cors_policy,
85
- value: S3_BUCKET_CORS_POLICY,
82
+ key: :s3_bucket_cors_rule,
83
+ value: S3_BUCKET_CORS_RULE,
84
+ hidden: true
85
+ },
86
+ {
87
+ key: :database_username,
88
+ value: 'example_app',
89
+ hidden: true
90
+ },
91
+ {
92
+ key: :database_password,
93
+ value: -> { SecureRandom.hex(16) },
86
94
  hidden: true
87
95
  }
88
96
  ]
@@ -92,54 +100,138 @@ config = prompt_for_config
92
100
 
93
101
  backup_convox_host_and_rack
94
102
  install_convox
95
-
96
- validate_convox_auth_and_write_host!
97
- validate_convox_rack!
103
+ validate_convox_rack_and_write_current!
104
+ validate_convox_rack_api!
98
105
 
99
106
  create_convox_app!
100
107
  set_default_app_for_directory!
101
108
  add_docker_registry!
102
- create_s3_bucket!
103
109
 
104
- puts '=> Generating secret keys for authentication sessions and encryption...'
105
- secret_key_base = SecureRandom.hex(64)
106
- data_encryption_key = SecureRandom.hex(32)
110
+ add_s3_bucket
111
+ add_rds_database
112
+ add_elasticache_cluster
113
+
114
+ apply_terraform_update!
115
+
116
+ unless config[:sidekiq_cloudwatch_iam_credentials]
117
+ logger.info "Looking up IAM user for Sidekiq CloudWatch metrics (#{config.fetch(:sidekiq_cloudwatch_iam_username)})..."
107
118
 
108
- puts "======> Default domain: #{default_service_domain_name}"
109
- puts ' You can use this as a CNAME record after configuring a domain in convox.yml'
110
- puts ' (Note: SSL will be configured automatically.)'
119
+ aws_cli_credentials = "AWS_ACCESS_KEY_ID=#{config.fetch(:aws_access_key_id)} " \
120
+ "AWS_SECRET_ACCESS_KEY=#{config.fetch(:aws_secret_access_key)}"
121
+ `#{aws_cli_credentials} aws iam get-user \
122
+ --user-name #{config.fetch(:sidekiq_cloudwatch_iam_username)} 2>/dev/null`
123
+ unless $CHILD_STATUS.success?
124
+ logger.info "Creating IAM user: #{config.fetch(:sidekiq_cloudwatch_iam_username)} with CloudWatchAgentServerPolicy..."
125
+ # IAM user needs the CloudWatchAgentServerPolicy policy
126
+ `#{aws_cli_credentials} aws iam create-user \
127
+ --user-name #{config.fetch(:sidekiq_cloudwatch_iam_username)}`
128
+ unless $CHILD_STATUS.success?
129
+ raise "Sorry, something went wrong while creating the #{config.fetch(:sidekiq_cloudwatch_iam_username)} IAM user!"
130
+ end
111
131
 
112
- puts '=> Setting environment variables to configure the application...'
132
+ logger.info 'Attaching CloudWatchAgentServerPolicy...'
133
+ `#{aws_cli_credentials} aws iam attach-user-policy \
134
+ --user-name #{config.fetch(:sidekiq_cloudwatch_iam_username)} \
135
+ --policy-arn arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy`
136
+ unless $CHILD_STATUS.success?
137
+ raise 'Sorry, something went wrong while attaching the CloudWatchAgentServerPolicy policy!'
138
+ end
139
+ end
140
+ logger.info "Creating IAM access token for #{config.fetch(:sidekiq_cloudwatch_iam_username)}..."
113
141
 
114
- env = {
115
- 'HEALTH_CHECK_PATH' => MINIMAL_HEALTH_CHECK_PATH,
116
- 'DOMAIN_NAME' => default_service_domain_name,
142
+ create_access_key_output_json = `#{aws_cli_credentials} aws iam create-access-key \
143
+ --user-name #{config.fetch(:sidekiq_cloudwatch_iam_username)}`
144
+ unless $CHILD_STATUS.success?
145
+ raise "Sorry, something went wrong while creating the access token for #{config.fetch(:sidekiq_cloudwatch_iam_username)}!"
146
+ end
147
+
148
+ config[:sidekiq_cloudwatch_iam_credentials] =
149
+ JSON.parse(create_access_key_output_json)['AccessKey']
150
+
151
+ # Save credentials in the cached config file
152
+ File.open('./.installer_config.json', 'w') do |f|
153
+ f.puts(JSON.pretty_generate(config: config))
154
+ end
155
+ end
156
+
157
+ logger.info "======> Default domain: #{default_service_domain_name}"
158
+ logger.info ' You can use this as a CNAME record after configuring a domain in convox.yml'
159
+ logger.info ' (Note: SSL will be configured automatically.)'
160
+
161
+ logger.info 'Checking convox env...'
162
+ convox_env_output = `convox env --rack #{config.fetch(:stack_name)}`
163
+ raise 'Error running convox env' unless $CHILD_STATUS.success?
164
+
165
+ convox_env = begin
166
+ convox_env_output.split("\n").map { |s| s.split('=', 2) }.to_h
167
+ rescue StandardError
168
+ {}
169
+ end
170
+
171
+ # Add database and redis
172
+ desired_env = {
173
+ 'DATABASE_URL' => rds_details[:postgres_url],
174
+ 'REDIS_URL' => elasticache_details[:redis_url],
117
175
  'AWS_ACCESS_KEY_ID' => s3_bucket_details.fetch(:access_key_id),
118
176
  'AWS_ACCESS_KEY_SECRET' => s3_bucket_details.fetch(:secret_access_key),
119
177
  'AWS_UPLOADS_S3_BUCKET' => s3_bucket_details.fetch(:name),
120
178
  'AWS_UPLOADS_S3_REGION' => config.fetch(:aws_region),
121
- 'SECRET_KEY_BASE' => secret_key_base,
122
- 'DATA_ENCRYPTION_KEY' => data_encryption_key,
179
+ 'SECRET_KEY_BASE' => config.fetch(:secret_key_base),
180
+ 'SUBMISSION_DATA_ENCRYPTION_KEY' => config.fetch(:data_encryption_key),
123
181
  'ADMIN_NAME' => 'Admin',
124
182
  'ADMIN_EMAIL' => config.fetch(:admin_email),
125
- 'ADMIN_PASSWORD' => config.fetch(:admin_password)
183
+ 'ADMIN_PASSWORD' => config.fetch(:admin_password),
184
+ 'DOCSPRING_LICENSE' => config.fetch(:docspring_license),
185
+ 'DISABLE_EMAILS' => 'true'
126
186
  }
127
187
 
128
- env_command_params = env.map { |k, v| "#{k}=\"#{v}\"" }.join(' ')
129
- run_convox_command! "env set #{env_command_params}"
188
+ # Only set health check path and domain if it's not already present.
189
+ desired_env['HEALTH_CHECK_PATH'] = MINIMAL_HEALTH_CHECK_PATH if convox_env['HEALTH_CHECK_PATH'].nil?
190
+ desired_env['DOMAIN_NAME'] = default_service_domain_name if convox_env['DOMAIN_NAME'].nil?
191
+
192
+ updated_keys = []
193
+ desired_env.each_key do |key|
194
+ updated_keys << key if convox_env[key] != desired_env[key]
195
+ end
196
+
197
+ if updated_keys.none?
198
+ logger.info '=> Convox env has already been configured.'
199
+ logger.info ' You can update this by running: convox env set ...'
200
+ else
201
+ logger.info "=> Setting environment variables to configure DocSpring: #{updated_keys.join(', ')}"
202
+ env_command_params = desired_env.map { |k, v| "#{k}=\"#{v}\"" }.join(' ')
203
+ run_convox_command! "env set #{env_command_params}"
204
+ end
205
+
206
+ # If we are already using the complete health check path, then we can skip the rest.
207
+ if convox_env['HEALTH_CHECK_PATH'] == COMPLETE_HEALTH_CHECK_PATH
208
+ logger.info 'DocSpring is already set up and running.'
209
+ else
210
+ logger.info 'Checking convox processes...'
211
+ convox_processes = `convox ps --rack #{config.fetch(:stack_name)}`
212
+ if convox_processes.include?('web') && convox_processes.include?('worker')
213
+ logger.info '=> Initial deploy for DocSpring Enterprise is already done.'
214
+ else
215
+ logger.info '=> Initial deploy for DocSpring Enterprise...'
216
+ logger.info '-----> Documentation: https://docs.convox.com/deployment/deploying-changes/'
217
+ run_convox_command! 'deploy'
218
+ end
219
+
220
+ logger.info '=> Ensuring the DocSpring application container can boot successfully...'
221
+ run_convox_command! 'run command ./bin/smoke_test'
130
222
 
131
- puts '=> Initial deploy...'
132
- puts '-----> Documentation: https://docs.convox.com/deployment/builds'
133
- run_convox_command! 'deploy --wait'
223
+ logger.info '=> Setting up the DocSpring database...'
224
+ run_convox_command! 'run command rake db:create db:migrate db:seed'
134
225
 
135
- puts '=> Setting up the database...'
136
- run_convox_command! 'run web rake db:create db:migrate db:seed'
226
+ logger.info '=> Checking Postgres, Redis, Rails cache, S3 uploads, Sidekiq job processing...'
227
+ run_convox_command! 'run command rake tests:health_check'
137
228
 
138
- puts '=> Updating the health check path to include database tests...'
139
- run_convox_command! "env set --promote --wait HEALTH_CHECK_PATH=#{COMPLETE_HEALTH_CHECK_PATH}"
229
+ logger.info '=> Updating the health check path to include database tests...'
230
+ run_convox_command! "env set --promote HEALTH_CHECK_PATH=#{COMPLETE_HEALTH_CHECK_PATH}"
231
+ end
140
232
 
141
233
  puts
142
- puts 'All done!'
234
+ logger.info 'All done!'
143
235
  puts
144
236
  puts "You can now visit #{default_service_domain_name} and sign in with:"
145
237
  puts
@@ -159,24 +251,26 @@ puts
159
251
  puts 'To learn more about the convox CLI, run: convox --help'
160
252
  puts
161
253
  puts ' * View the Convox documentation: https://docs.convox.com/'
254
+ puts ' * View the DocSpring documentation: https://docspring.com/docs/'
162
255
  puts
163
256
  puts
164
- puts 'To completely uninstall Convox from your AWS account,'
257
+ puts 'To completely uninstall Convox and DocSpring from your AWS account,'
165
258
  puts 'run the following steps (in this order):'
166
259
  puts
167
260
  puts ' 1) Disable "Termination Protection" for any resource where it was enabled.'
168
261
  puts
169
- puts " 2) Delete all files from the #{config.fetch(:s3_bucket_name)} S3 bucket:"
262
+ puts " 2) Delete all files from the #{s3_bucket_details.fetch(:name)} S3 bucket:"
170
263
  puts
171
264
  puts " export AWS_ACCESS_KEY_ID=#{config.fetch(:aws_access_key_id)}"
172
265
  puts " export AWS_SECRET_ACCESS_KEY=#{config.fetch(:aws_secret_access_key)}"
173
266
  puts " aws s3 rm s3://#{s3_bucket_details.fetch(:name)} --recursive"
174
267
  puts
175
- puts " 3) Delete the #{config.fetch(:s3_bucket_name)} S3 bucket:"
268
+ puts ' 3) Uninstall Convox (deletes all AWS resources via Terraform):'
176
269
  puts
177
- puts " convox rack resources delete #{config.fetch(:s3_bucket_name)} --wait"
270
+ puts " convox rack uninstall #{config.fetch(:stack_name)}"
178
271
  puts
179
- puts ' 4) Uninstall Convox (deletes all CloudFormation stacks and AWS resources):'
180
272
  puts
181
- puts " convox rack uninstall aws #{config.fetch(:stack_name)}"
273
+ puts '------------------------------------------------------------------------------------'
274
+ puts 'Thank you for using DocSpring! Please contact support@docspring.com if you need any help.'
275
+ puts '------------------------------------------------------------------------------------'
182
276
  puts