rails_template_18f 1.3.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +11 -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 +152 -163
  10. data/lib/generators/rails_template18f/github_actions/github_actions_generator.rb +31 -30
  11. data/lib/generators/rails_template18f/github_actions/templates/github/actions/compile-assets/action.yml +50 -0
  12. data/lib/generators/rails_template18f/github_actions/templates/github/actions/setup-project/action.yml.tt +4 -8
  13. data/lib/generators/rails_template18f/github_actions/templates/github/dependabot.yml.tt +2 -4
  14. data/lib/generators/rails_template18f/github_actions/templates/github/workflows/deploy-production.yml +72 -0
  15. data/lib/generators/rails_template18f/github_actions/templates/github/workflows/deploy-staging.yml +72 -0
  16. data/lib/generators/rails_template18f/github_actions/templates/github/workflows/owasp-daily-scan.yml.tt +10 -1
  17. data/lib/generators/rails_template18f/github_actions/templates/github/workflows/owasp-scan.yml.tt +1 -1
  18. data/lib/generators/rails_template18f/github_actions/templates/github/workflows/pa11y.yml.tt +2 -2
  19. data/lib/generators/rails_template18f/github_actions/templates/github/workflows/terraform-production.yml +46 -3
  20. data/lib/generators/rails_template18f/github_actions/templates/github/workflows/terraform-staging.yml +46 -3
  21. data/lib/generators/rails_template18f/github_actions/templates/github/workflows/validate-ssp.yml +2 -2
  22. data/lib/generators/rails_template18f/i18n_js/i18n_js_generator.rb +2 -2
  23. data/lib/generators/rails_template18f/i18n_js/templates/app/javascript/{i18n.js → i18n/index.js} +1 -1
  24. data/lib/generators/rails_template18f/i18n_js/templates/config/i18n-js.yml +1 -1
  25. data/lib/generators/rails_template18f/newrelic/newrelic_generator.rb +4 -2
  26. data/lib/generators/rails_template18f/public_egress/public_egress_generator.rb +86 -54
  27. data/lib/generators/rails_template18f/sidekiq/sidekiq_generator.rb +8 -17
  28. data/lib/generators/rails_template18f/terraform/templates/full_bootstrap/imports.tf.tftpl +25 -0
  29. data/lib/generators/rails_template18f/terraform/templates/full_bootstrap/main.tf.tt +159 -0
  30. data/lib/generators/rails_template18f/terraform/templates/sandbox_bootstrap/imports.tf.tftpl +10 -0
  31. data/lib/generators/rails_template18f/terraform/templates/sandbox_bootstrap/main.tf.tt +117 -0
  32. data/lib/generators/rails_template18f/terraform/templates/terraform/README.md.tt +77 -93
  33. data/lib/generators/rails_template18f/terraform/templates/terraform/app.tf.tt +63 -0
  34. data/lib/generators/rails_template18f/terraform/templates/terraform/bootstrap/apply.sh +15 -0
  35. data/lib/generators/rails_template18f/terraform/templates/terraform/bootstrap/templates/backend_config.tftpl +8 -0
  36. data/lib/generators/rails_template18f/terraform/templates/terraform/bootstrap/templates/bot_secrets.tftpl +5 -0
  37. data/lib/generators/rails_template18f/terraform/templates/terraform/bootstrap/users.auto.tfvars +5 -0
  38. data/lib/generators/rails_template18f/terraform/templates/terraform/main.tf.tt +106 -0
  39. data/lib/generators/rails_template18f/terraform/templates/terraform/production.tfvars.tt +10 -0
  40. data/lib/generators/rails_template18f/terraform/templates/terraform/providers.tf.tt +32 -0
  41. data/lib/generators/rails_template18f/terraform/templates/terraform/sandbox_bot/main.tf +74 -0
  42. data/lib/generators/rails_template18f/terraform/templates/terraform/sandbox_bot/run.sh +17 -0
  43. data/lib/generators/rails_template18f/terraform/templates/terraform/staging.tfvars.tt +8 -0
  44. data/lib/generators/rails_template18f/terraform/templates/terraform/terraform.sh.tt +135 -0
  45. data/lib/generators/rails_template18f/terraform/templates/terraform/variables.tf.tt +99 -0
  46. data/lib/generators/rails_template18f/terraform/terraform_generator.rb +13 -4
  47. data/lib/rails_template18f/generators/cloud_gov_options.rb +9 -6
  48. data/lib/rails_template18f/generators/cloud_gov_parsing.rb +7 -7
  49. data/lib/rails_template18f/generators.rb +0 -1
  50. data/lib/rails_template18f/version.rb +1 -1
  51. data/rails-template-18f.gemspec +4 -4
  52. data/railsrc +4 -2
  53. data/railsrc-hotwire +4 -2
  54. data/template.rb +61 -71
  55. data/templates/README.md.tt +21 -8
  56. data/templates/app/assets/stylesheets/uswds-settings.scss +3 -2
  57. data/templates/app/views/application/_header.html.erb +1 -1
  58. data/templates/app/views/application/_usa_banner.html.erb +3 -3
  59. data/templates/bin/ops/create_service_account.sh.tt +20 -11
  60. data/templates/bin/ops/destroy_service_account.sh.tt +3 -3
  61. data/templates/browserslistrc +1 -2
  62. data/templates/doc/compliance/TODO.md +1 -4
  63. metadata +30 -29
  64. data/lib/generators/rails_template18f/github_actions/templates/github/workflows/deploy-production.yml.tt +0 -50
  65. data/lib/generators/rails_template18f/github_actions/templates/github/workflows/deploy-staging.yml.tt +0 -50
  66. data/lib/generators/rails_template18f/terraform/templates/terraform/bootstrap/import.sh +0 -13
  67. data/lib/generators/rails_template18f/terraform/templates/terraform/bootstrap/main.tf.tt +0 -22
  68. data/lib/generators/rails_template18f/terraform/templates/terraform/bootstrap/providers.tf +0 -16
  69. data/lib/generators/rails_template18f/terraform/templates/terraform/bootstrap/run.sh.tt +0 -40
  70. data/lib/generators/rails_template18f/terraform/templates/terraform/bootstrap/teardown_creds.sh.tt +0 -5
  71. data/lib/generators/rails_template18f/terraform/templates/terraform/bootstrap/variables.tf +0 -2
  72. data/lib/generators/rails_template18f/terraform/templates/terraform/production/main.tf.tt +0 -90
  73. data/lib/generators/rails_template18f/terraform/templates/terraform/production/providers.tf +0 -23
  74. data/lib/generators/rails_template18f/terraform/templates/terraform/production/variables.tf +0 -2
  75. data/lib/generators/rails_template18f/terraform/templates/terraform/staging/main.tf.tt +0 -70
  76. data/lib/generators/rails_template18f/terraform/templates/terraform/staging/providers.tf +0 -23
  77. data/lib/generators/rails_template18f/terraform/templates/terraform/staging/variables.tf +0 -2
  78. data/lib/rails_template18f/generators/pipeline_options.rb +0 -18
  79. data/templates/app/assets/images/uswds.js +0 -6
  80. data/templates/config/deployment/production.yml +0 -3
  81. data/templates/config/deployment/staging.yml +0 -3
  82. data/templates/manifest.yml.tt +0 -17
