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
@@ -0,0 +1,72 @@
1
+ name: Deploy Production
2
+
3
+ on:
4
+ push:
5
+ branches: [ production ]
6
+ paths-ignore:
7
+ - 'doc/**'
8
+ - 'README.md'
9
+
10
+ permissions:
11
+ contents: read
12
+ pull-requests: write
13
+
14
+ jobs:
15
+ build-assets:
16
+ name: Compile and clean assets
17
+ runs-on: ubuntu-latest
18
+ steps:
19
+ - uses: actions/checkout@v4
20
+ - name: Compile assets
21
+ uses: ./.github/actions/compile-assets
22
+ with:
23
+ rails_env: production
24
+ save_cache: true
25
+ - name: Upload assets
26
+ uses: actions/upload-artifact@v4
27
+ with:
28
+ name: production-assets
29
+ path: public/assets
30
+
31
+ deploy:
32
+ name: Deploy to production
33
+ runs-on: ubuntu-latest
34
+ needs: build-assets
35
+ environment: production
36
+ env:
37
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38
+ steps:
39
+ - uses: actions/checkout@v4
40
+
41
+ - name: Download assets
42
+ uses: actions/download-artifact@v4
43
+ with:
44
+ name: production-assets
45
+ path: public/assets
46
+
47
+ - name: Terraform apply
48
+ uses: dflook/terraform-apply@v1
49
+ env:
50
+ TF_VAR_cf_user: ${{ secrets.CF_USERNAME }}
51
+ TF_VAR_cf_password: ${{ secrets.CF_PASSWORD }}
52
+ TF_VAR_rails_master_key: ${{ secrets.RAILS_MASTER_KEY }}
53
+ TERRAFORM_PRE_RUN: |
54
+ apt-get update
55
+ apt-get install -y zip
56
+ with:
57
+ path: terraform
58
+ var_file: terraform/production.tfvars
59
+ backend_config: >
60
+ access_key=${{ secrets.TERRAFORM_STATE_ACCESS_KEY }}
61
+ secret_key=${{ secrets.TERRAFORM_STATE_SECRET_ACCESS_KEY }}
62
+ bucket=${{ secrets.TERRAFORM_STATE_BUCKET_NAME }}
63
+ key=terraform.tfstate.production
64
+
65
+ - name: Save app zip for debugging
66
+ if: failure()
67
+ uses: actions/upload-artifact@v4
68
+ with:
69
+ name: app-src-apply
70
+ path: terraform/dist/src.zip
71
+ compression-level: 0
72
+ retention-days: 1
@@ -0,0 +1,72 @@
1
+ name: Deploy Staging
2
+
3
+ on:
4
+ push:
5
+ branches: [ main ]
6
+ paths-ignore:
7
+ - 'doc/**'
8
+ - 'README.md'
9
+
10
+ permissions:
11
+ contents: read
12
+ pull-requests: write
13
+
14
+ jobs:
15
+ build-assets:
16
+ name: Compile and clean assets
17
+ runs-on: ubuntu-latest
18
+ steps:
19
+ - uses: actions/checkout@v4
20
+ - name: Compile assets
21
+ uses: ./.github/actions/compile-assets
22
+ with:
23
+ rails_env: staging
24
+ save_cache: true
25
+ - name: Upload assets
26
+ uses: actions/upload-artifact@v4
27
+ with:
28
+ name: staging-assets
29
+ path: public/assets
30
+
31
+ deploy:
32
+ name: Deploy to staging
33
+ runs-on: ubuntu-latest
34
+ needs: build-assets
35
+ environment: staging
36
+ env:
37
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38
+ steps:
39
+ - uses: actions/checkout@v4
40
+
41
+ - name: Download assets
42
+ uses: actions/download-artifact@v4
43
+ with:
44
+ name: staging-assets
45
+ path: public/assets
46
+
47
+ - name: Terraform apply
48
+ uses: dflook/terraform-apply@v1
49
+ env:
50
+ TF_VAR_cf_user: ${{ secrets.CF_USERNAME }}
51
+ TF_VAR_cf_password: ${{ secrets.CF_PASSWORD }}
52
+ TF_VAR_rails_master_key: ${{ secrets.RAILS_MASTER_KEY }}
53
+ TERRAFORM_PRE_RUN: |
54
+ apt-get update
55
+ apt-get install -y zip
56
+ with:
57
+ path: terraform
58
+ var_file: terraform/staging.tfvars
59
+ backend_config: >
60
+ access_key=${{ secrets.TERRAFORM_STATE_ACCESS_KEY }}
61
+ secret_key=${{ secrets.TERRAFORM_STATE_SECRET_ACCESS_KEY }}
62
+ bucket=${{ secrets.TERRAFORM_STATE_BUCKET_NAME }}
63
+ key=terraform.tfstate.staging
64
+
65
+ - name: Save app zip for debugging
66
+ if: failure()
67
+ uses: actions/upload-artifact@v4
68
+ with:
69
+ name: app-src-apply
70
+ path: terraform/dist/src.zip
71
+ compression-level: 0
72
+ retention-days: 1
@@ -31,6 +31,15 @@ jobs:
31
31
  steps:
