Skip to content

Commit

Permalink
add /var/lib/plausible
Browse files Browse the repository at this point in the history
  • Loading branch information
ruslandoga committed Aug 28, 2024
1 parent 8b06c91 commit 893d0e5
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,15 @@ RUN apk add --no-cache openssl ncurses libstdc++ libgcc ca-certificates
COPY --from=buildcontainer --chmod=a+rX /app/_build/${MIX_ENV}/rel/plausible /app
COPY --chmod=755 ./rel/docker-entrypoint.sh /entrypoint.sh

# we need to allow "others" access to app folder, because
# docker container can be started with arbitrary uid
RUN mkdir -p /var/lib/plausible && chmod ugo+rw -R /var/lib/plausible

USER 999
WORKDIR /app
ENV LISTEN_IP=0.0.0.0
ENTRYPOINT ["/entrypoint.sh"]
EXPOSE 8000
ENV DEFAULT_DATA_DIR=/var/lib/plausible
VOLUME /var/lib/plausible
CMD ["run"]
3 changes: 2 additions & 1 deletion config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ maxmind_edition = get_var_from_path_or_env(config_dir, "MAXMIND_EDITION", "GeoLi
data_dir = get_var_from_path_or_env(config_dir, "DATA_DIR")
persistent_cache_dir = get_var_from_path_or_env(config_dir, "PERSISTENT_CACHE_DIR")

data_dir = data_dir || persistent_cache_dir
# DEFAULT_DATA_DIR comes from the container image, please see our Dockerfile
data_dir = data_dir || persistent_cache_dir || System.get_env("DEFAULT_DATA_DIR")
persistent_cache_dir = persistent_cache_dir || data_dir

enable_email_verification =
Expand Down
4 changes: 3 additions & 1 deletion lib/plausible/imported/csv_importer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,9 @@ defmodule Plausible.Imported.CSVImporter do
@doc """
Returns local directory for CSV imports storage.
Builds upon `$DATA_DIR` or `$PERSISTENT_CACHE_DIR` (if set) and falls back to /tmp
Builds upon `$DATA_DIR`, `$PERSISTENT_CACHE_DIR` or `$DEFAULT_DATA_DIR` (if set) and falls back to /tmp.
`$DEFAULT_DATA_DIR` is set to `/var/lib/plausible` in container images.
Examples:
Expand Down
36 changes: 36 additions & 0 deletions test/plausible/config_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,42 @@ defmodule Plausible.ConfigTest do
end

describe "storage" do
test "defaults" do

Check failure on line 298 in test/plausible/config_test.exs

View workflow job for this annotation

GitHub Actions / Build and test (ce_test, postgres:16)

test storage defaults (Plausible.ConfigTest)

Check failure on line 298 in test/plausible/config_test.exs

View workflow job for this annotation

GitHub Actions / Build and test (test, postgres:15)

test storage defaults (Plausible.ConfigTest)
env = [
{"MAXMIND_LICENSE_KEY", "abc"},
{"PERSISTENT_CACHE_DIR", nil},
{"DATA_DIR", nil}
]

config = runtime_config(env)

# exports/imports
assert get_in(config, [:plausible, :data_dir]) == nil
# locus (mmdb cache)
assert get_in(config, [:plausible, Plausible.Geo, :cache_dir]) == "/var/lib/plausible"
# tzdata (timezones cache)
assert get_in(config, [:tzdata, :data_dir]) == "/var/lib/plausible/tzdata_data"
end

test "defaults in container" do
env = [
{"MAXMIND_LICENSE_KEY", "abc"},
{"PERSISTENT_CACHE_DIR", nil},
{"DATA_DIR", nil},
# please see our Dockerfile
{"DEFAULT_DATA_DIR", "/var/lib/plausible"}
]

config = runtime_config(env)

# exports/imports
assert get_in(config, [:plausible, :data_dir]) == "/var/lib/plausible"
# locus (mmdb cache)
assert get_in(config, [:plausible, Plausible.Geo, :cache_dir]) == "/var/lib/plausible"
# tzdata (timezones cache)
assert get_in(config, [:tzdata, :data_dir]) == "/var/lib/plausible/tzdata_data"
end

test "with only DATA_DIR set" do
env = [
{"MAXMIND_LICENSE_KEY", "abc"},
Expand Down

0 comments on commit 893d0e5

Please sign in to comment.