terra_boi 0.0.11 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +84 -159
  3. data/lib/generators/extensions.rb +5 -5
  4. data/lib/generators/terra_boi/boilerplate_generator.rb +39 -32
  5. data/lib/generators/terra_boi/dockerfile_generator.rb +19 -18
  6. data/lib/generators/terra_boi/host_initializer_generator.rb +18 -18
  7. data/lib/generators/terra_boi/templates/Dockerfile.erb +4 -23
  8. data/lib/generators/terra_boi/templates/cert/main.tf.erb +32 -0
  9. data/lib/generators/terra_boi/templates/cert/var.tf.erb +15 -0
  10. data/lib/generators/terra_boi/templates/data_storage_config.erb +7 -7
  11. data/lib/generators/terra_boi/templates/ecr/ecs_role.tf.erb +41 -0
  12. data/lib/generators/terra_boi/templates/ecr/main.tf.erb +26 -0
  13. data/lib/generators/terra_boi/templates/ecr/output.tf.erb +11 -0
  14. data/lib/generators/terra_boi/templates/ecr/var.tf.erb +15 -0
  15. data/lib/generators/terra_boi/templates/{data_main.erb → env/data/main.tf.erb} +2 -2
  16. data/lib/generators/terra_boi/templates/{data_output.erb → env/data/output.tf.erb} +1 -1
  17. data/lib/generators/terra_boi/templates/env/ecs_cluster/ecs_cluster.tf.erb +24 -0
  18. data/lib/generators/terra_boi/templates/env/head_worker/ecs.tf.erb +55 -0
  19. data/lib/generators/terra_boi/templates/env/web_app/ecs.tf.erb +59 -0
  20. data/lib/generators/terra_boi/templates/lib/scripts/push_to_ecr.sh.erb +21 -0
  21. data/lib/generators/terra_boi/templates/lib/scripts/update_service_pull_from_ecr.sh.erb +18 -0
  22. data/lib/generators/terra_boi/templates/lib/task_templates/head_worker.json.erb +61 -0
  23. data/lib/generators/terra_boi/templates/lib/task_templates/web_app.json.erb +58 -0
  24. data/lib/generators/terra_boi/templates/lib/terraform_modules/ecs_cluster/main.tf.erb +12 -0
  25. data/lib/generators/terra_boi/templates/lib/terraform_modules/ecs_cluster/var.tf.erb +20 -0
  26. data/lib/generators/terra_boi/templates/lib/terraform_modules/ecs_web_app/ecs_role.tf.erb +7 -0
  27. data/lib/generators/terra_boi/templates/lib/terraform_modules/ecs_web_app/load_balancer.tf.erb +92 -0
  28. data/lib/generators/terra_boi/templates/lib/terraform_modules/ecs_web_app/main.tf.erb +134 -0
  29. data/lib/generators/terra_boi/templates/lib/terraform_modules/ecs_web_app/output.tf.erb +11 -0
  30. data/lib/generators/terra_boi/templates/lib/terraform_modules/ecs_web_app/var.tf.erb +63 -0
  31. data/lib/generators/terra_boi/templates/lib/terraform_modules/ecs_worker/ecs_role.tf.erb +7 -0
  32. data/lib/generators/terra_boi/templates/lib/terraform_modules/ecs_worker/main.tf.erb +120 -0
  33. data/lib/generators/terra_boi/templates/lib/terraform_modules/ecs_worker/output.tf.erb +7 -0
  34. data/lib/generators/terra_boi/templates/lib/terraform_modules/ecs_worker/var.tf.erb +57 -0
  35. data/lib/generators/terra_boi/templates/state_main.erb +1 -1
  36. data/lib/generators/terra_boi/tf_cert_generator.rb +28 -0
  37. data/lib/generators/terra_boi/tf_ecr_generator.rb +28 -0
  38. data/lib/generators/terra_boi/tf_env_generator.rb +54 -0
  39. data/lib/generators/terra_boi/tf_lib_generator.rb +57 -0
  40. data/lib/generators/terra_boi/tf_state_generator.rb +24 -0
  41. data/lib/tasks/terra_boi_tasks.rake +280 -4
  42. data/lib/terra_boi/railtie.rb +5 -2
  43. data/lib/terra_boi/version.rb +1 -1
  44. metadata +51 -22
  45. data/lib/generators/terra_boi/data_generator.rb +0 -38
  46. data/lib/generators/terra_boi/master_worker_generator.rb +0 -47
  47. data/lib/generators/terra_boi/packer_generator.rb +0 -26
  48. data/lib/generators/terra_boi/state_generator.rb +0 -25
  49. data/lib/generators/terra_boi/templates/master_worker_main.erb +0 -26
  50. data/lib/generators/terra_boi/templates/master_worker_output.erb +0 -14
  51. data/lib/generators/terra_boi/templates/master_worker_user_data.erb +0 -33
  52. data/lib/generators/terra_boi/templates/packer_ami_build.erb +0 -27
  53. data/lib/generators/terra_boi/templates/packer_application.erb +0 -49
  54. data/lib/generators/terra_boi/templates/web_servers_main.erb +0 -31
  55. data/lib/generators/terra_boi/templates/web_servers_output.erb +0 -14
  56. data/lib/generators/terra_boi/templates/web_servers_user_data.erb +0 -29
  57. data/lib/generators/terra_boi/web_servers_generator.rb +0 -48
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dd8d2f6505e7bc89ef66206252e88ed84e169940ffcab9058146b2f99e1c1f6a
4
- data.tar.gz: 0d88f6ebd23475bcc15efbfad3661d7031645f505e77b0f25c59490ffc557fd4
3
+ metadata.gz: c36dc0d2b46ebcc92f0b6ed5ef50266ba726528f7d5af498358242f25f9f3a2f
4
+ data.tar.gz: 2fecb45f6a00eb0d7b288c49c6a83b5a52723365057c89663375eca4a0aa85ca
5
5
  SHA512:
