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
|
2023-10-24 11:33:48 +03:00
|
|
|
FROM hexpm/elixir:1.15.7-erlang-26.1.2-alpine-3.18.4 as buildcontainer
|
2020-05-26 16:09:34 +03:00
|
|
|
|
|
|
|
# preparation
|
|
|
|
ENV MIX_ENV=prod
|
|
|
|
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
|
2023-02-22 11:49:43 +03:00
|
|
|
RUN apk add --no-cache git nodejs yarn python3 npm ca-certificates wget gnupg make gcc libc-dev && \
|
2022-05-27 15:24:11 +03:00
|
|
|
npm install npm@latest -g && \
|
|
|
|
npm install -g webpack
|
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 && \
|
|
|
|
mix deps.get --only prod && \
|
|
|
|
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
|
|
|
|
|
|
|
|
RUN npm run deploy --prefix ./assets && \
|
2022-05-27 15:24:11 +03:00
|
|
|
npm run deploy --prefix ./tracker && \
|
|
|
|
mix phx.digest priv/static && \
|
|
|
|
mix download_country_database && \
|
|
|
|
# https://hexdocs.pm/sentry/Sentry.Sources.html#module-source-code-storage
|
2022-10-04 10:54:24 +03:00
|
|
|
mix sentry_recompile
|
2020-05-26 16:09:34 +03:00
|
|
|
|
|
|
|
WORKDIR /app
|
|
|
|
COPY rel rel
|
|
|
|
RUN mix release plausible
|
|
|
|
|
|
|
|
# Main Docker Image
|
2023-10-24 11:33:48 +03:00
|
|
|
FROM alpine:3.18.4
|
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
|
|
|
|
|
2021-11-04 15:17:40 +03:00
|
|
|
RUN apk upgrade --no-cache
|
2021-01-13 11:31:16 +03:00
|
|
|
|
2023-02-14 13:21:37 +03:00
|
|
|
RUN apk add --no-cache openssl ncurses libstdc++ libgcc ca-certificates
|
2020-05-26 16:09:34 +03:00
|
|
|
|
2022-09-13 14:28:28 +03:00
|
|
|
COPY ./rel/docker-entrypoint.sh /entrypoint.sh
|
2020-05-26 16:09:34 +03:00
|
|
|
|
|
|
|
RUN chmod a+x /entrypoint.sh && \
|
2022-05-27 15:24:11 +03:00
|
|
|
adduser -h /app -u 1000 -s /bin/sh -D plausibleuser
|
2020-05-26 16:09:34 +03:00
|
|
|
|
|
|
|
COPY --from=buildcontainer /app/_build/prod/rel/plausible /app
|
|
|
|
RUN chown -R plausibleuser:plausibleuser /app
|
2020-10-15 11:22:04 +03:00
|
|
|
USER plausibleuser
|
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
|
2020-05-26 16:09:34 +03:00
|
|
|
CMD ["run"]
|