32
32
  - uses: actions/checkout@v4
33
33
 
34
+ - name: Touch staging cache
35
+ uses: ./.github/actions/compile-assets
36
+ with:
37
+ rails_env: staging
38
+ - name: Touch production cache
39
+ uses: ./.github/actions/compile-assets
40
+ with:
41
+ rails_env: production
42
+
34
43
  - id: setup
35
44
  uses: ./.github/actions/setup-project
36
45
 
@@ -39,7 +48,7 @@ jobs:
39
48
  database_url: ${{ steps.setup.outputs.database_url }}
40
49
 
41
50
  - name: Run OWASP Full Scan
42
- uses: zaproxy/action-full-scan@v0.10.0
51
+ uses: zaproxy/action-full-scan@v0.12.0
43
52
  with:
44
53
  token: ${{ secrets.GITHUB_TOKEN }}
45
54
  docker_name: 'ghcr.io/zaproxy/zaproxy:weekly'
@@ -38,7 +38,7 @@ jobs:
38
38
  database_url: ${{ steps.setup.outputs.database_url }}
39
39
 
40
40
  - name: Run OWASP Baseline Scan
41
- uses: zaproxy/action-baseline@v0.12.0
41
+ uses: zaproxy/action-baseline@v0.14.0
42
42
  with:
43
43
  docker_name: 'ghcr.io/zaproxy/zaproxy:weekly'
44
44
  target: 'http://localhost:3000/'
@@ -49,7 +49,7 @@ jobs:
49
49
 
50
50
  - name: Comment on pull request
51
51
  if: failure()
52
- uses: actions/github-script@v4
52
+ uses: actions/github-script@v7
53
53
  with:
54
54
  script: |
55
55
  const output = `Pa11y Failures detected
@@ -61,7 +61,7 @@ jobs:
61
61
  \`\`\`
62
62
  </details>`;
63
63
 
