Dockerfile 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. # syntax=docker/dockerfile:1.4
  2. # This needs to be bullseye-slim because the Ruby image is built on bullseye-slim
  3. ARG NODE_VERSION="16.20-bullseye-slim"
  4. FROM ghcr.io/moritzheiber/ruby-jemalloc:3.2.2-slim as ruby
  5. FROM node:${NODE_VERSION} as build
  6. COPY --link --from=ruby /opt/ruby /opt/ruby
  7. ENV DEBIAN_FRONTEND="noninteractive" \
  8. PATH="${PATH}:/opt/ruby/bin"
  9. SHELL ["/bin/bash", "-o", "pipefail", "-c"]
  10. WORKDIR /opt/mastodon
  11. COPY Gemfile* package.json yarn.lock /opt/mastodon/
  12. # hadolint ignore=DL3008
  13. RUN apt-get update && \
  14. apt-get install -y --no-install-recommends build-essential \
  15. git \
  16. libicu-dev \
  17. libidn11-dev \
  18. libpq-dev \
  19. libjemalloc-dev \
  20. zlib1g-dev \
  21. libgdbm-dev \
  22. libgmp-dev \
  23. libssl-dev \
  24. libyaml-0-2 \
  25. ca-certificates \
  26. libreadline8 \
  27. python3 \
  28. shared-mime-info && \
  29. bundle config set --local deployment 'true' && \
  30. bundle config set --local without 'development test' && \
  31. bundle config set silence_root_warning true && \
  32. bundle install -j"$(nproc)" && \
  33. yarn install --pure-lockfile --production --network-timeout 600000 && \
  34. yarn cache clean
  35. FROM node:${NODE_VERSION}
  36. # Use those args to specify your own version flags & suffixes
  37. ARG MASTODON_VERSION_FLAGS=""
  38. ARG MASTODON_VERSION_SUFFIX=""
  39. ARG UID="991"
  40. ARG GID="991"
  41. COPY --link --from=ruby /opt/ruby /opt/ruby
  42. SHELL ["/bin/bash", "-o", "pipefail", "-c"]
  43. ENV DEBIAN_FRONTEND="noninteractive" \
  44. PATH="${PATH}:/opt/ruby/bin:/opt/mastodon/bin"
  45. # Ignoring these here since we don't want to pin any versions and the Debian image removes apt-get content after use
  46. # hadolint ignore=DL3008,DL3009
  47. RUN apt-get update && \
  48. echo "Etc/UTC" > /etc/localtime && \
  49. groupadd -g "${GID}" mastodon && \
  50. useradd -l -u "$UID" -g "${GID}" -m -d /opt/mastodon mastodon && \
  51. apt-get -y --no-install-recommends install whois \
  52. wget \
  53. procps \
  54. libssl1.1 \
  55. libpq5 \
  56. imagemagick \
  57. ffmpeg \
  58. libjemalloc2 \
  59. libicu67 \
  60. libidn11 \
  61. libyaml-0-2 \
  62. file \
  63. ca-certificates \
  64. tzdata \
  65. libreadline8 \
  66. tini && \
  67. ln -s /opt/mastodon /mastodon
  68. # Note: no, cleaning here since Debian does this automatically
  69. # See the file /etc/apt/apt.conf.d/docker-clean within the Docker image's filesystem
  70. COPY --chown=mastodon:mastodon . /opt/mastodon
  71. COPY --chown=mastodon:mastodon --from=build /opt/mastodon /opt/mastodon
  72. ENV RAILS_ENV="production" \
  73. NODE_ENV="production" \
  74. RAILS_SERVE_STATIC_FILES="true" \
  75. BIND="0.0.0.0" \
  76. MASTODON_VERSION_FLAGS="${MASTODON_VERSION_FLAGS}" \
  77. MASTODON_VERSION_SUFFIX="${MASTODON_VERSION_SUFFIX}"
  78. # Set the run user
  79. USER mastodon
  80. WORKDIR /opt/mastodon
  81. # Precompile assets
  82. RUN OTP_SECRET=precompile_placeholder SECRET_KEY_BASE=precompile_placeholder rails assets:precompile
  83. # Set the work dir and the container entry point
  84. ENTRYPOINT ["/usr/bin/tini", "--"]
  85. EXPOSE 3000 4000