hephaestus 0.8.11 → 0.8.12.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (127) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/CHANGELOG.md +12 -0
  4. data/README.md +3 -1
  5. data/bin/hephaestus +37 -19
  6. data/lib/hephaestus/app_builder.rb +23 -145
  7. data/lib/hephaestus/app_name.rb +33 -0
  8. data/lib/hephaestus/generators/app_generator.rb +79 -75
  9. data/lib/hephaestus/generators/base.rb +0 -1
  10. data/lib/hephaestus/generators/config_generator.rb +3 -114
  11. data/lib/hephaestus/generators/core_generator.rb +18 -58
  12. data/lib/hephaestus/generators/db_generator.rb +12 -0
  13. data/lib/hephaestus/generators/deployment_generator.rb +3 -8
  14. data/lib/hephaestus/generators/lib_generator.rb +0 -10
  15. data/lib/hephaestus/generators/license_generator.rb +4 -1
  16. data/lib/hephaestus/generators/rubocop_generator.rb +1 -1
  17. data/lib/hephaestus/version.rb +1 -1
  18. data/lib/hephaestus.rb +2 -1
  19. data/templates/Dockerfile +7 -75
  20. data/templates/Gemfile +73 -0
  21. data/templates/Procfile +2 -0
  22. data/templates/app/controllers/app_controller.rb.tt +35 -0
  23. data/templates/app/controllers/application_controller.rb +1 -7
  24. data/templates/app/controllers/concerns/authable.rb.tt +50 -0
  25. data/templates/app/controllers/settings_controller.rb +5 -28
  26. data/templates/app/controllers/yetto_controller.rb +9 -10
  27. data/templates/app/lib/body_parameter/yetto_parameters.rb +8 -29
  28. data/templates/app/lib/{constants/app.rb → constants.rb} +1 -3
  29. data/templates/app/services/{http_service.rb → app_service.rb.tt} +6 -6
  30. data/templates/app/views/settings/new.json.jbuilder.tt +18 -0
  31. data/templates/bin/bundle +115 -0
  32. data/templates/bin/docker-entrypoint +20 -10
  33. data/templates/bin/foreman +27 -0
  34. data/templates/bin/jobs +7 -0
  35. data/templates/bin/rails +6 -0
  36. data/templates/bin/rake +6 -0
  37. data/templates/bin/setup +28 -0
  38. data/templates/bin/tapioca +27 -0
  39. data/templates/config/application.rb.tt +36 -0
  40. data/templates/config/boot.rb +7 -0
  41. data/templates/config/environment.rb +8 -0
  42. data/templates/config/environments/blank.rb +7 -0
  43. data/templates/config/initializers/environment.rb +2 -36
  44. data/templates/config/locales/en.yml +5 -31
  45. data/templates/config/puma.rb +5 -0
  46. data/templates/config/routes.rb.tt +28 -0
  47. data/templates/config.ru +9 -0
  48. data/templates/db/queue_schema.rb +132 -0
  49. data/templates/db/schema.rb +17 -0
  50. data/templates/hephaestus_env.sample +12 -0
  51. data/templates/hephaestus_github/dependabot.yml +27 -0
  52. data/templates/hephaestus_github/workflows/automerge.yml +14 -0
  53. data/templates/hephaestus_github/workflows/deploy.yml +30 -0
  54. data/templates/hephaestus_github/workflows/licenses.yml +17 -0
  55. data/templates/hephaestus_github/workflows/lint.yml +17 -0
  56. data/templates/hephaestus_github/workflows/security.yml +19 -0
  57. data/templates/hephaestus_github/workflows/sorbet.yml +19 -0
  58. data/templates/hephaestus_github/workflows/test.yml.tt +21 -0
  59. data/templates/hephaestus_github/workflows/updater.yml +18 -0
  60. data/templates/hephaestus_vscode/extensions.json +9 -0
  61. data/templates/hephaestus_vscode/launch.json +13 -0
  62. data/templates/hephaestus_vscode/settings.json +58 -0
  63. data/templates/lib/schemas/api/2023-03-06/components/parameters/headers/yetto.json +42 -0
  64. data/templates/lib/schemas/api/2023-03-06/components/parameters/plugInstallation.json +12 -0
  65. data/templates/lib/schemas/api/2023-03-06/components/schemas/plug.json +9 -0
  66. data/templates/lib/schemas/api/2023-03-06/components/schemas/responses.json +64 -0
  67. data/templates/lib/schemas/api/2023-03-06/components/schemas/yetto.json +116 -0
  68. data/templates/lib/schemas/api/2023-03-06/openapi.json +30 -0
  69. data/templates/lib/schemas/api/2023-03-06/paths/app.json +90 -0
  70. data/templates/lib/schemas/api/2023-03-06/paths/yetto/message_created.json +51 -0
  71. data/templates/lib/schemas/api/2023-03-06/paths/yetto/plug_installation_created.json +51 -0
  72. data/templates/script/docker-build-prod.tt +11 -0
  73. data/templates/script/docker-run.tt +8 -0
  74. data/templates/script/edit-credentials +12 -3
  75. data/templates/script/hmac_text +1 -1
  76. data/templates/script/ngrok.tt +7 -0
  77. data/templates/script/server +6 -45
  78. data/templates/test/controllers/app_controller_test.rb.tt +188 -0
  79. data/templates/test/controllers/settings_controller_test.rb.tt +125 -0
  80. data/templates/test/controllers/yetto_controller_test.rb +100 -71
  81. data/templates/test/fixtures/files/plug_installation_settings/valid.json +1 -1
  82. data/templates/test/support/rails.rb +16 -36
  83. data/templates/test/support/webmocks/app_webmock.rb.tt +29 -0
  84. data/templates/test/test_helper.rb +1 -31
  85. data/templates/vendor/fly/{fly-production.toml → fly-production.toml.tt} +24 -11
  86. data/templates/vendor/fly/{fly-staging.toml → fly-staging.toml.tt} +18 -15
  87. metadata +59 -72
  88. data/lib/hephaestus/exit_on_failure.rb +0 -22
  89. data/templates/Gemfile.erb +0 -120
  90. data/templates/Procfile.debug +0 -2
  91. data/templates/Procfile.dev +0 -2
  92. data/templates/app/controllers/app_controller.rb +0 -72
  93. data/templates/app/controllers/concerns/authable.rb +0 -50
  94. data/templates/app/controllers/staff_controller.rb +0 -15
  95. data/templates/app/jobs/update_yetto_job.rb +0 -26
  96. data/templates/app/lib/headers/yetto.rb +0 -19
  97. data/templates/app/lib/headers.rb +0 -5
  98. data/templates/app/lib/path_parameter/settings_parameters.rb +0 -22
  99. data/templates/app/lib/path_parameter/yetto_parameters.rb +0 -28
  100. data/templates/app/lib/path_parameter.rb +0 -8
  101. data/templates/app/lib/plug_app/http.rb +0 -37
  102. data/templates/app/lib/plug_app/middleware/malformed_request.rb +0 -110
  103. data/templates/app/lib/plug_app/middleware/openapi_validation.rb +0 -83
  104. data/templates/app/lib/plug_app/middleware/tracing_attributes.rb +0 -46
  105. data/templates/app/lib/query_parameter.rb +0 -6
  106. data/templates/app/serializers/error_serializer.rb +0 -16
  107. data/templates/app/services/yetto_service.rb +0 -51
  108. data/templates/app/views/settings/new.json.jbuilder +0 -21
  109. data/templates/compose.yml +0 -5
  110. data/templates/config/initializers/000-oj.rb +0 -6
  111. data/templates/config/initializers/cors.rb +0 -19
  112. data/templates/config/initializers/filter_parameter_logging.rb +0 -25
  113. data/templates/config/initializers/inflections.rb +0 -20
  114. data/templates/config/initializers/lograge.rb +0 -25
  115. data/templates/config/initializers/opentelemetry.rb +0 -32
  116. data/templates/config/initializers/sidekiq.rb +0 -11
  117. data/templates/config/initializers/slack_webhook_logger.rb +0 -17
  118. data/templates/config/sidekiq.yml +0 -20
  119. data/templates/script/ngrok +0 -5
  120. data/templates/test/controllers/settings_controller_test.rb +0 -27
  121. data/templates/test/fixtures/plug_installation_settings/invalid.json +0 -3
  122. data/templates/test/fixtures/plug_installation_settings/valid.json +0 -3
  123. data/templates/test/jobs/update_yetto_job_test.rb +0 -26
  124. data/templates/test/support/api.rb +0 -76
  125. data/templates/test/support/webmocks/slack_webmock.rb +0 -24
  126. data/templates/test/support/webmocks/yetto_webmock.rb +0 -119
  127. data/templates/test/support/webmocks.rb +0 -5
