Advertisement
Guest User

Untitled

a guest
Jan 11th, 2022
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 2.60 KB | None | 0 0
  1. # Find eligible builder and runner images on Docker Hub. We use Ubuntu/Debian instead of
  2. # Alpine to avoid DNS resolution issues in production.
  3. #
  4. # https://hub.docker.com/r/hexpm/elixir/tags?page=1&name=ubuntu
  5. # https://hub.docker.com/_/ubuntu?tab=tags
  6. #
  7. #
  8. # This file is based on these images:
  9. #
  10. #   - https://hub.docker.com/r/hexpm/elixir/tags - for the build image
  11. #   - https://hub.docker.com/_/debian?tab=tags&page=1&name=bullseye-20210902-slim - for the release image
  12. #   - https://pkgs.org/ - resource for finding needed packages
  13. #   - Ex: hexpm/elixir:1.13.1-erlang-24.2-debian-bullseye-20210902-slim
  14. #
  15. ARG BUILDER_IMAGE="hexpm/elixir:1.13.1-erlang-24.2-debian-bullseye-20210902-slim"
  16. ARG RUNNER_IMAGE="debian:bullseye-20210902-slim"
  17.  
  18. FROM ${BUILDER_IMAGE} as builder
  19.  
  20. # install build dependencies
  21. RUN apt-get update -y && apt-get install -y build-essential git npm \
  22.   && apt-get clean && rm -f /var/lib/apt/lists/*_*
  23.  
  24. # prepare build dir
  25. WORKDIR /app
  26.  
  27. # install hex + rebar
  28. RUN mix local.hex --force && \
  29.   mix local.rebar --force
  30.  
  31. # set build ENV
  32. ENV MIX_ENV="prod"
  33.  
  34. # install mix dependencies
  35. COPY mix.exs mix.lock ./
  36. RUN mix deps.get --only $MIX_ENV
  37. RUN mkdir config
  38.  
  39. # copy compile-time config files before we compile dependencies
  40. # to ensure any relevant config change will trigger the dependencies
  41. # to be re-compiled.
  42. COPY config/config.exs config/${MIX_ENV}.exs config/
  43. RUN mix deps.compile
  44.  
  45. COPY priv priv
  46.  
  47. # note: if your project uses a tool like https://purgecss.com/,
  48. # which customizes asset compilation based on what it finds in
  49. # your Elixir templates, you will need to move the asset compilation
  50. # step down so that `lib` is available.
  51. COPY assets assets
  52.  
  53. # compile assets
  54. RUN cd assets && npm install
  55. RUN mix assets.deploy
  56.  
  57. # Compile the release
  58. COPY lib lib
  59.  
  60. RUN mix compile
  61.  
  62. # Changes to config/runtime.exs don't require recompiling the code
  63. COPY config/runtime.exs config/
  64.  
  65. COPY rel rel
  66. RUN mix release
  67.  
  68. # start a new build stage so that the final image will only contain
  69. # the compiled release and other runtime necessities
  70. FROM ${RUNNER_IMAGE}
  71.  
  72. RUN apt-get update -y && apt-get install -y libstdc++6 openssl libncurses5 locales \
  73.   && apt-get clean && rm -f /var/lib/apt/lists/*_*
  74.  
  75. # Set the locale
  76. RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen
  77.  
  78. ENV LANG en_US.UTF-8
  79. ENV LANGUAGE en_US:en
  80. ENV LC_ALL en_US.UTF-8
  81.  
  82. WORKDIR "/app"
  83. RUN chown nobody /app
  84.  
  85. # Only copy the final release from the build stage
  86. COPY --from=builder --chown=nobody:root /app/_build/prod/rel/wb_portfolio ./
  87.  
  88. USER nobody
  89.  
  90. CMD ["/app/bin/server"]
  91.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement