Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dockerfile and co updates #3811

Merged
merged 29 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
60641ba
wip
ruslandoga Feb 16, 2024
57698c1
more env, setup user before packages to avoid them picking our uid
ruslandoga Feb 16, 2024
2289051
make entrypoint.sh executable by all again
ruslandoga May 30, 2023
b6a9e0a
apparently it's a best practice to have executables be owned by root
ruslandoga May 30, 2023
7abc335
make entrypoint executable in COPY
ruslandoga May 30, 2023
608fd06
stop writing to /app, write to /tmp if needed
ruslandoga Oct 25, 2023
7b0635a
fewer changes
ruslandoga Feb 16, 2024
e99b63c
system user
ruslandoga Jun 1, 2023
7c459cb
keep same style for multiline commands
ruslandoga Jun 1, 2023
47a8cd0
fewer changes
ruslandoga Jun 1, 2023
64c5e01
add changelog entry
ruslandoga Feb 16, 2024
cbd0a7b
fix group assignment for plausible user
ruslandoga Jun 1, 2023
58a799b
use gid=999
ruslandoga Jun 1, 2023
74919ec
no home
ruslandoga Jun 1, 2023
925ead8
no home
ruslandoga Jun 1, 2023
bbc8cea
add gecos
ruslandoga Jun 1, 2023
fea37b1
add plausible user to nogroup instead of creating a custom one
ruslandoga Jun 2, 2023
1305b80
eh
ruslandoga Oct 25, 2023
4ddb4ae
fewer changes
ruslandoga Feb 16, 2024
55199db
fewer changes
ruslandoga Feb 16, 2024
f2f8b52
fewer changes
ruslandoga Feb 16, 2024
abcedbe
use PERSISTENT_CACHE_DIR instead of STORAGE_DIR
ruslandoga Feb 16, 2024
6b34d05
ignore more
ruslandoga Feb 16, 2024
5afde46
cleanup
ruslandoga Feb 16, 2024
12c74f0
remove hex timeout env var
ruslandoga Feb 16, 2024
cfe8d35
use ERL_FLAGS=+JMsingle true in public builds
ruslandoga Feb 16, 2024
64089b8
Merge branch 'master' into dockerfile-wip
cnkk Feb 22, 2024
13e8211
fallback to /tmp and nest under /tzdata_data/ for tzdata
ruslandoga Feb 24, 2024
d413ba9
Merge branch 'master' into dockerfile-wip
cnkk Mar 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# This file excludes paths from the Docker build context.
#
# By default, Docker's build context includes all files (and folders) in the
# current directory. Even if a file isn't copied into the container it is still sent to
# the Docker daemon.
#
# There are multiple reasons to exclude files from the build context:
#
# 1. Prevent nested folders from being copied into the container (ex: exclude
# /assets/node_modules when copying /assets)
# 2. Reduce the size of the build context and improve build time (ex. /build, /deps, /doc)
# 3. Avoid sending files containing sensitive information
#
# More information on using .dockerignore is available here:
# https://docs.docker.com/engine/reference/builder/#dockerignore-file

.dockerignore

# Ignore git, but keep git HEAD and refs to access current commit hash if needed:
#
# $ cat .git/HEAD | awk '{print ".git/"$2}' | xargs cat
# d0b8727759e1e0e7aa3d41707d12376e373d5ecc
.git
!.git/HEAD
!.git/refs

# Common development/test artifacts
/cover/
/doc/
/test/
/tmp/
.elixir_ls
plausible-report.xml
.env
.idea
*.iml
*.log
*.code-workspace
.vscode

# Mix artifacts
/_build/
/deps/
*.ez

# Generated on crash by the VM
erl_crash.dump

# If NPM crashes, it generates a log, let's ignore it too.
npm-debug.log

# Static artifacts - These should be fetched and built inside the Docker image
/assets/node_modules/
/tracker/node_modules/
/priv/static/cache_manifest.json
/priv/static/css
/priv/static/js
/priv/version.json