@@ -1,10 +1,10 @@
1
1
  version: 2.1
2
2
 
3
3
  orbs:
4
- ruby: circleci/ruby@2.1.3
5
- node: circleci/node@5.2.0
6
- browser-tools: circleci/browser-tools@1.4.8<% if terraform? %>
7
- terraform: circleci/terraform@3.2.1<% end %>
4
+ ruby: circleci/ruby@2.3.1
5
+ node: circleci/node@7.0.0
6
+ browser-tools: circleci/browser-tools@1.5.0
7
+ terraform: circleci/terraform@3.5.0
8
8
 
9
9
  commands:
10
10
  setup-project:
@@ -15,7 +15,51 @@ commands:
15
15
  install-yarn: true
16
16
  - node/install-packages:
17
17
  cache-only-lockfile: false
18
- pkg-manager: yarn<% if oscal_dir_exists? %>
18
+ pkg-manager: yarn
19
+ compile-assets:
20
+ description: Restore asset cache and compile, optionally saving back to the cache
21
+ parameters:
22
+ rails_env:
23
+ description: RAILS_ENV to use for precompilation
24
+ type: string
25
+ restore_only:
26
+ description: Whether to skip compilation and cleaning
27
+ type: boolean
28
+ default: false
29
+ save_cache:
30
+ description: Whether to save the resulting asset cache
31
+ type: boolean
32
+ default: true
33
+ steps:
34
+ # Precompile assets
35
+ # Load assets from cache if possible, precompile assets then save cache
36
+ # Multiple caches are used to increase the chance of a cache hit
37
+ # https://circleci.com/docs/2.0/caching/#full-example-of-saving-and-restoring-cache
38
+ - restore_cache:
39
+ keys:
40
+ - asset-cache-v1-<< parameters.rails_env >>-{{ .Branch }}
41
+ - asset-cache-v1-<< parameters.rails_env >>
42
+ - when:
43
+ condition:
44
+ equal: [ false, << parameters.restore_only >> ]
45
+ steps:
46
+ - run:
47
+ environment:
48
+ RAILS_ENV: << parameters.rails_env >>
49
+ SECRET_KEY_BASE_DUMMY: 1
50
+ command: ./bin/rake assets:precompile
51
+ - run:
52
+ envronment:
53
+ RAILS_ENV: << parameters.rails_env >>
54
+ SECRET_KEY_BASE_DUMMY: 1
55
+ command: ./bin/rake assets:clean
56
+ - when:
57
+ condition: << parameters.save_cache >>
58
+ steps:
59
+ - save_cache:
60
+ key: asset-cache-v1-<< parameters.rails_env >>-{{ .Branch }}-{{ checksum "public/assets/.manifest.json" }}
61
+ paths:
62
+ - public/assets<% if oscal_dir_exists? %>
19
63
  trestle-cmd:
