I’m trying to add PhoenixAnalytics by @lalabuy948 to a Phoenix project. I got it to work locally, but I can’t make it work on my Hetzner server. My guess is that I’ve got to change my Dockerfile but I’ve gone back and forth with the LLMs and I got nowhere. Hoping anyone can point me to some more troubleshooting ideas.
Let me start from the end.
In the application logs, here’s the error:
05:45:14.329 request_id=F__EY628KPIaoG4AAABD [info] GET /api/v1/
05:45:14.329 request_id=F__EY628KPIaoG4AAABD [info] Sent 200 in 481µs
05:45:15.206 [error] GenServer PhoenixAnalytics.Services.Batcher terminating
** (MatchError) no match of right hand side value: {:error, "Table 'requests' could not be found"}
(phoenix_analytics 0.2.0) lib/phoenix_analytics/repo.ex:215: PhoenixAnalytics.Repo.insert_many/1
(phoenix_analytics 0.2.0) lib/phoenix_analytics/services/batcher.ex:101: PhoenixAnalytics.Services.Batcher.handle_info/2
(stdlib 6.0) gen_server.erl:2173: :gen_server.try_handle_info/3
(stdlib 6.0) gen_server.erl:2261: :gen_server.handle_msg/6
(stdlib 6.0) proc_lib.erl:329: :proc_lib.init_p_do_apply/3
Last message: :check_batch
Coolify setup
Persistent storage
Host Server
I can see that directory if I hop on the host server
inside the Docker container
Environment Variables
I add DUCKDB_PATH as an env variable
/app/data/analytics.duckdb
Elixir setup
config.exs
Here’s the bit I added
config :phoenix_analytics,
duckdb_path: System.get_env("DUCKDB_PATH") || "/app/data/analytics.duckdb",
app_domain: System.get_env("PHX_HOST") || "reabra.com.br"
endpoint.ex
I add the following
plug Plug.Static,
at: "/",
from: :reabra,
gzip: false,
only: ReabraWeb.static_paths()
plug PhoenixAnalytics.Plugs.RequestTracker
...
router.ex
...
use PhoenixAnalytics.Web, :router
...
scope "/admin", ReabraWeb do
pipe_through [:browser, :require_authenticated_user, :require_admin]
phoenix_analytics_dashboard("/analytics")
...
Dockerfile
Here’s my Dockerfile
ARG ELIXIR_VERSION=1.17.2
ARG OTP_VERSION=27.0
ARG DEBIAN_VERSION=bullseye-20240701-slim
ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-debian-${DEBIAN_VERSION}"
ARG RUNNER_IMAGE="debian:${DEBIAN_VERSION}"
FROM ${BUILDER_IMAGE} AS builder
# install build dependencies
RUN apt-get update -y && apt-get install -y build-essential git \
&& apt-get clean && rm -f /var/lib/apt/lists/*_*
# prepare build dir
WORKDIR /app
# install hex + rebar
RUN mix local.hex --force && \
mix local.rebar --force
# set build ENV
ENV MIX_ENV="prod"
# install mix dependencies
COPY mix.exs mix.lock ./
RUN mix deps.get --only $MIX_ENV
RUN mkdir config
# copy compile-time config files before we compile dependencies
# to ensure any relevant config change will trigger the dependencies
# to be re-compiled.
COPY config/config.exs config/${MIX_ENV}.exs config/
RUN mix deps.compile
COPY priv priv
COPY lib lib
COPY assets assets
# compile assets
RUN mix assets.deploy
# Compile the release
RUN mix compile
# Changes to config/runtime.exs don't require recompiling the code
COPY config/runtime.exs config/
COPY rel rel
RUN mix release
# start a new build stage so that the final image will only contain
# the compiled release and other runtime necessities
FROM ${RUNNER_IMAGE}
ARG DUCKDB_PATH
RUN apt-get update -y && \
apt-get install -y libstdc++6 openssl libncurses5 locales ca-certificates curl wget unzip \
&& apt-get clean && rm -f /var/lib/apt/lists/*_*
# Install DuckDB
RUN wget https://github.com/duckdb/duckdb/releases/download/v1.1.2/duckdb_cli-linux-amd64.zip \
&& unzip duckdb_cli-linux-amd64.zip \
&& mv duckdb /usr/local/bin/ \
&& rm duckdb_cli-linux-amd64.zip
# Set the locale
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen
ENV LANG=en_US.UTF-8
ENV LANGUAGE=en_US:en
ENV LC_ALL=en_US.UTF-8
ENV DUCKDB_PATH=${DUCKDB_PATH}
WORKDIR "/app"
RUN mkdir -p /app/data && chown -R nobody:root /app/data
RUN touch /app/data/analytics.duckdb && chown nobody:root /app/data/analytics.duckdb
RUN chown nobody /app
# set runner ENV
ENV MIX_ENV="prod"
# Only copy the final release from the build stage
COPY --from=builder --chown=nobody:root /app/_build/${MIX_ENV}/rel/reabra ./
USER nobody
# If using an environment that doesn't automatically reap zombie processes, it is
# advised to add an init process such as tini via `apt-get install`
# above and adding an entrypoint. See https://github.com/krallin/tini for details
# ENTRYPOINT ["/tini", "--"]
# CMD ["/app/bin/server"]
CMD ["sh", "-c", "/app/bin/migrate && /app/bin/server"]
Migration
I added the necessary migration
defmodule Reabra.Repo.Migrations.AddPhoenixAnalytics do
use Ecto.Migration
def up, do: PhoenixAnalytics.Migration.up()
def down, do: PhoenixAnalytics.Migration.down()
end
FYI: There’s a nice walkthrough / demo here: