itsi 0.1.7 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (249) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +21 -0
  3. data/crates/itsi_error/src/from.rs +26 -29
  4. data/crates/itsi_server/Cargo.lock +2956 -0
  5. data/crates/itsi_server/Cargo.toml +1 -1
  6. data/crates/itsi_server/src/lib.rs +5 -0
  7. data/crates/itsi_server/src/request/itsi_request.rs +37 -9
  8. data/crates/itsi_server/src/response/itsi_response.rs +12 -2
  9. data/crates/itsi_server/src/server/bind.rs +4 -3
  10. data/crates/itsi_server/src/server/itsi_server.rs +128 -78
  11. data/crates/itsi_server/src/server/listener.rs +98 -107
  12. data/crates/itsi_server/src/server/serve_strategy/single_mode.rs +40 -24
  13. data/crates/itsi_server/src/server/signal.rs +7 -0
  14. data/crates/itsi_server/src/server/thread_worker.rs +3 -4
  15. data/crates/itsi_server/src/server/tls.rs +20 -13
  16. data/crates/itsi_tracing/src/lib.rs +18 -1
  17. data/gems/scheduler/Cargo.lock +12 -12
  18. data/gems/scheduler/ext/itsi_error/src/from.rs +26 -29
  19. data/gems/scheduler/ext/itsi_server/Cargo.lock +2956 -0
  20. data/gems/scheduler/ext/itsi_server/Cargo.toml +1 -1
  21. data/gems/scheduler/ext/itsi_server/src/lib.rs +5 -0
  22. data/gems/scheduler/ext/itsi_server/src/request/itsi_request.rs +37 -9
  23. data/gems/scheduler/ext/itsi_server/src/response/itsi_response.rs +12 -2
  24. data/gems/scheduler/ext/itsi_server/src/server/bind.rs +4 -3
  25. data/gems/scheduler/ext/itsi_server/src/server/itsi_server.rs +128 -78
  26. data/gems/scheduler/ext/itsi_server/src/server/listener.rs +98 -107
  27. data/gems/scheduler/ext/itsi_server/src/server/serve_strategy/single_mode.rs +40 -24
  28. data/gems/scheduler/ext/itsi_server/src/server/signal.rs +7 -0
  29. data/gems/scheduler/ext/itsi_server/src/server/thread_worker.rs +3 -4
  30. data/gems/scheduler/ext/itsi_server/src/server/tls.rs +20 -13
  31. data/gems/scheduler/ext/itsi_tracing/src/lib.rs +18 -1
  32. data/gems/scheduler/lib/itsi/scheduler/version.rb +1 -1
  33. data/gems/scheduler/test/test_address_resolve.rb +0 -1
  34. data/gems/scheduler/test/test_file_io.rb +0 -1
  35. data/gems/scheduler/test/test_kernel_sleep.rb +3 -4
  36. data/gems/server/Cargo.lock +2917 -0
  37. data/gems/server/Cargo.toml +7 -0
  38. data/gems/server/Rakefile +8 -1
  39. data/gems/server/ext/itsi_error/src/from.rs +26 -29
  40. data/gems/server/ext/itsi_server/Cargo.lock +2956 -0
  41. data/gems/server/ext/itsi_server/Cargo.toml +1 -1
  42. data/gems/server/ext/itsi_server/src/lib.rs +5 -0
  43. data/gems/server/ext/itsi_server/src/request/itsi_request.rs +37 -9
  44. data/gems/server/ext/itsi_server/src/response/itsi_response.rs +12 -2
  45. data/gems/server/ext/itsi_server/src/server/bind.rs +4 -3
  46. data/gems/server/ext/itsi_server/src/server/itsi_server.rs +128 -78
  47. data/gems/server/ext/itsi_server/src/server/listener.rs +98 -107
  48. data/gems/server/ext/itsi_server/src/server/serve_strategy/single_mode.rs +40 -24
  49. data/gems/server/ext/itsi_server/src/server/signal.rs +7 -0
  50. data/gems/server/ext/itsi_server/src/server/thread_worker.rs +3 -4
  51. data/gems/server/ext/itsi_server/src/server/tls.rs +20 -13
  52. data/gems/server/ext/itsi_tracing/src/lib.rs +18 -1
  53. data/gems/server/lib/itsi/index.html +91 -0
  54. data/gems/server/lib/itsi/request.rb +29 -21
  55. data/gems/server/lib/itsi/server/rack/handler/itsi.rb +3 -4
  56. data/gems/server/lib/itsi/server/rack_interface.rb +79 -0
  57. data/gems/server/lib/itsi/server/scheduler_interface.rb +21 -0
  58. data/gems/server/lib/itsi/server/scheduler_mode.rb +1 -1
  59. data/gems/server/lib/itsi/server/signal_trap.rb +24 -0
  60. data/gems/server/lib/itsi/server/version.rb +1 -1
  61. data/gems/server/lib/itsi/server.rb +68 -82
  62. data/gems/server/test/helpers/test_helper.rb +28 -0
  63. data/gems/server/test/test_itsi_server.rb +275 -3
  64. data/lib/itsi/version.rb +1 -1
  65. data/sandbox/deploy/main.tf +238 -0
  66. data/sandbox/deploy/outputs.tf +4 -0
  67. data/sandbox/deploy/vars.tf +11 -0
  68. data/sandbox/falcon_benchmark/Gemfile +10 -0
  69. data/sandbox/falcon_benchmark/Gemfile.lock +140 -0
  70. data/sandbox/falcon_benchmark/config.ru +54 -0
  71. data/sandbox/itsi_sandbox_async/Gemfile +10 -0
  72. data/sandbox/itsi_sandbox_async/Gemfile.lock +69 -0
  73. data/sandbox/itsi_sandbox_async/config.ru +10 -0
  74. data/sandbox/itsi_sandbox_hanami/.env +2 -0
  75. data/sandbox/itsi_sandbox_hanami/.gitignore +6 -0
  76. data/sandbox/itsi_sandbox_hanami/.rspec +1 -0
  77. data/sandbox/itsi_sandbox_hanami/Gemfile +49 -0
  78. data/sandbox/itsi_sandbox_hanami/Gemfile.lock +440 -0
  79. data/sandbox/itsi_sandbox_hanami/Guardfile +9 -0
  80. data/sandbox/itsi_sandbox_hanami/Procfile.dev +2 -0
  81. data/sandbox/itsi_sandbox_hanami/README.md +1 -0
  82. data/sandbox/itsi_sandbox_hanami/Rakefile +3 -0
  83. data/sandbox/itsi_sandbox_hanami/app/action.rb +12 -0
  84. data/sandbox/itsi_sandbox_hanami/app/actions/.keep +0 -0
  85. data/sandbox/itsi_sandbox_hanami/app/assets/css/app.css +5 -0
  86. data/sandbox/itsi_sandbox_hanami/app/assets/images/favicon.ico +0 -0
  87. data/sandbox/itsi_sandbox_hanami/app/assets/js/app.js +1 -0
  88. data/sandbox/itsi_sandbox_hanami/app/db/relation.rb +10 -0
  89. data/sandbox/itsi_sandbox_hanami/app/db/repo.rb +10 -0
  90. data/sandbox/itsi_sandbox_hanami/app/db/struct.rb +10 -0
  91. data/sandbox/itsi_sandbox_hanami/app/operation.rb +9 -0
  92. data/sandbox/itsi_sandbox_hanami/app/relations/.keep +0 -0
  93. data/sandbox/itsi_sandbox_hanami/app/repos/.keep +0 -0
  94. data/sandbox/itsi_sandbox_hanami/app/structs/.keep +0 -0
  95. data/sandbox/itsi_sandbox_hanami/app/templates/layouts/app.html.erb +14 -0
  96. data/sandbox/itsi_sandbox_hanami/app/view.rb +9 -0
  97. data/sandbox/itsi_sandbox_hanami/app/views/helpers.rb +10 -0
  98. data/sandbox/itsi_sandbox_hanami/bin/dev +8 -0
  99. data/sandbox/itsi_sandbox_hanami/config/app.rb +8 -0
  100. data/sandbox/itsi_sandbox_hanami/config/assets.js +16 -0
  101. data/sandbox/itsi_sandbox_hanami/config/db/migrate/.keep +0 -0
  102. data/sandbox/itsi_sandbox_hanami/config/db/seeds.rb +15 -0
  103. data/sandbox/itsi_sandbox_hanami/config/puma.rb +47 -0
  104. data/sandbox/itsi_sandbox_hanami/config/routes.rb +7 -0
  105. data/sandbox/itsi_sandbox_hanami/config/settings.rb +9 -0
  106. data/sandbox/itsi_sandbox_hanami/config.ru +5 -0
  107. data/sandbox/itsi_sandbox_hanami/db/.keep +0 -0
  108. data/sandbox/itsi_sandbox_hanami/lib/itsi_hanami/types.rb +11 -0
  109. data/sandbox/itsi_sandbox_hanami/lib/tasks/.keep +0 -0
  110. data/sandbox/itsi_sandbox_hanami/package-lock.json +946 -0
  111. data/sandbox/itsi_sandbox_hanami/package.json +8 -0
  112. data/sandbox/itsi_sandbox_hanami/spec/requests/root_spec.rb +11 -0
  113. data/sandbox/itsi_sandbox_hanami/spec/spec_helper.rb +9 -0
  114. data/sandbox/itsi_sandbox_hanami/spec/support/db/cleaning.rb +42 -0
  115. data/sandbox/itsi_sandbox_hanami/spec/support/db.rb +10 -0
  116. data/sandbox/itsi_sandbox_hanami/spec/support/features.rb +5 -0
  117. data/sandbox/itsi_sandbox_hanami/spec/support/operations.rb +8 -0
  118. data/sandbox/itsi_sandbox_hanami/spec/support/requests.rb +13 -0
  119. data/sandbox/itsi_sandbox_hanami/spec/support/rspec.rb +61 -0
  120. data/sandbox/itsi_sandbox_rack/Gemfile +17 -0
  121. data/sandbox/itsi_sandbox_rack/Gemfile.lock +153 -0
  122. data/sandbox/itsi_sandbox_rack/config.ru +18 -0
  123. data/sandbox/itsi_sandbox_rack_lint/Gemfile +7 -0
  124. data/sandbox/itsi_sandbox_rack_lint/Gemfile.lock +27 -0
  125. data/sandbox/itsi_sandbox_rack_lint/config.ru +3 -0
  126. data/sandbox/itsi_sandbox_rails/.dockerignore +51 -0
  127. data/sandbox/itsi_sandbox_rails/.gitattributes +9 -0
  128. data/sandbox/itsi_sandbox_rails/.github/dependabot.yml +12 -0
  129. data/sandbox/itsi_sandbox_rails/.github/workflows/ci.yml +90 -0
  130. data/sandbox/itsi_sandbox_rails/.gitignore +34 -0
  131. data/sandbox/itsi_sandbox_rails/.kamal/hooks/docker-setup.sample +3 -0
  132. data/sandbox/itsi_sandbox_rails/.kamal/hooks/post-app-boot.sample +3 -0
  133. data/sandbox/itsi_sandbox_rails/.kamal/hooks/post-deploy.sample +14 -0
  134. data/sandbox/itsi_sandbox_rails/.kamal/hooks/post-proxy-reboot.sample +3 -0
  135. data/sandbox/itsi_sandbox_rails/.kamal/hooks/pre-app-boot.sample +3 -0
  136. data/sandbox/itsi_sandbox_rails/.kamal/hooks/pre-build.sample +51 -0
  137. data/sandbox/itsi_sandbox_rails/.kamal/hooks/pre-connect.sample +47 -0
  138. data/sandbox/itsi_sandbox_rails/.kamal/hooks/pre-deploy.sample +109 -0
  139. data/sandbox/itsi_sandbox_rails/.kamal/hooks/pre-proxy-reboot.sample +3 -0
  140. data/sandbox/itsi_sandbox_rails/.kamal/secrets +17 -0
  141. data/sandbox/itsi_sandbox_rails/.rubocop.yml +8 -0
  142. data/sandbox/itsi_sandbox_rails/.ruby-version +1 -0
  143. data/sandbox/itsi_sandbox_rails/Dockerfile +72 -0
  144. data/sandbox/itsi_sandbox_rails/Gemfile +72 -0
  145. data/sandbox/itsi_sandbox_rails/Gemfile.lock +480 -0
  146. data/sandbox/itsi_sandbox_rails/README.md +24 -0
  147. data/sandbox/itsi_sandbox_rails/Rakefile +6 -0
  148. data/sandbox/itsi_sandbox_rails/app/assets/images/.keep +0 -0
  149. data/sandbox/itsi_sandbox_rails/app/assets/stylesheets/application.css +10 -0
  150. data/sandbox/itsi_sandbox_rails/app/controllers/application_controller.rb +4 -0
  151. data/sandbox/itsi_sandbox_rails/app/controllers/concerns/.keep +0 -0
  152. data/sandbox/itsi_sandbox_rails/app/controllers/home_controller.rb +51 -0
  153. data/sandbox/itsi_sandbox_rails/app/controllers/live_controller.rb +41 -0
  154. data/sandbox/itsi_sandbox_rails/app/controllers/uploads_controller.rb +32 -0
  155. data/sandbox/itsi_sandbox_rails/app/helpers/application_helper.rb +2 -0
  156. data/sandbox/itsi_sandbox_rails/app/javascript/application.js +3 -0
  157. data/sandbox/itsi_sandbox_rails/app/javascript/controllers/application.js +9 -0
  158. data/sandbox/itsi_sandbox_rails/app/javascript/controllers/hello_controller.js +7 -0
  159. data/sandbox/itsi_sandbox_rails/app/javascript/controllers/index.js +4 -0
  160. data/sandbox/itsi_sandbox_rails/app/jobs/application_job.rb +7 -0
  161. data/sandbox/itsi_sandbox_rails/app/mailers/application_mailer.rb +4 -0
  162. data/sandbox/itsi_sandbox_rails/app/models/application_record.rb +3 -0
  163. data/sandbox/itsi_sandbox_rails/app/models/concerns/.keep +0 -0
  164. data/sandbox/itsi_sandbox_rails/app/models/post.rb +2 -0
  165. data/sandbox/itsi_sandbox_rails/app/views/layouts/application.html.erb +28 -0
  166. data/sandbox/itsi_sandbox_rails/app/views/layouts/mailer.html.erb +13 -0
  167. data/sandbox/itsi_sandbox_rails/app/views/layouts/mailer.text.erb +1 -0
  168. data/sandbox/itsi_sandbox_rails/app/views/pwa/manifest.json.erb +22 -0
  169. data/sandbox/itsi_sandbox_rails/app/views/pwa/service-worker.js +26 -0
  170. data/sandbox/itsi_sandbox_rails/bin/brakeman +7 -0
  171. data/sandbox/itsi_sandbox_rails/bin/bundle +109 -0
  172. data/sandbox/itsi_sandbox_rails/bin/dev +2 -0
  173. data/sandbox/itsi_sandbox_rails/bin/docker-entrypoint +14 -0
  174. data/sandbox/itsi_sandbox_rails/bin/importmap +4 -0
  175. data/sandbox/itsi_sandbox_rails/bin/jobs +6 -0
  176. data/sandbox/itsi_sandbox_rails/bin/kamal +27 -0
  177. data/sandbox/itsi_sandbox_rails/bin/rails +4 -0
  178. data/sandbox/itsi_sandbox_rails/bin/rake +4 -0
  179. data/sandbox/itsi_sandbox_rails/bin/rubocop +8 -0
  180. data/sandbox/itsi_sandbox_rails/bin/setup +34 -0
  181. data/sandbox/itsi_sandbox_rails/bin/thrust +5 -0
  182. data/sandbox/itsi_sandbox_rails/config/application.rb +61 -0
  183. data/sandbox/itsi_sandbox_rails/config/boot.rb +4 -0
  184. data/sandbox/itsi_sandbox_rails/config/cable.yml +17 -0
  185. data/sandbox/itsi_sandbox_rails/config/cache.yml +16 -0
  186. data/sandbox/itsi_sandbox_rails/config/credentials.yml.enc +1 -0
  187. data/sandbox/itsi_sandbox_rails/config/database.yml +40 -0
  188. data/sandbox/itsi_sandbox_rails/config/deploy.yml +116 -0
  189. data/sandbox/itsi_sandbox_rails/config/environment.rb +5 -0
  190. data/sandbox/itsi_sandbox_rails/config/environments/development.rb +72 -0
  191. data/sandbox/itsi_sandbox_rails/config/environments/production.rb +90 -0
  192. data/sandbox/itsi_sandbox_rails/config/environments/test.rb +53 -0
  193. data/sandbox/itsi_sandbox_rails/config/importmap.rb +7 -0
  194. data/sandbox/itsi_sandbox_rails/config/initializers/assets.rb +7 -0
  195. data/sandbox/itsi_sandbox_rails/config/initializers/content_security_policy.rb +25 -0
  196. data/sandbox/itsi_sandbox_rails/config/initializers/filter_parameter_logging.rb +8 -0
  197. data/sandbox/itsi_sandbox_rails/config/initializers/inflections.rb +16 -0
  198. data/sandbox/itsi_sandbox_rails/config/locales/en.yml +31 -0
  199. data/sandbox/itsi_sandbox_rails/config/puma.rb +41 -0
  200. data/sandbox/itsi_sandbox_rails/config/queue.yml +18 -0
  201. data/sandbox/itsi_sandbox_rails/config/recurring.yml +10 -0
  202. data/sandbox/itsi_sandbox_rails/config/routes.rb +21 -0
  203. data/sandbox/itsi_sandbox_rails/config/storage.yml +34 -0
  204. data/sandbox/itsi_sandbox_rails/config.ru +7 -0
  205. data/sandbox/itsi_sandbox_rails/db/cable_schema.rb +11 -0
  206. data/sandbox/itsi_sandbox_rails/db/cache_schema.rb +14 -0
  207. data/sandbox/itsi_sandbox_rails/db/migrate/20250301041554_create_posts.rb +10 -0
  208. data/sandbox/itsi_sandbox_rails/db/queue_schema.rb +129 -0
  209. data/sandbox/itsi_sandbox_rails/db/schema.rb +23 -0
  210. data/sandbox/itsi_sandbox_rails/db/seeds.rb +9 -0
  211. data/sandbox/itsi_sandbox_rails/lib/tasks/.keep +0 -0
  212. data/sandbox/itsi_sandbox_rails/log/.keep +0 -0
  213. data/sandbox/itsi_sandbox_rails/public/400.html +114 -0
  214. data/sandbox/itsi_sandbox_rails/public/404.html +114 -0
  215. data/sandbox/itsi_sandbox_rails/public/406-unsupported-browser.html +114 -0
  216. data/sandbox/itsi_sandbox_rails/public/422.html +114 -0
  217. data/sandbox/itsi_sandbox_rails/public/500.html +114 -0
  218. data/sandbox/itsi_sandbox_rails/public/icon.png +0 -0
  219. data/sandbox/itsi_sandbox_rails/public/icon.svg +3 -0
  220. data/sandbox/itsi_sandbox_rails/public/robots.txt +1 -0
  221. data/sandbox/itsi_sandbox_rails/script/.keep +0 -0
  222. data/sandbox/itsi_sandbox_rails/storage/.keep +0 -0
  223. data/sandbox/itsi_sandbox_rails/test/application_system_test_case.rb +5 -0
  224. data/sandbox/itsi_sandbox_rails/test/controllers/.keep +0 -0
  225. data/sandbox/itsi_sandbox_rails/test/fixtures/files/.keep +0 -0
  226. data/sandbox/itsi_sandbox_rails/test/fixtures/posts.yml +9 -0
  227. data/sandbox/itsi_sandbox_rails/test/helpers/.keep +0 -0
  228. data/sandbox/itsi_sandbox_rails/test/integration/.keep +0 -0
  229. data/sandbox/itsi_sandbox_rails/test/mailers/.keep +0 -0
  230. data/sandbox/itsi_sandbox_rails/test/models/.keep +0 -0
  231. data/sandbox/itsi_sandbox_rails/test/models/post_test.rb +7 -0
  232. data/sandbox/itsi_sandbox_rails/test/system/.keep +0 -0
  233. data/sandbox/itsi_sandbox_rails/test/test_helper.rb +15 -0
  234. data/sandbox/itsi_sandbox_rails/tmp/.keep +0 -0
  235. data/sandbox/itsi_sandbox_rails/tmp/pids/.keep +0 -0
  236. data/sandbox/itsi_sandbox_rails/tmp/storage/.keep +0 -0
  237. data/sandbox/itsi_sandbox_rails/vendor/.keep +0 -0
  238. data/sandbox/itsi_sandbox_rails/vendor/javascript/.keep +0 -0
  239. data/sandbox/itsi_sandbox_roda/Gemfile +5 -0
  240. data/sandbox/itsi_sandbox_roda/Gemfile.lock +44 -0
  241. data/sandbox/itsi_sandbox_roda/config.ru +39 -0
  242. data/sandbox/itsi_sinatra/Gemfile +9 -0
  243. data/sandbox/itsi_sinatra/Gemfile.lock +81 -0
  244. data/sandbox/itsi_sinatra/app.rb +9 -0
  245. data/sandbox/pebble/docker-compose.yml +11 -0
  246. data/tasks.txt +4 -4
  247. metadata +199 -10
  248. data/gems/server/lib/itsi/signals.rb +0 -23
  249. data/gems/server/test/test_helper.rb +0 -7
