1 FROM ubuntu:18.04 as build-dep
3 # Use bash for the shell
8 RUN echo "Etc/UTC" > /etc/localtime && \
10 apt -y install wget make gcc g++ python && \
12 wget https://nodejs.org/download/release/v$NODE_VER/node-v$NODE_VER.tar.gz && \
13 tar xf node-v$NODE_VER.tar.gz && \
14 cd node-v$NODE_VER && \
15 ./configure --prefix=/opt/node && \
16 make -j$(nproc) > /dev/null && \
22 apt -y install autoconf && \
24 wget https://github.com/jemalloc/jemalloc/archive/$JE_VER.tar.gz && \
25 tar xf $JE_VER.tar.gz && \
26 cd jemalloc-$JE_VER && \
28 ./configure --prefix=/opt/jemalloc && \
29 make -j$(nproc) > /dev/null && \
30 make install_bin install_include install_lib
34 ENV CPPFLAGS="-I/opt/jemalloc/include"
35 ENV LDFLAGS="-L/opt/jemalloc/lib/"
37 apt -y install build-essential \
38 bison libyaml-dev libgdbm-dev libreadline-dev \
39 libncurses5-dev libffi-dev zlib1g-dev libssl-dev && \
41 wget https://cache.ruby-lang.org/pub/ruby/${RUBY_VER%.*}/ruby-$RUBY_VER.tar.gz && \
42 tar xf ruby-$RUBY_VER.tar.gz && \
43 cd ruby-$RUBY_VER && \
44 ./configure --prefix=/opt/ruby \
47 --disable-install-doc && \
48 ln -s /opt/jemalloc/lib/* /usr/lib/ && \
49 make -j$(nproc) > /dev/null && \
52 ENV PATH="${PATH}:/opt/ruby/bin:/opt/node/bin"
54 RUN npm install -g yarn && \
55 gem install bundler && \
57 apt -y install git libicu-dev libidn11-dev \
58 libpq-dev libprotobuf-dev protobuf-compiler
60 COPY Gemfile* package.json yarn.lock /opt/mastodon/
62 RUN cd /opt/mastodon && \
63 bundle install -j$(nproc) --deployment --without development test && \
64 yarn install --pure-lockfile
68 # Copy over all the langs needed for runtime
69 COPY --from=build-dep /opt/node /opt/node
70 COPY --from=build-dep /opt/ruby /opt/ruby
71 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"
76 # Create the mastodon user
80 echo "Etc/UTC" > /etc/localtime && \
81 ln -s /opt/jemalloc/lib/* /usr/lib/ && \
82 apt install -y whois wget && \
83 addgroup --gid $GID mastodon && \
84 useradd -m -u $UID -g $GID -d /opt/mastodon mastodon && \
85 echo "mastodon:`head /dev/urandom | tr -dc A-Za-z0-9 | head -c 24 | mkpasswd -s -m sha-256`" | chpasswd
87 # Install mastodon runtime deps
88 RUN apt -y --no-install-recommends install \
89 libssl1.1 libpq5 imagemagick ffmpeg \
90 libicu60 libprotobuf10 libidn11 libyaml-0-2 \
91 file ca-certificates tzdata libreadline7 && \
92 apt -y install gcc && \
93 ln -s /opt/mastodon /mastodon && \
94 gem install bundler && \
95 rm -rf /var/cache && \
96 rm -rf /var/lib/apt/lists/*
99 ENV TINI_VERSION="0.18.0"
100 ENV TINI_SUM="12d20136605531b09a2c2dac02ccee85e1b874eb322ef6baf7561cd93f93c855"
101 ADD https://github.com/krallin/tini/releases/download/v${TINI_VERSION}/tini /tini
102 RUN echo "$TINI_SUM tini" | sha256sum -c -
105 # Copy over mastodon source, and dependencies from building, and set permissions
106 COPY --chown=mastodon:mastodon . /opt/mastodon
107 COPY --from=build-dep --chown=mastodon:mastodon /opt/mastodon /opt/mastodon
109 # Run mastodon services in prod mode
110 ENV RAILS_ENV="production"
111 ENV NODE_ENV="production"
113 # Tell rails to serve static files
114 ENV RAILS_SERVE_STATIC_FILES="true"
122 OTP_SECRET=precompile_placeholder SECRET_KEY_BASE=precompile_placeholder rails assets:precompile && \
125 # Set the work dir and the container entry point
126 WORKDIR /opt/mastodon
127 ENTRYPOINT ["/tini", "--"]