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.

118 lines
3.7 KiB

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