20
64
  description: Set up environment for running docker-trestle commands
21
65
  parameters:
@@ -30,58 +74,6 @@ commands:
30
74
  - run:
31
75
  name: Run trestle command
32
76
  command: docker run -u "$(id -u):$(id -g)" -v $(pwd)/doc/compliance/oscal:/app/docs:rw ghcr.io/gsa-tts/trestle:<< parameters.tag >> << parameters.cmd >><% end %>
33
- cg-deploy:
34
- description: "Login to cloud foundry space with service account credentials
35
- and push application using deployment configuration file."
36
- parameters:
37
- cloudgov_username:
38
- description: "Name of CircleCI project environment variable that
39
- holdes deployer username for cloudgov space"
40
- type: env_var_name
41
- cloudgov_password:
42
- description: "Name of CircleCI project environment variable that
43
- holds deployer password for cloudgov space"
44
- type: env_var_name
45
- cloudgov_org:
46
- description: "cloud.gov organization name"
47
- type: string
48
- cloudgov_space:
49
- description: "cloud.gov space name"
50
- type: string
51
- deploy_config_file:
52
- description: "Path to deployment configuration file"
53
- type: string
54
- rails_master_key:
55
- description: "Name of CircleCI project environment variable holding the RAILS_MASTER_KEY"
56
- type: env_var_name
57
- steps:
58
- - run:
59
- name: Vendor gems
60
- command: bundle cache --all
61
- - run:
62
- name: Install Cloud Foundry CLI
63
- command: |
64
- curl -v -L -o cf-cli_amd64.deb 'https://packages.cloudfoundry.org/stable?release=debian64&version=v8&source=github'
65
- sudo dpkg -i cf-cli_amd64.deb
66
- - run:
67
- name: Login with service account
68
- command: |
69
- cf login -a api.fr.cloud.gov \
70
- -u ${<< parameters.cloudgov_username >>} \
71
- -p ${<< parameters.cloudgov_password >>} \
72
- -o << parameters.cloudgov_org >> \
73
- -s << parameters.cloudgov_space >>
74
- - run:
75
- name: Set restricted egress
76
- command: |
77
- cf bind-security-group trusted_local_networks_egress << parameters.cloudgov_org >> \
78
- --space << parameters.cloudgov_space >>
79
- - run:
80
- name: Push application with deployment vars
81
- command: |
82
- cf push --strategy rolling \
83
- --vars-file << parameters.deploy_config_file >> \
84
- --var rails_master_key=${<< parameters.rails_master_key >>}
85
77
 
86
78
  jobs:
87
79
  build:
@@ -89,6 +81,8 @@ jobs:
89
81
  - image: cimg/ruby:<%= ruby_version %>
90
82
  steps:
91
83
  - setup-project
84
+ - compile-assets:
85
+ rails_env: ci
92
86
 
93
87
  test:
94
88
  parallelism: 3
@@ -116,25 +110,8 @@ jobs:
116
110
  - run:
117
111
  name: Database setup
118
112
  command: bundle exec rails db:schema:load --trace
119
-
120
- # Precompile assets
121
- # Load assets from cache if possible, precompile assets then save cache
122
- # Multiple caches are used to increase the chance of a cache hit
123
- # https://circleci.com/docs/2.0/caching/#full-example-of-saving-and-restoring-cache
124
- - restore_cache:
125
- keys:
126
- - asset-cache-v1-{{ .Environment.RAILS_ENV }}-{{ arch }}-{{ .Branch }}-{{ .Environment.CIRCLE_SHA1 }}
127
- - asset-cache-v1-{{ .Environment.RAILS_ENV }}-{{ arch }}-{{ .Branch }}
128
- - asset-cache-v1-{{ .Environment.RAILS_ENV }}
129
-
130
- - run: bundle exec rake assets:precompile
131
-
132
- - save_cache:
133
- key: asset-cache-v1-{{ .Environment.RAILS_ENV }}-{{ arch }}-{{ .Branch }}-{{ .Environment.CIRCLE_SHA1 }}
134
- paths:
135
- - public/assets
136
- - tmp/cache/assets/sprockets
137
-
113
+ - compile-assets:
114
+ rails_env: test
138
115
  - ruby/rspec-test
139
116
  <% if oscal_dir_exists? %>
140
117
  validate_ssp:
@@ -203,6 +180,9 @@ jobs:
203
180
  - restore_cache:
204
181
  keys:
205
182
  - node-deps-{{ arch }}-v1-{{ .Branch }}-{{ checksum "package.json" }}-{{ checksum "yarn.lock" }}
183
+ - compile-assets:
184
+ rails_env: ci
185
+ restore_only: true
206
186
 
207
187
  - run:
208
188
  name: Start up local server
@@ -233,6 +213,9 @@ jobs:
233
213
  - restore_cache:
234
214
  keys:
235
215
  - node-deps-{{ arch }}-v1-{{ .Branch }}-{{ checksum "package.json" }}-{{ checksum "yarn.lock" }}
216
+ - compile-assets:
217
+ rails_env: ci
218
+ restore_only: true
236
219
 
237
220
  - run:
238
221
  name: Start up local server
@@ -275,23 +258,9 @@ jobs:
275
258
  name: Database setup
276
259
  command: bundle exec rails db:schema:load --trace
277
260
 
278
- # Precompile assets
279
- # Load assets from cache if possible, precompile assets then save cache
280
- # Multiple caches are used to increase the chance of a cache hit
281
- # https://circleci.com/docs/2.0/caching/#full-example-of-saving-and-restoring-cache
282
- - restore_cache:
283
- keys:
284
- - asset-cache-v1-{{ .Environment.RAILS_ENV }}-{{ arch }}-{{ .Branch }}-{{ .Environment.CIRCLE_SHA1 }}
285
- - asset-cache-v1-{{ .Environment.RAILS_ENV }}-{{ arch }}-{{ .Branch }}
286
- - asset-cache-v1-{{ .Environment.RAILS_ENV }}
287
-
288
- - run: bundle exec rake assets:precompile
289
-
290
- - save_cache:
291
- key: asset-cache-v1-{{ .Environment.RAILS_ENV }}-{{ arch }}-{{ .Branch }}-{{ .Environment.CIRCLE_SHA1 }}
292
- paths:
293
- - public/assets
294
- - tmp/cache/assets/sprockets
261
+ - compile-assets:
262
+ rails_env: ci
263
+ save_cache: false
295
264
 
