rails_template_18f 1.2.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +18 -0
  3. data/Gemfile +1 -1
  4. data/Gemfile.lock +71 -70
  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 -158
  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 +12 -20
  23. data/lib/generators/rails_template18f/i18n_js/templates/app/javascript/i18n/index.js +11 -0
  24. data/lib/generators/rails_template18f/i18n_js/templates/config/i18n-js.yml +4 -0
  25. data/lib/generators/rails_template18f/i18n_js/templates/config/initializers/i18n_js.rb +5 -0
  26. data/lib/generators/rails_template18f/i18n_js/templates/lib/tasks/i18n.rake +8 -7
  27. data/lib/generators/rails_template18f/newrelic/newrelic_generator.rb +4 -2
  28. data/lib/generators/rails_template18f/public_egress/public_egress_generator.rb +168 -0
  29. data/lib/generators/rails_template18f/sidekiq/sidekiq_generator.rb +8 -17
  30. data/lib/generators/rails_template18f/terraform/templates/full_bootstrap/imports.tf.tftpl +25 -0
  31. data/lib/generators/rails_template18f/terraform/templates/full_bootstrap/main.tf.tt +159 -0
  32. data/lib/generators/rails_template18f/terraform/templates/sandbox_bootstrap/imports.tf.tftpl +10 -0
  33. data/lib/generators/rails_template18f/terraform/templates/sandbox_bootstrap/main.tf.tt +117 -0
  34. data/lib/generators/rails_template18f/terraform/templates/terraform/README.md.tt +77 -93
  35. data/lib/generators/rails_template18f/terraform/templates/terraform/app.tf.tt +63 -0
  36. data/lib/generators/rails_template18f/terraform/templates/terraform/bootstrap/apply.sh +15 -0
  37. data/lib/generators/rails_template18f/terraform/templates/terraform/bootstrap/templates/backend_config.tftpl +8 -0
  38. data/lib/generators/rails_template18f/terraform/templates/terraform/bootstrap/templates/bot_secrets.tftpl +5 -0
  39. data/lib/generators/rails_template18f/terraform/templates/terraform/bootstrap/users.auto.tfvars +5 -0
  40. data/lib/generators/rails_template18f/terraform/templates/terraform/main.tf.tt +106 -0
  41. data/lib/generators/rails_template18f/terraform/templates/terraform/production.tfvars.tt +10 -0
  42. data/lib/generators/rails_template18f/terraform/templates/terraform/providers.tf.tt +32 -0
  43. data/lib/generators/rails_template18f/terraform/templates/terraform/sandbox_bot/main.tf +74 -0
  44. data/lib/generators/rails_template18f/terraform/templates/terraform/sandbox_bot/run.sh +17 -0
  45. data/lib/generators/rails_template18f/terraform/templates/terraform/staging.tfvars.tt +8 -0
  46. data/lib/generators/rails_template18f/terraform/templates/terraform/terraform.sh.tt +135 -0
  47. data/lib/generators/rails_template18f/terraform/templates/terraform/variables.tf.tt +99 -0
  48. data/lib/generators/rails_template18f/terraform/terraform_generator.rb +13 -4
  49. data/lib/rails_template18f/generators/base.rb +7 -0
  50. data/lib/rails_template18f/generators/cloud_gov_options.rb +10 -27
  51. data/lib/rails_template18f/generators/cloud_gov_parsing.rb +41 -0
  52. data/lib/rails_template18f/generators.rb +1 -1
  53. data/lib/rails_template18f/version.rb +1 -1
  54. data/rails-template-18f.gemspec +4 -4
  55. data/railsrc +4 -2
  56. data/railsrc-hotwire +4 -2
  57. data/template.rb +61 -71
  58. data/templates/README.md.tt +21 -8
  59. data/templates/app/assets/stylesheets/uswds-settings.scss +3 -2
  60. data/templates/app/views/application/_header.html.erb +1 -1
  61. data/templates/app/views/application/_usa_banner.html.erb +3 -3
  62. data/templates/bin/ops/create_service_account.sh.tt +30 -9
  63. data/templates/bin/ops/destroy_service_account.sh.tt +3 -6
  64. data/templates/browserslistrc +1 -2
  65. data/templates/doc/compliance/TODO.md +1 -4
  66. metadata +34 -28
  67. data/lib/generators/rails_template18f/github_actions/templates/github/workflows/deploy-production.yml.tt +0 -42
  68. data/lib/generators/rails_template18f/github_actions/templates/github/workflows/deploy-staging.yml.tt +0 -42
  69. data/lib/generators/rails_template18f/terraform/templates/terraform/bootstrap/import.sh +0 -13
  70. data/lib/generators/rails_template18f/terraform/templates/terraform/bootstrap/main.tf.tt +0 -22
  71. data/lib/generators/rails_template18f/terraform/templates/terraform/bootstrap/providers.tf +0 -16
  72. data/lib/generators/rails_template18f/terraform/templates/terraform/bootstrap/run.sh.tt +0 -39
  73. data/lib/generators/rails_template18f/terraform/templates/terraform/bootstrap/teardown_creds.sh.tt +0 -5
  74. data/lib/generators/rails_template18f/terraform/templates/terraform/bootstrap/variables.tf +0 -2
  75. data/lib/generators/rails_template18f/terraform/templates/terraform/production/main.tf.tt +0 -70
  76. data/lib/generators/rails_template18f/terraform/templates/terraform/production/providers.tf.tt +0 -23
  77. data/lib/generators/rails_template18f/terraform/templates/terraform/production/variables.tf +0 -2
  78. data/lib/generators/rails_template18f/terraform/templates/terraform/staging/main.tf.tt +0 -52
  79. data/lib/generators/rails_template18f/terraform/templates/terraform/staging/providers.tf.tt +0 -23
  80. data/lib/generators/rails_template18f/terraform/templates/terraform/staging/variables.tf +0 -2
  81. data/lib/rails_template18f/generators/pipeline_options.rb +0 -18
  82. data/templates/app/assets/images/uswds.js +0 -6
  83. data/templates/config/deployment/production.yml +0 -3
  84. data/templates/config/deployment/staging.yml +0 -3
  85. 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,53 +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: Push application with deployment vars
