rails_template_18f 1.3.0 → 2.1.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.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +16 -0
  3. data/Gemfile +1 -1
  4. data/Gemfile.lock +64 -61
  5. data/README.md +11 -16
  6. data/lib/generators/rails_template18f/active_storage/active_storage_generator.rb +7 -6
  7. data/lib/generators/rails_template18f/circleci/circleci_generator.rb +28 -27
  8. data/lib/generators/rails_template18f/circleci/templates/Dockerfile.ci.tt +0 -1
  9. data/lib/generators/rails_template18f/circleci/templates/circleci/config.yml.tt +162 -163
  10. data/lib/generators/rails_template18f/cloud_gov_config/templates/app/models/cloud_gov_config.rb +9 -1
  11. data/lib/generators/rails_template18f/github_actions/github_actions_generator.rb +31 -30
  12. data/lib/generators/rails_template18f/github_actions/templates/github/actions/compile-assets/action.yml +50 -0
  13. data/lib/generators/rails_template18f/github_actions/templates/github/actions/setup-project/action.yml.tt +4 -8
  14. data/lib/generators/rails_template18f/github_actions/templates/github/dependabot.yml.tt +2 -4
  15. data/lib/generators/rails_template18f/github_actions/templates/github/workflows/deploy-production.yml +74 -0
  16. data/lib/generators/rails_template18f/github_actions/templates/github/workflows/deploy-staging.yml +74 -0
  17. data/lib/generators/rails_template18f/github_actions/templates/github/workflows/owasp-daily-scan.yml.tt +10 -1
  18. data/lib/generators/rails_template18f/github_actions/templates/github/workflows/owasp-scan.yml.tt +1 -1
  19. data/lib/generators/rails_template18f/github_actions/templates/github/workflows/pa11y.yml.tt +2 -2
  20. data/lib/generators/rails_template18f/github_actions/templates/github/workflows/terraform-production.yml +49 -4
  21. data/lib/generators/rails_template18f/github_actions/templates/github/workflows/terraform-staging.yml +49 -4
  22. data/lib/generators/rails_template18f/github_actions/templates/github/workflows/validate-ssp.yml +2 -2
  23. data/lib/generators/rails_template18f/gitlab_ci/gitlab_ci_generator.rb +147 -0
  24. data/lib/generators/rails_template18f/gitlab_ci/templates/gitlab/node.yml.tt +11 -0
  25. data/lib/generators/rails_template18f/gitlab_ci/templates/gitlab/rails.yml +75 -0
  26. data/lib/generators/rails_template18f/gitlab_ci/templates/gitlab/ruby.yml +7 -0
  27. data/lib/generators/rails_template18f/gitlab_ci/templates/gitlab/terraform.yml +28 -0
  28. data/lib/generators/rails_template18f/gitlab_ci/templates/gitlab-ci.yml.tt +212 -0
  29. data/lib/generators/rails_template18f/i18n_js/i18n_js_generator.rb +2 -2
  30. data/lib/generators/rails_template18f/i18n_js/templates/app/javascript/{i18n.js → i18n/index.js} +1 -1
  31. data/lib/generators/rails_template18f/i18n_js/templates/config/i18n-js.yml +1 -1
  32. data/lib/generators/rails_template18f/newrelic/newrelic_generator.rb +4 -2
  33. data/lib/generators/rails_template18f/public_egress/public_egress_generator.rb +71 -55
  34. data/lib/generators/rails_template18f/sidekiq/sidekiq_generator.rb +8 -17
  35. data/lib/generators/rails_template18f/terraform/templates/full_bootstrap/imports.tf.tftpl +25 -0
  36. data/lib/generators/rails_template18f/terraform/templates/full_bootstrap/main.tf.tt +159 -0
  37. data/lib/generators/rails_template18f/terraform/templates/sandbox_bootstrap/imports.tf.tftpl +10 -0
  38. data/lib/generators/rails_template18f/terraform/templates/sandbox_bootstrap/main.tf.tt +117 -0
  39. data/lib/generators/rails_template18f/terraform/templates/terraform/README.md.tt +69 -95
  40. data/lib/generators/rails_template18f/terraform/templates/terraform/app.tf.tt +57 -0
  41. data/lib/generators/rails_template18f/terraform/templates/terraform/bootstrap/apply.sh +15 -0
  42. data/lib/generators/rails_template18f/terraform/templates/terraform/bootstrap/templates/backend_config.tftpl +8 -0
  43. data/lib/generators/rails_template18f/terraform/templates/terraform/bootstrap/templates/bot_secrets.tftpl +5 -0
  44. data/lib/generators/rails_template18f/terraform/templates/terraform/bootstrap/users.auto.tfvars +5 -0
  45. data/lib/generators/rails_template18f/terraform/templates/terraform/main.tf.tt +117 -0
  46. data/lib/generators/rails_template18f/terraform/templates/terraform/production.tfvars.tt +13 -0
  47. data/lib/generators/rails_template18f/terraform/templates/terraform/providers.tf.tt +18 -0
  48. data/lib/generators/rails_template18f/terraform/templates/terraform/staging.tfvars.tt +8 -0
  49. data/lib/generators/rails_template18f/terraform/templates/terraform/terraform.sh.tt +95 -0
  50. data/lib/generators/rails_template18f/terraform/templates/terraform/variables.tf.tt +98 -0
  51. data/lib/generators/rails_template18f/terraform/terraform_generator.rb +12 -4
  52. data/lib/rails_template18f/generators/cloud_gov_options.rb +9 -6
  53. data/lib/rails_template18f/generators/cloud_gov_parsing.rb +7 -7
  54. data/lib/rails_template18f/generators.rb +0 -1
  55. data/lib/rails_template18f/version.rb +1 -1
  56. data/rails-template-18f.gemspec +4 -4
  57. data/railsrc +4 -2
  58. data/railsrc-hotwire +4 -2
  59. data/template.rb +80 -82
  60. data/templates/README.md.tt +21 -8
  61. data/templates/app/assets/stylesheets/uswds-settings.scss +3 -2
  62. data/templates/app/views/application/_header.html.erb +1 -1
  63. data/templates/app/views/application/_usa_banner.html.erb +3 -3
  64. data/templates/bin/ops/create_service_account.sh.tt +20 -11
  65. data/templates/bin/ops/destroy_service_account.sh.tt +3 -3
  66. data/templates/browserslistrc +1 -2
  67. data/templates/doc/compliance/TODO.md +1 -4
  68. data/templates/{pa11yci.js → pa11yci.js.tt} +5 -0
  69. metadata +36 -35
  70. data/lib/generators/rails_template18f/github_actions/templates/github/workflows/deploy-production.yml.tt +0 -50
  71. data/lib/generators/rails_template18f/github_actions/templates/github/workflows/deploy-staging.yml.tt +0 -50
  72. data/lib/generators/rails_template18f/terraform/templates/terraform/bootstrap/import.sh +0 -13
  73. data/lib/generators/rails_template18f/terraform/templates/terraform/bootstrap/main.tf.tt +0 -22
  74. data/lib/generators/rails_template18f/terraform/templates/terraform/bootstrap/providers.tf +0 -16
  75. data/lib/generators/rails_template18f/terraform/templates/terraform/bootstrap/run.sh.tt +0 -40
  76. data/lib/generators/rails_template18f/terraform/templates/terraform/bootstrap/teardown_creds.sh.tt +0 -5
  77. data/lib/generators/rails_template18f/terraform/templates/terraform/bootstrap/variables.tf +0 -2
  78. data/lib/generators/rails_template18f/terraform/templates/terraform/production/main.tf.tt +0 -90
  79. data/lib/generators/rails_template18f/terraform/templates/terraform/production/providers.tf +0 -23
  80. data/lib/generators/rails_template18f/terraform/templates/terraform/production/variables.tf +0 -2
  81. data/lib/generators/rails_template18f/terraform/templates/terraform/staging/main.tf.tt +0 -70
  82. data/lib/generators/rails_template18f/terraform/templates/terraform/staging/providers.tf +0 -23
  83. data/lib/generators/rails_template18f/terraform/templates/terraform/staging/variables.tf +0 -2
  84. data/lib/rails_template18f/generators/pipeline_options.rb +0 -18
  85. data/templates/app/assets/images/uswds.js +0 -6
  86. data/templates/config/deployment/production.yml +0 -3
  87. data/templates/config/deployment/staging.yml +0 -3
  88. data/templates/manifest.yml.tt +0 -17