# Auto-generated tracker files
/priv/tracker/js/*.js

# Dializer
/priv/plts/*.plt
/priv/plts/*.plt.hash

# Geolocation databases
/priv/geodb/*.mmdb
/priv/geodb/*.mmdb.gz

# Docker volumes
.clickhouse_db_vol*
plausible_db*
2 changes: 1 addition & 1 deletion .github/workflows/build-public-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
build-args: |
MIX_ENV=small
BUILD_METADATA=${{ steps.meta.outputs.json }}
ERL_FLAGS=+JPperf true
ERL_FLAGS=+JMsingle true

- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ All notable changes to this project will be documented in this file.
- Allow custom event timeseries in stats API plausible/analytics#3505
- Fixes for sites with UTF characters in domain plausible/analytics#3560
- Fix crash when using special characters in filter plausible/analytics#3634
- Allow running the container with arbitrary UID plausible/analytics#2986

## v2.0.0 - 2023-07-12

Expand Down
13 changes: 5 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,15 @@ ENV LANG=C.UTF-8
ARG MIX_ENV=small
ENV MIX_ENV=$MIX_ENV

RUN apk upgrade --no-cache
RUN adduser -S -H -u 999 -G nogroup plausible -g 'Plausible Analytics'

RUN apk upgrade --no-cache
RUN apk add --no-cache openssl ncurses libstdc++ libgcc ca-certificates

COPY ./rel/docker-entrypoint.sh /entrypoint.sh

RUN chmod a+x /entrypoint.sh && \
adduser -h /app -u 1000 -s /bin/sh -D plausibleuser
COPY --from=buildcontainer --chmod=a+rX /app/_build/${MIX_ENV}/rel/plausible /app
COPY --chmod=755 ./rel/docker-entrypoint.sh /entrypoint.sh

COPY --from=buildcontainer /app/_build/${MIX_ENV}/rel/plausible /app
RUN chown -R plausibleuser:plausibleuser /app
USER plausibleuser
USER 999
WORKDIR /app
ENV LISTEN_IP=0.0.0.0
ENTRYPOINT ["/entrypoint.sh"]
Expand Down
8 changes: 3 additions & 5 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ ip_geolocation_db = get_var_from_path_or_env(config_dir, "IP_GEOLOCATION_DB", ge
geonames_source_file = get_var_from_path_or_env(config_dir, "GEONAMES_SOURCE_FILE")
maxmind_license_key = get_var_from_path_or_env(config_dir, "MAXMIND_LICENSE_KEY")
maxmind_edition = get_var_from_path_or_env(config_dir, "MAXMIND_EDITION", "GeoLite2-City")
maxmind_cache_dir = get_var_from_path_or_env(config_dir, "PERSISTENT_CACHE_DIR")
persistent_cache_dir = get_var_from_path_or_env(config_dir, "PERSISTENT_CACHE_DIR")

if System.get_env("DISABLE_AUTH") do
Logger.warning("DISABLE_AUTH env var is no longer supported")
Expand Down Expand Up @@ -637,7 +637,7 @@ geo_opts =
[
license_key: maxmind_license_key,
edition: maxmind_edition,
cache_dir: maxmind_cache_dir,
cache_dir: persistent_cache_dir,
async: true
]

Expand Down Expand Up @@ -689,9 +689,7 @@ else
traces_exporter: :none
end

config :tzdata,
:data_dir,
get_var_from_path_or_env(config_dir, "STORAGE_DIR", Application.app_dir(:tzdata, "priv"))
config :tzdata, :data_dir, Path.join(persistent_cache_dir || System.tmp_dir!(), "tzdata_data")

# Temporarily disable tzdata auto-updating
config :tzdata, :autoupdate, :disabled
Expand Down
21 changes: 13 additions & 8 deletions lib/plausible/geo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ defmodule Plausible.Geo do
* `:edition` - the name of the MaxMind database to be downloaded from MaxMind
servers. Defaults to `GeoLite2-City`.

* `:cache_dir` - if set, the downloaded .mmdb files are cached there across
restarts.

* `:async` - when used, configures the database loading to run
asynchronously.

Expand All @@ -42,17 +45,19 @@ defmodule Plausible.Geo do
cond do
license_key = opts[:license_key] ->
edition = opts[:edition] || "GeoLite2-City"
maxmind_opts = [license_key: license_key]

if is_binary(opts[:cache_dir]) do
:ok =
:locus.start_loader(@db, {:maxmind, edition},
license_key: license_key,
loader_opts =
if is_binary(opts[:cache_dir]) do
[
database_cache_file:
String.to_charlist(Path.join(opts[:cache_dir], edition <> ".mmdb.gz"))
)
else
:ok = :locus.start_loader(@db, {:maxmind, edition}, license_key: license_key)
end
]
else
[:no_cache]
end

:ok = :locus.start_loader(@db, {:maxmind, edition}, maxmind_opts ++ loader_opts)

path = opts[:path] ->
:ok = :locus.start_loader(@db, path)
Expand Down