76
- command: |
77
- cf push --strategy rolling \
78
- --vars-file << parameters.deploy_config_file >> \
79
- --var rails_master_key=${<< parameters.rails_master_key >>}
80
77
 
81
78
  jobs:
82
79
  build:
@@ -84,6 +81,8 @@ jobs:
84
81
  - image: cimg/ruby:<%= ruby_version %>
85
82
  steps:
86
83
  - setup-project
84
+ - compile-assets:
85
+ rails_env: ci
87
86
 
88
87
  test:
89
88
  parallelism: 3
@@ -111,25 +110,8 @@ jobs:
111
110
  - run:
112
111
  name: Database setup
113
112
  command: bundle exec rails db:schema:load --trace
114
-
115
- # Precompile assets
116
- # Load assets from cache if possible, precompile assets then save cache
117
- # Multiple caches are used to increase the chance of a cache hit
118
- # https://circleci.com/docs/2.0/caching/#full-example-of-saving-and-restoring-cache
119
- - restore_cache:
120
- keys:
121
- - asset-cache-v1-{{ .Environment.RAILS_ENV }}-{{ arch }}-{{ .Branch }}-{{ .Environment.CIRCLE_SHA1 }}
122
- - asset-cache-v1-{{ .Environment.RAILS_ENV }}-{{ arch }}-{{ .Branch }}
123
- - asset-cache-v1-{{ .Environment.RAILS_ENV }}
124
-
125
- - run: bundle exec rake assets:precompile
126
-
127
- - save_cache:
128
- key: asset-cache-v1-{{ .Environment.RAILS_ENV }}-{{ arch }}-{{ .Branch }}-{{ .Environment.CIRCLE_SHA1 }}
129
- paths:
130
- - public/assets
131
- - tmp/cache/assets/sprockets
132
-
113
+ - compile-assets:
114
+ rails_env: test
133
115
  - ruby/rspec-test
