Commit ·
acb29be
1
Parent(s): 9fc140a
fix: Configure ChromicPDF for all environments
Browse files- README.md +1 -0
- config/prod.exs +3 -0
- config/test.exs +2 -0
- lib/medicode/application.ex +46 -37
README.md
CHANGED
|
@@ -13,6 +13,7 @@ To start your Phoenix server:
|
|
| 13 |
|
| 14 |
- Run `mix setup` to install and setup dependencies
|
| 15 |
- Run `mix build_code_vectors` to download the ICD-9 codelist, precompute vectors, and store the results in the database.
|
|
|
|
| 16 |
- Start Phoenix endpoint with `mix phx.server` or inside IEx with `iex -S mix phx.server`
|
| 17 |
|
| 18 |
Now you can visit [`localhost:4000`](http://localhost:4000) from your browser.
|
|
|
|
| 13 |
|
| 14 |
- Run `mix setup` to install and setup dependencies
|
| 15 |
- Run `mix build_code_vectors` to download the ICD-9 codelist, precompute vectors, and store the results in the database.
|
| 16 |
+
- PDF generation is managed with [ChromicPDF](https://github.com/bitcrowd/chromic_pdf/tree/2c13cd2690204e6a30d817e72a3d1ef13e8a2441) which assumes an executable is available at [these locations](https://github.com/bitcrowd/chromic_pdf/blob/2c13cd2690204e6a30d817e72a3d1ef13e8a2441/lib/chromic_pdf/pdf/chrome_runner.ex#L64). If you are having trouble getting Chrome to launch, this [StackExchange](https://apple.stackexchange.com/a/467415) was useful.
|
| 17 |
- Start Phoenix endpoint with `mix phx.server` or inside IEx with `iex -S mix phx.server`
|
| 18 |
|
| 19 |
Now you can visit [`localhost:4000`](http://localhost:4000) from your browser.
|
config/prod.exs
CHANGED
|
@@ -16,5 +16,8 @@ config :swoosh, local: false
|
|
| 16 |
# Do not print debug messages in production
|
| 17 |
config :logger, level: :info
|
| 18 |
|
|
|
|
|
|
|
|
|
|
| 19 |
# Runtime production configuration, including reading
|
| 20 |
# of environment variables, is done on config/runtime.exs.
|
|
|
|
| 16 |
# Do not print debug messages in production
|
| 17 |
config :logger, level: :info
|
| 18 |
|
| 19 |
+
# NOTE: This path is the default from `apt-get install google-chrome-stable_current_amd64.deb` as found in Dockerfile
|
| 20 |
+
config :medicode, chrome_executable: "/usr/bin/google-chrome"
|
| 21 |
+
|
| 22 |
# Runtime production configuration, including reading
|
| 23 |
# of environment variables, is done on config/runtime.exs.
|
config/test.exs
CHANGED
|
@@ -39,3 +39,5 @@ config :logger, level: :warning
|
|
| 39 |
|
| 40 |
# Initialize plugs at runtime for faster test compilation
|
| 41 |
config :phoenix, :plug_init_mode, :runtime
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
# Initialize plugs at runtime for faster test compilation
|
| 41 |
config :phoenix, :plug_init_mode, :runtime
|
| 42 |
+
|
| 43 |
+
config :medicode, skip_chromic_pdf: true
|
lib/medicode/application.ex
CHANGED
|
@@ -10,31 +10,32 @@ defmodule Medicode.Application do
|
|
| 10 |
|
| 11 |
@impl true
|
| 12 |
def start(_type, _args) do
|
| 13 |
-
children =
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
|
|
|
| 38 |
|
| 39 |
# See https://hexdocs.pm/elixir/Supervisor.html
|
| 40 |
# for other strategies and supported options
|
|
@@ -62,17 +63,25 @@ defmodule Medicode.Application do
|
|
| 62 |
Vectors.child_spec(Medicode.TextEmbeddingServing)
|
| 63 |
end
|
| 64 |
|
| 65 |
-
defp
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
end
|
| 78 |
end
|
|
|
|
| 10 |
|
| 11 |
@impl true
|
| 12 |
def start(_type, _args) do
|
| 13 |
+
children =
|
| 14 |
+
[
|
| 15 |
+
MedicodeWeb.Telemetry,
|
| 16 |
+
Medicode.Repo,
|
| 17 |
+
{DNSCluster, query: Application.get_env(:medicode, :dns_cluster_query) || :ignore},
|
| 18 |
+
{Phoenix.PubSub, name: :medicode_pubsub},
|
| 19 |
+
# Start the Finch HTTP client for sending emails
|
| 20 |
+
{Finch, name: Medicode.Finch},
|
| 21 |
+
transcription_spec(),
|
| 22 |
+
token_classification_spec(),
|
| 23 |
+
text_embedding_spec(),
|
| 24 |
+
{Registry, keys: :unique, name: :transcription_registry},
|
| 25 |
+
{
|
| 26 |
+
Medicode.TranscriptionSupervisor,
|
| 27 |
+
strategy: :one_for_one, max_restarts: 1
|
| 28 |
+
},
|
| 29 |
+
{
|
| 30 |
+
Medicode.ClassificationSupervisor,
|
| 31 |
+
strategy: :one_for_one, max_restarts: 1
|
| 32 |
+
}
|
| 33 |
+
] ++ chromic_pdf_spec()
|
| 34 |
+
|
| 35 |
+
# Start a worker by calling: Medicode.Worker.start_link(arg)
|
| 36 |
+
# {Medicode.Worker, arg},
|
| 37 |
+
# Start to serve requests, typically the last entry
|
| 38 |
+
children = children ++ [MedicodeWeb.Endpoint]
|
| 39 |
|
| 40 |
# See https://hexdocs.pm/elixir/Supervisor.html
|
| 41 |
# for other strategies and supported options
|
|
|
|
| 63 |
Vectors.child_spec(Medicode.TextEmbeddingServing)
|
| 64 |
end
|
| 65 |
|
| 66 |
+
defp chromic_pdf_spec do
|
| 67 |
+
if Application.get_env(:medicode, :skip_chromic_pdf, false) do
|
| 68 |
+
[]
|
| 69 |
+
else
|
| 70 |
+
# NOTE: Security implications of using Chrome:
|
| 71 |
+
# https://github.com/bitcrowd/chromic_pdf/blob/2c13cd2690204e6a30d817e72a3d1ef13e8a2441/lib/chromic_pdf.ex#L71
|
| 72 |
+
#
|
| 73 |
+
# `chrome_executable` recommendation found here:
|
| 74 |
+
# https://community.fly.io/t/cant-install-chrome-chromium-via-dockerfile-or-ssh/5303/6
|
| 75 |
+
[
|
| 76 |
+
{ChromicPDF,
|
| 77 |
+
[
|
| 78 |
+
disable_scripts: true,
|
| 79 |
+
offline: true,
|
| 80 |
+
no_sandbox: true,
|
| 81 |
+
chrome_executable: Application.get_env(:medicode, :chrome_executable) || nil,
|
| 82 |
+
discard_stderr: false
|
| 83 |
+
]}
|
| 84 |
+
]
|
| 85 |
+
end
|
| 86 |
end
|
| 87 |
end
|