@@ -0,0 +1,95 @@
1
+ #!/usr/bin/env bash
2
+
3
+ rmk_file="../config/master.key"
4
+ cmd="plan"
5
+
6
+ usage="
7
+ $0: Run terraform commands against a given environment
8
+
9
+ Usage:
10
+ $0 -h
11
+ $0 -e <ENV NAME> [-k <RAILS_MASTER_KEY>] [-f] [-c <TERRAFORM-CMD>] [-- <EXTRA CMD ARGUMENTS>]
12
+
13
+ Options:
14
+ -h: show help and exit
15
+ -e ENV_NAME: The name of the environment to run terraform against
16
+ -k RAILS_MASTER_KEY: RAILS_MASTER_KEY value. Defaults to contents of $rmk_file
17
+ -f: Force, pass -auto-approve to all invocations of terraform
18
+ -c TERRAFORM-CMD: command to run. Defaults to $cmd
19
+ [<EXTRA CMD ARGUMENTS>]: arguments to pass as-is to terraform
20
+ "
21
+
22
+
23
+ rmk=`cat $rmk_file || echo -n ""`
24
+ env=""
25
+ force=""
26
+ args_to_shift=0
27
+
28
+ set -e
29
+ while getopts ":he:k:fc:" opt; do
30
+ case "$opt" in
31
+ e)
32
+ env=${OPTARG}
33
+ args_to_shift=$((args_to_shift + 2))
34
+ ;;
35
+ k)
36
+ rmk=${OPTARG}
37
+ args_to_shift=$((args_to_shift + 2))
38
+ ;;
39
+ f)
40
+ force="-auto-approve"
41
+ args_to_shift=$((args_to_shift + 1))
42
+ ;;
43
+ c)
44
+ cmd=${OPTARG}
45
+ args_to_shift=$((args_to_shift + 2))
46
+ ;;
47
+ h)
48
+ echo "$usage"
49
+ exit 0
50
+ ;;
51
+ esac
52
+ done
53
+
54
+ shift $args_to_shift
55
+ if [[ "$1" = "--" ]]; then
56
+ shift 1
57
+ fi
58
+
59
+ if [[ -z "$env" ]]; then
60
+ echo "-e <ENV_NAME> is required"
61
+ echo "$usage"
62
+ exit 1
63
+ fi
64
+
65
+ if [[ ! -f "$env.tfvars" ]]; then
66
+ echo "$env.tfvars file is missing. Create it first"
67
+ exit 1
68
+ fi
69
+
70
+ # ensure we're logged in via cli
71
+ cf spaces &> /dev/null || cf login -a api.fr.cloud.gov --sso
72
+
73
+ tfm_needs_init=true
74
+ if [[ -f .terraform/terraform.tfstate ]]; then
75
+ backend_state_env=`cat .terraform/terraform.tfstate | jq -r ".backend.config.key" | cut -d '.' -f3`
76
+ if [[ "$backend_state_env" = "$env" ]]; then
77
+ tfm_needs_init=false
78
+ fi
79
+ fi
80
+
81
+ if [[ $tfm_needs_init = true ]]; then
82
+ if [[ ! -f secrets.backend.tfvars ]]; then
83
+ echo "=============================================================================================================="
84
+ echo "= Recreating backend config file. It is fine if this step wants to delete any local_sensitive_file resources"
85
+ echo "=============================================================================================================="
86
+ (cd bootstrap && ./apply.sh -auto-approve)
87
+ fi
88
+ terraform init -backend-config=secrets.backend.tfvars -backend-config="key=terraform.tfstate.$env" -reconfigure
89
+ rm secrets.backend.tfvars
90
+ fi
91
+
92
+ echo "=============================================================================================================="
93
+ echo "= Calling $cmd $force on the application infrastructure"
94
+ echo "=============================================================================================================="
95
+ terraform "$cmd" -var-file="$env.tfvars" -var rails_master_key="$rmk" $force "$@"
@@ -0,0 +1,98 @@
1
+ # Deploy user settings
2
+ variable "cf_user" {
3
+ type = string
4
+ description = "The user email or service account running the terraform"
5
+ }
6
+
7
+ # app_space settings
8
+ variable "cf_space_name" {
9
+ type = string
10
+ description = "The space name to deploy the app into"
11
+ }<% if terraform_manage_spaces? %>
12
+ variable "space_deployers" {
13
+ type = set(string)
14
+ default = []
15
+ description = "A list of users to be granted SpaceDeveloper & SpaceManager on cf_space_name"
16
+ }
17
+ variable "space_developers" {
18
+ type = set(string)
19
+ default = []
20
+ description = "A list of users to be granted SpaceDeveloper on cf_space_name"
21
+ }
22
+ variable "space_auditors" {
23
+ type = set(string)
24
+ default = []
25
+ description = "A list of users to be granted SpaceAuditor on cf_space_name"
26
+ }
27
+ variable "allow_space_ssh" {
28
+ type = bool
29
+ default = false
30
+ description = "Whether to allow ssh to cf_space_name"
31
+ }<% end %>
32
+
33
+ # supporting services settings
34
+ variable "rds_plan_name" {
35
+ type = string
36
+ default = "micro-psql"
37
+ description = "The name of the rds plan to create"
38
+ }
39
+ <% if has_active_job? %>
40
+ variable "redis_plan_name" {
41
+ type = string
42
+ default = "redis-dev"
43
+ description = "The name of the redis plan to create"
44
+ }
45
+ <% end %>
46
+ <% if has_active_storage? %>
47
+ variable "s3_plan_name" {
48
+ type = string
49
+ default = "basic-sandbox"
50
+ description = "The name of the s3 plan to use"
51
+ }
52
+ <% end %>
53
+ # routing settings
54
+ variable "custom_domain_name" {
55
+ type = string
56
+ default = null
57
+ description = "The custom domain name to associate with the app. Leave as null to disable the domain service and use an *.app.cloud.gov route"
58
+ }
59
+ variable "host_name" {
60
+ type = string
61
+ default = null
62
+ description = "An optional hostname to prepend to either the custom domain name or app.cloud.gov"
63
+ }
64
+
65
+ # App environment settings
66
+ variable "env" {
67
+ type = string
68
+ description = "The RAILS_ENV to set for the app (staging or production)"
69
+ }
70
+
71
+ variable "rails_master_key" {
72
+ type = string
73
+ sensitive = true
74
+ description = "config/master.key"
75
+ }
76
+
77
+ variable "web_instances" {
78
+ type = number
79
+ default = 1
80
+ description = "The number of instances of the web process"
81
+ }
82
+ variable "web_memory" {
83
+ type = string
84
+ default = "256M"
85
+ description = "The amount of memory to assign to the web processes"
86
+ }
87
+ <% if has_active_job? %>
88
+ variable "worker_instances" {
89
+ type = number
90
+ default = 1
91
+ description = "The number of instances of the worker process"
92
+ }
93
+ variable "worker_memory" {
94
+ type = string
95
+ default = "256M"
96
+ description = "The amount of memory to assign to the worker processes"
97
+ }
98
+ <% end %>
@@ -15,8 +15,16 @@ module RailsTemplate18f
15
15
 