296
265
  - run:
297
266
  name: Start server
@@ -305,27 +274,57 @@ jobs:
305
274
  - run:
306
275
  name: Run pa11y-ci
307
276
  command: yarn run pa11y-ci -c pa11yci.js
308
- <% if terraform? %>
277
+
278
+ refresh_asset_caches:
279
+ docker:
280
+ - image: cimg/ruby:<%= ruby_version %>
281
+ steps:
282
+ - setup-project
283
+ - compile-assets:
284
+ rails_env: staging
285
+ restore_only: true<% if terraform_manage_spaces? %>
286
+ - compile-assets:
287
+ rails_env: production
288
+ restore_only: true<% end %>
289
+ compile_staging_assets:
290
+ docker:
291
+ - image: cimg/ruby:<%= ruby_version %>
292
+ steps:
293
+ - setup-project
294
+ - compile-assets:
295
+ rails_env: staging
296
+ - persist_to_workspace:
297
+ root: .
298
+ paths:
299
+ - public/assets
309
300
  terraform_plan_staging:
310
301
  executor: terraform/default
311
302
  steps:
312
303
  - checkout
313
304
  - terraform/init:
314
- path: terraform/staging
305
+ path: terraform
306
+ backend_config: >-
307
+ key=terraform.tfstate.staging,
308
+ bucket=$TERRAFORM_STATE_BUCKET_NAME
315
309
  - terraform/validate:
316
- path: terraform/staging
310
+ path: terraform
317
311
  - terraform/fmt:
318
- path: terraform/staging
319
- - run:
320
- name: Set terraform variables
321
- working_directory: terraform/staging
322
- command: echo -e "cf_user = \"$CF_STAGING_USERNAME\"\ncf_password = \"$CF_STAGING_PASSWORD\"" > secrets.auto.tfvars
312
+ path: terraform
313
+ recursive: true
314
+ - attach_workspace:
315
+ at: .
323
316
  - terraform/plan:
324
- path: terraform/staging
317
+ path: terraform
318
+ out: staging.out
319
+ var_file: staging.tfvars
320
+ var: >-
321
+ rails_master_key="$RAILS_MASTER_KEY",
322
+ cf_user="$CF_USERNAME",
323
+ cf_password="$CF_PASSWORD"
325
324
  - persist_to_workspace:
326
325
  root: .
327
326
  paths:
328
- - ./terraform/staging
327
+ - ./terraform
329
328
  terraform_apply_staging:
330
329
  executor: terraform/default
331
330
  steps:
@@ -333,27 +332,43 @@ jobs:
333
332
  - attach_workspace:
334
333
  at: .
335
334
  - terraform/apply:
336
- path: terraform/staging
335
+ path: terraform
336
+ plan: staging.out<% if terraform_manage_spaces? %>
337
+
338
+ compile_production_assets:
339
+ docker:
340
+ - image: cimg/ruby:<%= ruby_version %>
341
+ steps:
342
+ - setup-project
343
+ - compile-assets:
344
+ rails_env: production
345
+ - persist_to_workspace:
346
+ root: .
347
+ paths:
348
+ - public/assets
337
349
  terraform_plan_production:
338
350
  executor: terraform/default
339
351
  steps:
340
352
  - checkout
341
353
  - terraform/init:
342
- path: terraform/production
343
- - terraform/validate:
344
- path: terraform/production
345
- - terraform/fmt:
346
- path: terraform/production
347
- - run:
348
- name: Set terraform variables
349
- working_directory: terraform/production
350
- command: echo -e "cf_user = \"$CF_PRODUCTION_USERNAME\"\ncf_password = \"$CF_PRODUCTION_PASSWORD\"" > secrets.auto.tfvars
354
+ path: terraform
355
+ backend_config: >-
356
+ key=terraform.tfstate.production,
357
+ bucket=$TERRAFORM_STATE_BUCKET_NAME
358
+ - attach_workspace:
359
+ at: .
351
360
  - terraform/plan:
352
- path: terraform/production
361
+ path: terraform
362
+ out: production.out
363
+ var_file: production.tfvars
364
+ var: >-
365
+ rails_master_key="$PRODUCTION_RAILS_MASTER_KEY",
366
+ cf_user="$CF_USERNAME",
367
+ cf_password="$CF_PASSWORD"
353
368
  - persist_to_workspace:
