terra_boi 0.0.15 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +83 -158
- data/lib/generators/extensions.rb +5 -5
- data/lib/generators/terra_boi/boilerplate_generator.rb +39 -32
- data/lib/generators/terra_boi/dockerfile_generator.rb +19 -18
- data/lib/generators/terra_boi/host_initializer_generator.rb +18 -18
- data/lib/generators/terra_boi/templates/Dockerfile.erb +4 -23
- data/lib/generators/terra_boi/templates/cert/main.tf.erb +32 -0
- data/lib/generators/terra_boi/templates/cert/var.tf.erb +15 -0
- data/lib/generators/terra_boi/templates/data_storage_config.erb +7 -7
- data/lib/generators/terra_boi/templates/ecr/ecs_role.tf.erb +41 -0
- data/lib/generators/terra_boi/templates/ecr/main.tf.erb +26 -0
- data/lib/generators/terra_boi/templates/ecr/output.tf.erb +11 -0
- data/lib/generators/terra_boi/templates/ecr/var.tf.erb +15 -0
- data/lib/generators/terra_boi/templates/{data_main.erb → env/data/main.tf.erb} +2 -2
- data/lib/generators/terra_boi/templates/{data_output.erb → env/data/output.tf.erb} +1 -1
- data/lib/generators/terra_boi/templates/env/ecs_cluster/ecs_cluster.tf.erb +24 -0
- data/lib/generators/terra_boi/templates/env/head_worker/ecs.tf.erb +55 -0
- data/lib/generators/terra_boi/templates/env/web_app/ecs.tf.erb +59 -0
- data/lib/generators/terra_boi/templates/lib/scripts/push_to_ecr.sh.erb +21 -0
- data/lib/generators/terra_boi/templates/lib/scripts/update_service_pull_from_ecr.sh.erb +18 -0
- data/lib/generators/terra_boi/templates/lib/task_templates/head_worker.json.erb +61 -0
- data/lib/generators/terra_boi/templates/lib/task_templates/web_app.json.erb +58 -0
- data/lib/generators/terra_boi/templates/lib/terraform_modules/ecs_cluster/main.tf.erb +12 -0
- data/lib/generators/terra_boi/templates/lib/terraform_modules/ecs_cluster/var.tf.erb +20 -0
- data/lib/generators/terra_boi/templates/lib/terraform_modules/ecs_web_app/ecs_role.tf.erb +7 -0
- data/lib/generators/terra_boi/templates/lib/terraform_modules/ecs_web_app/load_balancer.tf.erb +92 -0
- data/lib/generators/terra_boi/templates/lib/terraform_modules/ecs_web_app/main.tf.erb +134 -0
- data/lib/generators/terra_boi/templates/lib/terraform_modules/ecs_web_app/output.tf.erb +11 -0
- data/lib/generators/terra_boi/templates/lib/terraform_modules/ecs_web_app/var.tf.erb +63 -0
- data/lib/generators/terra_boi/templates/lib/terraform_modules/ecs_worker/ecs_role.tf.erb +7 -0
- data/lib/generators/terra_boi/templates/lib/terraform_modules/ecs_worker/main.tf.erb +120 -0
- data/lib/generators/terra_boi/templates/lib/terraform_modules/ecs_worker/output.tf.erb +7 -0
- data/lib/generators/terra_boi/templates/lib/terraform_modules/ecs_worker/var.tf.erb +57 -0
- data/lib/generators/terra_boi/tf_cert_generator.rb +28 -0
- data/lib/generators/terra_boi/tf_ecr_generator.rb +28 -0
- data/lib/generators/terra_boi/tf_env_generator.rb +54 -0
- data/lib/generators/terra_boi/tf_lib_generator.rb +57 -0
- data/lib/generators/terra_boi/tf_state_generator.rb +24 -0
- data/lib/tasks/terra_boi_tasks.rake +280 -4
- data/lib/terra_boi/railtie.rb +5 -2
- data/lib/terra_boi/version.rb +1 -1
- metadata +56 -28
- data/lib/generators/terra_boi/data_generator.rb +0 -38
- data/lib/generators/terra_boi/master_worker_generator.rb +0 -54
- data/lib/generators/terra_boi/packer_generator.rb +0 -26
- data/lib/generators/terra_boi/state_generator.rb +0 -25
- data/lib/generators/terra_boi/templates/master_worker_main.erb +0 -26
- data/lib/generators/terra_boi/templates/master_worker_output.erb +0 -14
- data/lib/generators/terra_boi/templates/master_worker_start_script.erb +0 -12
- data/lib/generators/terra_boi/templates/master_worker_user_data.erb +0 -27
- data/lib/generators/terra_boi/templates/packer_ami_build.erb +0 -27
- data/lib/generators/terra_boi/templates/packer_application.erb +0 -49
- data/lib/generators/terra_boi/templates/web_servers_main.erb +0 -31
- data/lib/generators/terra_boi/templates/web_servers_output.erb +0 -14
- data/lib/generators/terra_boi/templates/web_servers_user_data.erb +0 -29
- 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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c36dc0d2b46ebcc92f0b6ed5ef50266ba726528f7d5af498358242f25f9f3a2f
|
|
4
|
+
data.tar.gz: 2fecb45f6a00eb0d7b288c49c6a83b5a52723365057c89663375eca4a0aa85ca
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cbd2c30b16f582e5ac99384298e57e2c8125c762c644e55b7838c1edb37092a9216efc80cf5835cd5be82d2ac7aa16e7e4bfd3e6889ebbcd2472f467d00ffe13
|
|
7
|
+
data.tar.gz: 83b231de3fb16aa1a986437220b7a124313bb3a884e355255d885e8213438309de38ba2ff7cd8d682d78db79692562fe1d36d77fa074229ba90d24a1e56be22b
|
data/README.md
CHANGED
|
@@ -1,234 +1,159 @@
|
|
|
1
1
|
# TerraBoi
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## Introduction
|
|
4
4
|
|
|
5
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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/)
|
|
24
|
-
*
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
## Installation
|
|
28
|
-
|
|
29
|
-
**Note**: below installation steps should be completed in order.
|
|
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
|
|
30
18
|
|
|
31
|
-
|
|
19
|
+
#### Installation B: install ruby gems
|
|
32
20
|
|
|
33
|
-
Add
|
|
21
|
+
Add these lines to your (Rails) application's Gemfile:
|
|
34
22
|
|
|
35
23
|
```ruby
|
|
36
|
-
|
|
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
|
|
35
|
+
$ bundle && bundle exec wheneverize .
|
|
43
36
|
```
|
|
44
37
|
|
|
45
|
-
|
|
38
|
+
#### Installation C: set environment variables
|
|
46
39
|
|
|
47
|
-
Set
|
|
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:
|
|
40
|
+
Set and export terraform AWS and data-related environment variables in ~/.zprofile (or your respective shell dotfile e.g. ~/.bashrc)
|
|
49
41
|
|
|
50
42
|
```
|
|
51
|
-
|
|
52
|
-
|
|
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)
|
|
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
|
|
66
46
|
|
|
67
|
-
|
|
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
|
|
68
50
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
|
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
|
|
81
54
|
```
|
|
82
55
|
|
|
83
|
-
|
|
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`
|
|
56
|
+
After you've set and export the above environment variables, run `source ~/.zprofile` (or source your respective shell dotfile).
|
|
92
57
|
|
|
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
58
|
|
|
95
|
-
|
|
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
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
To deploy infrastructure to AWS:
|
|
107
|
-
|
|
108
|
-
```
|
|
109
|
-
terraform init # IF NOT ALREADY RUN
|
|
110
|
-
terraform apply
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
**C. Set up web servers:**
|
|
114
|
-
|
|
115
|
-
`cd terraform/[ENV]/web_servers`
|
|
59
|
+
## Usage
|
|
116
60
|
|
|
117
|
-
|
|
61
|
+
#### Usage A: generate infrastructure rake task
|
|
118
62
|
|
|
119
63
|
```
|
|
120
|
-
|
|
121
|
-
terraform apply
|
|
64
|
+
rake terra_boi:generate_infra
|
|
122
65
|
```
|
|
123
66
|
|
|
124
|
-
|
|
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)
|
|
67
|
+
The above rake task will ask you some interactive questions, so stay close to your terminal!
|
|
131
68
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
## Usage
|
|
69
|
+
Expected rake task duration: ~20 minutes (provisioning AWS infrastructure takes a while).
|
|
137
70
|
|
|
138
|
-
|
|
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.
|
|
139
72
|
|
|
140
|
-
|
|
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.
|
|
141
74
|
|
|
142
|
-
|
|
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
|
-
|
|
78
|
+
rake deploy
|
|
152
79
|
|
|
153
|
-
|
|
80
|
+
# Alternatively: rake "deploy[staging]", rake "deploy[staging prod]", etc.
|
|
154
81
|
```
|
|
155
82
|
|
|
156
|
-
|
|
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).
|
|
83
|
+
The above rake task will ask you an interactive question, so stay close to your terminal!
|
|
159
84
|
|
|
160
|
-
|
|
85
|
+
Expected rake task duration: 5 - 10 minutes.
|
|
161
86
|
|
|
162
|
-
|
|
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.
|
|
163
88
|
|
|
164
|
-
|
|
89
|
+
#### Usage C: recommendations
|
|
165
90
|
|
|
166
|
-
`
|
|
91
|
+
- Uncomment `config.force_ssl = true` in `config/environments/production.rb` file.
|
|
167
92
|
|
|
168
|
-
To deploy infrastructure to AWS:
|
|
169
93
|
|
|
170
|
-
|
|
171
|
-
terraform init # IF NOT ALREADY RUN
|
|
172
|
-
terraform apply
|
|
173
|
-
```
|
|
94
|
+
## Infrastructure customization
|
|
174
95
|
|
|
175
|
-
|
|
96
|
+
Because terra_boi uses Terraform modules, small customizations can be made by changing variables in .tf files.
|
|
176
97
|
|
|
177
|
-
|
|
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`.
|
|
178
99
|
|
|
179
|
-
|
|
180
|
-
ssh ubuntu@PUBLICIPOFINSTANCE
|
|
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.
|
|
181
101
|
|
|
182
|
-
|
|
183
|
-
```
|
|
102
|
+
## Appendix
|
|
184
103
|
|
|
104
|
+
#### Appendix - infrastructure / code generated by terra_boi
|
|
185
105
|
|
|
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
|
|
186
119
|
|
|
187
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
132
|
+
OR
|
|
200
133
|
|
|
201
134
|
```
|
|
202
|
-
rake
|
|
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
|
-
|
|
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
|
-
|
|
148
|
+
Recommended contribution: terraform infrastructure generation testing
|
|
226
149
|
|
|
227
|
-
|
|
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
|
-
|
|
156
|
+
#### Appendix - updating gem version (for maintainers)
|
|
232
157
|
|
|
233
158
|
**1. Update version**
|
|
234
159
|
|
|
@@ -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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
"
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
desc (<<-EOF
|
|
10
|
+
Generate Dockerfile for rails app
|
|
11
|
+
|
|
12
|
+
To execute, run rails generate terra_boi:dockerfile
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
Can pass in --ruby_version command line argument. Defaults to 2.5.1.
|
|
15
|
+
EOF
|
|
16
|
+
.gsub(/\t/, '')
|
|
17
|
+
)
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
def init
|
|
20
|
+
self.application_name = generate_application_name
|
|
21
|
+
self.class_options = options
|
|
22
|
+
end
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
def create_dockerfile
|
|
25
|
+
template "Dockerfile.erb", "Dockerfile"
|
|
26
|
+
template ".dockerignore.erb", ".dockerignore"
|
|
27
|
+
end
|
|
27
28
|
end
|
|
28
29
|
end
|