You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

125 lines
3.7 KiB

  1. FROM ubuntu:18.04 as build-dep
  2. # Use bash for the shell
  3. SHELL ["bash", "-c"]
  4. # Install Node
  5. ENV NODE_VER="12.11.1"
  6. RUN echo "Etc/UTC" > /etc/localtime && \
  7. apt update && \
  8. apt -y install wget python && \
  9. cd ~ && \
  10. wget https://nodejs.org/download/release/v$NODE_VER/node-v$NODE_VER-linux-x64.tar.gz && \
  11. tar xf node-v$NODE_VER-linux-x64.tar.gz && \
  12. rm node-v$NODE_VER-linux-x64.tar.gz && \
  13. mv node-v$NODE_VER-linux-x64 /opt/node
  14. # Install jemalloc
  15. ENV JE_VER="5.2.1"
  16. RUN apt update && \
  17. apt -y install make autoconf gcc g++ && \
  18. cd ~ && \
  19. wget https://github.com/jemalloc/jemalloc/archive/$JE_VER.tar.gz && \
  20. tar xf $JE_VER.tar.gz && \
  21. cd jemalloc-$JE_VER && \
  22. ./autogen.sh && \
  23. ./configure --prefix=/opt/jemalloc && \
  24. make -j$(nproc) > /dev/null && \
  25. make install_bin install_include install_lib
  26. # Install ruby
  27. ENV RUBY_VER="2.6.5"
  28. ENV CPPFLAGS="-I/opt/jemalloc/include"
  29. ENV LDFLAGS="-L/opt/jemalloc/lib/"
  30. RUN apt update && \
  31. apt -y install build-essential \
  32. bison libyaml-dev libgdbm-dev libreadline-dev \
  33. libncurses5-dev libffi-dev zlib1g-dev libssl-dev && \
  34. cd ~ && \
  35. wget https://cache.ruby-lang.org/pub/ruby/${RUBY_VER%.*}/ruby-$RUBY_VER.tar.gz && \
  36. tar xf ruby-$RUBY_VER.tar.gz && \
  37. cd ruby-$RUBY_VER && \
  38. ./configure --prefix=/opt/ruby \
  39. --with-jemalloc \
  40. --with-shared \
  41. --disable-install-doc && \
  42. ln -s /opt/jemalloc/lib/* /usr/lib/ && \
  43. make -j$(nproc) > /dev/null && \
  44. make install
  45. ENV PATH="${PATH}:/opt/ruby/bin:/opt/node/bin"
  46. RUN npm install -g yarn && \
  47. gem install bundler && \
  48. apt update && \
  49. apt -y install git libicu-dev libidn11-dev \
  50. libpq-dev libprotobuf-dev protobuf-compiler
  51. COPY Gemfile* package.json yarn.lock /opt/mastodon/
  52. RUN cd /opt/mastodon && \
  53. bundle install -j$(nproc) --deployment --without development test && \
  54. yarn install --pure-lockfile
  55. FROM ubuntu:18.04
  56. # Copy over all the langs needed for runtime
  57. COPY --from=build-dep /opt/node /opt/node
  58. COPY --from=build-dep /opt/ruby /opt/ruby
  59. COPY --from=build-dep /opt/jemalloc /opt/jemalloc
  60. # Add more PATHs to the PATH
  61. ENV PATH="${PATH}:/opt/ruby/bin:/opt/node/bin:/opt/mastodon/bin"
  62. # Create the mastodon user
  63. ARG UID=991
  64. ARG GID=991
  65. RUN apt update && \
  66. echo "Etc/UTC" > /etc/localtime && \
  67. ln -s /opt/jemalloc/lib/* /usr/lib/ && \
  68. apt install -y whois wget && \
  69. addgroup --gid $GID mastodon && \
  70. useradd -m -u $UID -g $GID -d /opt/mastodon mastodon && \
  71. echo "mastodon:`head /dev/urandom | tr -dc A-Za-z0-9 | head -c 24 | mkpasswd -s -m sha-256`" | chpasswd
  72. # Install mastodon runtime deps
  73. RUN apt -y --no-install-recommends install \
  74. libssl1.1 libpq5 imagemagick ffmpeg \
  75. libicu60 libprotobuf10 libidn11 libyaml-0-2 \
  76. file ca-certificates tzdata libreadline7 && \
  77. apt -y install gcc && \
  78. ln -s /opt/mastodon /mastodon && \
  79. gem install bundler && \
  80. rm -rf /var/cache && \
  81. rm -rf /var/lib/apt/lists/*
  82. # Add tini
  83. ENV TINI_VERSION="0.18.0"
  84. ENV TINI_SUM="12d20136605531b09a2c2dac02ccee85e1b874eb322ef6baf7561cd93f93c855"
  85. ADD https://github.com/krallin/tini/releases/download/v${TINI_VERSION}/tini /tini
  86. RUN echo "$TINI_SUM tini" | sha256sum -c -
  87. RUN chmod +x /tini
  88. # Copy over mastodon source, and dependencies from building, and set permissions
  89. COPY --chown=mastodon:mastodon . /opt/mastodon
  90. COPY --from=build-dep --chown=mastodon:mastodon /opt/mastodon /opt/mastodon
  91. # Run mastodon services in prod mode
  92. ENV RAILS_ENV="production"
  93. ENV NODE_ENV="production"
  94. # Tell rails to serve static files
  95. ENV RAILS_SERVE_STATIC_FILES="true"
  96. ENV BIND="0.0.0.0"
  97. # Set the run user
  98. USER mastodon
  99. # Precompile assets
  100. RUN cd ~ && \
  101. OTP_SECRET=precompile_placeholder SECRET_KEY_BASE=precompile_placeholder rails assets:precompile && \
  102. yarn cache clean
  103. # Set the work dir and the container entry point
  104. WORKDIR /opt/mastodon
  105. ENTRYPOINT ["/tini", "--"]