terra_boi 0.0.13 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +85 -156
  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 +25 -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 +274 -4
  42. data/lib/terra_boi/railtie.rb +5 -2
  43. data/lib/terra_boi/version.rb +1 -1
  44. metadata +60 -32
  45. data/lib/generators/terra_boi/data_generator.rb +0 -38
  46. data/lib/generators/terra_boi/master_worker_generator.rb +0 -54
  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_start_script.erb +0 -12
  52. data/lib/generators/terra_boi/templates/master_worker_user_data.erb +0 -27
  53. data/lib/generators/terra_boi/templates/packer_ami_build.erb +0 -27
  54. data/lib/generators/terra_boi/templates/packer_application.erb +0 -49
  55. data/lib/generators/terra_boi/templates/web_servers_main.erb +0 -31
  56. data/lib/generators/terra_boi/templates/web_servers_output.erb +0 -14
  57. data/lib/generators/terra_boi/templates/web_servers_user_data.erb +0 -29
  58. 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: a3778d98d44fb92002f085027ce5e14b51d77d4dfee1ef11c97a4474191c200c
4
- data.tar.gz: 9f8786b9e4c67d19d366cf6a0822ae5f72694480dac17bdf36cde7720d8ee8bf
3
+ metadata.gz: 3f586f964ace1990c78dd488bec9045c589493bb6a8d3bb76bd1184535d19927
4
+ data.tar.gz: 2d04e5da26bee200183935911f7b5a60820099750bd79ff17326378a52f05212
5
5
  SHA512:
6
- metadata.gz: 954ea0480e5c6dc1272983f665d5a8e3b46f2e3093df85b9acf4e41c18b8e27cb8a70bfb4f55cab8021a452c11de75598330ee48b482afd96f7a75e1345fbc92
7
- data.tar.gz: b93f8776203b459762dee8311880630afe61096ee8921343d9a40e9fdca86f9ce2d0bb3f7bb0a54fe2d9a56988bb41d6c1d6a9372a3c68b3e4e8c2b33a7acd62
6
+ metadata.gz: dd77679206ecc88ff7f9816494da339d7bdc5b6bf09a9ea3597f67fac2d1550723c5a857ead2b6c3a8265ce582e6cd716619e55c539d43a7f041aa9a1818f315
7
+ data.tar.gz: 283ca1f89860f934937a2f85c1389904936fd5512c11fa26a5dc0b17794227d4f7419e952423d7e5c01af3658be55197801808997e87bca116f22dc93f94836a
data/README.md CHANGED
@@ -1,234 +1,163 @@
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
+ Deploy your rails application to AWS with `rake deploy`.
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)
7
+ 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). Subsequent deployment is 1 step (`rake deploy`).
12
8
 
13
- **Note**: generated Terraform files create / support remote state locking, load-balancing, auto-scaling, zero-downtime web app deployments, DBs, and S3 buckets.
9
+ It is free to use.
14
10
 
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.
11
+ 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
12
 
17
13
 
14
+ ## Installation
18
15
 
19
- ## Pre-requisites
16
+ #### Installation A: pre-requisites
20
17
 
21
18
  * [Terraform](https://www.terraform.io/) installed on your computer
22
- * [Packer](https://www.packer.io/downloads.html) installed on your computer
23
19
  * [Amazon Web Services (AWS) account](http://aws.amazon.com/)
20
+ * [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)
21
+ * Rails ~> 6.0
24
22
 
23
+ #### Installation B: install ruby gems
25
24
 
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:
25
+ Add these lines to your (Rails) application's Gemfile:
34
26
 
35
27
  ```ruby
36
- gem 'terra_boi'
28
+ group :development do
29
+ gem 'terra_boi'
30
+ end
31
+
32
+ gem 'pg' # Postgresql
33
+ gem 'whenever', require: false # For cron jobs set in config/schedule.rb
37
34
  ```
38
35
 
39
36
  And then execute:
40
37
 
41
38
  ```bash
42
- $ bundle
39
+ $ bundle && bundle exec wheneverize .
43
40
  ```
44
41
 
45
- ### Installation - AWS access
42
+ #### Installation C: set environment variables
46
43
 
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:
44
+ Set and export terraform AWS and data-related environment variables in ~/.zprofile (or your respective shell dotfile e.g. ~/.bashrc)
49
45
 
50
46
  ```
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
-
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.
58
-
59
- ### Installation - generate infrastructure code
60
-
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**
47
+ TF_VAR_db_password=your_password # whatever you want it to be
48
+ TF_VAR_db_username=your_username # whatever you want it to be
49
+ export TF_VAR_db_password TF_VAR_db_username
68
50
 
69
- Create private DockerHub repository for your rails application (if possible, use the exact same name as your rails application).
51
+ AWS_ACCESS_KEY=your_access_key
52
+ TF_VAR_aws_access_key=$AWS_ACCESS_KEY
53
+ export AWS_ACCESS_KEY TF_VAR_aws_access_key
70
54
 
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
- ```
82
-
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)
100
-
101
- ```
102
- TF_VAR_db_password=your_password
103
- TF_VAR_db_username=your_username
55
+ AWS_SECRET_KEY=your_secret_access_key
56
+ TF_VAR_aws_secret_key=$AWS_SECRET_KEY
57
+ export AWS_SECRET_KEY TF_VAR_aws_secret_key
104
58
  ```
105
59
 
106
- To deploy infrastructure to AWS:
60
+ After you've set and export the above environment variables, run `source ~/.zprofile` (or source your respective shell dotfile).
107
61
 
108
- ```
109
- terraform init # IF NOT ALREADY RUN
110
- terraform apply
111
- ```
112
-
113
- **C. Set up web servers:**
114
62
 
115
- `cd terraform/[ENV]/web_servers`
63
+ ## Usage
116
64
 
117
- To deploy infrastructure to AWS:
65
+ #### Usage A: generate infrastructure rake task
118
66
 
119
67
  ```
120
- terraform init # IF NOT ALREADY RUN
121
- terraform apply
68
+ rake terra_boi:generate_infra
122
69
  ```
123
70
 
124
- While aws_acm_certificate_validation.cert is creating (it will hang if you don't add CNAME verification record in ACM):
125
-
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)
71
+ The above rake task will ask you some interactive questions, so stay close to your terminal!
131
72
 
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
73
+ Expected rake task duration: ~20 minutes (provisioning AWS infrastructure takes a while).
137
74
 
138
- **Note**: below usage steps should be completed in order
75
+ 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.
139
76
 
140
- ### Usage - Packer (creating web server AMIs)
77
+ 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.
141
78
 
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:**
79
+ #### Usage B: deploy application updates rake task
149
80
 
150
81
  ```
151
- cd packer
82
+ rake deploy
152
83
 
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
84
+ # Alternatively: rake "deploy[staging]", rake "deploy[staging prod]", etc.
154
85
  ```
155
86
 
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).
87
+ The above rake task will ask you an interactive question, so stay close to your terminal!
159
88
 
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).
89
+ Expected rake task duration: 5 - 10 minutes.
161
90
 