6
- metadata.gz: 67e096f669eeea983ed50f465eb37f01cfe0710d831c98e67b849697aaf87665b0ce0fe789391686cc738ea164694e9fc8a9655992395a1be16a3301657b7080
7
- data.tar.gz: 8e5c302a0bd6cb7c8ea62c33f579e3d4493062d2543db84a0239097e9ef3031009954eeb318b87025914cb4b1126a6cfcddd64a12f06267dae41421cfad66cf9
6
+ metadata.gz: cbd2c30b16f582e5ac99384298e57e2c8125c762c644e55b7838c1edb37092a9216efc80cf5835cd5be82d2ac7aa16e7e4bfd3e6889ebbcd2472f467d00ffe13
7
+ data.tar.gz: 83b231de3fb16aa1a986437220b7a124313bb3a884e355255d885e8213438309de38ba2ff7cd8d682d78db79692562fe1d36d77fa074229ba90d24a1e56be22b
data/README.md CHANGED
@@ -1,234 +1,159 @@
1
1
  # TerraBoi
2
2
 
3
- This ruby gem was created by [Charlie Reese](https://charliereese.ca/about) at [Clientelify](https://clientelify.com) to get rails applications deployed into production as quickly and easily as possible.
3
+ ## Introduction
4
4
 
5
- **Raison d'etre**: creating basic infrastructure to house production SaaS applications on AWS is tedious and boring. It's often a similar process every time, and every time it sucks.
5
+ This ruby / rails gem was created by [Charlie Reese](https://charliereese.ca/about) for [Clientelify](https://clientelify.com). It creates AWS infrastructure for your rails application and deploys it in 5 steps (3 installation steps and 2 rake tasks). It is free to use.
6
6
 
7
- List of items created by this gem's generators:
8
- - Dockerfile
9
- - Rails initializer file (for setting up config.hosts)
10
- - Packer repository (for creating AMIs)
11
- - Terraform repository (for creating infrastructure as code to immediately deploy staging / prod infrastructure as well as rolling out application updates)
12
-
13
- **Note**: generated Terraform files create / support remote state locking, load-balancing, auto-scaling, zero-downtime web app deployments, DBs, and S3 buckets.
14
-
15
- **Note**: after infrastructure files are generated, you will be ready to deploy your application to staging / production on AWS. If you have more advanced infrastructure needs (e.g. Redis / Solr instances), you may add to the generated Terraform files to support this.
7
+ Out of the box, terra_boi provides remote state locking, load-balancing, simple scaling, zero-downtime deployments, CloudWatch logging, DBs, and S3 buckets for multiple infrastructure environments: by default, terra_boi creates staging and prod environments for your web app.
16
8
 
17
9
 
10
+ ## Installation
18
11
 
19
- ## Pre-requisites
12
+ #### Installation A: pre-requisites
20
13
 
21
14
  * [Terraform](https://www.terraform.io/) installed on your computer
22
- * [Packer](https://www.packer.io/downloads.html) installed on your computer
23
15
  * [Amazon Web Services (AWS) account](http://aws.amazon.com/)
16
+ * [AWS access key and secret key](https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys) (to be used below shortly)
17
+ * Rails ~> 6.0
24
18
 
19
+ #### Installation B: install ruby gems
25
20
 
26
-
27
- ## Installation
28
-
29
- **Note**: below installation steps should be completed in order.
30
-
31
- ### Installation - gem
32
-
33
- Add this line to your (Rails) application's Gemfile:
21
+ Add these lines to your (Rails) application's Gemfile:
34
22
 
35
23
  ```ruby
36
- gem 'terra_boi'
24
+ group :development do
25
+ gem 'terra_boi'
26
+ end
27
+
28
+ gem 'pg' # Postgresql
29
+ gem 'whenever', require: false # For cron jobs set in config/schedule.rb
37
30
  ```
38
31
 
39
32
  And then execute:
40
33
 
41
34
  ```bash
42
- $ bundle
43
- ```
44
-
45
- ### Installation - AWS access
46
-
47
- Set up your [AWS access / secret access
48
- keys](http://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys) in `~/.zprofile` (or equivalent file for your shell if not using .zsh) as environment variables:
49
-
35
+ $ bundle && bundle exec wheneverize .
50
36
  ```
51
- export AWS_ACCESS_KEY_ID=your_access_key_id
52
- export AWS_SECRET_ACCESS_KEY=your_secret_access_key
53
- ```
54
-
55
- Then run `source ~/.zprofile` (or equivalent command for your shell if not using .zsh)
56
37
 
57
- Note: SSH access to created EC2 instances is granted using SSH keys existing at `~/.ssh/id_rsa.pub` and `~/.ssh/id_rsa` on your local machine. If they do not exist, create them.
38
+ #### Installation C: set environment variables
58
39
 
59
- ### Installation - generate infrastructure code
40
+ Set and export terraform AWS and data-related environment variables in ~/.zprofile (or your respective shell dotfile e.g. ~/.bashrc)
60
41
 
61
- To generate boilerplate infrastructure code (config.host initializer filer, Dockerfile, Packer repository, and terraform repository):
62
-
63
- `rails generate terra_boi:boilerplate --domain_name DOMAIN.COM --ruby_version 2.5.1`
64
-
65
- ### Installation - Packer (creating web server AMIs)
66
-
67
- **A. Create private DockerHub repository**
68
-
69
- Create private DockerHub repository for your rails application (if possible, use the exact same name as your rails application).
70
-
71
- **Note**: packer generator will assume your DockerHub repository has the same name as your rails application folder. If this isn't true, update generated Packer `ami_build.json` file after it is generated.
72
-
73
- **B. Setup DockerHub access:**
74
-
75
- Add DockerHub username and access key to `~/.zprofile` (or equivalent file for your shell if not using .zsh) as environment variables (if your image is in a private repository):
76
-
77
- ```
78
- DOCKERHUB_USERNAME=myname
79
- DOCKERHUB_ACCESS_TOKEN=myAccessToken
80
- export DOCKERHUB_USERNAME DOCKERHUB_ACCESS_TOKEN
81
42
  ```
43
+ TF_VAR_db_password=your_password # whatever you want it to be
44
+ TF_VAR_db_username=your_username # whatever you want it to be
45
+ export TF_VAR_db_password TF_VAR_db_username
82
46
 
83
- Then run `source ~/.zprofile` (or equivalent command for your shell if not using .zsh)
84
-
85
- **Note**: DockerHub access key can be found at https://hub.docker.com/settings/security
86
-
87
- ### Installation - Terraform (deploying DBs + web server AMIs)
88
-
89
- **A. Set up remote state:**
90
-
91
- `cd terraform/state`
92
-
93
- Run `terraform init` and then `terraform apply` to set up s3 bucket and dynamoDB for remote state and locking (this will work for both prod and staging).
94
-
95
- **B. Set up DB / S3:**
96
-
97
- `cd terraform/[ENV]/data`
98
-
99
- Set terraform data-related environment variables in .zprofile (or your respective shell dotfile)
47
+ AWS_ACCESS_KEY=your_access_key
48
+ TF_VAR_aws_access_key=$AWS_ACCESS_KEY
49
+ export AWS_ACCESS_KEY TF_VAR_aws_access_key
100
50
 
101
- ```
102
- TF_VAR_db_password=your_password
103
- TF_VAR_db_username=your_username
51
+ AWS_SECRET_KEY=your_secret_access_key
52
+ TF_VAR_aws_secret_key=$AWS_SECRET_KEY
53
+ export AWS_SECRET_KEY TF_VAR_aws_secret_key
104
54
  ```
105
55
 
106
- To deploy infrastructure to AWS:
56
+ After you've set and export the above environment variables, run `source ~/.zprofile` (or source your respective shell dotfile).
107
57
 
108
- ```
109
- terraform init # IF NOT ALREADY RUN
110
- terraform apply
111
- ```
112
58
 
113
- **C. Set up web servers:**
114
-
115
- `cd terraform/[ENV]/web_servers`
59
+ ## Usage
116
60
 
117
- To deploy infrastructure to AWS:
61
+ #### Usage A: generate infrastructure rake task
118
62
 
119
63
  ```
120
- terraform init # IF NOT ALREADY RUN
121
- terraform apply
64
+ rake terra_boi:generate_infra
122
65
  ```
123
66
 
124
- While aws_acm_certificate_validation.cert is creating (it will hang if you don't add CNAME verification record in ACM):
67
+ The above rake task will ask you some interactive questions, so stay close to your terminal!
125
68
 
126
- i. Log into AWS console, go to certificate management, and add the created CNAME record specified to the DNS configuration for your domain
127
- ii. Redirect domain name to Application load balancer:
128
- - Go to your domain registrar of choice
129
- - Create alias record that points to the dns name of the application load balancer (use subdomain in alias record like STAGING.example.com for staging)
130
- - Create URL redirect record for prod (redirect www.site.com to site.com)
69
+ Expected rake task duration: ~20 minutes (provisioning AWS infrastructure takes a while).
131
70
 
132
- After these changes propogate (should take about an hour or two locally), your webservers should be set up, https should be working, and you should be good to go!
133
-
134
-
135
-
136
- ## Usage
71
+ Note: the above rake task takes an optional argument for environments (e.g. `rake \"terra_boi:generate_infra[dev staging prod]\"`). Infrastructure environments default to staging and prod.
137
72
 
138
- **Note**: below usage steps should be completed in order
73
+ Note: this command will also deploy your application after infrastructure has been created. If you only wish to deploy an update, use the below command.
139
74
 
140
- ### Usage - Packer (creating web server AMIs)
141
-
142
- **A. Push latest application image to DockerHub**
143
-
144
- You can automatically trigger DockerHub image builds when new code is pushed to a repository's master branch using DockerHub's free Github integration.
145
-
146
- Otherwise, `docker build . && docker container create [IMAGE_ID] && docker commit [CONTAINER_ID] [DOCKER_USERNAME]/[APPLICATION_NAME]:latest && docker push [DOCKER_USERNAME]/[APPLICATION_NAME]:latest`. Make sure you are pushing to a private repository.
147
-
148
- **B. Create Packer AMI:**
75
+ #### Usage B: deploy application updates rake task
149
76
 
150
77
  ```
151
- cd packer
78
+ rake deploy
152
79
 
153
- packer build -var DOCKERHUB_ACCESS_TOKEN=$DOCKERHUB_ACCESS_TOKEN -var DOCKERHUB_USERNAME=$DOCKERHUB_USERNAME -var DB_PASSWORD=$TF_VAR_db_password -var AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID -var AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY application.json
80
+ # Alternatively: rake "deploy[staging]", rake "deploy[staging prod]", etc.
154
81
  ```
155
82
 
156
- **C. Clean up:**
157
-
158
- Every so often you'll want to remove old AMIs created by Packer (unless you want to be charged a couple cents a month).
159
-
160
- To remove them, deregister them on the [AWS AMI management page](https://us-east-2.console.aws.amazon.com/ec2/v2/home?region=us-east-2#Images:sort=name), then delete the associated snapshot on the [AWS snapshot management page](https://us-east-2.console.aws.amazon.com/ec2/home?region=us-east-2#Snapshots:sort=snapshotId).
161
-
162
- ### Usage - Terraform (update web server AMIs)
163
-
164
- **A. Update Terraform web server AMIs:**
83
+ The above rake task will ask you an interactive question, so stay close to your terminal!
165
84
 
166
- `cd terraform/[ENV]/web_servers`
85
+ Expected rake task duration: 5 - 10 minutes.
167
86
 
168
- To deploy infrastructure to AWS:
87
+ Note: the above rake task takes an optional argument for environments (e.g. `rake \"deploy[staging prod]\"`). By default, it will deploy to staging then prod infrastructure.
169
88
 
170
- ```
171
- terraform init # IF NOT ALREADY RUN
172
- terraform apply
173
- ```
89
+ #### Usage C: recommendations
174
90
 
175
- ### Usage - ssh access
91
+ - Uncomment `config.force_ssl = true` in `config/environments/production.rb` file.
176
92
 
177
- ssh into ec2 instance and run bash in container:
178
93
 
179
- ```
180
- ssh ubuntu@PUBLICIPOFINSTANCE
181
-
182
- docker container exec -it APP_NAME bash
183
- ```
94
+ ## Infrastructure customization
184
95
 
96
+ Because terra_boi uses Terraform modules, small customizations can be made by changing variables in .tf files.
185
97
 
98
+ For example, if you wanted to run 10 web app instances behind the load balancer in your prod environment (instead of the default 2), you could change the web_app_task => desired_count argument from 2 to 10 in the file `terraform/prod/web_app/ecs.tf`. Similarly, if your web app task container requires more memory, you could change the web_app_task => memory argument in the file `terraform/prod/web_app/ecs.tf`.
186
99
 
187
- ## Infrastructure created
100
+ **Note**: if your rails application has more advanced infrastructure customization needs (e.g. Redis / Solr instances), you may add the resources required to the Terraform files created by terra_boi.
188
101
 
189
- The aforementioned generators create a `terraform` directory with `state`, `prod`, and `staging` subdirectories.
102
+ ## Appendix
190
103
 
191
- The `state` directory contains an S3 bucket and a DynamoDB table to store and lock state (for both prod and staging).
104
+ #### Appendix - infrastructure / code generated by terra_boi
192
105
 
193
- The `prod` and `staging` subdirectories contain `data` (DB + S3) and `web_servers` (SSL cert, load balancing, autoscaling, EC2) directories.
106
+ - AWS Elastic Container Registry (ECR)
107
+ - AWS Application Load Balancer (ALB)
108
+ - AWS Elastic Container Services (for your web app and worker)
109
+ - AWS Fargate tasks (for your web app and worker)
110
+ - AWS CloudWatch logging
111
+ - AWS Security Groups
112
+ - AWS DynamoDB for remote state locking
113
+ - AWS RDS Postgresql DBs
114
+ - Rails DB config file
115
+ - Rails data config file
116
+ - Rails initializer file (for setting up config.hosts)
117
+ - Dockerfile
118
+ - HTTPS / SSL certificate
194
119
 
120
+ #### Appendix - destroying your infrastructure
195
121
 
122
+ To destroy infrastructure created by terra_boi, run `terraform destroy` in the following directories in the following order:
196
123
 
197
- ## Running tests
124
+ - terraform/ENV/head_worker
125
+ - terraform/ENV/web_app
126
+ - terraform/ENV/ecs_cluster
127
+ - terraform/ENV/data
128
+ - terraform/ecr
129
+ - terraform/cert
130
+ - terraform/state
198
131
 
199
- From the root directory:
132
+ OR
200
133
 
201
134
  ```
202
- rake test
135
+ rake terra_boi:destroy_infra
203
136
  ```
204
137
 
138
+ Note: the above rake task takes an optional argument for environments (e.g. `rake \"terra_boi:destroy_infra[dev staging prod]\"`). Infrastructure environments default to staging and prod.
205
139
 
140
+ #### Appendix - license
206
141
 
207
- ## Other tips
208
-
209
- Clean up terraform infrastructure when no longer planning to use (DANGER FOR PROD, WILL DESTROY INFRASTRUCTURE):
210
-
211
- `terraform destroy`
212
-
213
- **For extra security in staging:** update Terraform web_servers `main.tf` file to only allow ingress web_server connections from your IP / your team's IPs
214
-
215
-
216
-
217
- ## Contributing
218
-
219
- This gem is currently not actively accepting contributions.
220
-
221
- With that in mind, if you'd like to make a fix / change, please create a pull request (and when I have a moment - probably in a couple weeks time - I'll have a look)!
142
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
222
143
 
144
+ #### Appendix - contributing
223
145
 
146
+ If you'd like to make a fix / change, please create a pull request! When I have a moment, I'll have a look!
224
147
 
225
- ## License
148
+ Recommended contribution: terraform infrastructure generation testing
226
149
 
227
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
150
+ #### Appendix - other tips
228
151
 
152
+ **Something didn't work and you aren't sure why?** If you're running `rake terra_boi:generate_infra`, try running it again. Sometimes Terraform / the AWS API will throw sporadic errors without reason!
229
153
 
154
+ **For extra security in staging / internal applications:** update Terraform security groups to only allow ingress web_app connections from your team's IP addresses
230
155
 
231
- ## Updating gem version (for maintainers)
156
+ #### Appendix - updating gem version (for maintainers)
232
157
 
233
158
  **1. Update version**
234
159
 
@@ -247,4 +172,4 @@ In `lib/terra_boi/version.rb` update version.
247
172
  `git add -A`
248
173
  `git commit -m "Msg"`
249
174
  `git tag -a vX.X.X -m "Msg"`
250
- `git push --tags`
175
+ `git push && git push --tags`
@@ -3,16 +3,16 @@ module TerraBoi
3
3
  # https://api.rubyonrails.org/classes/Rails/Generators/NamedBase.html#method-i-application_name
4
4
  def generate_application_name
5
5
  if defined?(Rails) && Rails.application
6
- Rails.application.class.name.split("::").first.underscore
7
- else
8
- "application"
9
- end
6
+ Rails.application.class.name.split("::").first.underscore
7
+ else
8
+ "application"
9
+ end
10
10
  end
11
11
 
12
12
  def generate_terraform_files(args)
13
13
  args[:env].each do |env|
14
14
  template(args[:template],
15
- "terraform/#{env}/#{args[:file_path]}",
15
+ "terraform_v2/#{env}/#{args[:file_path]}",
16
16
  {
17
17
  env: env,
18
18
  domain_name: (class_options && class_options[:domain_name]) || generate_application_name + '.com'
@@ -1,38 +1,45 @@
1
1
  module TerraBoi
2
2
  class BoilerplateGenerator < Rails::Generators::Base
3
3
  attr_accessor :application_name, :class_options
4
- class_option :ruby_version, type: :string, default: "2.5.1"
5
- class_option :domain_name, type: :string, default: 'example.com'
6
- source_root File.expand_path('templates', __dir__)
7
-
8
- desc (<<-EOF
9
- This generator runs the terra_boi web_servers, data,
10
- and state generators. It sets up all boilerplate
11
- terraform infrastructure needed for a standard web app:
12
- DB + load balancer + zero downtime, scalable web app
13
- launch config + S3 bucket.
14
-
15
- To execute, run rails generate terra_boi:boilerplate --domain_name example.com
16
- EOF
17
- .gsub(/[\t]/, '')
18
- )
19
-
20
- def init
21
- self.class_options = options
22
- puts application_name
23
- end
24
-
25
- def run_other_generators
26
- generate "terra_boi:web_servers --domain_name #{class_options[:domain_name]}"
27
- generate "terra_boi:data"
28
- generate "terra_boi:state"
29
- generate "terra_boi:dockerfile --ruby_version #{class_options[:ruby_version]}"
30
- generate "terra_boi:host_initializer --domain_name #{class_options[:domain_name]}"
31
- generate "terra_boi:db_config"
32
- generate "terra_boi:data_config"
33
- generate "terra_boi:packer"
34
- generate "terra_boi:master_worker"
35
- end
4
+ class_option :ruby_version, type: :string, default: "2.7.1", aliases: ["r"]
5
+ class_option :domain_name, type: :string, default: 'example.com', aliases: ["d"]
6
+ class_option :envs, type: :array, default: ['staging', 'prod'], aliases: ["e"]
7
+ source_root File.expand_path('templates', __dir__)
8
+
9
+ desc (<<-EOF
10
+ This generator runs the terra_boi web_servers, data,
11
+ and state generators. It sets up all boilerplate
12
+ terraform infrastructure needed for a standard web app:
13
+ DB + load balancer + zero downtime, scalable web app
14
+ launch config + S3 bucket.
15
+
16
+ To execute, run rails g terra_boi:boilerplate --domain_name example.com --ruby_version 2.7.1 --envs staging prod
17
+
18
+ OR
19
+
20
+ rails g terra_boi:boilerplate --d example.com --r 2.7.1 -e staging prod
21
+
22
+ Note: --ruby_version option is for base Dockerfile ruby image. Defaults to 2.7.1.
23
+ EOF
24
+ .gsub(/[\t]/, '')
25
+ )
26
+
27
+ def init
28
+ self.class_options = options
29
+ puts application_name
30
+ end
31
+
32
+ def run_other_generators
33
+ generate "terra_boi:tf_cert -d #{class_options[:domain_name]}"
34
+ generate "terra_boi:tf_ecr"
35
+ generate "terra_boi:tf_lib -d #{class_options[:domain_name]}"
36
+ generate "terra_boi:tf_env -e #{class_options[:envs].join(' ')} -d #{class_options[:domain_name]}"
37
+ generate "terra_boi:tf_state"
38
+ generate "terra_boi:dockerfile --ruby_version #{class_options[:ruby_version]}"
39
+ generate "terra_boi:host_initializer -d #{class_options[:domain_name]}"
40
+ generate "terra_boi:db_config"
41
+ generate "terra_boi:data_config"
42
+ end
36
43
 
37
44
  end
38
45
  end
@@ -2,27 +2,28 @@ require "generators/extensions"
2
2
 
3
3
  module TerraBoi
4
4
  class DockerfileGenerator < Rails::Generators::Base
5
- attr_accessor :application_name, :class_options
6
- class_option :ruby_version, type: :string, default: "2.5.1"
7
- source_root File.expand_path('templates', __dir__)
5
+ attr_accessor :application_name, :class_options
6
+ class_option :ruby_version, type: :string, default: "2.7"
7
+ source_root File.expand_path('templates', __dir__)
8
8
 
9
- desc (<<-EOF
10
- Generate Dockerfile for rails app
11
-
12
- To execute, run rails generate terra_boi:dockerfile
9
+ desc (<<-EOF
10
+ Generate Dockerfile for rails app
11
+
12
+ To execute, run rails generate terra_boi:dockerfile
13
13
 
14
- Can pass in --ruby_version command line argument. Defaults to 2.5.1.
15
- EOF
16
- .gsub(/\t/, '')
17
- )
14
+ Can pass in --ruby_version command line argument. Defaults to 2.5.1.
15
+ EOF
16
+ .gsub(/\t/, '')
17
+ )
18
18
 
19
- def init
20
- self.application_name = generate_application_name
21
- self.class_options = options
22
- end
19
+ def init
20
+ self.application_name = generate_application_name
21
+ self.class_options = options
22
+ end
23
23
 
24
- def create_dockerfile
25
- template "Dockerfile.erb", "Dockerfile"
26
- end
24
+ def create_dockerfile
25
+ template "Dockerfile.erb", "Dockerfile"
26
+ template ".dockerignore.erb", ".dockerignore"
27
+ end
27
28
  end
28
29
  end