Dockerfile 3.9 KB

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