Dockerfile 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. FROM ubuntu:20.04 as build-dep
  2. # Use bash for the shell
  3. SHELL ["/bin/bash", "-c"]
  4. RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
  5. # Install Node v16 (LTS)
  6. ENV NODE_VER="16.17.1"
  7. RUN ARCH= && \
  8. dpkgArch="$(dpkg --print-architecture)" && \
  9. case "${dpkgArch##*-}" in \
  10. amd64) ARCH='x64';; \
  11. ppc64el) ARCH='ppc64le';; \
  12. s390x) ARCH='s390x';; \
  13. arm64) ARCH='arm64';; \
  14. armhf) ARCH='armv7l';; \
  15. i386) ARCH='x86';; \
  16. *) echo "unsupported architecture"; exit 1 ;; \
  17. esac && \
  18. echo "Etc/UTC" > /etc/localtime && \
  19. apt-get update && \
  20. apt-get install -y --no-install-recommends ca-certificates wget python3 apt-utils && \
  21. cd ~ && \
  22. wget -q https://nodejs.org/download/release/v$NODE_VER/node-v$NODE_VER-linux-$ARCH.tar.gz && \
  23. tar xf node-v$NODE_VER-linux-$ARCH.tar.gz && \
  24. rm node-v$NODE_VER-linux-$ARCH.tar.gz && \
  25. mv node-v$NODE_VER-linux-$ARCH /opt/node
  26. # Install Ruby 3.0
  27. ENV RUBY_VER="3.0.4"
  28. RUN apt-get update && \
  29. apt-get install -y --no-install-recommends build-essential \
  30. bison libyaml-dev libgdbm-dev libreadline-dev libjemalloc-dev \
  31. libncurses5-dev libffi-dev zlib1g-dev libssl-dev && \
  32. cd ~ && \
  33. wget https://cache.ruby-lang.org/pub/ruby/${RUBY_VER%.*}/ruby-$RUBY_VER.tar.gz && \
  34. tar xf ruby-$RUBY_VER.tar.gz && \
  35. cd ruby-$RUBY_VER && \
  36. ./configure --prefix=/opt/ruby \
  37. --with-jemalloc \
  38. --with-shared \
  39. --disable-install-doc && \
  40. make -j"$(nproc)" > /dev/null && \
  41. make install && \
  42. rm -rf ../ruby-$RUBY_VER.tar.gz ../ruby-$RUBY_VER
  43. ENV PATH="${PATH}:/opt/ruby/bin:/opt/node/bin"
  44. RUN npm install -g npm@latest && \
  45. npm install -g yarn && \
  46. gem install bundler && \
  47. apt-get update && \
  48. apt-get install -y --no-install-recommends git libicu-dev libidn11-dev \
  49. libpq-dev shared-mime-info
  50. COPY Gemfile* package.json yarn.lock /opt/mastodon/
  51. RUN cd /opt/mastodon && \
  52. bundle config set --local deployment 'true' && \
  53. bundle config set --local without 'development test' && \
  54. bundle config set silence_root_warning true && \
  55. bundle install -j"$(nproc)" && \
  56. yarn install --pure-lockfile
  57. FROM ubuntu:20.04
  58. # Copy over all the langs needed for runtime
  59. COPY --from=build-dep /opt/node /opt/node
  60. COPY --from=build-dep /opt/ruby /opt/ruby
  61. # Add more PATHs to the PATH
  62. ENV PATH="${PATH}:/opt/ruby/bin:/opt/node/bin:/opt/mastodon/bin"
  63. # Create the mastodon user
  64. ARG UID=991
  65. ARG GID=991
  66. SHELL ["/bin/bash", "-o", "pipefail", "-c"]
  67. RUN apt-get update && \
  68. echo "Etc/UTC" > /etc/localtime && \
  69. apt-get install -y --no-install-recommends whois wget && \
  70. addgroup --gid $GID mastodon && \
  71. useradd -m -u $UID -g $GID -d /opt/mastodon mastodon && \
  72. echo "mastodon:$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 24 | mkpasswd -s -m sha-256)" | chpasswd && \
  73. rm -rf /var/lib/apt/lists/*
  74. # Install mastodon runtime deps
  75. RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
  76. RUN apt-get update && \
  77. apt-get -y --no-install-recommends install \
  78. libssl1.1 libpq5 imagemagick ffmpeg libjemalloc2 \
  79. libicu66 libidn11 libyaml-0-2 \
  80. file ca-certificates tzdata libreadline8 gcc tini apt-utils && \
  81. ln -s /opt/mastodon /mastodon && \
  82. gem install bundler && \
  83. rm -rf /var/cache && \
  84. rm -rf /var/lib/apt/lists/*
  85. # Copy over mastodon source, and dependencies from building, and set permissions
  86. COPY --chown=mastodon:mastodon . /opt/mastodon
  87. COPY --from=build-dep --chown=mastodon:mastodon /opt/mastodon /opt/mastodon
  88. # Run mastodon services in prod mode
  89. ENV RAILS_ENV="production"
  90. ENV NODE_ENV="production"
  91. # Tell rails to serve static files
  92. ENV RAILS_SERVE_STATIC_FILES="true"
  93. ENV BIND="0.0.0.0"
  94. # Set the run user
  95. USER mastodon
  96. # Precompile assets
  97. RUN cd ~ && \
  98. OTP_SECRET=precompile_placeholder SECRET_KEY_BASE=precompile_placeholder rails assets:precompile && \
  99. yarn cache clean
  100. # Set the work dir and the container entry point
  101. WORKDIR /opt/mastodon
  102. ENTRYPOINT ["/usr/bin/tini", "--"]
  103. EXPOSE 3000 4000