Dockerfile 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # we can not use the pre-built tar because the distribution is
  2. # platform specific, it makes sense to build it in the docker
  3. #### Builder
  4. FROM hexpm/elixir:1.16.0-erlang-26.2.1-alpine-3.18.4 as buildcontainer
  5. ARG MIX_ENV=small
  6. # preparation
  7. ENV MIX_ENV=$MIX_ENV
  8. ENV NODE_ENV=production
  9. ENV NODE_OPTIONS=--openssl-legacy-provider
  10. # custom ERL_FLAGS are passed for (public) multi-platform builds
  11. # to fix qemu segfault, more info: https://github.com/erlang/otp/pull/6340
  12. ARG ERL_FLAGS
  13. ENV ERL_FLAGS=$ERL_FLAGS
  14. RUN mkdir /app
  15. WORKDIR /app
  16. # install build dependencies
  17. RUN apk add --no-cache git nodejs yarn python3 npm ca-certificates wget gnupg make gcc libc-dev && \
  18. npm install npm@latest -g
  19. COPY mix.exs ./
  20. COPY mix.lock ./
  21. COPY config ./config
  22. RUN mix local.hex --force && \
  23. mix local.rebar --force && \
  24. mix deps.get --only prod && \
  25. mix deps.compile
  26. COPY assets/package.json assets/package-lock.json ./assets/
  27. COPY tracker/package.json tracker/package-lock.json ./tracker/
  28. RUN npm install --prefix ./assets && \
  29. npm install --prefix ./tracker
  30. COPY assets ./assets
  31. COPY tracker ./tracker
  32. COPY priv ./priv
  33. COPY lib ./lib
  34. COPY extra ./extra
  35. RUN npm run deploy --prefix ./tracker && \
  36. mix assets.deploy && \
  37. mix phx.digest priv/static && \
  38. mix download_country_database && \
  39. # https://hexdocs.pm/sentry/Sentry.Sources.html#module-source-code-storage
  40. mix sentry_recompile
  41. WORKDIR /app
  42. COPY rel rel
  43. RUN mix release plausible
  44. # Main Docker Image
  45. FROM alpine:3.18.4
  46. LABEL maintainer="plausible.io <hello@plausible.io>"
  47. ARG BUILD_METADATA={}
  48. ENV BUILD_METADATA=$BUILD_METADATA
  49. ENV LANG=C.UTF-8
  50. ARG MIX_ENV=small
  51. ENV MIX_ENV=$MIX_ENV
  52. RUN apk upgrade --no-cache
  53. RUN apk add --no-cache openssl ncurses libstdc++ libgcc ca-certificates
  54. COPY ./rel/docker-entrypoint.sh /entrypoint.sh
  55. RUN chmod a+x /entrypoint.sh && \
  56. adduser -h /app -u 1000 -s /bin/sh -D plausibleuser
  57. COPY --from=buildcontainer /app/_build/${MIX_ENV}/rel/plausible /app
  58. RUN chown -R plausibleuser:plausibleuser /app
  59. USER plausibleuser
  60. WORKDIR /app
  61. ENV LISTEN_IP=0.0.0.0
  62. ENTRYPOINT ["/entrypoint.sh"]
  63. EXPOSE 8000
  64. CMD ["run"]