354
369
  root: .
355
370
  paths:
356
- - ./terraform/production
371
+ - ./terraform
357
372
  terraform_apply_production:
358
373
  executor: terraform/default
359
374
  steps:
@@ -361,32 +376,8 @@ jobs:
361
376
  - attach_workspace:
362
377
  at: .
363
378
  - terraform/apply:
364
- path: terraform/production
365
- <% end %>
366
- deploy_staging:
367
- docker:
368
- - image: cimg/ruby:<%= ruby_version %>
369
- steps:
370
- - setup-project
371
- - cg-deploy:
372
- cloudgov_username: CF_STAGING_USERNAME
373
- cloudgov_password: CF_STAGING_PASSWORD
374
- cloudgov_org: <%= cloud_gov_organization %>
375
- cloudgov_space: <%= cloud_gov_staging_space %>
376
- deploy_config_file: config/deployment/staging.yml
377
- rails_master_key: RAILS_MASTER_KEY
378
- deploy_production:
379
- docker:
380
- - image: cimg/ruby:<%= ruby_version %>
381
- steps:
382
- - setup-project
383
- - cg-deploy:
384
- cloudgov_username: CF_PRODUCTION_USERNAME
385
- cloudgov_password: CF_PRODUCTION_PASSWORD
386
- cloudgov_org: <%= cloud_gov_organization %>
387
- cloudgov_space: <%= cloud_gov_production_space %>
388
- deploy_config_file: config/deployment/production.yml
389
- rails_master_key: PRODUCTION_RAILS_MASTER_KEY
379
+ path: terraform
380
+ plan: production.out<% end %>
390
381
 
391
382
  workflows:
392
383
  version: 2.1
@@ -414,18 +405,33 @@ workflows:
414
405
  - build
415
406
  - a11y_scan:
416
407
  requires:
417
- - build<% if terraform? %>
408
+ - build
409
+ - compile_staging_assets:
410
+ filters:
411
+ branches:
412
+ ignore: production
418
413
  - terraform_plan_staging:
419
414
  filters:
420
415
  branches:
421
416
  ignore: production
417
+ requires:
418
+ - compile_staging_assets
422
419
  - terraform_apply_staging:
423
420
  filters:
424
421
  branches:
425
422
  only: main
426
423
  requires:
427
424
  - terraform_plan_staging
428
- - terraform_plan_production
425
+ - owasp_scan
426
+ - static_security_scans
427
+ - test
428
+ - a11y_scan<% if terraform_manage_spaces? %>
429
+ production_plan_and_apply:
430
+ jobs:
431
+ - compile_production_assets
432
+ - terraform_plan_production:
433
+ requires:
434
+ - compile_production_assets
429
435
  - approve_production_terraform:
430
436
  type: approval
431
437
  filters:
@@ -439,26 +445,6 @@ workflows:
439
445
  only: production
440
446
  requires:
441
447
  - approve_production_terraform<% end %>
442
- - deploy_staging:
443
- filters:
444
- branches:
445
- only: main
446
- requires:
447
- - test
448
- - static_security_scans
449
- - owasp_scan
450
- - a11y_scan<% if terraform? %>
451
- - terraform_apply_staging<% end %>
452
- - deploy_production:
453
- filters:
454
- branches:
455
- only: production
456
- requires:
457
- - test
458
- - static_security_scans
459
- - owasp_scan
460
- - a11y_scan<% if terraform? %>
461
- - terraform_apply_production<% end %>
462
448
  daily_scan:
463
449
  triggers:
464
450
  - schedule:
@@ -471,6 +457,9 @@ workflows:
471
457
  - production
472
458
  jobs:
473
459
  - build
460
+ - refresh_asset_caches:
461
+ requires:
462
+ - build
474
463
  - static_security_scans:
475
464
  requires:
476
465
  - build
@@ -6,7 +6,7 @@ module RailsTemplate18f
6
6
  module Generators
7
7
  class GithubActionsGenerator < ::Rails::Generators::Base
8
8
  include Base
