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.

139 lines
4.1 KiB

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