Dockerfile 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. FROM ubuntu:20.04 as build-dep
  2. # Use bash for the shell
  3. SHELL ["/bin/bash", "-c"]
  4. # Install Node v12 (LTS)
  5. ENV NODE_VER="12.21.0"
  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.3"
  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 install -j"$(nproc)" && \
  53. yarn install --pure-lockfile
  54. FROM ubuntu:20.04
  55. # Copy over all the langs needed for runtime
  56. COPY --from=build-dep /opt/node /opt/node
  57. COPY --from=build-dep /opt/ruby /opt/ruby
  58. # Add more PATHs to the PATH
  59. ENV PATH="${PATH}:/opt/ruby/bin:/opt/node/bin:/opt/mastodon/bin"
  60. # Create the mastodon user
  61. ARG UID=991
  62. ARG GID=991
  63. SHELL ["/bin/bash", "-o", "pipefail", "-c"]
  64. RUN apt-get update && \
  65. echo "Etc/UTC" > /etc/localtime && \
  66. apt-get install -y --no-install-recommends whois wget && \
  67. addgroup --gid $GID mastodon && \
  68. useradd -m -u $UID -g $GID -d /opt/mastodon mastodon && \
  69. echo "mastodon:$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 24 | mkpasswd -s -m sha-256)" | chpasswd && \
  70. rm -rf /var/lib/apt/lists/*
  71. # Install mastodon runtime deps
  72. RUN apt-get update && \
  73. apt-get -y --no-install-recommends install \
  74. libssl1.1 libpq5 imagemagick ffmpeg libjemalloc2 \
  75. libicu66 libprotobuf17 libidn11 libyaml-0-2 \
  76. file ca-certificates tzdata libreadline8 gcc tini && \
  77. ln -s /opt/mastodon /mastodon && \
  78. gem install bundler && \
  79. rm -rf /var/cache && \
  80. rm -rf /var/lib/apt/lists/*
  81. # Copy over mastodon source, and dependencies from building, and set permissions
  82. COPY --chown=mastodon:mastodon . /opt/mastodon
  83. COPY --from=build-dep --chown=mastodon:mastodon /opt/mastodon /opt/mastodon
  84. # Run mastodon services in prod mode
  85. ENV RAILS_ENV="production"
  86. ENV NODE_ENV="production"
  87. # Tell rails to serve static files
  88. ENV RAILS_SERVE_STATIC_FILES="true"
  89. ENV BIND="0.0.0.0"
  90. # Set the run user
  91. USER mastodon
  92. # Precompile assets
  93. RUN cd ~ && \
  94. OTP_SECRET=precompile_placeholder SECRET_KEY_BASE=precompile_placeholder rails assets:precompile && \
  95. yarn cache clean
  96. # Set the work dir and the container entry point
  97. WORKDIR /opt/mastodon
  98. ENTRYPOINT ["/usr/bin/tini", "--"]
  99. EXPOSE 3000 4000