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.

126 lines
3.6 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="8.15.0"
  6. RUN echo "Etc/UTC" > /etc/localtime && \
  7. apt update && \
  8. apt -y dist-upgrade && \
  9. apt -y install wget make gcc g++ python && \
  10. cd ~ && \
  11. wget https://nodejs.org/download/release/v$NODE_VER/node-v$NODE_VER.tar.gz && \
  12. tar xf node-v$NODE_VER.tar.gz && \
  13. cd node-v$NODE_VER && \
  14. ./configure --prefix=/opt/node && \
  15. make -j$(nproc) > /dev/null && \
  16. make install
  17. # Install jemalloc
  18. ENV JE_VER="5.1.0"
  19. RUN apt -y install autoconf && \
  20. cd ~ && \
  21. wget https://github.com/jemalloc/jemalloc/archive/$JE_VER.tar.gz && \
  22. tar xf $JE_VER.tar.gz && \
  23. cd jemalloc-$JE_VER && \
  24. ./autogen.sh && \
  25. ./configure --prefix=/opt/jemalloc && \
  26. make -j$(nproc) > /dev/null && \
  27. make install_bin install_include install_lib
  28. # Install ruby
  29. ENV RUBY_VER="2.6.1"
  30. ENV CPPFLAGS="-I/opt/jemalloc/include"
  31. ENV LDFLAGS="-L/opt/jemalloc/lib/"
  32. RUN apt -y install build-essential \
  33. bison libyaml-dev libgdbm-dev libreadline-dev \
  34. libncurses5-dev libffi-dev zlib1g-dev libssl-dev && \
  35. cd ~ && \
  36. wget https://cache.ruby-lang.org/pub/ruby/${RUBY_VER%.*}/ruby-$RUBY_VER.tar.gz && \
  37. tar xf ruby-$RUBY_VER.tar.gz && \
  38. cd ruby-$RUBY_VER && \
  39. ./configure --prefix=/opt/ruby \
  40. --with-jemalloc \
  41. --with-shared \
  42. --disable-install-doc && \
  43. ln -s /opt/jemalloc/lib/* /usr/lib/ && \
  44. make -j$(nproc) > /dev/null && \
  45. make install
  46. ENV PATH="${PATH}:/opt/ruby/bin:/opt/node/bin"
  47. RUN npm install -g yarn && \
  48. gem install bundler
  49. COPY . /opt/mastodon
  50. RUN apt -y install git libicu-dev libidn11-dev \
  51. libpq-dev libprotobuf-dev protobuf-compiler && \
  52. 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 -y dist-upgrade && \
  69. apt install -y whois && \
  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. # Copy over masto source from building and set permissions
  74. COPY --from=build-dep --chown=mastodon:mastodon /opt/mastodon /opt/mastodon
  75. # Install masto runtime deps
  76. RUN apt -y --no-install-recommends install \
  77. libssl1.1 libpq5 imagemagick ffmpeg \
  78. libicu60 libprotobuf10 libidn11 libyaml-0-2 \
  79. file ca-certificates tzdata libreadline7 && \
  80. apt -y install gcc && \
  81. ln -s /opt/mastodon /mastodon && \
  82. gem install bundler
  83. # Clean up more dirs
  84. RUN rm -rf /var/cache && \
  85. rm -rf /var/apt
  86. # Add tini
  87. ENV TINI_VERSION="0.18.0"
  88. ENV TINI_SUM="12d20136605531b09a2c2dac02ccee85e1b874eb322ef6baf7561cd93f93c855"
  89. ADD https://github.com/krallin/tini/releases/download/v${TINI_VERSION}/tini /tini
  90. RUN echo "$TINI_SUM tini" | sha256sum -c -
  91. RUN chmod +x /tini
  92. # Run masto services in prod mode
  93. ENV RAILS_ENV="production"
  94. ENV NODE_ENV="production"
  95. # Tell rails to serve static files
  96. ENV RAILS_SERVE_STATIC_FILES="true"
  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", "--"]