9
- include PipelineOptions
9
+ include CloudGovOptions
10
10
 
11
11
  class_option :node_version, desc: "Node version to test against in actions"
12
12
 
@@ -17,14 +17,14 @@ module RailsTemplate18f
17
17
 
18
18
  def install_actions
19
19
  directory "github", ".github"
20
- if !terraform?
21
- remove_file ".github/workflows/terraform-staging.yml"
22
- remove_file ".github/workflows/terraform-production.yml"
23
- end
24
20
  if !oscal_dir_exists?
25
21
  remove_file ".github/workflows/validate-ssp.yml"
26
22
  remove_file ".github/workflows/assemble-ssp.yml"
27
23
  end
24
+ if !terraform_manage_spaces?
25
+ remove_file ".github/workflows/terraform-production.yml"
26
+ remove_file ".github/workflows/deploy-production.yml"
27
+ end
28
28
  end
29
29
 
30
30
  def update_readme
@@ -80,8 +80,7 @@ EOB
80
80
  def readme_staging_deploy
81
81
  <<~EOM
82
82
 
83
- Deploys to staging#{terraform? ? ", including applying changes in terraform," : ""} happen
84
- on every push to the `main` branch in GitHub.
83
+ Deploys to staging happen via terraform on every push to the `main` branch in GitHub.
85
84
 
