convox_installer 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4aa7edf7f211c8c4fabf9f11c189b8634e16f6345771aa84ea3d68a94171474e
4
+ data.tar.gz: 188957c8d8471ba8d9cb39356cd5ef1f051b4f515a0b7de955a092edfe0b2188
5
+ SHA512:
6
+ metadata.gz: 1fb7fe4c0522649b7b4850f5270d58c6eb2e7df7e27919e27f4d5b4e51a0869a3406096ae1ebe4e44cfc69047c9b12c64e86a7ad5ef77b82ce0bb5b6bd1dab31
7
+ data.tar.gz: 136b4634a4be218eb349f07d3dc04ff868d09e1da3fda18b35effd277ec1e256cdd35ddd49628f1436d904796e325f25517e1666e7e64cd9c0e94e74bb175ea6
data/.bundle/config ADDED
@@ -0,0 +1,2 @@
1
+ ---
2
+ BUNDLE_JOBS: "8"
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ mkmf.log
2
+ log
3
+ convox.yml
4
+ .convox
5
+ convox_installer-*.gem
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,41 @@
1
+ require: rubocop-rspec
2
+ TargetRubyVersion: "2.3"
3
+
4
+ Metrics/LineLength:
5
+ Max: 100
6
+
7
+ Style/StringLiterals:
8
+ EnforcedStyle: single_quotes
9
+
10
+ Style/Documentation:
11
+ Enabled: false
12
+
13
+ Style/IfUnlessModifier:
14
+ Enabled: false
15
+
16
+ Metrics/AbcSize:
17
+ Enabled: false
18
+
19
+ Metrics/ClassLength:
20
+ Enabled: false
21
+
22
+ Metrics/CyclomaticComplexity:
23
+ Enabled: false
24
+
25
+ Metrics/PerceivedComplexity:
26
+ Enabled: false
27
+
28
+ Metrics/MethodLength:
29
+ Enabled: false
30
+
31
+ Metrics/ModuleLength:
32
+ Enabled: false
33
+
34
+ Metrics/ParameterLists:
35
+ Enabled: false
36
+
37
+ Metrics/BlockLength:
38
+ Enabled: false
39
+
40
+ Metrics/BlockNesting:
41
+ Max: 7
@@ -0,0 +1,4 @@
1
+ {
2
+ "editor.formatOnSave": true,
3
+ "editor.formatOnSaveTimeout": 5000
4
+ }
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
6
+
7
+ group :test do
8
+ gem 'pry'
9
+ gem 'pry-byebug'
10
+ gem 'rspec'
11
+ gem 'rubocop'
12
+ gem 'rubocop-rspec'
13
+ gem 'vcr'
14
+ gem 'webmock'
15
+ end
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2019 Form Applications, Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # Convox Installer
2
+
3
+ [Convox](https://convox.com/) is an awesome open source PaaS, which is like Heroku for your own AWS account. [`convox/rack`](https://github.com/convox/rack) is completely open source and free to use, but you can also sign up for a free or paid account to use the hosted service on convox.com.
4
+
5
+ `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.
6
+
7
+ I've rewritten this installation script in Ruby, which provides very good cross-platform support, and also allows me to write tests.
8
+
9
+ # Usage
10
+
11
+ You should create a new git repo for your own installation script, and then use the provided classes and methods to build your own installation workflow. You must also include a `convox.yml`.
12
+
13
+ You can see an example in [`examples/full_installation.rb`](./examples/full_installation.rb).
14
+ (This Ruby file uses `bundler/inline`, so it will download and install the `convox_installer` gem before running the script.)
15
+
16
+ # Config
17
+
18
+ Config is loaded from ENV vars, or from saved JSON data at
19
+ `~/.convox/installer_config`.
20
+
21
+ ### License
22
+
23
+ [MIT](./LICENSE)
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.push File.expand_path("lib", __dir__)
4
+ require "convox_installer/version"
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "convox_installer"
8
+ s.version = ConvoxInstaller::VERSION
9
+ s.platform = Gem::Platform::RUBY
10
+ s.authors = ["Form Applications Inc."]
11
+ s.email = ["support@formapi.io"]
12
+ s.homepage = "https://github.com/FormAPI/convox_installer"
13
+ s.summary = "Build a Convox installation workflow"
14
+ s.description = "Build a Convox installation workflow"
15
+ s.license = "MIT"
16
+ s.required_ruby_version = ">= 2.3"
17
+
18
+ s.add_runtime_dependency "highline", ">= 1.7.10"
19
+ s.add_runtime_dependency "json", ">= 2.2.0"
20
+ s.add_runtime_dependency "os", ">= 1.0.1"
21
+ s.add_runtime_dependency "httparty", ">= 0.17.0"
22
+ s.add_runtime_dependency "activesupport", ">= 5.2.3"
23
+
24
+ s.files = `git ls-files`.split("\n").uniq.sort.reject(&:empty?) - ["Gemfile.lock"]
25
+ s.test_files = `git ls-files spec test`.split("\n")
26
+ s.executables = []
27
+ s.require_paths = ["lib"]
28
+ end
@@ -0,0 +1,182 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # Use Bundler inline for your real installation script
5
+ # require "bundler/inline"
6
+
7
+ # gemfile do
8
+ # source "https://rubygems.org"
9
+ # gem "convox_installer"
10
+ # end
11
+
12
+ $LOAD_PATH << File.expand_path("../../lib", __FILE__)
13
+ require "pry-byebug"
14
+
15
+ require "convox_installer"
16
+ include ConvoxInstaller
17
+
18
+ @log_level = Logger::DEBUG
19
+
20
+ MINIMAL_HEALTH_CHECK_PATH = "/health/site"
21
+ COMPLETE_HEALTH_CHECK_PATH = "/health"
22
+
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
+ ]
33
+ }
34
+ JSON
35
+
36
+ @prompts = ConvoxInstaller::Config::DEFAULT_PROMPTS + [
37
+ {
38
+ section: "ECR Authentication",
39
+ info: "You should have received authentication details for the Docker Registry\n" \
40
+ "via email. If not, please contact support@example.com",
41
+ },
42
+ {
43
+ key: :docker_registry_url,
44
+ title: "Docker Registry URL",
45
+ value: "691950705664.dkr.ecr.us-east-1.amazonaws.com",
46
+ },
47
+ {
48
+ key: :docker_registry_username,
49
+ title: "Docker Registry Username",
50
+ },
51
+ {
52
+ key: :docker_registry_password,
53
+ title: "Docker Registry Password",
54
+ },
55
+ {
56
+ key: :convox_app_name,
57
+ title: "Convox App Name",
58
+ value: "convox-app",
59
+ },
60
+ {
61
+ key: :default_service,
62
+ title: "Default Convox Service (for domain)",
63
+ value: "web",
64
+ hidden: true,
65
+ },
66
+ {
67
+ key: :admin_email,
68
+ title: "Admin User Email",
69
+ prompt: "Please enter the email address you would like to use " \
70
+ "for the default admin user",
71
+ default: "admin@example.com",
72
+ },
73
+ {
74
+ key: :admin_password,
75
+ title: "Admin User Password",
76
+ value: -> () { SecureRandom.hex(8) },
77
+ },
78
+ {
79
+ key: :s3_bucket_name,
80
+ title: "S3 Bucket for Uploads",
81
+ value: -> () { "app-uploads-#{SecureRandom.hex(4)}" },
82
+ },
83
+ {
84
+ key: :s3_bucket_cors_policy,
85
+ value: S3_BUCKET_CORS_POLICY,
86
+ hidden: true,
87
+ },
88
+ ]
89
+
90
+ ensure_requirements!
91
+ config = prompt_for_config
92
+
93
+ backup_convox_host_and_rack
94
+ install_convox
95
+
96
+ validate_convox_auth_and_set_host!
97
+ validate_convox_rack!
98
+
99
+ create_convox_app!
100
+ set_default_app_for_directory!
101
+ add_docker_registry!
102
+ create_s3_bucket!
103
+
104
+ puts "=> Generating secret keys for authentication sessions and encryption..."
105
+ secret_key_base = SecureRandom.hex(64)
106
+ data_encryption_key = SecureRandom.hex(32)
107
+
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.)"
111
+
112
+ puts "=> Setting environment variables to configure the application..."
113
+
114
+ env = {
115
+ "HEALTH_CHECK_PATH" => MINIMAL_HEALTH_CHECK_PATH,
116
+ "DOMAIN_NAME" => default_service_domain_name,
117
+ "AWS_ACCESS_KEY_ID" => config.fetch(:aws_access_key_id),
118
+ "AWS_ACCESS_KEY_SECRET" => config.fetch(:aws_secret_access_key),
119
+ "AWS_UPLOADS_S3_BUCKET" => s3_bucket_details.fetch(:name),
120
+ "AWS_UPLOADS_S3_REGION" => config.fetch(:aws_region),
121
+ "SECRET_KEY_BASE" => secret_key_base,
122
+ "DATA_ENCRYPTION_KEY" => data_encryption_key,
123
+ "ADMIN_NAME" => "Admin",
124
+ "ADMIN_EMAIL" => config.fetch(:admin_email),
125
+ "ADMIN_PASSWORD" => config.fetch(:admin_password),
126
+ }
127
+
128
+ env_command_params = env.map { |k, v| "#{k}=\"#{v}\"" }.join(" ")
129
+ run_convox_command! "env set #{env_command_params}"
130
+
131
+ puts "=> Initial deploy..."
132
+ puts "-----> Documentation: https://docs.convox.com/deployment/builds"
133
+ run_convox_command! "deploy --wait"
134
+
135
+ puts "=> Setting up the database..."
136
+ run_convox_command! "run web rake db:create db:migrate db:seed"
137
+
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}"
140
+
141
+ puts
142
+ puts "All done!"
143
+ puts
144
+ puts "You can now visit #{default_service_domain_name} and sign in with:"
145
+ puts
146
+ puts " Email: #{config.fetch(:admin_email)}"
147
+ puts " Password: #{config.fetch(:admin_password)}"
148
+ puts
149
+ puts "You can configure a custom domain name, auto-scaling, and other options in convox.yml."
150
+ puts "To deploy your changes, run: convox deploy --wait"
151
+ puts
152
+ puts "IMPORTANT: You should be very careful with the 'resources' section in convox.yml."
153
+ puts "If you remove, rename, or change these resources, then Convox will delete"
154
+ puts "your database. This will result in downtime and a loss of data."
155
+ puts "To prevent this from happening, you can sign into your AWS account,"
156
+ puts "visit the RDS and ElastiCache services, and enable \"Termination Protection\""
157
+ puts "for your database resources."
158
+ puts
159
+ puts "To learn more about the convox CLI, run: convox --help"
160
+ puts
161
+ puts " * View the Convox documentation: https://docs.convox.com/"
162
+ puts
163
+ puts
164
+ puts "To completely uninstall Convox from your AWS account,"
165
+ puts "run the following steps (in this order):"
166
+ puts
167
+ puts " 1) Disable \"Termination Protection\" for any resource where it was enabled."
168
+ puts
169
+ puts " 2) Delete all files from the #{config.fetch(:s3_bucket_name)} S3 bucket:"
170
+ puts
171
+ puts " export AWS_ACCESS_KEY_ID=#{config.fetch(:aws_access_key_id)}"
172
+ puts " export AWS_SECRET_ACCESS_KEY=#{config.fetch(:aws_secret_access_key)}"
173
+ puts " aws s3 rm s3://#{s3_bucket_details.fetch(:name)} --recursive"
174
+ puts
175
+ puts " 3) Delete the #{config.fetch(:s3_bucket_name)} S3 bucket:"
176
+ puts
177
+ puts " convox rack resources delete #{config.fetch(:s3_bucket_name)} --wait"
178
+ puts
179
+ puts " 4) Uninstall Convox (deletes all CloudFormation stacks and AWS resources):"
180
+ puts
181
+ puts " convox rack uninstall aws #{config.fetch(:stack_name)}"
182
+ puts