@@ -0,0 +1,125 @@
1
+ # typed: false
2
+ # frozen_string_literal: true
3
+
4
+ require "test_helper"
5
+
6
+ class SettingsControllerTest < ActionDispatch::IntegrationTest
7
+ include Hephaestus::API::TestHelpers
8
+
9
+ include Hephaestus::Webmocks::SlackWebmock
10
+ include Hephaestus::Webmocks::YettoWebmock
11
+ include Webmocks::<%= capital_plug_name %>Webmock
12
+
13
+ def setup
14
+ super
15
+ @valid_<%= plug_name %>_installations = JSON.parse(file_fixture_path("plug_installation_settings", "valid.json").read).deep_symbolize_keys
16
+ @response = create_installation
17
+ end
18
+
19
+ test "GET /settings without asking for JSON fails" do
20
+ api(:get, "/settings", headers: nil)
21
+
22
+ assert_response :not_acceptable
23
+ end
24
+
25
+ test "GET /settings asking for JSON without number works" do
26
+ settings_json = api(:get, "/settings")
27
+
28
+ assert_response :ok
29
+
30
+ settings = settings_json["settings"]
31
+
32
+ assert_equal "2023-03-06", settings_json["version"]
33
+ assert_equal 1, settings.length
34
+ assert settings.key?("step")
35
+ end
36
+
37
+ test "GET /settings asking for JSON with number works" do
38
+ settings_json = api(:get, "/settings?step=2")
39
+
40
+ assert_response :ok
41
+
42
+ settings = settings_json["settings"]
43
+
44
+ assert_equal "2023-03-06", settings_json["version"]
45
+ assert_equal 1, settings.length
46
+ assert settings.key?("step")
47
+ end
48
+
49
+ test "GET /edit does not panic if Yetto is unavailable" do
50
+ stub_post_access_token(@plug_installation_id)
51
+ stub_get_plug_installation(@plug_installation_id, status: 500)
52
+
53
+ stub_send_to_slack_log
54
+ api(:get, "/settings/org_id/inbox_id/#{@plug_installation_id}/edit")
55
+
56
+ assert_response :not_acceptable
57
+
58
+ assert_requested_send_to_slack_log
59
+ assert_requested_post_access_token(@plug_installation_id)
60
+ end
61
+
62
+ test "GET /edit does not panic if Yetto provides bad token data" do
63
+ stub_post_access_token(@plug_installation_id)
64
+
65
+ response = {
66
+ credentials: {},
67
+ }
68
+
69
+ stub_get_plug_installation(@plug_installation_id, response:)
70
+
71
+ stub_send_to_slack_log
72
+ api(:get, "/settings/org_id/inbox_id/#{@plug_installation_id}/edit")
73
+
74
+ # error page returned
75
+ assert_response :bad_request
76
+
77
+ assert_requested_send_to_slack_log
78
+ assert_requested_post_access_token(@plug_installation_id)
79
+ end
80
+
81
+ test "GET /edit works even if step is not provided" do
82
+ stub_post_access_token(@plug_installation_id)
83
+ stub_get_plug_installation(@plug_installation_id, response: @response)
84
+ stub_request_<%= plug_name %>_app_installations
85
+
86
+ api(:get, "/settings/org_id/#{@inbox_id}/#{@plug_installation_id}/edit")
87
+
88
+ assert_response :ok
89
+
90
+ assert_requested_post_access_token(@plug_installation_id)
91
+ assert_requested_get_plug_installation(@plug_installation_id)
92
+ assert_requested_<%= plug_name %>_app_installations
93
+ end
94
+
95
+ test "GET /edit works if step is explicitly provided" do
96
+ stub_post_access_token(@plug_installation_id)
97
+ stub_get_plug_installation(@plug_installation_id, response: @response)
98
+ stub_request_<%= plug_name %>_app_installation_repositories
99
+
100
+ api(:get, "/settings/org_id/inbox_id/#{@plug_installation_id}/edit?step=2")
101
+
102
+ assert_response :ok
103
+
104
+ assert_requested_post_access_token(@plug_installation_id)
105
+ assert_requested_get_plug_installation(@plug_installation_id)
106
+ assert_requested_<%= plug_name %>_app_installation_repositories
107
+ end
108
+
109
+ test "GET /edit does not panic if <%= capital_plug_name %> is down" do
110
+ stub_post_access_token(@plug_installation_id)
111
+ stub_get_plug_installation(@plug_installation_id, response: @response)
112
+ stub_request_<%= plug_name %>_app_installation_repositories(status: 500)
113
+ stub_send_to_slack_log
114
+
115
+ api(:get, "/settings/org_id/inbox_id/#{@plug_installation_id}/edit?step=2")
116
+
117
+ assert_response :not_acceptable
118
+
119
+ assert_requested_send_to_slack_log
120
+ assert_requested_<%= plug_name %>_app_installation_repositories
121
+ assert_requested_post_access_token(@plug_installation_id)
122
+ end
123
+
124
+ # TODO: Add your own settings tests here
125
+ end
@@ -4,55 +4,61 @@
4
4
  require "test_helper"
