sergiotapia / magnetissimo

Web application that indexes all popular torrent sites, and saves it to the local database.
MIT License
2.98k stars 187 forks source link

Add Docker Compose file #148

Closed loganmarchione closed 1 year ago

loganmarchione commented 1 year ago

This is a basic docker-compose.yml file. A couple things:

  1. Because the images aren't published to DockerHub or GHCR, I'm having to use the build element to build the image each time (this takes about a minute on a modern-ish laptop). Ideally, you would pre-build and publish the images for users to consume.
  2. What is SECRET_KEY_BASE? The app wouldn't start unless I set an environment variable for SECRET_KEY_BASE.

    ERROR! Config provider Config.Reader failed with:
    ** (RuntimeError) environment variable SECRET_KEY_BASE is missing.
    You can generate one by calling: mix phx.gen.secret
    
    /app/releases/2.0.0/runtime.exs:46: (file)
    (elixir 1.14.4) src/elixir.erl:309: anonymous fn/4 in :elixir.eval_external_handler/1
    (stdlib 4.1.1) erl_eval.erl:748: :erl_eval.do_apply/7
    (stdlib 4.1.1) erl_eval.erl:492: :erl_eval.expr/6
    (stdlib 4.1.1) erl_eval.erl:136: :erl_eval.exprs/6
    (elixir 1.14.4) src/elixir.erl:294: :elixir.eval_forms/4
    (elixir 1.14.4) lib/module/parallel_checker.ex:110: Module.ParallelChecker.verify/1
    (elixir 1.14.4) lib/code.ex:425: Code.validated_eval_string/3
  3. When I had the SECRET_KEY_BASE set to asdf, it complained that it was too short. I had to run openssl rand -hex 32 to generate a key. Does this need to stay static for the life of the database? What kind of characters should make up this key? Is 64 characters enough, or should it be longer?
    23:56:46.653 request_id=F1Wj3UYqF21tkncAAABB [info] GET /
    23:56:46.661 request_id=F1Wj3UYqF21tkncAAABB [info] Sent 500 in 8ms
    23:56:46.661 [error] #PID<0.2601.0> running MagnetissimoWeb.Endpoint (connection #PID<0.2600.0>, stream id 1) terminated
    Server: localhost:4000 (http)
    Request: GET /
    ** (exit) an exception was raised:
    ** (ArgumentError) cookie store expects conn.secret_key_base to be at least 64 bytes
        (plug 1.14.2) lib/plug/session/cookie.ex:185: Plug.Session.COOKIE.validate_secret_key_base/1
        (plug 1.14.2) lib/plug/session/cookie.ex:177: Plug.Session.COOKIE.derive/3
        (plug 1.14.2) lib/plug/session/cookie.ex:96: Plug.Session.COOKIE.put/4
        (plug 1.14.2) lib/plug/session.ex:96: anonymous fn/3 in Plug.Session.before_send/2
        (elixir 1.14.4) lib/enum.ex:2468: Enum."-reduce/3-lists^foldl/2-0-"/3
        (plug 1.14.2) lib/plug/conn.ex:1836: Plug.Conn.run_before_send/2
        (plug 1.14.2) lib/plug/conn.ex:443: Plug.Conn.send_resp/1
        (phoenix 1.7.2) lib/phoenix/router.ex:430: Phoenix.Router.__call__/5
  4. Maybe it's just me, but the app loaded on http://localhost:4000, but kept saying We can't find the internet...
sergiotapia commented 1 year ago

@loganmarchione thanks for the PR! You can run mix phx.gen.secret and use that value for the env var. It should be static and not regenerated every time you run the app.

loganmarchione commented 1 year ago

I'm not a developer and I don't want to install Elixir/Mix/Phoenix/Hex on my machine (and I'm sure most users won't want to either). What are the requirements of the SECRET_KEY_BASE string? Length? Character sets?

I had to use this really long, ugly command to run mix phx.gen.secret in Docker.

docker run -it --rm elixir /bin/bash -c "mix local.hex --force && \
mix archive.install --force hex phx_new && \
mix phx.new --no-install test && \
cd test && \
mix local.rebar --force && \
mix deps.get && \
mix phx.gen.secret"

If we can use a different program that most users have installed, like openssl or md5sum, to generate random strings, that would be easier (some examples here).

sergiotapia commented 1 year ago

For sure, the only requirement is a 32 to 64 length string. Good idea!

sergiotapia commented 1 year ago

Thanks again @loganmarchione merging this and making some small tweaks to it.