86
85
  The following secrets must be set within the `staging` [environment secrets](https://docs.github.com/en/actions/reference/encrypted-secrets#creating-encrypted-secrets-for-an-environment)
87
86
  to enable a deploy to work:
@@ -96,28 +95,31 @@ EOB
96
95
  end
97
96
 
98
97
  def readme_prod_deploy
99
- <<~EOM
100
-
101
- Deploys to production#{terraform? ? ", including applying changes in terraform," : ""} happen
102
- on every push to the `production` branch in GitHub.
103
-
104
- The following secrets must be set within the `production` [environment secrets](https://docs.github.com/en/actions/reference/encrypted-secrets#creating-encrypted-secrets-for-an-environment)
105
- to enable a deploy to work:
106
-
107
- | Secret Name | Description |
108
- | ----------- | ----------- |
109
- | `CF_USERNAME` | cloud.gov SpaceDeployer username |
110
- | `CF_PASSWORD` | cloud.gov SpaceDeployer password |
111
- | `RAILS_MASTER_KEY` | `config/credentials/production.key` |
112
- #{terraform_secret_values}
113
- EOM
98
+ if terraform_manage_spaces?
99
+ <<~EOM
100
+
101
+ Deploys to production happen via terraform on every push to the `production` branch in GitHub.
102
+
103
+ The following secrets must be set within the `production` [environment secrets](https://docs.github.com/en/actions/reference/encrypted-secrets#creating-encrypted-secrets-for-an-environment)
104
+ to enable a deploy to work:
105
+
106
+ | Secret Name | Description |
107
+ | ----------- | ----------- |
108
+ | `CF_USERNAME` | cloud.gov SpaceDeployer username |
109
+ | `CF_PASSWORD` | cloud.gov SpaceDeployer password |
110
+ | `RAILS_MASTER_KEY` | `config/credentials/production.key` |
111
+ #{terraform_secret_values}
112
+ EOM
113
+ else
114
+ "Production deploys are not supported in the sandbox organization."
115
+ end
114
116
  end
115
117
 
116
118
  def readme_credentials
117
119
  <<~EOM
118
120
 
119
121
  1. Store variables that must be secret using [GitHub Environment Secrets](https://docs.github.com/en/actions/reference/encrypted-secrets#creating-encrypted-secrets-for-an-environment)
120
- 1. Add the appropriate `--var` addition to the `cf_command` line on the deploy action like the existing `rails_master_key`
122
+ 1. Add the appropriate `TF_VAR_<variable name>` addition to the `terraform-<env>.yml` and `deploy-<env>.yml` workflows like the existing `TF_VAR_rails_master_key`
121
123
  EOM
122
124
  end
123
125
  end
@@ -125,12 +127,11 @@ EOB
125
127
  private
126
128
 
127
129
  def terraform_secret_values
128
- if terraform?
129
- <<~EOM
130
- | `TERRAFORM_STATE_ACCESS_KEY` | Access key for terraform state bucket |
131
- | `TERRAFORM_STATE_SECRET_ACCESS_KEY` | Secret key for terraform state bucket |
132
- EOM
133
- end
130
+ <<~EOM
131
+ | `TERRAFORM_STATE_ACCESS_KEY` | Access key for terraform state bucket |
132
+ | `TERRAFORM_STATE_SECRET_ACCESS_KEY` | Secret key for terraform state bucket |
133
+ | `TERRAFORM_STATE_BUCKET_NAME` | Bucket name for terraform state bucket |
134
+ EOM
134
135
  end
135
136
 
136
137
  def node_version
@@ -139,7 +140,7 @@ EOB
139
140
  elsif File.exist?(nvmrc_path)
140
141
  File.read(nvmrc_path).strip
141
142
  else
142
- "16.15"
143
+ "20.16"
143
144
  end
144
145
  end
145
146
 
@@ -0,0 +1,50 @@
1
+ name: Compile assets
2
+ description: Restore an asset cache, precompile, clean, and optionally save the cache back
3
+ inputs:
4
+ rails_env:
5
+ description: RAILS_ENV in use.
6
+ required: true
7
+ fail_on_missing_cache:
8
+ description: Whether to fail the action on a missing cache restore
9
+ required: false
10
+ default: 'false'
11
+ save_cache:
12
+ description: Whether to save the compiled assets cache
13
+ required: false
14
+ default: 'false'
15
+ runs:
16
+ using: composite
17
+ steps:
18
+ - uses: ./.github/actions/setup-languages
19
+
20
+ - name: Restore asset cache
21
+ uses: actions/cache/restore@v4
22
+ with:
23
+ key: ${{ inputs.rails_env }}-assets-
24
+ fail-on-cache-miss: ${{ inputs.fail_on_missing_cache }}
25
+ path: |
26
+ public/assets
27
+ app/assets/builds
28
+
29
+ - name: Precompile assets
30
+ env:
31
+ RAILS_ENV: ${{ inputs.rails_env }}
32
+ SECRET_KEY_BASE_DUMMY: 1
33
+ shell: bash
34
+ run: ./bin/rake assets:precompile
35
+
36
+ - name: "Clean old assets, keeping current + 2 old versions + anything created within past 1 hour"
37
+ env:
38
+ RAILS_ENV: ${{ inputs.rails_env }}
39
+ SECRET_KEY_BASE_DUMMY: 1
40
+ shell: bash
41
+ run: ./bin/rake assets:clean
42
+
43
+ - name: Save cache
44
+ if: ${{ inputs.save_cache == 'true' }}
45
+ uses: actions/cache/save@v4
46
+ with:
47
+ key: ${{ inputs.rails_env }}-assets-${{ hashFiles('public/assets/.manifest.json') }}
48
+ path: |
49
+ public/assets
50
+ app/assets/builds
@@ -15,15 +15,11 @@ outputs:
15
15
  runs:
16
16
  using: composite
17
17
  steps:
18
- - name: Set up Ruby & Javascript
19
- uses: ./.github/actions/setup-languages
20
-
21
18
  - name: Precompile assets
22
- env:
23
- RAILS_ENV: ${{ inputs.rails_env }}
24
- SECRET_KEY_BASE: not-actually-secret
25
- shell: bash
26
- run: bundle exec rake assets:precompile
19
+ uses: ./.github/actions/compile-assets
20
+ with:
21
+ rails_env: ${{ inputs.rails_env }}
22
+ save_cache: true
27
23
 
28
24
  - name: Set up database
29
25
  env:
@@ -14,12 +14,10 @@ updates:
14
14
  directory: "/"
15
15
  schedule:
16
16
  interval: daily
17
- open-pull-requests-limit: 10<% if terraform? %>
17
+ open-pull-requests-limit: 10
18
18
  - package-ecosystem: terraform
19
19
  directories:
20
- - "/terraform/production"
21
- - "/terraform/staging"
20
+ - "/terraform"
22
21
  schedule:
23
22
  interval: weekly
24
23
  open-pull-requests-limit: 10
25
- <% end %>