2020-05-26 16:09:34 +03:00
|
|
|
# we can not use the pre-built tar because the distribution is
|
|
|
|
# platform specific, it makes sense to build it in the docker
|
|
|
|
|
|
|
|
#### Builder
|
2024-08-28 14:11:37 +03:00
|
|
|
FROM hexpm/elixir:1.17.1-erlang-27.0-alpine-3.20.1 AS buildcontainer
|
2020-05-26 16:09:34 +03:00
|
|
|
|
2024-04-29 09:05:33 +03:00
|
|
|
ARG MIX_ENV=ce
|
2023-11-30 14:39:34 +03:00
|
|
|
|
2020-05-26 16:09:34 +03:00
|
|
|
# preparation
|
2023-11-30 14:39:34 +03:00
|
|
|
ENV MIX_ENV=$MIX_ENV
|
2020-05-26 16:09:34 +03:00
|
|
|
ENV NODE_ENV=production
|
2023-02-22 11:49:43 +03:00
|
|
|
ENV NODE_OPTIONS=--openssl-legacy-provider
|
2020-05-26 16:09:34 +03:00
|
|
|
|
2023-05-03 14:13:22 +03:00
|
|
|
# custom ERL_FLAGS are passed for (public) multi-platform builds
|
|
|
|
# to fix qemu segfault, more info: https://github.com/erlang/otp/pull/6340
|
|
|
|
ARG ERL_FLAGS
|
|
|
|
ENV ERL_FLAGS=$ERL_FLAGS
|
|
|
|
|
2020-05-26 16:09:34 +03:00
|
|
|
RUN mkdir /app
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
|
# install build dependencies
|
2024-09-03 14:54:11 +03:00
|
|
|
RUN apk add --no-cache git nodejs yarn python3 npm ca-certificates wget gnupg make gcc libc-dev brotli && \
|
2023-11-01 17:27:29 +03:00
|
|
|
npm install npm@latest -g
|
2020-05-26 16:09:34 +03:00
|
|
|
|
|
|
|
COPY mix.exs ./
|
|
|
|
COPY mix.lock ./
|
2022-09-21 14:42:22 +03:00
|
|
|
COPY config ./config
|
2020-05-26 16:09:34 +03:00
|
|
|
RUN mix local.hex --force && \
|
2022-05-27 15:24:11 +03:00
|
|
|
mix local.rebar --force && \
|
2024-06-25 08:13:59 +03:00
|
|
|
mix deps.get --only ${MIX_ENV} && \
|
2022-05-27 15:24:11 +03:00
|
|
|
mix deps.compile
|
2020-05-26 16:09:34 +03:00
|
|
|
|
2020-10-05 15:01:54 +03:00
|
|
|
COPY assets/package.json assets/package-lock.json ./assets/
|
|
|
|
COPY tracker/package.json tracker/package-lock.json ./tracker/
|
|
|
|
|
2021-05-12 13:07:55 +03:00
|
|
|
RUN npm install --prefix ./assets && \
|
2022-05-27 15:24:11 +03:00
|
|
|
npm install --prefix ./tracker
|
2020-10-05 15:01:54 +03:00
|
|
|
|
|
|
|
COPY assets ./assets
|
|
|
|
COPY tracker ./tracker
|
|
|
|
COPY priv ./priv
|
|
|
|
COPY lib ./lib
|
2023-11-20 15:21:56 +03:00
|
|
|
COPY extra ./extra
|
2020-10-05 15:01:54 +03:00
|
|
|
|
2023-11-01 17:27:29 +03:00
|
|
|
RUN npm run deploy --prefix ./tracker && \
|
|
|
|
mix assets.deploy && \
|
2022-05-27 15:24:11 +03:00
|
|
|
mix phx.digest priv/static && \
|
|
|
|
mix download_country_database && \
|
2024-03-18 12:10:20 +03:00
|
|
|
mix sentry.package_source_code
|
2020-05-26 16:09:34 +03:00
|
|
|
|
|
|
|
WORKDIR /app
|
|
|
|
COPY rel rel
|
|
|
|
RUN mix release plausible
|
|
|
|
|
|
|
|
# Main Docker Image
|
2024-08-28 14:11:37 +03:00
|
|
|
FROM alpine:3.20.1
|
2023-02-22 11:49:43 +03:00
|
|
|
LABEL maintainer="plausible.io <hello@plausible.io>"
|
2022-05-27 15:24:11 +03:00
|
|
|
|
|
|
|
ARG BUILD_METADATA={}
|
|
|
|
ENV BUILD_METADATA=$BUILD_METADATA
|
2020-05-26 16:09:34 +03:00
|
|
|
ENV LANG=C.UTF-8
|
2024-04-29 09:05:33 +03:00
|
|
|
ARG MIX_ENV=ce
|
2023-11-30 14:39:34 +03:00
|
|
|
ENV MIX_ENV=$MIX_ENV
|
2020-05-26 16:09:34 +03:00
|
|
|
|
2024-05-23 10:43:01 +03:00
|
|
|
RUN adduser -S -H -u 999 -G nogroup plausible
|
2021-01-13 11:31:16 +03:00
|
|
|
|
2024-03-08 17:33:55 +03:00
|
|
|
RUN apk upgrade --no-cache
|
2024-09-10 15:15:43 +03:00
|
|
|
RUN apk add --no-cache openssl ncurses libstdc++ libgcc ca-certificates \
|
|
|
|
&& if [ "$MIX_ENV" = "ce" ]; then apk add --no-cache certbot; fi
|
2020-05-26 16:09:34 +03:00
|
|
|
|
2024-03-08 17:33:55 +03:00
|
|
|
COPY --from=buildcontainer --chmod=a+rX /app/_build/${MIX_ENV}/rel/plausible /app
|
|
|
|
COPY --chmod=755 ./rel/docker-entrypoint.sh /entrypoint.sh
|
2020-05-26 16:09:34 +03:00
|
|
|
|
2024-08-28 14:44:53 +03:00
|
|
|
# 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
|
|
|
|
|
2024-03-08 17:33:55 +03:00
|
|
|
USER 999
|
2020-05-26 16:09:34 +03:00
|
|
|
WORKDIR /app
|
2022-01-21 23:23:09 +03:00
|
|
|
ENV LISTEN_IP=0.0.0.0
|
2020-05-26 16:09:34 +03:00
|
|
|
ENTRYPOINT ["/entrypoint.sh"]
|
2021-02-05 12:27:44 +03:00
|
|
|
EXPOSE 8000
|
2024-08-28 14:44:53 +03:00
|
|
|
ENV DEFAULT_DATA_DIR=/var/lib/plausible
|
|
|
|
VOLUME /var/lib/plausible
|
2020-05-26 16:09:34 +03:00
|
|
|
CMD ["run"]
|