134
116
  <% if oscal_dir_exists? %>
135
117
  validate_ssp:
@@ -198,6 +180,9 @@ jobs:
198
180
  - restore_cache:
199
181
  keys:
200
182
  - node-deps-{{ arch }}-v1-{{ .Branch }}-{{ checksum "package.json" }}-{{ checksum "yarn.lock" }}
183
+ - compile-assets:
184
+ rails_env: ci
185
+ restore_only: true
201
186
 
202
187
  - run:
203
188
  name: Start up local server
@@ -228,6 +213,9 @@ jobs:
228
213
  - restore_cache:
229
214
  keys:
230
215
  - node-deps-{{ arch }}-v1-{{ .Branch }}-{{ checksum "package.json" }}-{{ checksum "yarn.lock" }}
216
+ - compile-assets:
217
+ rails_env: ci
218
+ restore_only: true
231
219
 
232
220
  - run:
233
221
  name: Start up local server
@@ -270,23 +258,9 @@ jobs:
270
258
  name: Database setup
271
259
  command: bundle exec rails db:schema:load --trace
272
260
 
273
- # Precompile assets
274
- # Load assets from cache if possible, precompile assets then save cache
275
- # Multiple caches are used to increase the chance of a cache hit
276
- # https://circleci.com/docs/2.0/caching/#full-example-of-saving-and-restoring-cache
277
- - restore_cache:
278
- keys:
279
- - asset-cache-v1-{{ .Environment.RAILS_ENV }}-{{ arch }}-{{ .Branch }}-{{ .Environment.CIRCLE_SHA1 }}
280
- - asset-cache-v1-{{ .Environment.RAILS_ENV }}-{{ arch }}-{{ .Branch }}
281
- - asset-cache-v1-{{ .Environment.RAILS_ENV }}
282
-
283
- - run: bundle exec rake assets:precompile
284
-
285
- - save_cache:
286
- key: asset-cache-v1-{{ .Environment.RAILS_ENV }}-{{ arch }}-{{ .Branch }}-{{ .Environment.CIRCLE_SHA1 }}
287
- paths:
288
- - public/assets
289
- - tmp/cache/assets/sprockets
261
+ - compile-assets:
262
+ rails_env: ci
263
+ save_cache: false
290
264
 
291
265
  - run:
292
266
  name: Start server
@@ -300,27 +274,57 @@ jobs:
300
274
  - run:
301
275
  name: Run pa11y-ci
302
276
  command: yarn run pa11y-ci -c pa11yci.js
303
- <% 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
304
300
  terraform_plan_staging:
305
301
  executor: terraform/default
306
302
  steps:
307
303
  - checkout
308
304
  - terraform/init:
309
- path: terraform/staging
305
+ path: terraform
306
+ backend_config: >-
307
+ key=terraform.tfstate.staging,
308
+ bucket=$TERRAFORM_STATE_BUCKET_NAME
310
309
  - terraform/validate:
311
- path: terraform/staging
310
+ path: terraform
312
311
  - terraform/fmt:
313
- path: terraform/staging
314
- - run:
315
- name: Set terraform variables
316
- working_directory: terraform/staging
317
- 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: .
318
316
  - terraform/plan:
319
- 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"
320
324
  - persist_to_workspace:
321
325
  root: .
322
326
  paths:
323
- - ./terraform/staging
327
+ - ./terraform
324
328
  terraform_apply_staging:
325
329
  executor: terraform/default
326
330
  steps:
@@ -328,27 +332,43 @@ jobs:
328
332
  - attach_workspace:
329
333
  at: .
330
334
  - terraform/apply:
331
- 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
332
349
  terraform_plan_production:
