rails_template_18f 0.1.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +4 -1
- data/README.md +16 -19
- data/exe/rails_template_18f +60 -0
- data/lib/generators/rails_template18f/active_storage/active_storage_generator.rb +135 -0
- data/lib/generators/rails_template18f/active_storage/templates/app/jobs/file_scan_job.rb +33 -0
- data/lib/generators/rails_template18f/active_storage/templates/app/models/file_upload.rb +25 -0
- data/lib/generators/rails_template18f/active_storage/templates/doc/adr/clamav.md.tt +30 -0
- data/lib/generators/rails_template18f/active_storage/templates/spec/jobs/file_scan_job_spec.rb +35 -0
- data/lib/generators/rails_template18f/active_storage/templates/spec/models/file_upload_spec.rb +38 -0
- data/lib/generators/rails_template18f/circleci/circleci_generator.rb +26 -10
- data/lib/generators/rails_template18f/cloud_gov_config/cloud_gov_config_generator.rb +28 -0
- data/lib/generators/rails_template18f/cloud_gov_config/templates/app/models/cloud_gov_config.rb +15 -0
- data/lib/generators/rails_template18f/cloud_gov_config/templates/spec/models/cloud_gov_config_spec.rb +44 -0
- data/lib/generators/rails_template18f/dap/dap_generator.rb +72 -0
- data/lib/generators/rails_template18f/github_actions/github_actions_generator.rb +27 -11
- data/lib/generators/rails_template18f/i18n/i18n_generator.rb +107 -0
- data/{templates → lib/generators/rails_template18f/i18n/templates}/config/locales/en.yml.tt +3 -3
- data/{templates → lib/generators/rails_template18f/i18n/templates}/config/locales/es.yml +3 -3
- data/{templates → lib/generators/rails_template18f/i18n/templates}/config/locales/fr.yml +3 -6
- data/{templates → lib/generators/rails_template18f/i18n/templates}/config/locales/zh.yml +0 -0
- data/lib/generators/rails_template18f/i18n_js/i18n_js_generator.rb +60 -0
- data/lib/generators/rails_template18f/i18n_js/templates/lib/tasks/i18n.rake +9 -0
- data/lib/generators/rails_template18f/newrelic/newrelic_generator.rb +79 -0
- data/{templates/config/newrelic.yml → lib/generators/rails_template18f/newrelic/templates/config/newrelic.yml.tt} +7 -7
- data/lib/generators/rails_template18f/sidekiq/sidekiq_generator.rb +70 -0
- data/lib/generators/rails_template18f/sidekiq/templates/config/initializers/redis.rb +14 -0
- data/{templates → lib/generators/rails_template18f/terraform/templates}/terraform/README.md.tt +0 -0
- data/{templates → lib/generators/rails_template18f/terraform/templates}/terraform/bootstrap/import.sh +0 -0
- data/{templates → lib/generators/rails_template18f/terraform/templates}/terraform/bootstrap/main.tf.tt +3 -3
- data/{templates → lib/generators/rails_template18f/terraform/templates}/terraform/bootstrap/providers.tf +0 -0
- data/{templates → lib/generators/rails_template18f/terraform/templates}/terraform/bootstrap/run.sh.tt +1 -1
- data/lib/generators/rails_template18f/terraform/templates/terraform/bootstrap/teardown_creds.sh.tt +5 -0
- data/{templates → lib/generators/rails_template18f/terraform/templates}/terraform/bootstrap/variables.tf +0 -0
- data/{templates → lib/generators/rails_template18f/terraform/templates}/terraform/create_space_deployer.sh +0 -0
- data/{templates → lib/generators/rails_template18f/terraform/templates}/terraform/destroy_space_deployer.sh +0 -0
- data/lib/generators/rails_template18f/terraform/templates/terraform/production/main.tf.tt +82 -0
- data/{templates → lib/generators/rails_template18f/terraform/templates}/terraform/production/providers.tf.tt +0 -0
- data/{templates → lib/generators/rails_template18f/terraform/templates}/terraform/production/variables.tf +0 -0
- data/lib/generators/rails_template18f/terraform/templates/terraform/shared/clamav/main.tf.tt +50 -0
- data/{templates/terraform/shared/database → lib/generators/rails_template18f/terraform/templates/terraform/shared/clamav}/providers.tf +0 -0
- data/lib/generators/rails_template18f/terraform/templates/terraform/shared/clamav/variables.tf +47 -0
- data/{templates → lib/generators/rails_template18f/terraform/templates}/terraform/shared/database/main.tf.tt +0 -0
- data/{templates/terraform/shared/domain → lib/generators/rails_template18f/terraform/templates/terraform/shared/database}/providers.tf +0 -0
- data/{templates → lib/generators/rails_template18f/terraform/templates}/terraform/shared/database/variables.tf +0 -0
- data/{templates → lib/generators/rails_template18f/terraform/templates}/terraform/shared/domain/main.tf.tt +1 -1
- data/{templates/terraform/shared/s3 → lib/generators/rails_template18f/terraform/templates/terraform/shared/domain}/providers.tf +0 -0
- data/{templates → lib/generators/rails_template18f/terraform/templates}/terraform/shared/domain/variables.tf +0 -0
- data/lib/generators/rails_template18f/terraform/templates/terraform/shared/redis/main.tf.tt +23 -0
- data/lib/generators/rails_template18f/terraform/templates/terraform/shared/redis/providers.tf +16 -0
- data/lib/generators/rails_template18f/terraform/templates/terraform/shared/redis/variables.tf +42 -0
- data/{templates → lib/generators/rails_template18f/terraform/templates}/terraform/shared/s3/main.tf +0 -0
- data/lib/generators/rails_template18f/terraform/templates/terraform/shared/s3/providers.tf +16 -0
- data/{templates → lib/generators/rails_template18f/terraform/templates}/terraform/shared/s3/variables.tf +0 -0
- data/lib/generators/rails_template18f/terraform/templates/terraform/staging/main.tf.tt +62 -0
- data/{templates → lib/generators/rails_template18f/terraform/templates}/terraform/staging/providers.tf.tt +0 -0
- data/{templates → lib/generators/rails_template18f/terraform/templates}/terraform/staging/variables.tf +0 -0
- data/lib/generators/rails_template18f/terraform/terraform_generator.rb +84 -0
- data/lib/rails_template18f/app_updater.rb +19 -0
- data/lib/rails_template18f/generators/base.rb +53 -0
- data/lib/rails_template18f/generators/cloud_gov_options.rb +53 -0
- data/lib/rails_template18f/generators/pipeline_options.rb +18 -0
- data/lib/rails_template18f/generators.rb +11 -0
- data/lib/rails_template18f/version.rb +1 -1
- data/lib/rails_template_18f.rb +1 -4
- data/rails-template-18f.gemspec +1 -0
- data/template.rb +84 -148
- data/templates/README.md.tt +7 -44
- data/templates/config/deployment/staging.yml +1 -1
- data/templates/config/environments/ci.rb +0 -1
- data/templates/doc/compliance/apps/application.boundary.md.tt +4 -31
- data/templates/githooks/{pre-commit.tt → pre-commit} +0 -15
- data/templates/manifest.yml.tt +1 -2
- metadata +77 -34
- data/lib/rails_template18f/terraform_options.rb +0 -68
- data/templates/terraform/bootstrap/teardown_creds.sh.tt +0 -5
- data/templates/terraform/production/main.tf.tt +0 -50
- data/templates/terraform/staging/main.tf.tt +0 -30
File without changes
|
File without changes
|
@@ -0,0 +1,82 @@
|
|
1
|
+
locals {
|
2
|
+
cf_org_name = "<%= cloud_gov_organization %>"
|
3
|
+
cf_space_name = "<%= cloud_gov_production_space %>"
|
4
|
+
env = "production"
|
5
|
+
recursive_delete = false
|
6
|
+
}
|
7
|
+
|
8
|
+
module "database" {
|
9
|
+
source = "../shared/database"
|
10
|
+
|
11
|
+
cf_user = var.cf_user
|
12
|
+
cf_password = var.cf_password
|
13
|
+
cf_org_name = local.cf_org_name
|
14
|
+
cf_space_name = local.cf_space_name
|
15
|
+
env = local.env
|
16
|
+
recursive_delete = local.recursive_delete
|
17
|
+
rds_plan_name = "TKTK-production-rds-plan"
|
18
|
+
}
|
19
|
+
<% if has_active_job? %>
|
20
|
+
module "redis" {
|
21
|
+
source = "../shared/redis"
|
22
|
+
|
23
|
+
cf_user = var.cf_user
|
24
|
+
cf_password = var.cf_password
|
25
|
+
cf_org_name = local.cf_org_name
|
26
|
+
cf_space_name = local.cf_space_name
|
27
|
+
env = local.env
|
28
|
+
recursive_delete = local.recursive_delete
|
29
|
+
redis_plan_name = "TKTK-production-redis-plan"
|
30
|
+
}
|
31
|
+
<% end %>
|
32
|
+
<% if has_active_storage? %>
|
33
|
+
module "s3" {
|
34
|
+
source = "../shared/s3"
|
35
|
+
|
36
|
+
cf_user = var.cf_user
|
37
|
+
cf_password = var.cf_password
|
38
|
+
cf_org_name = local.cf_org_name
|
39
|
+
cf_space_name = local.cf_space_name
|
40
|
+
recursive_delete = local.recursive_delete
|
41
|
+
s3_service_name = "<%= app_name %>-s3-${local.env}"<% if cloud_gov_organization == "sandbox-gsa" %>
|
42
|
+
s3_plan_name = "basic-sandbox"<% end %>
|
43
|
+
}
|
44
|
+
|
45
|
+
###########################################################################
|
46
|
+
# The following lines need to be commented out for the initial `terraform apply`
|
47
|
+
# It can be re-enabled after:
|
48
|
+
# 1) the app has first been deployed
|
49
|
+
# 2) Your organization has sufficient memory. Each clamav app requires 3GB
|
50
|
+
###########################################################################
|
51
|
+
# module "clamav" {
|
52
|
+
# source = "../shared/clamav"
|
53
|
+
#
|
54
|
+
# cf_user = var.cf_user
|
55
|
+
# cf_password = var.cf_password
|
56
|
+
# cf_org_name = local.cf_org_name
|
57
|
+
# cf_space_name = local.cf_space_name
|
58
|
+
# env = local.env
|
59
|
+
# clamav_image = "ajilaag/clamav-rest:20211229"
|
60
|
+
# max_file_size = "30M"
|
61
|
+
# }
|
62
|
+
<% end %>
|
63
|
+
|
64
|
+
###########################################################################
|
65
|
+
# The following lines need to be commented out for the initial `terraform apply`
|
66
|
+
# It can be re-enabled after:
|
67
|
+
# 1) the app has first been deployed
|
68
|
+
# 2) the route has been manually created by an OrgManager:
|
69
|
+
# `cf create-domain <%= cloud_gov_organization %> TKTK-production-domain-name`
|
70
|
+
###########################################################################
|
71
|
+
# module "domain" {
|
72
|
+
# source = "../shared/domain"
|
73
|
+
#
|
74
|
+
# cf_user = var.cf_user
|
75
|
+
# cf_password = var.cf_password
|
76
|
+
# cf_org_name = local.cf_org_name
|
77
|
+
# cf_space_name = local.cf_space_name
|
78
|
+
# env = local.env
|
79
|
+
# recursive_delete = local.recursive_delete
|
80
|
+
# cdn_plan_name = "domain"
|
81
|
+
# domain_name = "TKTK-production-domain-name"
|
82
|
+
# }
|
File without changes
|
File without changes
|
@@ -0,0 +1,50 @@
|
|
1
|
+
###
|
2
|
+
# Target space/org
|
3
|
+
###
|
4
|
+
|
5
|
+
data "cloudfoundry_space" "space" {
|
6
|
+
org_name = var.cf_org_name
|
7
|
+
name = var.cf_space_name
|
8
|
+
}
|
9
|
+
|
10
|
+
data "cloudfoundry_domain" "internal" {
|
11
|
+
name = "apps.internal"
|
12
|
+
}
|
13
|
+
|
14
|
+
data "cloudfoundry_app" "app" {
|
15
|
+
name_or_id = "<%= app_name %>-${var.env}"
|
16
|
+
space = data.cloudfoundry_space.space.id
|
17
|
+
}
|
18
|
+
|
19
|
+
###
|
20
|
+
# ClamAV API app
|
21
|
+
###
|
22
|
+
|
23
|
+
resource "cloudfoundry_route" "clamav_route" {
|
24
|
+
space = data.cloudfoundry_space.space.id
|
25
|
+
domain = data.cloudfoundry_domain.internal.id
|
26
|
+
hostname = "<%= app_name %>-clamapi-${var.env}"
|
27
|
+
}
|
28
|
+
|
29
|
+
resource "cloudfoundry_app" "clamav_api" {
|
30
|
+
name = "<%= app_name %>-clamav-api-${var.env}"
|
31
|
+
space = data.cloudfoundry_space.space.id
|
32
|
+
memory = var.clamav_memory
|
33
|
+
disk_quota = 2048
|
34
|
+
timeout = 600
|
35
|
+
docker_image = var.clamav_image
|
36
|
+
routes {
|
37
|
+
route = cloudfoundry_route.clamav_route.id
|
38
|
+
}
|
39
|
+
environment = {
|
40
|
+
MAX_FILE_SIZE = var.max_file_size
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
resource "cloudfoundry_network_policy" "clamav_routing" {
|
45
|
+
policy {
|
46
|
+
source_app = data.cloudfoundry_app.app.id
|
47
|
+
destination_app = cloudfoundry_app.clamav_api.id
|
48
|
+
port = "9443"
|
49
|
+
}
|
50
|
+
}
|
File without changes
|
data/lib/generators/rails_template18f/terraform/templates/terraform/shared/clamav/variables.tf
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
variable "cf_api_url" {
|
2
|
+
type = string
|
3
|
+
description = "cloud.gov api url"
|
4
|
+
default = "https://api.fr.cloud.gov"
|
5
|
+
}
|
6
|
+
|
7
|
+
variable "cf_user" {
|
8
|
+
type = string
|
9
|
+
description = "cloud.gov deployer account user"
|
10
|
+
}
|
11
|
+
|
12
|
+
variable "cf_password" {
|
13
|
+
type = string
|
14
|
+
description = "secret; cloud.gov deployer account password"
|
15
|
+
sensitive = true
|
16
|
+
}
|
17
|
+
|
18
|
+
variable "cf_org_name" {
|
19
|
+
type = string
|
20
|
+
description = "cloud.gov organization name"
|
21
|
+
}
|
22
|
+
|
23
|
+
variable "cf_space_name" {
|
24
|
+
type = string
|
25
|
+
description = "cloud.gov space name (staging or prod)"
|
26
|
+
}
|
27
|
+
|
28
|
+
variable "env" {
|
29
|
+
type = string
|
30
|
+
description = "deployment environment (staging, production)"
|
31
|
+
}
|
32
|
+
|
33
|
+
variable "clamav_image" {
|
34
|
+
type = string
|
35
|
+
description = "Docker image to deploy the clamav api app"
|
36
|
+
}
|
37
|
+
|
38
|
+
variable "clamav_memory" {
|
39
|
+
type = number
|
40
|
+
description = "Memory in MB to allocate to clamav app"
|
41
|
+
default = 3072
|
42
|
+
}
|
43
|
+
|
44
|
+
variable "max_file_size" {
|
45
|
+
type = string
|
46
|
+
description = "Maximum file size the API will accept for scanning"
|
47
|
+
}
|
File without changes
|
File without changes
|
File without changes
|
@@ -19,7 +19,7 @@ data "cloudfoundry_app" "app" {
|
|
19
19
|
###########################################################################
|
20
20
|
# Route must be manually created by an OrgManager before terraform is run:
|
21
21
|
#
|
22
|
-
# cf create-domain <%=
|
22
|
+
# cf create-domain <%= cloud_gov_organization %> TKTK-production-domain-name
|
23
23
|
###########################################################################
|
24
24
|
data "cloudfoundry_domain" "origin_url" {
|
25
25
|
name = var.domain_name
|
File without changes
|
File without changes
|
@@ -0,0 +1,23 @@
|
|
1
|
+
###
|
2
|
+
# Target space/org
|
3
|
+
###
|
4
|
+
|
5
|
+
data "cloudfoundry_space" "space" {
|
6
|
+
org_name = var.cf_org_name
|
7
|
+
name = var.cf_space_name
|
8
|
+
}
|
9
|
+
|
10
|
+
###
|
11
|
+
# RDS instance
|
12
|
+
###
|
13
|
+
|
14
|
+
data "cloudfoundry_service" "redis" {
|
15
|
+
name = "aws-elasticache-redis"
|
16
|
+
}
|
17
|
+
|
18
|
+
resource "cloudfoundry_service_instance" "redis" {
|
19
|
+
name = "<%= app_name %>-redis-${var.env}"
|
20
|
+
space = data.cloudfoundry_space.space.id
|
21
|
+
service_plan = data.cloudfoundry_service.redis.service_plans[var.redis_plan_name]
|
22
|
+
recursive_delete = var.recursive_delete
|
23
|
+
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
terraform {
|
2
|
+
required_version = "~> 1.0"
|
3
|
+
required_providers {
|
4
|
+
cloudfoundry = {
|
5
|
+
source = "cloudfoundry-community/cloudfoundry"
|
6
|
+
version = "0.15.0"
|
7
|
+
}
|
8
|
+
}
|
9
|
+
}
|
10
|
+
|
11
|
+
provider "cloudfoundry" {
|
12
|
+
api_url = var.cf_api_url
|
13
|
+
user = var.cf_user
|
14
|
+
password = var.cf_password
|
15
|
+
app_logs_max = 30
|
16
|
+
}
|
@@ -0,0 +1,42 @@
|
|
1
|
+
variable "cf_api_url" {
|
2
|
+
type = string
|
3
|
+
description = "cloud.gov api url"
|
4
|
+
default = "https://api.fr.cloud.gov"
|
5
|
+
}
|
6
|
+
|
7
|
+
variable "cf_user" {
|
8
|
+
type = string
|
9
|
+
description = "cloud.gov deployer account user"
|
10
|
+
}
|
11
|
+
|
12
|
+
variable "cf_password" {
|
13
|
+
type = string
|
14
|
+
description = "secret; cloud.gov deployer account password"
|
15
|
+
sensitive = true
|
16
|
+
}
|
17
|
+
|
18
|
+
variable "cf_org_name" {
|
19
|
+
type = string
|
20
|
+
description = "cloud.gov organization name"
|
21
|
+
}
|
22
|
+
|
23
|
+
variable "cf_space_name" {
|
24
|
+
type = string
|
25
|
+
description = "cloud.gov space name (staging or prod)"
|
26
|
+
}
|
27
|
+
|
28
|
+
variable "env" {
|
29
|
+
type = string
|
30
|
+
description = "deployment environment (staging, production)"
|
31
|
+
}
|
32
|
+
|
33
|
+
variable "recursive_delete" {
|
34
|
+
type = bool
|
35
|
+
description = "when true, deletes service bindings attached to the resource (not recommended for production)"
|
36
|
+
default = false
|
37
|
+
}
|
38
|
+
|
39
|
+
variable "redis_plan_name" {
|
40
|
+
type = string
|
41
|
+
description = "name of the service plan name to create"
|
42
|
+
}
|
data/{templates → lib/generators/rails_template18f/terraform/templates}/terraform/shared/s3/main.tf
RENAMED
File without changes
|
@@ -0,0 +1,16 @@
|
|
1
|
+
terraform {
|
2
|
+
required_version = "~> 1.0"
|
3
|
+
required_providers {
|
4
|
+
cloudfoundry = {
|
5
|
+
source = "cloudfoundry-community/cloudfoundry"
|
6
|
+
version = "0.15.0"
|
7
|
+
}
|
8
|
+
}
|
9
|
+
}
|
10
|
+
|
11
|
+
provider "cloudfoundry" {
|
12
|
+
api_url = var.cf_api_url
|
13
|
+
user = var.cf_user
|
14
|
+
password = var.cf_password
|
15
|
+
app_logs_max = 30
|
16
|
+
}
|
File without changes
|
@@ -0,0 +1,62 @@
|
|
1
|
+
locals {
|
2
|
+
cf_org_name = "<%= cloud_gov_organization %>"
|
3
|
+
cf_space_name = "<%= cloud_gov_staging_space %>"
|
4
|
+
env = "staging"
|
5
|
+
recursive_delete = true
|
6
|
+
}
|
7
|
+
|
8
|
+
module "database" {
|
9
|
+
source = "../shared/database"
|
10
|
+
|
11
|
+
cf_user = var.cf_user
|
12
|
+
cf_password = var.cf_password
|
13
|
+
cf_org_name = local.cf_org_name
|
14
|
+
cf_space_name = local.cf_space_name
|
15
|
+
env = local.env
|
16
|
+
recursive_delete = local.recursive_delete
|
17
|
+
rds_plan_name = "micro-psql"
|
18
|
+
}
|
19
|
+
<% if has_active_job? %>
|
20
|
+
module "redis" {
|
21
|
+
source = "../shared/redis"
|
22
|
+
|
23
|
+
cf_user = var.cf_user
|
24
|
+
cf_password = var.cf_password
|
25
|
+
cf_org_name = local.cf_org_name
|
26
|
+
cf_space_name = local.cf_space_name
|
27
|
+
env = local.env
|
28
|
+
recursive_delete = local.recursive_delete
|
29
|
+
redis_plan_name = "redis-dev"
|
30
|
+
}
|
31
|
+
<% end %>
|
32
|
+
<% if has_active_storage? %>
|
33
|
+
module "s3" {
|
34
|
+
source = "../shared/s3"
|
35
|
+
|
36
|
+
cf_user = var.cf_user
|
37
|
+
cf_password = var.cf_password
|
38
|
+
cf_org_name = local.cf_org_name
|
39
|
+
cf_space_name = local.cf_space_name
|
40
|
+
recursive_delete = local.recursive_delete
|
41
|
+
s3_service_name = "<%= app_name %>-s3-${local.env}"<% if cloud_gov_organization == "sandbox-gsa" %>
|
42
|
+
s3_plan_name = "basic-sandbox"<% end %>
|
43
|
+
}
|
44
|
+
|
45
|
+
###########################################################################
|
46
|
+
# The following lines need to be commented out for the initial `terraform apply`
|
47
|
+
# It can be re-enabled after:
|
48
|
+
# 1) the app has first been deployed
|
49
|
+
# 2) Your organization has sufficient memory. Each clamav app requires 3GB
|
50
|
+
###########################################################################
|
51
|
+
# module "clamav" {
|
52
|
+
# source = "../shared/clamav"
|
53
|
+
#
|
54
|
+
# cf_user = var.cf_user
|
55
|
+
# cf_password = var.cf_password
|
56
|
+
# cf_org_name = local.cf_org_name
|
57
|
+
# cf_space_name = local.cf_space_name
|
58
|
+
# env = local.env
|
59
|
+
# clamav_image = "ajilaag/clamav-rest:20211229"
|
60
|
+
# max_file_size = "30M"
|
61
|
+
# }
|
62
|
+
<% end %>
|
File without changes
|
File without changes
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rails/generators"
|
4
|
+
|
5
|
+
module RailsTemplate18f
|
6
|
+
module Generators
|
7
|
+
class TerraformGenerator < ::Rails::Generators::Base
|
8
|
+
include Base
|
9
|
+
include CloudGovOptions
|
10
|
+
|
11
|
+
desc <<~DESC
|
12
|
+
Description:
|
13
|
+
Install terraform files for cloud.gov database and s3 services
|
14
|
+
DESC
|
15
|
+
|
16
|
+
def install
|
17
|
+
directory "terraform", mode: :preserve
|
18
|
+
chmod "terraform/bootstrap/run.sh", 0o755
|
19
|
+
chmod "terraform/bootstrap/teardown_creds.sh", 0o755
|
20
|
+
end
|
21
|
+
|
22
|
+
def ignore_files
|
23
|
+
unless skip_git?
|
24
|
+
append_to_file ".gitignore", <<~EOM
|
25
|
+
|
26
|
+
# Terraform
|
27
|
+
.terraform.lock.hcl
|
28
|
+
**/.terraform/*
|
29
|
+
secrets.auto.tfvars
|
30
|
+
terraform.tfstate
|
31
|
+
terraform.tfstate.backup
|
32
|
+
EOM
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def update_readme
|
37
|
+
gsub_file "README.md", /^(### Automatic linting)/, '\1 and terraform formatting'
|
38
|
+
gsub_file "README.md", /(ruby linting) (on every)/, '\1 and terraform formatting \2'
|
39
|
+
gsub_file "README.md", /^Before the first deploy only.*$/, "Follow the instructions in `terraform/README.md` to create the supporting services."
|
40
|
+
end
|
41
|
+
|
42
|
+
def install_githook
|
43
|
+
githook_file = ".githooks/pre-commit"
|
44
|
+
if File.exist?(File.expand_path(githook_file, destination_root))
|
45
|
+
append_to_file githook_file, "\n#{githook_content}"
|
46
|
+
else
|
47
|
+
create_file githook_file, <<~EOM
|
48
|
+
#! /usr/bin/env bash
|
49
|
+
#
|
50
|
+
# This hook runs on `git commit` and will prevent you from committing without
|
51
|
+
# approval from the linter and tests.
|
52
|
+
#
|
53
|
+
# To run, this file must be symlinked to:
|
54
|
+
# .git/hooks/pre-commit
|
55
|
+
#
|
56
|
+
# To bypass this hook, run:
|
57
|
+
# $ git commit --no-verify
|
58
|
+
# $ git commit -n
|
59
|
+
|
60
|
+
#{githook_content}
|
61
|
+
EOM
|
62
|
+
chmod githook_file, 0o755
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
no_tasks do
|
67
|
+
def githook_content
|
68
|
+
<<~EOM
|
69
|
+
echo "Running Terraform formatter"
|
70
|
+
files=$(git diff --cached --name-only terraform)
|
71
|
+
for f in $files
|
72
|
+
do
|
73
|
+
# Format any *.tf files that were cached/staged
|
74
|
+
if [ -e "$f" ] && [[ $f == *.tf ]]; then
|
75
|
+
terraform fmt "$f"
|
76
|
+
git add "$f"
|
77
|
+
fi
|
78
|
+
done
|
79
|
+
EOM
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "rails/app_updater"
|
2
|
+
|
3
|
+
module AppUpdaterOptions
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
class_methods do
|
7
|
+
def generator_options
|
8
|
+
options = super
|
9
|
+
# These options all end up hardcoded to true in the default `rails app:update`
|
10
|
+
options[:skip_active_job] = !defined?(ActiveJob::Railtie)
|
11
|
+
options[:skip_action_mailbox] = !defined?(ActionMailbox::Engine)
|
12
|
+
options[:skip_action_text] = !defined?(ActionText::Engine)
|
13
|
+
options[:skip_test] = !defined?(Rails::TestUnitRailtie)
|
14
|
+
options
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
Rails::AppUpdater.prepend(AppUpdaterOptions)
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RailsTemplate18f
|
4
|
+
module Generators
|
5
|
+
module Base
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
include ::Rails::Generators::AppName
|
8
|
+
|
9
|
+
class_methods do
|
10
|
+
attr_accessor :source_path
|
11
|
+
|
12
|
+
def source_root
|
13
|
+
@source_root ||= File.expand_path("templates", File.dirname(source_path))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
included do
|
18
|
+
self.source_path = RailsTemplate18f::Generators.const_source_location(name).first
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def file_content(filename)
|
24
|
+
file_path = File.expand_path(filename, destination_root)
|
25
|
+
if File.exist? file_path
|
26
|
+
File.read(file_path)
|
27
|
+
else
|
28
|
+
""
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def ruby_version
|
33
|
+
RUBY_VERSION
|
34
|
+
end
|
35
|
+
|
36
|
+
def terraform_dir_exists?
|
37
|
+
Dir.exist? File.expand_path("terraform", destination_root)
|
38
|
+
end
|
39
|
+
|
40
|
+
def skip_git?
|
41
|
+
!Dir.exist?(File.expand_path(".git", destination_root))
|
42
|
+
end
|
43
|
+
|
44
|
+
def has_active_job?
|
45
|
+
defined?(::ActiveJob)
|
46
|
+
end
|
47
|
+
|
48
|
+
def has_active_storage?
|
49
|
+
defined?(::ActiveStorage)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RailsTemplate18f
|
4
|
+
module Generators
|
5
|
+
module CloudGovOptions
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
class_option :cg_org, desc: "cloud.gov organization name"
|
10
|
+
class_option :cg_staging, desc: "cloud.gov space name for staging"
|
11
|
+
class_option :cg_prod, desc: "cloud.gov space name for production"
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def cloud_gov_organization
|
17
|
+
if options[:cg_org].present?
|
18
|
+
return options[:cg_org]
|
19
|
+
elsif terraform_dir_exists?
|
20
|
+
staging_main = file_content("terraform/staging/main.tf")
|
21
|
+
if (matches = staging_main.match(/cf_org_name\s+= "(?<org_name>.*)"/))
|
22
|
+
return matches[:org_name]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
"TKTK-cloud.gov-org-name"
|
26
|
+
end
|
27
|
+
|
28
|
+
def cloud_gov_staging_space
|
29
|
+
if options[:cg_staging].present?
|
30
|
+
return options[:cg_staging]
|
31
|
+
elsif terraform_dir_exists?
|
32
|
+
staging_main = file_content("terraform/staging/main.tf")
|
33
|
+
if (matches = staging_main.match(/cf_space_name\s+= "(?<space_name>.*)"/))
|
34
|
+
return matches[:space_name]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
"staging"
|
38
|
+
end
|
39
|
+
|
40
|
+
def cloud_gov_production_space
|
41
|
+
if options[:cg_prod].present?
|
42
|
+
return options[:cg_prod]
|
43
|
+
elsif terraform_dir_exists?
|
44
|
+
prod_main = file_content("terraform/production/main.tf")
|
45
|
+
if (matches = prod_main.match(/cf_space_name\s+= "(?<space_name>.*)"/))
|
46
|
+
return matches[:space_name]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
"prod"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RailsTemplate18f
|
4
|
+
module Generators
|
5
|
+
module PipelineOptions
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
include CloudGovOptions
|
8
|
+
|
9
|
+
included do
|
10
|
+
class_option :terraform, type: :boolean, desc: "Generate actions for planning and applying terraform"
|
11
|
+
end
|
12
|
+
|
13
|
+
def terraform?
|
14
|
+
options[:terraform].nil? ? terraform_dir_exists? : options[:terraform]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/rails_template_18f.rb
CHANGED
@@ -1,12 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative "rails_template18f/version"
|
4
|
+
require_relative "rails_template18f/generators"
|
4
5
|
|
5
6
|
module RailsTemplate18f
|
6
|
-
extend ActiveSupport::Autoload
|
7
|
-
|
8
|
-
autoload :TerraformOptions
|
9
|
-
|
10
7
|
class Error < StandardError; end
|
11
8
|
|
12
9
|
class Railtie < ::Rails::Railtie; end
|
data/rails-template-18f.gemspec
CHANGED
@@ -33,6 +33,7 @@ Gem::Specification.new do |spec|
|
|
33
33
|
# guide at: https://bundler.io/guides/creating_gem.html
|
34
34
|
spec.add_dependency "railties", "~> 7.0.0"
|
35
35
|
spec.add_dependency "activesupport", "~> 7.0.0"
|
36
|
+
spec.add_dependency "thor", "~> 1.0"
|
36
37
|
|
37
38
|
spec.add_development_dependency "rspec", "~> 3.11"
|
38
39
|
spec.add_development_dependency "ammeter", "~> 1.1"
|