Dockerfile 3.0 KB

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