5
5
 
6
6
  class YettoControllerTest < ActionDispatch::IntegrationTest
7
- include API::TestHelpers
7
+ include Hephaestus::API::TestHelpers
8
8
 
9
- include Webmocks::YettoWebmock
9
+ include Hephaestus::Webmocks::YettoWebmock
10
10
 
11
11
  def setup
12
12
  super
13
13
  @after_create_plug_installation = {
14
- plug_installation: {
15
- id: @plug_installation_id,
16
- settings: {
17
- from_email: "new@from.company",
18
- reply_to_email: "new@from.company",
14
+ yetto: {
15
+ plug_installation: {
16
+ id: @plug_installation_id,
17
+ settings: {},
18
+ },
19
+ organization: {
20
+ id: @organization_id,
21
+ },
22
+ plug: {
23
+ id: @plug_id,
24
+ },
25
+ inbox: {
26
+ id: @inbox_id,
19
27
  },
20
- },
21
- organization: {
22
- id: @organization_id,
23
- },
24
- plug: {
25
- id: @plug_id,
26
- },
27
- inbox: {
28
- id: @inbox_id,
29
28
  },
30
29
  }
31
30
 
32
31
  @after_create_message = {
33
- plug_installation: {
34
- id: @plug_installation_id,
35
- settings: {},
36
- credentials: {},
37
- },
38
- message: {
39
- id: @message_id,
40
- text_content: "blern",
41
- html_content: "<p>blern</p>",
42
- metadata: {},
43
- conversation: {
44
- id: @conversation_id,
45
- title: "Hey there?",
46
- metadata: {
47
- "in-reply-to" => "123",
48
- },
32
+ yetto: {
33
+ plug_installation: {
34
+ id: @plug_installation_id,
35
+ settings: {}, # This is where you would put your settings that identify your platform
36
+ credentials: {},
49
37
  },
50
- },
51
- inbox: {
52
- id: @inbox_id,
53
- organization: {
54
- id: @organization_id,
55
- status: "active",
38
+ message: {
39
+ id: @message_id,
40
+ text_content: "blern",
41
+ html_content: "<p>blern</p>",
42
+ metadata: {},
43
+ conversation: {
44
+ id: @conversation_id,
45
+ title: "Hey there?",
46
+ metadata: {
47
+ "in-reply-to" => "123",
48
+ },
49
+ inbox: {
50
+ id: @inbox_id,
51
+ organization: {
52
+ id: @organization_id,
53
+ status: "active",
54
+ },
55
+ },
56
+ },
57
+ created_by_membership: {
58
+ user: {
59
+ name: "someone",
60
+ },
61
+ },
56
62
  },
57
63
  },
58
64
  }
@@ -60,41 +66,12 @@ class YettoControllerTest < ActionDispatch::IntegrationTest
60
66
 
61
67
  def headers(body)
62
68
  {
63
- Headers::Yetto::HEADER_EVENT => "created",
64
- Headers::Yetto::HEADER_RECORD_TYPE => "plug_installation",
65
- Headers::Yetto::HEADER_SIGNATURE => yetto_auth_header(body),
69
+ Hephaestus::Headers::HEADER_EVENT => "created",
70
+ Hephaestus::Headers::HEADER_RECORD_TYPE => "plug_installation",
71
+ Hephaestus::Headers::HEADER_SIGNATURE => yetto_auth_header(body),
66
72
  }
67
73
  end
68
74
 
69
- test "it handles null headers" do
70
- api(:post, "/plug_installation/created", headers: nil)
71
-
72
- assert_response :bad_request
73
- end
74
-
75
- test "it handles missing headers" do
76
- api(:post, "/plug_installation/created", headers: {})
77
-
78
- assert_response :bad_request
79
- end
80
-
81
- test "it handles incorrect headers" do
82
- api(:post, "/plug_installation/created", headers: { "X-Yetto-Signature" => "Basic jabroni:lies" })
83
-
84
- assert_response :bad_request
85
-
86
- api(:post, "/plug_installation/created", headers: { "X-Yetto-Signature" => "sha256=123456" })
87
-
88
- assert_response :bad_request
89
- end
90
-
91
- test "it handles missing body" do
92
- body = {}
93
- api(:post, "/plug_installation/created", headers: headers(body), body: body)
94
-
95
- assert_response :bad_request
96
- end
97
-
98
75
  test "it handles wrong event" do
99
76
  body = @after_create_plug_installation
100
77
  api(:post, "/bloop/plug_installation", headers: headers(body), body: body)
@@ -105,7 +82,7 @@ class YettoControllerTest < ActionDispatch::IntegrationTest
105
82
  test "it handles wrong record type" do
106
83
  body = @after_create_plug_installation
107
84
 
108
- api(:post, "/after_create/plug_instunk", headers: headers(body), body: body)
85
+ api(:post, "/plug_instunk/created", headers: headers(body), body: body)
109
86
 
110
87
  assert_response :not_found
111
88
  end
@@ -126,4 +103,56 @@ class YettoControllerTest < ActionDispatch::IntegrationTest
126
103
 
127
104
  assert_response :bad_request
128
105
  end
106
+
107
+ test "it performs some job to do something to your platform" do
108
+ incoming_body = @after_create_message
109
+
110
+ job_args = {
111
+ create_issue_data: {
112
+ gh_installation_id: @after_create_message[:yetto][:plug_installation][:settings][:github_installations],
113
+ gh_repo_id: @after_create_message[:yetto][:plug_installation][:settings][:github_repositories].to_i,
114
+ title: @after_create_message[:yetto][:message][:conversation][:title],
115
+ body: @after_create_message[:yetto][:message][:text_content],
116
+ },
117
+ message: {
118
+ id: @message_id,
119
+ author: {
120
+ name: "someone",
121
+ },
122
+ metadata: {},
123
+ },
124
+ conversation: {
125
+ id: @conversation_id,
126
+ },
127
+ plug_installation: {
128
+ id: @plug_installation_id,
129
+ },
130
+ inbox: {
131
+ id: @inbox_id,
132
+ },
133
+ }
134
+
135
+ assert_enqueued_with(job: "SomeJob", args: assert_expected_args(job_args)) do
136
+ api(:post, "/message/created", body: incoming_body, headers: headers(incoming_body))
137
+
138
+ assert_response :no_content
139
+ end
140
+ end
141
+
142
+ # You should also add jobs for when your installation is created, updated, or destroy, similar to
143
+ # the below EXAMPLE showing how to test the job that is enqueued when a plug installation is updated.
144
+ # test "it performs UpdateYettoJob after the installation is updated" do
145
+ # incoming_body = @after_update_plug_installation
146
+
147
+ # job_args = {
148
+ # gh_installation_id: incoming_body[:yetto][:plug_installation][:settings][:github_installations],
149
+ # gh_repo_id: incoming_body[:yetto][:plug_installation][:settings][:github_repositories].to_i,
150
+ # }
151
+
152
+ # assert_enqueued_with(job: CreateLabelJob, args: assert_expected_args(job_args)) do
153
+ # api(:post, "/plug_installation/updated", body: incoming_body, headers: headers(incoming_body))
154
+
155
+ # assert_response :no_content
156
+ # end
157
+ # end
129
158
  end
@@ -1,3 +1,3 @@
1
1
  {
2
- "github_installations": "gh_installation_id"
2
+ "app_id": "123"
3
3
  }
@@ -1,40 +1,20 @@
1
1
  # typed: false
2
2
  # frozen_string_literal: true
3
3
 
4
- ENV["RAILS_ENV"] ||= "test"
5
- require_relative "../../config/environment"
6
-
7
- module ActiveSupport
8
- class TestCase
9
- extend T::Sig
10
-
11
- # Run tests in parallel with specified workers
12
- parallelize(workers: :number_of_processors)
13
-
14
- def setup
15
- @organization_id ||= "org_#{Faker::Alphanumeric.alphanumeric(number: 26).upcase}"
16
- @plug_installation_id ||= "pli_#{Faker::Alphanumeric.alphanumeric(number: 26).upcase}"
17
- @inbox_id ||= "ibx_#{Faker::Alphanumeric.alphanumeric(number: 26).upcase}"
18
- @plug_id ||= "plg_#{Faker::Alphanumeric.alphanumeric(number: 26).upcase}"
19
- @message_id ||= "msg_#{Faker::Alphanumeric.alphanumeric(number: 26).upcase}"
20
- @conversation_id ||= "cnv_#{Faker::Alphanumeric.alphanumeric(number: 26).upcase}"
21
- end
22
-
23
- def file_fixture_path(dir, name)
24
- Rails.root.join("test", "fixtures", "files", dir, name)
25
- end
26
-
27
- def assert_expected_args(expected_args)
28
- lambda do |job_args_arr|
29
- job_args_arr.first.each do |actual_args|
30
- actual_key = actual_args.first
31
- actual_value = actual_args.second
32
-
33
- expected_value = expected_args[actual_key]
34
-
35
- assert_equal(expected_value, actual_value, "Expected `#{actual_key}` to be `#{expected_value.nil? ? "nil" : expected_value}`, but was `#{actual_value.nil? ? "nil" : actual_value}`")
36
- end
37
- end
38
- end
39
- end
4
+ def create_installation(valid: true, expires_at: 8.hours.from_now)
5
+ {
6
+ installed_on_inbox: {
7
+ id: @inbox_id,
8
+ organization: {
9
+ id: @organization_id,
10
+ status: "active",
11
+ },
12
+ },
13
+ plug: {
14
+ id: @plug_id,
15
+ },
16
+ # TODO: fill these out!
17
+ settings: {},
18
+ credentials: {},
19
+ }
40
20
  end
@@ -0,0 +1,29 @@
1
+ # typed: false
2
+ # frozen_string_literal: true
3
+
4
+ module Webmocks
5
+ module <%= capital_plug_name %>Webmock
6
+ extend T::Sig
7
+ extend T::Helpers
8
+
9
+ # TODO: Add webmocks here which are specific to your application
10
+ # For example, if your application interacts with GitHub, you can add webmocks for GitHub here
11
+ #
12
+ # sig { params(state: String).returns(T.untyped) }
13
+ # def assert_requested_user_access_token(state)
14
+ # assert_requested(:post, "https://github.com/login/oauth/access_token?#{token_query_params(state)}")
15
+ # end
16
+
17
+ # sig { params(state: String, valid: T::Boolean, status: Integer).returns(T.untyped) }
18
+ # def stub_request_user_access_token(state, valid: true, status: 200)
19
+ # response_body = JSON.parse(file_fixture_path("gh_access_token", valid ? "valid.json" : "invalid.json").read).deep_symbolize_keys
20
+ # stub_request(:post, "https://github.com/login/oauth/access_token?#{token_query_params(state)}")
21
+ # .to_return(
22
+ # status: status,
23
+ # headers: { content_type: "application/json; charset=utf-8" },
24
+ # body: response_body.to_json,
25
+ # )
26
+ # end
27
+
28
+ end
29
+ end
@@ -1,37 +1,7 @@
1
1
  # typed: false
2
2
  # frozen_string_literal: true
3
3
 
4
- require "debug" if ENV.fetch("DEBUG", false)
4
+ require "hephaestus/test_helper"
5
5
 
6
- if ENV["COVERAGE"] == "1"
7
- require "simplecov"
8
- require "simplecov-console"
9
-
10
- SimpleCov.start("rails")
11
-
12
- # do not crash on failure; we want a distinct job to report the coverage error
13
- module SimpleCov
14
- class << self
15
- def result_exit_status(_)
16
- SimpleCov::ExitCodes::SUCCESS
17
- end
18
- end
19
- end
20
- end
21
-
22
- require "httpx"
23
- require "webmock/minitest"
24
- require "httpx/adapters/webmock"
25
- WebMock.enable!
26
- WebMock.disable_net_connect!(allow_localhost: true)
27
-
28
- require_relative "support/rails"
29
-
30
- require "minitest/pride"
31
-
32
- require "webmock/minitest"
33
6
  # Load everything else from test/support
34
7
  Dir[File.expand_path("support/**/*.rb", __dir__)].each { |rb| require(rb) }
35
-
36
- # https://github.com/freerange/mocha#rails
37
- require "mocha/minitest"
@@ -2,16 +2,12 @@
2
2
  # See https://fly.io/docs/reference/configuration/ for information about how to use this file.
3
3
  #
4
4
 
5
- app = "plug-app-production"
5
+ app = "plug-<%= plug_name %>-production"
6
6
  primary_region = "iad"
7
7
 
8
- [env]
9
- RAILS_ENV = "production"
10
- LD_PRELOAD_PATH = "/usr/lib/x86_64-linux-gnu/libjemalloc.so.2"
11
-
12
8
  [processes]
13
- web = "./bin/rails server"
14
- worker = "bundle exec sidekiq"
9
+ web = "/app/bin/rails server"
10
+ supervisor = "/app/bin/jobs"
15
11
 
16
12
  [[vm]]
17
13
  cpu_kind = "performance"
@@ -23,7 +19,17 @@ processes = ["web"]
23
19
  cpu_kind = "performance"
24
20
  cpus = 1
25
21
  memory = "2gb"
26
- processes = ["worker"]
22
+ processes = ["supervisor"]
23
+
24
+ [[restart]]
25
+ policy = "always"
26
+ retries = 5
27
+ processes = ["supervisor"]
28
+
29
+ [[restart]]
30
+ policy = "on-failure"
31
+ retries = 5
32
+ processes = ["web"]
27
33
 
28
34
  [http_service]
29
35
  internal_port = 3000
@@ -39,13 +45,20 @@ hard_limit = 250
39
45
 
40
46
  [checks]
41
47
  [checks.alive]
42
- type = "tcp"
43
- interval = "15s"
48
+ type = "http"
49
+ interval = "10s"
44
50
  timeout = "2s"
45
51
  grace_period = "5s"
52
+ method = "GET"
53
+ path = "/up"
54
+ protocol = "http"
55
+ tls_skip_verify = false
56
+ processes = ["web"]
57
+ [checks.alive.headers]
58
+ X-Forwarded-Proto = "https"
46
59
 
47
60
  [[statics]]
48
- guest_path = "/plug-app/public"
61
+ guest_path = "/plug-<%= plug_name %>/public"
49
62
  url_prefix = "/"
50
63
 
51
64
  [deploy]
@@ -1,13 +1,13 @@
1
- app = "plug-app-staging"
2
- primary_region = "iad"
1
+ #
2
+ # See https://fly.io/docs/reference/configuration/ for information about how to use this file.
3
+ #
3
4
 
4
- [env]
5
- RAILS_ENV = "staging"
6
- LD_PRELOAD_PATH = "/usr/lib/x86_64-linux-gnu/libjemalloc.so.2"
5
+ app = "plug-<%= plug_name %>-staging"
6
+ primary_region = "iad"
7
7
 
8
8
  [processes]
9
- web = "./bin/rails server"
10
- worker = "bundle exec sidekiq"
9
+ web = "/app/bin/rails server"
10
+ supervisor = "/app/bin/jobs"
11
11
 
12
12
  [[vm]]
13
13
  cpu_kind = "shared"
@@ -19,7 +19,11 @@ processes = ["web"]
19
19
  cpu_kind = "shared"
20
20
  cpus = 2
21
21
  memory = "1gb"
22
- processes = ["worker"]
22
+ processes = ["supervisor"]
23
+
24
+ [[restart]]
25
+ policy = "on-failure"
26
+ retries = 5
23
27
 
24
28
  [http_service]
25
29
  internal_port = 3000
@@ -33,15 +37,14 @@ type = "requests"
33
37
  soft_limit = 200
34
38
  hard_limit = 250
35
39
 
36
- [checks]
37
- [checks.alive]
38
- type = "tcp"
39
- interval = "15s"
40
- timeout = "2s"
41
- grace_period = "5s"
40
+ [[services]]
41
+ auto_stop_machines = "stop"
42
+ auto_start_machines = true
43
+ min_machines_running = 0
44
+ processes = ["supervisor"]
42
45
 
43
46
  [[statics]]
44
- guest_path = "/plug-app/public"
47
+ guest_path = "/plug-<%= plug_name %>/public"
45
48
  url_prefix = "/"
46
49
 
47
50
  [deploy]