@@ -0,0 +1,51 @@
1
+ #!/bin/sh
2
+
3
+ # A sample pre-build hook
4
+ #
5
+ # Checks:
6
+ # 1. We have a clean checkout
7
+ # 2. A remote is configured
8
+ # 3. The branch has been pushed to the remote
9
+ # 4. The version we are deploying matches the remote
10
+ #
11
+ # These environment variables are available:
12
+ # KAMAL_RECORDED_AT
13
+ # KAMAL_PERFORMER
14
+ # KAMAL_VERSION
15
+ # KAMAL_HOSTS
16
+ # KAMAL_ROLE (if set)
17
+ # KAMAL_DESTINATION (if set)
18
+
19
+ if [ -n "$(git status --porcelain)" ]; then
20
+ echo "Git checkout is not clean, aborting..." >&2
21
+ git status --porcelain >&2
22
+ exit 1
23
+ fi
24
+
25
+ first_remote=$(git remote)
26
+
27
+ if [ -z "$first_remote" ]; then
28
+ echo "No git remote set, aborting..." >&2
29
+ exit 1
30
+ fi
31
+
32
+ current_branch=$(git branch --show-current)
33
+
34
+ if [ -z "$current_branch" ]; then
35
+ echo "Not on a git branch, aborting..." >&2
36
+ exit 1
37
+ fi
38
+
39
+ remote_head=$(git ls-remote $first_remote --tags $current_branch | cut -f1)
40
+
41
+ if [ -z "$remote_head" ]; then
42
+ echo "Branch not pushed to remote, aborting..." >&2
43
+ exit 1
44
+ fi
45
+
46
+ if [ "$KAMAL_VERSION" != "$remote_head" ]; then
47
+ echo "Version ($KAMAL_VERSION) does not match remote HEAD ($remote_head), aborting..." >&2
48
+ exit 1
49
+ fi
50
+
51
+ exit 0
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # A sample pre-connect check
4
+ #
5
+ # Warms DNS before connecting to hosts in parallel
6
+ #
7
+ # These environment variables are available:
8
+ # KAMAL_RECORDED_AT
9
+ # KAMAL_PERFORMER
10
+ # KAMAL_VERSION
11
+ # KAMAL_HOSTS
12
+ # KAMAL_ROLE (if set)
13
+ # KAMAL_DESTINATION (if set)
14
+ # KAMAL_RUNTIME
15
+
16
+ hosts = ENV["KAMAL_HOSTS"].split(",")
17
+ results = nil
18
+ max = 3
19
+
20
+ elapsed = Benchmark.realtime do
21
+ results = hosts.map do |host|
22
+ Thread.new do
23
+ tries = 1
24
+
25
+ begin
26
+ Socket.getaddrinfo(host, 0, Socket::AF_UNSPEC, Socket::SOCK_STREAM, nil, Socket::AI_CANONNAME)
27
+ rescue SocketError
28
+ if tries < max
29
+ puts "Retrying DNS warmup: #{host}"
30
+ tries += 1
31
+ sleep rand
32
+ retry
33
+ else
34
+ puts "DNS warmup failed: #{host}"
35
+ host
36
+ end
37
+ end
38
+
39
+ tries
40
+ end
41
+ end.map(&:value)
42
+ end
43
+
44
+ retries = results.sum - hosts.size
45
+ nopes = results.count { |r| r == max }
46
+
47
+ puts "Prewarmed %d DNS lookups in %.2f sec: %d retries, %d failures" % [ hosts.size, elapsed, retries, nopes ]
@@ -0,0 +1,109 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # A sample pre-deploy hook
4
+ #
5
+ # Checks the Github status of the build, waiting for a pending build to complete for up to 720 seconds.
6
+ #
7
+ # Fails unless the combined status is "success"
8
+ #
9
+ # These environment variables are available:
10
+ # KAMAL_RECORDED_AT
11
+ # KAMAL_PERFORMER
12
+ # KAMAL_VERSION
13
+ # KAMAL_HOSTS
14
+ # KAMAL_COMMAND
15
+ # KAMAL_SUBCOMMAND
16
+ # KAMAL_ROLE (if set)
17
+ # KAMAL_DESTINATION (if set)
18
+
19
+ # Only check the build status for production deployments
20
+ if ENV["KAMAL_COMMAND"] == "rollback" || ENV["KAMAL_DESTINATION"] != "production"
21
+ exit 0
22
+ end
23
+
24
+ require "bundler/inline"
25
+
26
+ # true = install gems so this is fast on repeat invocations
27
+ gemfile(true, quiet: true) do
28
+ source "https://rubygems.org"
29
+
30
+ gem "octokit"
31
+ gem "faraday-retry"
32
+ end
33
+
34
+ MAX_ATTEMPTS = 72
35
+ ATTEMPTS_GAP = 10
36
+
37
+ def exit_with_error(message)
38
+ $stderr.puts message
39
+ exit 1
40
+ end
41
+
42
+ class GithubStatusChecks
43
+ attr_reader :remote_url, :git_sha, :github_client, :combined_status
44
+
45
+ def initialize
46
+ @remote_url = `git config --get remote.origin.url`.strip.delete_prefix("https://github.com/")
47
+ @git_sha = `git rev-parse HEAD`.strip
48
+ @github_client = Octokit::Client.new(access_token: ENV["GITHUB_TOKEN"])
49
+ refresh!
50
+ end
51
+
52
+ def refresh!
53
+ @combined_status = github_client.combined_status(remote_url, git_sha)
54
+ end
55
+
56
+ def state
57
+ combined_status[:state]
58
+ end
59
+
60
+ def first_status_url
61
+ first_status = combined_status[:statuses].find { |status| status[:state] == state }
62
+ first_status && first_status[:target_url]
63
+ end
64
+
65
+ def complete_count
66
+ combined_status[:statuses].count { |status| status[:state] != "pending"}
67
+ end
68
+
69
+ def total_count
70
+ combined_status[:statuses].count
71
+ end
72
+
73
+ def current_status
74
+ if total_count > 0
75
+ "Completed #{complete_count}/#{total_count} checks, see #{first_status_url} ..."
76
+ else
77
+ "Build not started..."
78
+ end
79
+ end
80
+ end
81
+
82
+
83
+ $stdout.sync = true
84
+
85
+ puts "Checking build status..."
86
+ attempts = 0
87
+ checks = GithubStatusChecks.new
88
+
89
+ begin
90
+ loop do
91
+ case checks.state
92
+ when "success"
93
+ puts "Checks passed, see #{checks.first_status_url}"
94
+ exit 0
95
+ when "failure"
96
+ exit_with_error "Checks failed, see #{checks.first_status_url}"
97
+ when "pending"
98
+ attempts += 1
99
+ end
100
+
101
+ exit_with_error "Checks are still pending, gave up after #{MAX_ATTEMPTS * ATTEMPTS_GAP} seconds" if attempts == MAX_ATTEMPTS
102
+
103
+ puts checks.current_status
104
+ sleep(ATTEMPTS_GAP)
105
+ checks.refresh!
106
+ end
107
+ rescue Octokit::NotFound
108
+ exit_with_error "Build status could not be found"
109
+ end
@@ -0,0 +1,3 @@
1
+ #!/bin/sh
2
+
3
+ echo "Rebooting kamal-proxy on $KAMAL_HOSTS..."
@@ -0,0 +1,17 @@
1
+ # Secrets defined here are available for reference under registry/password, env/secret, builder/secrets,
2
+ # and accessories/*/env/secret in config/deploy.yml. All secrets should be pulled from either
3
+ # password manager, ENV, or a file. DO NOT ENTER RAW CREDENTIALS HERE! This file needs to be safe for git.
4
+
5
+ # Example of extracting secrets from 1password (or another compatible pw manager)
6
+ # SECRETS=$(kamal secrets fetch --adapter 1password --account your-account --from Vault/Item KAMAL_REGISTRY_PASSWORD RAILS_MASTER_KEY)
7
+ # KAMAL_REGISTRY_PASSWORD=$(kamal secrets extract KAMAL_REGISTRY_PASSWORD ${SECRETS})
8
+ # RAILS_MASTER_KEY=$(kamal secrets extract RAILS_MASTER_KEY ${SECRETS})
9
+
10
+ # Use a GITHUB_TOKEN if private repositories are needed for the image
11
+ # GITHUB_TOKEN=$(gh config get -h github.com oauth_token)
12
+
13
+ # Grab the registry password from ENV
14
+ KAMAL_REGISTRY_PASSWORD=$KAMAL_REGISTRY_PASSWORD
15
+
16
+ # Improve security by using a password manager. Never check config/master.key into git!
17
+ RAILS_MASTER_KEY=$(cat config/master.key)
@@ -0,0 +1,8 @@
1
+ # Omakase Ruby styling for Rails
2
+ inherit_gem: { rubocop-rails-omakase: rubocop.yml }
3
+
4
+ # Overwrite or add rules to create your own house style
5
+ #
6
+ # # Use `[a, [b, c]]` not `[ a, [ b, c ] ]`
7
+ # Layout/SpaceInsideArrayLiteralBrackets:
8
+ # Enabled: false
@@ -0,0 +1 @@
1
+ ruby-3.4.2
@@ -0,0 +1,72 @@
1
+ # syntax=docker/dockerfile:1
2
+ # check=error=true
3
+
4
+ # This Dockerfile is designed for production, not development. Use with Kamal or build'n'run by hand:
5
+ # docker build -t itsi_sandbox_rails .
6
+ # docker run -d -p 80:80 -e RAILS_MASTER_KEY=<value from config/master.key> --name itsi_sandbox_rails itsi_sandbox_rails
7
+
8
+ # For a containerized dev environment, see Dev Containers: https://guides.rubyonrails.org/getting_started_with_devcontainer.html
9
+
10
+ # Make sure RUBY_VERSION matches the Ruby version in .ruby-version
11
+ ARG RUBY_VERSION=3.4.2
12
+ FROM docker.io/library/ruby:$RUBY_VERSION-slim AS base
13
+
14
+ # Rails app lives here
15
+ WORKDIR /rails
16
+
17
+ # Install base packages
18
+ RUN apt-get update -qq && \
19
+ apt-get install --no-install-recommends -y curl libjemalloc2 libvips sqlite3 && \
20
+ rm -rf /var/lib/apt/lists /var/cache/apt/archives
21
+
22
+ # Set production environment
23
+ ENV RAILS_ENV="production" \
24
+ BUNDLE_DEPLOYMENT="1" \
25
+ BUNDLE_PATH="/usr/local/bundle" \
26
+ BUNDLE_WITHOUT="development"
27
+
28
+ # Throw-away build stage to reduce size of final image
29
+ FROM base AS build
30
+
31
+ # Install packages needed to build gems
32
+ RUN apt-get update -qq && \
33
+ apt-get install --no-install-recommends -y build-essential git pkg-config && \
34
+ rm -rf /var/lib/apt/lists /var/cache/apt/archives
35
+
36
+ # Install application gems
37
+ COPY Gemfile Gemfile.lock ./
38
+ RUN bundle install && \
39
+ rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \
40
+ bundle exec bootsnap precompile --gemfile
41
+
42
+ # Copy application code
43
+ COPY . .
44
+
45
+ # Precompile bootsnap code for faster boot times
46
+ RUN bundle exec bootsnap precompile app/ lib/
47
+
48
+ # Precompiling assets for production without requiring secret RAILS_MASTER_KEY
49
+ RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile
50
+
51
+
52
+
53
+
54
+ # Final stage for app image
55
+ FROM base
56
+
57
+ # Copy built artifacts: gems, application
58
+ COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}"
59
+ COPY --from=build /rails /rails
60
+
61
+ # Run and own only the runtime files as a non-root user for security
62
+ RUN groupadd --system --gid 1000 rails && \
63
+ useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && \
64
+ chown -R rails:rails db log storage tmp
65
+ USER 1000:1000
66
+
67
+ # Entrypoint prepares the database.
68
+ ENTRYPOINT ["/rails/bin/docker-entrypoint"]
69
+
70
+ # Start server via Thruster by default, this can be overwritten at runtime
71
+ EXPOSE 80
72
+ CMD ["./bin/thrust", "./bin/rails", "server"]
@@ -0,0 +1,72 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
4
+ gem "rails", "~> 8.0.1"
5
+ # The modern asset pipeline for Rails [https://github.com/rails/propshaft]
6
+ gem "propshaft"
7
+ # Use sqlite3 as the database for Active Record
8
+ gem "sqlite3", ">= 2.1"
9
+ # Use the Puma web server [https://github.com/puma/puma]
10
+ gem "puma", ">= 5.0"
11
+ # Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails]
12
+ gem "importmap-rails"
13
+ # Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev]
14
+ gem "turbo-rails"
15
+ # Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev]
16
+ gem "stimulus-rails"
17
+ # Build JSON APIs with ease [https://github.com/rails/jbuilder]
18
+ gem "jbuilder"
19
+ gem "iodine"
20
+ gem "pg"
21
+ # Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]
22
+ # gem "bcrypt", "~> 3.1.7"
23
+
24
+ # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
25
+ gem "tzinfo-data", platforms: %i[ windows jruby ]
26
+
27
+ # Use the database-backed adapters for Rails.cache, Active Job, and Action Cable
28
+ gem "solid_cache"
29
+ gem "solid_queue"
30
+ gem "solid_cable"
31
+
32
+ # Reduces boot times through caching; required in config/boot.rb
33
+ gem "bootsnap", require: false
34
+
35
+ # Deploy this application anywhere as a Docker container [https://kamal-deploy.org]
36
+ gem "kamal", require: false
37
+
38
+ # Add HTTP asset caching/compression and X-Sendfile acceleration to Puma [https://github.com/basecamp/thruster/]
39
+ gem "thruster", require: false
40
+
41
+ # Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
42
+ # gem "image_processing", "~> 1.2"
43
+
44
+ group :development, :test do
45
+ # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
46
+ gem "debug", platforms: %i[ mri windows ], require: "debug/prelude"
47
+
48
+ # Static analysis for security vulnerabilities [https://brakemanscanner.org/]
49
+ gem "brakeman", require: false
50
+
51
+ # Omakase Ruby styling [https://github.com/rails/rubocop-rails-omakase/]
52
+ gem "rubocop-rails-omakase", require: false
53
+ end
54
+
55
+ group :development do
56
+ # Use console on exceptions pages [https://github.com/rails/web-console]
57
+ gem "web-console"
58
+ end
59
+
60
+ group :test do
61
+ # Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
62
+ gem "capybara"
63
+ gem "selenium-webdriver"
64
+ end
65
+
66
+
67
+ # gem "itsi", path: "../.."
68
+ gem "itsi-scheduler", path: "../../gems/scheduler"
69
+ gem "itsi-server", path: "../../gems/server"
70
+ gem "async"
71
+ gem "osprey_scheduler", path: "../../../osprey_scheduler"
72
+ gem "falcon"