64
- github.issues.createComment({
64
+ github.rest.issues.createComment({
65
65
  issue_number: context.issue.number,
66
66
  owner: context.repo.owner,
67
67
  repo: context.repo.repo,
@@ -9,9 +9,28 @@ permissions:
9
9
  pull-requests: write
10
10
 
11
11
  jobs:
12
+ build-assets:
13
+ name: Compile and clean assets
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+ - name: Compile assets
18
+ uses: ./.github/actions/compile-assets
19
+ with:
20
+ rails_env: production
21
+ # you may want to enable the next line to surface issues with missing assets,
22
+ # but not until after you've deployed once and the cache has been created
23
+ # fail_on_missing_cache: true
24
+ - name: Upload assets
25
+ uses: actions/upload-artifact@v4
26
+ with:
27
+ name: production-assets
28
+ path: public/assets
29
+
12
30
  terraform:
13
31
  name: Terraform plan
14
32
  runs-on: ubuntu-latest
33
+ needs: build-assets
15
34
  environment: production
16
35
  env:
17
36
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -22,20 +41,44 @@ jobs:
22
41
  - name: terraform validate
23
42
  uses: dflook/terraform-validate@v1
24
43
  with:
25
- path: terraform/production
44
+ path: terraform
26
45
 
27
46
  - name: terraform fmt
28
47
  uses: dflook/terraform-fmt-check@v1
29
48
  with:
30
- path: terraform/production
49
+ path: terraform
50
+
51
+ - name: Download assets
52
+ uses: actions/download-artifact@v4
53
+ with:
54
+ name: production-assets
55
+ path: public/assets
31
56
 
32
57
  - name: terraform plan
33
58
  uses: dflook/terraform-plan@v1
34
59
  env:
35
60
  TF_VAR_cf_user: ${{ secrets.CF_USERNAME }}
36
61
  TF_VAR_cf_password: ${{ secrets.CF_PASSWORD }}
62
+ TF_VAR_rails_master_key: ${{ secrets.RAILS_MASTER_KEY }}
63
+ TERRAFORM_PRE_RUN: |
64
+ apt-get update
65
+ apt-get install -y zip
37
66
  with:
38
- path: terraform/production
67
+ path: terraform
68
+ var_file: terraform/production.tfvars
69
+ add_github_comment: changes-only
39
70
  backend_config: >
40
71
  access_key=${{ secrets.TERRAFORM_STATE_ACCESS_KEY }}
41
72
  secret_key=${{ secrets.TERRAFORM_STATE_SECRET_ACCESS_KEY }}
73
+ bucket=${{ secrets.TERRAFORM_STATE_BUCKET_NAME }}
74
+ key=terraform.tfstate.production
75
+
76
+ # Uncomment this step if you need to debug issues
77
+ # with mismatched app checksum between plan and apply
78
+ # - name: Save app zip for debugging
79
+ # uses: actions/upload-artifact@v4
80
+ # with:
81
+ # name: app-src-plan
82
+ # path: terraform/dist/src.zip
83
+ # compression-level: 0
84
+ # retention-days: 1
@@ -9,9 +9,28 @@ permissions:
9
9
  pull-requests: write
10
10
 
11
11
  jobs:
12
+ build-assets:
13
+ name: Compile and clean assets
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+ - name: Compile assets
18
+ uses: ./.github/actions/compile-assets
19
+ with:
20
+ rails_env: staging
21
+ # you may want to enable the next line to surface issues with missing assets,
22
+ # but not until after you've deployed once and the cache has been created
23
+ # fail_on_missing_cache: true
24
+ - name: Upload assets
25
+ uses: actions/upload-artifact@v4
26
+ with:
27
+ name: staging-assets
28
+ path: public/assets
29
+
12
30
  terraform:
13
31
  name: Terraform plan
14
32
  runs-on: ubuntu-latest
33
+ needs: build-assets
15
34
  environment: staging
16
35
  env:
17
36
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -22,20 +41,44 @@ jobs:
22
41
  - name: terraform validate
23
42
  uses: dflook/terraform-validate@v1
24
43
  with:
25
- path: terraform/staging
44
+ path: terraform
26
45
 
27
46
  - name: terraform fmt
28
47
  uses: dflook/terraform-fmt-check@v1
29
48
  with:
30
- path: terraform/staging
49
+ path: terraform
50
+
51
+ - name: Download assets
52
+ uses: actions/download-artifact@v4
53
+ with:
54
+ name: staging-assets
55
+ path: public/assets
31
56
 
32
57
  - name: terraform plan
33
58
  uses: dflook/terraform-plan@v1
34
59
  env:
35
60
  TF_VAR_cf_user: ${{ secrets.CF_USERNAME }}
36
61
  TF_VAR_cf_password: ${{ secrets.CF_PASSWORD }}
62
+ TF_VAR_rails_master_key: ${{ secrets.RAILS_MASTER_KEY }}
63
+ TERRAFORM_PRE_RUN: |
64
+ apt-get update
65
+ apt-get install -y zip
37
66
  with:
38
- path: terraform/staging
67
+ path: terraform
68
+ var_file: terraform/staging.tfvars
69
+ add_github_comment: changes-only
39
70
  backend_config: >
40
71
  access_key=${{ secrets.TERRAFORM_STATE_ACCESS_KEY }}
41
72
  secret_key=${{ secrets.TERRAFORM_STATE_SECRET_ACCESS_KEY }}
73
+ bucket=${{ secrets.TERRAFORM_STATE_BUCKET_NAME }}
74
+ key=terraform.tfstate.staging
75
+
76
+ # Uncomment this step if you need to debug issues
77
+ # with mismatched app checksum between plan and apply
78
+ # - name: Save app zip for debugging
79
+ # uses: actions/upload-artifact@v4
80
+ # with:
81
+ # name: app-src-plan
82
+ # path: terraform/dist/src.zip
83
+ # compression-level: 0
84
+ # retention-days: 1
@@ -31,14 +31,14 @@ jobs:
31
31
 
32
32
  - name: Comment on pull request
33
33
  if: failure()
34
- uses: actions/github-script@v4
34
+ uses: actions/github-script@v7
35
35
  with:
36
36
  script: |
37
37
  const output = `SSP assembly detected changes that aren't checked in.
38
38
 
39
39
  Run \`bin/trestle assemble-ssp-json\` to ensure markdown changes are reflected in your SSP`;
40
40
 
41
- github.issues.createComment({
41
+ github.rest.issues.createComment({
42
42
  issue_number: context.issue.number,
43
43
  owner: context.repo.owner,
44
44
  repo: context.repo.repo,
@@ -12,37 +12,29 @@ module RailsTemplate18f
12
12
  Install and configure i18n-js gem to provide translations to JS code.
13
13
 
14
14
  By default, will only export translations with keys that match `*.js.*`
15
+
16
+ To use, add the following to your js code:
17
+
18
+ 1. `import { i18n } from './i18n';`
19
+ 2. `i18n.t('path.to.translation.key')`
15
20
  DESC
16
21
 
17
- def install_gem_and_tasks
18
- return if gem_installed?("i18n-js")
19
- gem "i18n-js", "~> 3.9"
22
+ def install_gems
23
+ gem "i18n-js", "~> 4.2" unless gem_installed?("i18n-js")
24
+ gem "listen", "~> 3.9", group: :development unless gem_installed?("listen")
20
25
  bundle_install do
21
26
  run "yarn add i18n-js"
22
- generate "i18n:js:config"
23
27
  end
24
28
  end
25
29
 
26
30
  def configure_translation_yaml
27
- append_to_file "config/i18n-js.yml", <<~EOYAML
28
- # remove `only` to include all translations
29
- translations:
30
- - file: "app/assets/builds/translations.js"
31
- only: "*.js.*"
32
- EOYAML
31
+ copy_file "config/i18n-js.yml"
33
32
  end
34
33
 
35
34
  def configure_asset_pipeline
36
35
  copy_file "lib/tasks/i18n.rake"
37
- environment "config.middleware.use I18n::JS::Middleware", env: :development
38
- insert_into_file "app/views/layouts/application.html.erb", indent(<<~EOHTML, 4), after: /<%= stylesheet_link_tag "application".*$\n/
39
- <%= javascript_include_tag "i18n", "data-turbo-track": "reload" %>
40
- <%= javascript_include_tag "translations", "data-turbo-track": "reload" %>
41
- EOHTML
42
- append_to_file "app/assets/config/manifest.js", <<~EOJS
43
- //= link i18n.js
44
- //= link translations.js
45
- EOJS
36
+ copy_file "config/initializers/i18n_js.rb"
37
+ copy_file "app/javascript/i18n/index.js"
46
38
  end
47
39
 
48
40
  def ignore_generated_file
@@ -50,7 +42,7 @@ module RailsTemplate18f
50
42
  append_to_file ".gitignore", <<~EOM
51
43
 
52
44
  # Generated by i18n-js
53
- /public/javascripts/i18n.js
45
+ /app/javascript/i18n/translations.json
54
46
  EOM
55
47
  end
56
48
  end
@@ -0,0 +1,11 @@
1
+ import { I18n } from 'i18n-js';
2
+ import translations from './translations.json';
3
+
4
+ const userLocale = document.documentElement.lang;
5
+
6
+ export const i18n = new I18n();
7
+
8
+ i18n.store(translations);
9
+ i18n.defaultLocale = "en";
10
+ i18n.enableFallback = true;
11
+ i18n.locale = userLocale;
@@ -0,0 +1,4 @@
1
+ translations:
2
+ - file: "app/javascript/i18n/translations.json"
3
+ patterns:
4
+ - "*.js.*"
@@ -0,0 +1,5 @@
1
+ Rails.application.config.after_initialize do
2
+ require "i18n-js/listen"
3
+ # This will only run in development
4
+ I18nJS.listen config_file: Rails.root.join("config/i18n-js.yml")
5
+ end
@@ -1,9 +1,10 @@
1
1
  # export translations as part of asset precompile
2
-
3
- Rake::Task["assets:precompile"].enhance(["i18n:js:export"])
4
-
5
- if Rake::Task.task_defined?("test:prepare")
6
- Rake::Task["test:prepare"].enhance(["i18n:js:export"])
7
- elsif Rake::Task.task_defined?("db:test:prepare")
8
- Rake::Task["db:test:prepare"].enhance(["i18n:js:export"])
2
+ namespace "i18n:js" do
3
+ desc "Call the i18n-js export method"
4
+ task :export do
5
+ require "i18n-js"
6
+ I18nJS.call(config_file: "config/i18n-js.yml")
7
+ end
9
8
  end
9
+
10
+ Rake::Task["javascript:build"].enhance(["i18n:js:export"])
@@ -24,7 +24,7 @@ module RailsTemplate18f
24
24
 
25
25
  def install_gem
26
26
  return if gem_installed?("newrelic_rpm")
27
- gem "newrelic_rpm", "~> 9.12"
27
+ gem "newrelic_rpm", "~> 9.16"
28
28
  bundle_install
29
29
  end
30
30
 
@@ -33,7 +33,9 @@ module RailsTemplate18f
33
33
  end
34
34
 
35
35
  def update_cloud_gov_manifest
36
- insert_into_file "manifest.yml", " NEW_RELIC_LOG: stdout\n", before: /^\s+processes:/
36
+ insert_into_file file_path("terraform/app.tf"), <<EOT, after: "environment = {\n"
37
+ NEW_RELIC_LOG = "stdout"
38
+ EOT
37
39
  end
38
40
 
39
41
  def update_readme
@@ -0,0 +1,168 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/generators"
4
+ require "colorize"
5
+
6
+ module RailsTemplate18f
7
+ module Generators
8
+ class PublicEgressGenerator < ::Rails::Generators::Base
9
+ include Base
10
+ include CloudGovParsing
11
+
12
+ desc <<~DESC
13
+ Description:
14
+ Install files for running cg-egress-proxy in <env>-egress cloud.gov spaces
15
+ Prerequisite: the terraform generator has been run already
16
+ DESC
17
+
18
+ def check_terraform_exists
19
+ unless terraform_dir_exists?
20
+ fail "Run `rails g rails_template18f:terraform` before running this generator"
21
+ end
22
+ end
23
+
24
+ def use_terraform_module
25
+ append_to_file file_path("terraform/main.tf"), terraform_module
26
+ append_to_file file_path("terraform/variables.tf"), <<~EOT
27
+ variable "egress_allowlist" {
28
+ type = set(string)
29
+ default = []
30
+ description = "The set of hostnames that the application is allowed to connect to"
31
+ }
32
+ EOT
33
+ insert_into_file file_path("terraform/app.tf"), <<EOT, after: "environment = {\n"
34
+ no_proxy = "apps.internal,s3-fips.us-gov-west-1.amazonaws.com"
35
+ EOT
36
+ insert_into_file file_path("terraform/app.tf"), <<EOT, after: "service_bindings = [\n"
37
+ { service_instance = "egress-proxy-${var.env}-credentials" },
38
+ EOT
39
+ insert_into_file file_path("terraform/app.tf"), <<EOT, after: "depends_on = [\n"
40
+ cloudfoundry_service_instance.egress_proxy_credentials,
41
+ EOT
42
+ end
43
+
44
+ def setup_terraform_provider
45
+ insert_into_file file_path("terraform/providers.tf"), after: "required_providers {\n" do
46
+ <<-EOT
47
+ cloudfoundry-community = {
48
+ source = "cloudfoundry-community/cloudfoundry"
49
+ version = "0.53.1"
50
+ }
51
+ EOT
52
+ end
53
+ append_to_file file_path("terraform/providers.tf"), <<~EOT
54
+ provider "cloudfoundry-community" {
55
+ api_url = "https://api.fr.cloud.gov"
56
+ user = var.cf_user
57
+ password = var.cf_password
58
+ }
59
+ EOT
60
+ end
61
+
62
+ def setup_proxy_vars
63
+ create_file ".profile", <<~EOP unless file_exists?(".profile")
64
+ ##
65
+ # Cloud Foundry app initialization script
66
+ # https://docs.cloudfoundry.org/devguide/deploy-apps/deploy-app.html#profile
67
+ ##
68
+
69
+ EOP
70
+ insert_into_file ".profile", <<~EOP
71
+ proxy_creds=$(echo "$VCAP_SERVICES" | jq --arg service_name "egress-proxy-$RAILS_ENV-credentials" '.[][] | select(.name == $service_name) | .credentials')
72
+ export http_proxy=$(echo "$proxy_creds" | jq --raw-output ".http_uri")
73
+ export https_proxy=$(echo "$proxy_creds" | jq --raw-output ".https_uri")
74
+ EOP
75
+ end
76
+
77
+ def update_readme
78
+ insert_into_file "README.md", readme_content, before: "## Documentation"
79
+ end
80
+
81
+ def update_boundary_diagram
82
+ boundary_filename = "doc/compliance/apps/application.boundary.md"
83
+ insert_into_file boundary_filename, <<EOB, after: "System_Boundary(inventory, \"Application\") {\n"
84
+ Boundary(restricted_space, "Restricted egress space") {
85
+ }
86
+ Boundary(egress_space, "Public egress space") {
87
+ Container(proxy, "<&layers> Egress Proxy", "Caddy, cg-egress-proxy", "Proxy with allow-list of external connections")
88
+ }
89
+ EOB
90
+ insert_into_file boundary_filename, <<~EOB, before: "@enduml"
91
+ Rel(app, proxy, "Proxy outbound connections", "https (443)")
92
+ EOB
93
+ puts "\n ================ TODO ================ \n".yellow
94
+ puts "Update your application boundary to:"
95
+ puts "1. Place application and services within the Restricted egress space"
96
+ puts "2. Connect outbound connections through the egress proxy"
97
+ end
98
+
99
+ def update_oscal_doc
100
+ copy_remote_oscal_component "cg-egress-proxy", "https://raw.githubusercontent.com/GSA-TTS/cg-egress-proxy/refs/heads/main/docs/compliance/component-definitions/cg-egress-proxy/component-definition.json"
101
+ end
102
+
103
+ no_tasks do
104
+ def readme_content
105
+ <<~README
106
+ ### Public Egress Proxy
107
+
108
+ Traffic to be delivered to the public internet must be proxied through the [cg-egress-proxy](https://github.com/GSA-TTS/cg-egress-proxy) app. Hostnames that the app should be able to
109
+ reach should be added to the `egress_allowlist` terraform variable in `terraform/production.tfvars` and `terraform/staging.tfvars`
110
+
111
+ See the [ruby troubleshooting doc](https://github.com/GSA-TTS/cg-egress-proxy/blob/main/docs/ruby.md) first if you have any problems making outbound connections through the proxy.
112
+
113
+ README
114
+ end
115
+
116
+ def terraform_module
117
+ <<~EOT
118
+
119
+ module "egress_space" {
120
+ source = "github.com/gsa-tts/terraform-cloudgov//cg_space?ref=v2.1.0"
121
+
122
+ cf_org_name = local.cf_org_name
123
+ cf_space_name = "${var.cf_space_name}-egress"
124
+ allow_ssh = var.allow_space_ssh
125
+ deployers = local.space_deployers
126
+ developers = var.space_developers
127
+ security_group_names = ["public_networks_egress"]
128
+ }
129
+
130
+ module "egress_proxy" {
131
+ source = "github.com/gsa-tts/terraform-cloudgov//egress_proxy?ref=v2.1.0"
132
+
133
+ cf_org_name = local.cf_org_name
134
+ cf_egress_space = module.egress_space.space
135
+ name = "egress-proxy-${var.env}"
136
+ allowlist = var.egress_allowlist
137
+ # depends_on line is needed only for initial creation and destruction. It should be commented out for updates to prevent unwanted cascading effects
138
+ depends_on = [module.app_space, module.egress_space]
139
+ }
140
+
141
+ resource "cloudfoundry_network_policy" "egress_routing" {
142
+ provider = cloudfoundry-community
143
+ policy {
144
+ source_app = cloudfoundry_app.app.id
145
+ destination_app = module.egress_proxy.app_id
146
+ port = "61443"
147
+ }
148
+ policy {
149
+ source_app = cloudfoundry_app.app.id
150
+ destination_app = module.egress_proxy.app_id
151
+ port = "8080"
152
+ }
153
+ }
154
+
155
+ resource "cloudfoundry_service_instance" "egress_proxy_credentials" {
156
+ name = "egress-proxy-${var.env}-credentials"
157
+ space = module.app_space.space_id
158
+ type = "user-provided"
159
+ credentials = module.egress_proxy.json_credentials
160
+ # depends_on line is needed only for initial creation and destruction. It should be commented out for updates to prevent unwanted cascading effects
161
+ depends_on = [module.app_space]
162
+ }
163
+ EOT
164
+ end
165
+ end
166
+ end
167
+ end
168
+ end