333
350
  executor: terraform/default
334
351
  steps:
335
352
  - checkout
336
353
  - terraform/init:
337
- path: terraform/production
338
- - terraform/validate:
339
- path: terraform/production
340
- - terraform/fmt:
341
- path: terraform/production
342
- - run:
343
- name: Set terraform variables
344
- working_directory: terraform/production
345
- 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: .
346
360
  - terraform/plan:
347
- 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"
348
368
  - persist_to_workspace:
349
369
  root: .
350
370
  paths:
351
- - ./terraform/production
371
+ - ./terraform
352
372
  terraform_apply_production:
353
373
  executor: terraform/default
354
374
  steps:
@@ -356,32 +376,8 @@ jobs:
356
376
  - attach_workspace:
357
377
  at: .
358
378
  - terraform/apply:
359
- path: terraform/production
360
- <% end %>
361
- deploy_staging:
362
- docker:
363
- - image: cimg/ruby:<%= ruby_version %>
364
- steps:
365
- - setup-project
366
- - cg-deploy:
367
- cloudgov_username: CF_STAGING_USERNAME
368
- cloudgov_password: CF_STAGING_PASSWORD
369
- cloudgov_org: <%= cloud_gov_organization %>
370
- cloudgov_space: <%= cloud_gov_staging_space %>
371
- deploy_config_file: config/deployment/staging.yml
372
- rails_master_key: RAILS_MASTER_KEY
373
- deploy_production:
374
- docker:
375
- - image: cimg/ruby:<%= ruby_version %>
376
- steps:
377
- - setup-project
378
- - cg-deploy:
379
- cloudgov_username: CF_PRODUCTION_USERNAME
380
- cloudgov_password: CF_PRODUCTION_PASSWORD
381
- cloudgov_org: <%= cloud_gov_organization %>
382
- cloudgov_space: <%= cloud_gov_production_space %>
383
- deploy_config_file: config/deployment/production.yml
384
- rails_master_key: PRODUCTION_RAILS_MASTER_KEY
379
+ path: terraform
380
+ plan: production.out<% end %>
385
381
 
386
382
  workflows:
387
383
  version: 2.1
@@ -409,18 +405,33 @@ workflows:
409
405
  - build
410
406
  - a11y_scan:
411
407
  requires:
412
- - build<% if terraform? %>
408
+ - build
409
+ - compile_staging_assets:
410
+ filters:
411
+ branches:
412
+ ignore: production
413
413
  - terraform_plan_staging:
414
414
  filters:
415
415
  branches:
416
416
  ignore: production
417
+ requires:
418
+ - compile_staging_assets
417
419
  - terraform_apply_staging:
418
420
  filters:
419
421
  branches:
420
422
  only: main
421
423
  requires:
422
424
  - terraform_plan_staging
423
- - 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
424
435
  - approve_production_terraform:
425
436
  type: approval
426
437
  filters:
@@ -434,26 +445,6 @@ workflows:
434
445
  only: production
435
446
  requires:
436
447
  - approve_production_terraform<% end %>
437
- - deploy_staging:
438
- filters:
439
- branches:
440
- only: main
441
- requires:
442
- - test
443
- - static_security_scans
444
- - owasp_scan
445
- - a11y_scan<% if terraform? %>
446
- - terraform_apply_staging<% end %>
447
- - deploy_production:
448
- filters:
449
- branches:
450
- only: production
451
- requires:
452
- - test
453
- - static_security_scans
454
- - owasp_scan
455
- - a11y_scan<% if terraform? %>
456
- - terraform_apply_production<% end %>
457
448
  daily_scan:
458
449
  triggers:
459
450
  - schedule:
@@ -466,6 +457,9 @@ workflows:
466
457
  - production
467
458
  jobs:
468
459
  - build
460
+ - refresh_asset_caches:
461
+ requires:
462
+ - build
469
463
  - static_security_scans:
470
464
  requires:
471
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 %>