162
- ### Usage - Terraform (update web server AMIs)
91
+ 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.
163
92
 
164
- **A. Update Terraform web server AMIs:**
93
+ #### Usage C: recommendations
165
94
 
166
- `cd terraform/[ENV]/web_servers`
95
+ - Uncomment `config.force_ssl = true` in `config/environments/production.rb` file.
167
96
 
168
- To deploy infrastructure to AWS:
169
97
 
170
- ```
171
- terraform init # IF NOT ALREADY RUN
172
- terraform apply
173
- ```
98
+ ## Infrastructure customization
174
99
 
175
- ### Usage - ssh access
100
+ Because terra_boi uses Terraform modules, small customizations can be made by changing variables in .tf files.
176
101
 
177
- ssh into ec2 instance and run bash in container:
102
+ 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`.
178
103
 
179
- ```
180
- ssh ubuntu@PUBLICIPOFINSTANCE
104
+ **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.
181
105
 
182
- docker container exec -it APP_NAME bash
183
- ```
106
+ ## Appendix
184
107
 
108
+ #### Appendix - infrastructure / code generated by terra_boi
185
109
 
110
+ - AWS Elastic Container Registry (ECR)
111
+ - AWS Application Load Balancer (ALB)
112
+ - AWS Elastic Container Services (for your web app and worker)
113
+ - AWS Fargate tasks (for your web app and worker)
114
+ - AWS CloudWatch logging
115
+ - AWS Security Groups
116
+ - AWS DynamoDB for remote state locking
117
+ - AWS RDS Postgresql DBs
118
+ - Rails DB config file
119
+ - Rails data config file
120
+ - Rails initializer file (for setting up config.hosts)
121
+ - Dockerfile
122
+ - HTTPS / SSL certificate
186
123
 
187
- ## Infrastructure created
188
-
189
- The aforementioned generators create a `terraform` directory with `state`, `prod`, and `staging` subdirectories.
190
-
191
- The `state` directory contains an S3 bucket and a DynamoDB table to store and lock state (for both prod and staging).
192
-
193
- The `prod` and `staging` subdirectories contain `data` (DB + S3) and `web_servers` (SSL cert, load balancing, autoscaling, EC2) directories.
194
-
124
+ #### Appendix - destroying your infrastructure
195
125
 
126
+ To destroy infrastructure created by terra_boi, run `terraform destroy` in the following directories in the following order:
196
127
 
197
- ## Running tests
128
+ - terraform/ENV/head_worker
129
+ - terraform/ENV/web_app
130
+ - terraform/ENV/ecs_cluster
131
+ - terraform/ENV/data
132
+ - terraform/ecr
133
+ - terraform/cert
134
+ - terraform/state
198
135
 
199
- From the root directory:
136
+ OR
200
137
 
201
138
  ```
202
- rake test
139
+ rake terra_boi:destroy_infra
203
140
  ```
204
141
 
142
+ 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
143
 
144
+ #### Appendix - license
206
145
 
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)!
146
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
222
147
 
148
+ #### Appendix - contributing
223
149
 
150
+ 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
151
 
225
- ## License
152
+ Recommended contribution: terraform infrastructure generation testing
226
153
 
227
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
154
+ #### Appendix - other tips
228
155
 
156
+ **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
157
 
158
+ **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
159
 
231
- ## Updating gem version (for maintainers)
160
+ #### Appendix - updating gem version (for maintainers)
232
161
 
233
162
  **1. Update version**
234
163
 
@@ -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