terra_boi 0.0.15 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +85 -156
- 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 +25 -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/templates/state_main.erb +3 -3
- 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 +274 -4
- data/lib/terra_boi/railtie.rb +5 -2
- data/lib/terra_boi/version.rb +1 -1
- metadata +65 -37
- 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: 343fd81eb86853318b6eeb8e67d2f810fccc8a6e713b1f53130bf1d9d5ac2ca4
|
4
|
+
data.tar.gz: a4bb5b81122c84b872b4639ee567d9eeb8972a6c68e7d7ddc819a439ffa666ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c70e52e3735f22cfd8e154d74bbb41defc70158d2deaf7a4d7250fe011d984ceb46fea5a1e46daa25363bbad0441d358bdd2dc2a86b959358186ff8a193f1ace
|
7
|
+
data.tar.gz: 6647dc338ce8a476930d1b9a53069e3f378b3048ba434a72d55daed693187be7c75e9748fce561d10f8aed9c1c07b629ff19cd1b11cb82e3b1ec8813e4a771f0
|
data/README.md
CHANGED
@@ -1,234 +1,163 @@
|
|
1
1
|
# TerraBoi
|
2
2
|
|
3
|
-
|
3
|
+
## Introduction
|
4
4
|
|
5
|
-
|
5
|
+
Deploy your rails application to AWS with `rake deploy`.
|
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)
|
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
|
-
|
9
|
+
It is free to use.
|
14
10
|
|
15
|
-
|
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
|
-
|
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/)
|
24
|
-
*
|
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
|
25
22
|
|
23
|
+
#### Installation B: install ruby gems
|
26
24
|
|
27
|
-
|
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
|
-
|
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
|
-
|
42
|
+
#### Installation C: set environment variables
|
46
43
|
|
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:
|
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
|
-
|
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)
|
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).
|
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
|
70
50
|
|
71
|
-
|
72
|
-
|
73
|
-
|
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):
|
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
|
76
54
|
|
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
|
77
58
|
```
|
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
59
|
|
93
|
-
|
60
|
+
After you've set and export the above environment variables, run `source ~/.zprofile` (or source your respective shell dotfile).
|
94
61
|
|
95
|
-
**B. Set up DB / S3:**
|
96
62
|
|
97
|
-
|
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`
|
63
|
+
## Usage
|
116
64
|
|
117
|
-
|
65
|
+
#### Usage A: generate infrastructure rake task
|
118
66
|
|
119
67
|
```
|
120
|
-
|
121
|
-
terraform apply
|
68
|
+
rake terra_boi:generate_infra
|
122
69
|
```
|
123
70
|
|
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)
|
131
|
-
|
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
|
137
|
-
|
138
|
-
**Note**: below usage steps should be completed in order
|
71
|
+
The above rake task will ask you some interactive questions, so stay close to your terminal!
|
139
72
|
|
140
|
-
|
73
|
+
Expected rake task duration: ~20 minutes (provisioning AWS infrastructure takes a while).
|
141
74
|
|
142
|
-
|
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.
|
143
76
|
|
144
|
-
|
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.
|
145
78
|
|
146
|
-
|
147
|
-
|
148
|
-
**B. Create Packer AMI:**
|
79
|
+
#### Usage B: deploy application updates rake task
|
149
80
|
|
150
81
|
```
|
151
|
-
|
82
|
+
rake deploy
|
152
83
|
|
153
|
-
|
84
|
+
# Alternatively: rake "deploy[staging]", rake "deploy[staging prod]", etc.
|
154
85
|
```
|
155
86
|
|
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).
|
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:**
|
165
|
-
|
166
|
-
`cd terraform/[ENV]/web_servers`
|
87
|
+
The above rake task will ask you an interactive question, so stay close to your terminal!
|
167
88
|
|
168
|
-
|
89
|
+
Expected rake task duration: 5 - 10 minutes.
|
169
90
|
|
170
|
-
|
171
|
-
terraform init # IF NOT ALREADY RUN
|
172
|
-
terraform apply
|
173
|
-
```
|
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.
|
174
92
|
|
175
|
-
|
93
|
+
#### Usage C: recommendations
|
176
94
|
|
177
|
-
|
95
|
+
- Uncomment `config.force_ssl = true` in `config/environments/production.rb` file.
|
178
96
|
|
179
|
-
```
|
180
|
-
ssh ubuntu@PUBLICIPOFINSTANCE
|
181
97
|
|
182
|
-
|
183
|
-
```
|
98
|
+
## Infrastructure customization
|
184
99
|
|
100
|
+
Because terra_boi uses Terraform modules, small customizations can be made by changing variables in .tf files.
|
185
101
|
|
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`.
|
186
103
|
|
187
|
-
|
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.
|
188
105
|
|
189
|
-
|
106
|
+
## Appendix
|
190
107
|
|
191
|
-
|
108
|
+
#### Appendix - infrastructure / code generated by terra_boi
|
192
109
|
|
193
|
-
|
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
|
194
123
|
|
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
|
-
|
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
|
-
|
136
|
+
OR
|
200
137
|
|
201
138
|
```
|
202
|
-
rake
|
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
|
-
|
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
|
-
|
152
|
+
Recommended contribution: terraform infrastructure generation testing
|
226
153
|
|
227
|
-
|
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
|
-
|
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
|
-
|
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
|