16
16
  def install
17
17
  directory "terraform", mode: :preserve
18
- chmod "terraform/bootstrap/run.sh", 0o755
19
- chmod "terraform/bootstrap/teardown_creds.sh", 0o755
18
+ chmod "terraform/terraform.sh", 0o755
19
+ if terraform_manage_spaces?
20
+ template "full_bootstrap/main.tf", "terraform/bootstrap/main.tf"
21
+ copy_file "full_bootstrap/imports.tf.tftpl", "terraform/bootstrap/templates/imports.tf.tftpl"
22
+ else
23
+ template "sandbox_bootstrap/main.tf", "terraform/bootstrap/main.tf"
24
+ copy_file "sandbox_bootstrap/imports.tf.tftpl", "terraform/bootstrap/templates/imports.tf.tftpl"
25
+ remove_file "terraform/bootstrap/users.auto.tfvars"
26
+ remove_file "terraform/production.tfvars"
27
+ end
20
28
  end
21
29
 
22
30
  def ignore_files
@@ -26,9 +34,10 @@ module RailsTemplate18f
26
34
  # Terraform
27
35
  .terraform.lock.hcl
28
36
  **/.terraform/*
29
- secrets.auto.tfvars
37
+ secrets.*.tfvars
30
38
  terraform.tfstate
31
39
  terraform.tfstate.backup
40
+ terraform/dist
32
41
  EOM
33
42
  end
34
43
  end
@@ -36,7 +45,6 @@ module RailsTemplate18f
36
45
  def update_readme
37
46
  gsub_file "README.md", /^(### Automatic linting)\s*$/, '\1 and terraform formatting'
38
47
  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
48
  end
41
49
 
42
50
  def install_githook
@@ -14,19 +14,22 @@ module RailsTemplate18f
14
14
 
15
15
  private
16
16
 
17
+ def terraform_manage_spaces?
18
+ # when operating in sandbox-gsa we can't use many features that rely
19
+ # on being an OrgManager
20
+ cloud_gov_organization != "sandbox-gsa"
21
+ end
22
+
17
23
  def cloud_gov_organization
18
- return options[:cg_org] if options[:cg_org].present?
19
- super
24
+ @cloud_gov_organization ||= (options[:cg_org].present? ? options[:cg_org] : super)
20
25
  end
21
26
 
22
27
  def cloud_gov_staging_space
23
- return options[:cg_staging] if options[:cg_staging].present?
24
- super
28
+ @cloud_gov_staging_space ||= (options[:cg_staging].present? ? options[:cg_staging] : super)
25
29
  end
26
30
 
27
31
  def cloud_gov_production_space
28
- return options[:cg_prod] if options[:cg_prod].present?
29
- super
32
+ @cloud_gov_production_space ||= (options[:cg_prod].present? ? options[:cg_prod] : super)
30
33
  end
31
34
  end
32
35
  end
@@ -9,8 +9,8 @@ module RailsTemplate18f
9
9
 
10
10
  def cloud_gov_organization
11
11
  if terraform_dir_exists?
12
- staging_main = file_content("terraform/staging/main.tf")
13
- if (matches = staging_main.match(/cf_org_name\s+= "(?<org_name>.*)"/))
12
+ main_tf = file_content("terraform/main.tf")
13
+ if (matches = main_tf.match(/cf_org_name\s+= "(?<org_name>.*)"/))
14
14
  return matches[:org_name]
15
15
  end
16
16
  end
@@ -19,8 +19,8 @@ module RailsTemplate18f
19
19
 
20
20
  def cloud_gov_staging_space
21
21
  if terraform_dir_exists?
22
- staging_main = file_content("terraform/staging/main.tf")
23
- if (matches = staging_main.match(/cf_space_name\s+= "(?<space_name>.*)"/))
22
+ staging_vars = file_content("terraform/staging.tfvars")
23
+ if (matches = staging_vars.match(/cf_space_name\s+= "(?<space_name>.*)"/))
24
24
  return matches[:space_name]
25
25
  end
26
26
  end
@@ -29,12 +29,12 @@ module RailsTemplate18f
29
29
 
30
30
  def cloud_gov_production_space
31
31
  if terraform_dir_exists?
32
- prod_main = file_content("terraform/production/main.tf")
33
- if (matches = prod_main.match(/cf_space_name\s+= "(?<space_name>.*)"/))
32
+ production_vars = file_content("terraform/production.tfvars")
33
+ if (matches = production_vars.match(/cf_space_name\s+= "(?<space_name>.*)"/))
34
34
  return matches[:space_name]
35
35
  end
36
36
  end
37
- "prod"
37
+ "production"
38
38
  end
39
39
  end
40
40
  end
@@ -7,6 +7,5 @@ module RailsTemplate18f
7
7
  autoload :Base
8
8
  autoload :CloudGovOptions
9
9
  autoload :CloudGovParsing
10
- autoload :PipelineOptions
11
10
  end
12
11
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsTemplate18f
4
- VERSION = "1.3.0"
4
+ VERSION = "2.1.0"
5
5
  end
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
 
11
11
  spec.summary = "Generators for creating an 18F-flavored Rails app"
12
12
  spec.homepage = "https://github.com/18f/rails-template"
13
- spec.required_ruby_version = ">= 2.7.5"
13
+ spec.required_ruby_version = ">= 3.2.0"
14
14
 
15
15
  spec.metadata["allowed_push_host"] = "https://rubygems.org/"
16
16
 
@@ -31,12 +31,12 @@ Gem::Specification.new do |spec|
31
31
 
32
32
  # For more information and examples about making a new gem, checkout our
33
33
  # guide at: https://bundler.io/guides/creating_gem.html
34
- spec.add_dependency "railties", "~> 7.2.0"
35
- spec.add_dependency "activesupport", "~> 7.2.0"
34
+ spec.add_dependency "railties", "~> 8.0.1"
35
+ spec.add_dependency "activesupport", "~> 8.0.1"
36
36
  spec.add_dependency "thor", "~> 1.3"
37
37
  spec.add_dependency "colorize", "~> 1.1"
38
38
 
39
39
  spec.add_development_dependency "rspec", "~> 3.13"
40
40
  spec.add_development_dependency "ammeter", "~> 1.1"
41
- spec.add_development_dependency "standard", "~> 1.40"
41
+ spec.add_development_dependency "standard", "~> 1.43"
42
42
  end
data/railsrc CHANGED
@@ -5,9 +5,11 @@
5
5
  --skip-hotwire
6
6
  --skip-docker
7
7
  --skip-test
8
- --javascript=webpack
9
- --css=postcss
8
+ --javascript=esbuild
9
+ --css=sass
10
10
  --template=template.rb
11
11
  --database=postgresql
12
12
  --skip-rubocop
13
13
  --skip-ci
14
+ --skip-kamal
15
+ --skip-solid
data/railsrc-hotwire CHANGED
@@ -3,9 +3,11 @@
3
3
  --skip-action-mailbox
4
4
  --skip-docker
5
5
  --skip-test
6
- --javascript=webpack
7
- --css=postcss
6
+ --javascript=esbuild
7
+ --css=sass
8
8
  --template=template.rb
9
9
  --database=postgresql
10
10
  --skip-rubocop
11
11
  --skip-ci
12
+ --skip-kamal
13
+ --skip-solid