1 FROM ubuntu:20.04 as build-dep
3 # Use bash for the shell
4 SHELL ["/bin/bash", "-c"]
6 # Install Node v12 (LTS)
9 dpkgArch="$(dpkg --print-architecture)" && \
10 case "${dpkgArch##*-}" in \
12 ppc64el) ARCH='ppc64le';; \
13 s390x) ARCH='s390x';; \
14 arm64) ARCH='arm64';; \
15 armhf) ARCH='armv7l';; \
17 *) echo "unsupported architecture"; exit 1 ;; \
19 echo "Etc/UTC" > /etc/localtime && \
21 apt-get install -y --no-install-recommends ca-certificates wget python && \
23 wget -q https://nodejs.org/download/release/v$NODE_VER/node-v$NODE_VER-linux-$ARCH.tar.gz && \
24 tar xf node-v$NODE_VER-linux-$ARCH.tar.gz && \
25 rm node-v$NODE_VER-linux-$ARCH.tar.gz && \
26 mv node-v$NODE_VER-linux-$ARCH /opt/node
30 RUN apt-get update && \
31 apt-get install -y --no-install-recommends build-essential \
32 bison libyaml-dev libgdbm-dev libreadline-dev libjemalloc-dev \
33 libncurses5-dev libffi-dev zlib1g-dev libssl-dev && \
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 \
41 --disable-install-doc && \
42 make -j"$(nproc)" > /dev/null && \
44 rm -rf ../ruby-$RUBY_VER.tar.gz ../ruby-$RUBY_VER
46 ENV PATH="${PATH}:/opt/ruby/bin:/opt/node/bin"
48 RUN npm install -g yarn && \
49 gem install bundler && \
51 apt-get install -y --no-install-recommends git libicu-dev libidn11-dev \
52 libpq-dev libprotobuf-dev protobuf-compiler shared-mime-info
54 COPY Gemfile* package.json yarn.lock /opt/mastodon/
56 RUN cd /opt/mastodon && \
57 bundle config set deployment 'true' && \
58 bundle config set without 'development test' && \
59 bundle install -j"$(nproc)" && \
60 yarn install --pure-lockfile
64 # Copy over all the langs needed for runtime
65 COPY --from=build-dep /opt/node /opt/node
66 COPY --from=build-dep /opt/ruby /opt/ruby
68 # Add more PATHs to the PATH
69 ENV PATH="${PATH}:/opt/ruby/bin:/opt/node/bin:/opt/mastodon/bin"
71 # Create the mastodon user
74 SHELL ["/bin/bash", "-o", "pipefail", "-c"]
75 RUN apt-get update && \
76 echo "Etc/UTC" > /etc/localtime && \
77 apt-get install -y --no-install-recommends whois wget && \
78 addgroup --gid $GID mastodon && \
79 useradd -m -u $UID -g $GID -d /opt/mastodon mastodon && \
80 echo "mastodon:$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 24 | mkpasswd -s -m sha-256)" | chpasswd && \
81 rm -rf /var/lib/apt/lists/*
83 # Install mastodon runtime deps
84 RUN apt-get update && \
85 apt-get -y --no-install-recommends install \
86 libssl1.1 libpq5 imagemagick ffmpeg libjemalloc2 \
87 libicu66 libprotobuf17 libidn11 libyaml-0-2 \
88 file ca-certificates tzdata libreadline8 gcc tini && \
89 ln -s /opt/mastodon /mastodon && \
90 gem install bundler && \
91 rm -rf /var/cache && \
92 rm -rf /var/lib/apt/lists/*
94 # Copy over mastodon source, and dependencies from building, and set permissions
95 COPY --chown=mastodon:mastodon . /opt/mastodon
96 COPY --from=build-dep --chown=mastodon:mastodon /opt/mastodon /opt/mastodon
98 # Run mastodon services in prod mode
99 ENV RAILS_ENV="production"
100 ENV NODE_ENV="production"
102 # Tell rails to serve static files
103 ENV RAILS_SERVE_STATIC_FILES="true"
111 OTP_SECRET=precompile_placeholder SECRET_KEY_BASE=precompile_placeholder rails assets:precompile && \
114 # Set the work dir and the container entry point
115 WORKDIR /opt/mastodon
116 ENTRYPOINT ["/usr/bin/tini", "--"]