Skip to content

Commit 63d81c0

Browse files
Sir-Boopshiyuki2578
authored andcommitted
Switch to Ubuntu for docker (mastodon#10100)
1 parent 0729586 commit 63d81c0

1 file changed

Lines changed: 121 additions & 84 deletions

File tree

Dockerfile

Lines changed: 121 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,126 @@
1-
FROM node:8.15-alpine as node
2-
FROM ruby:2.6-alpine3.9
3-
4-
LABEL maintainer="https://github.com/tootsuite/mastodon" \
5-
description="Your self-hosted, globally interconnected microblogging community"
6-
1+
FROM ubuntu:18.04 as build-dep
2+
3+
# Use bash for the shell
4+
SHELL ["bash", "-c"]
5+
6+
# Install Node
7+
ENV NODE_VER="8.15.0"
8+
RUN echo "Etc/UTC" > /etc/localtime && \
9+
apt update && \
10+
apt -y dist-upgrade && \
11+
apt -y install wget make gcc g++ python && \
12+
cd ~ && \
13+
wget https://nodejs.org/download/release/v$NODE_VER/node-v$NODE_VER.tar.gz && \
14+
tar xf node-v$NODE_VER.tar.gz && \
15+
cd node-v$NODE_VER && \
16+
./configure --prefix=/opt/node && \
17+
make -j$(nproc) > /dev/null && \
18+
make install
19+
20+
# Install jemalloc
21+
ENV JE_VER="5.1.0"
22+
RUN apt -y install autoconf && \
23+
cd ~ && \
24+
wget https://github.com/jemalloc/jemalloc/archive/$JE_VER.tar.gz && \
25+
tar xf $JE_VER.tar.gz && \
26+
cd jemalloc-$JE_VER && \
27+
./autogen.sh && \
28+
./configure --prefix=/opt/jemalloc && \
29+
make -j$(nproc) > /dev/null && \
30+
make install_bin install_include install_lib
31+
32+
# Install ruby
33+
ENV RUBY_VER="2.6.1"
34+
ENV CPPFLAGS="-I/opt/jemalloc/include"
35+
ENV LDFLAGS="-L/opt/jemalloc/lib/"
36+
RUN apt -y install build-essential \
37+
bison libyaml-dev libgdbm-dev libreadline-dev \
38+
libncurses5-dev libffi-dev zlib1g-dev libssl-dev && \
39+
cd ~ && \
40+
wget https://cache.ruby-lang.org/pub/ruby/${RUBY_VER%.*}/ruby-$RUBY_VER.tar.gz && \
41+
tar xf ruby-$RUBY_VER.tar.gz && \
42+
cd ruby-$RUBY_VER && \
43+
./configure --prefix=/opt/ruby \
44+
--with-jemalloc \
45+
--with-shared \
46+
--disable-install-doc && \
47+
ln -s /opt/jemalloc/lib/* /usr/lib/ && \
48+
make -j$(nproc) > /dev/null && \
49+
make install
50+
51+
ENV PATH="${PATH}:/opt/ruby/bin:/opt/node/bin"
52+
53+
RUN npm install -g yarn && \
54+
gem install bundler
55+
56+
COPY . /opt/mastodon
57+
58+
RUN apt -y install git libicu-dev libidn11-dev \
59+
libpq-dev libprotobuf-dev protobuf-compiler && \
60+
cd /opt/mastodon && \
61+
bundle install -j$(nproc) --deployment --without development test && \
62+
yarn install --pure-lockfile
63+
64+
FROM ubuntu:18.04
65+
66+
# Copy over all the langs needed for runtime
67+
COPY --from=build-dep /opt/node /opt/node
68+
COPY --from=build-dep /opt/ruby /opt/ruby
69+
COPY --from=build-dep /opt/jemalloc /opt/jemalloc
70+
71+
# Add more PATHs to the PATH
72+
ENV PATH="${PATH}:/opt/ruby/bin:/opt/node/bin:/opt/mastodon/bin"
73+
74+
# Create the mastodon user
775
ARG UID=991
876
ARG GID=991
9-
10-
ENV PATH=/mastodon/bin:$PATH \
11-
RAILS_SERVE_STATIC_FILES=true \
12-
RAILS_ENV=production \
13-
NODE_ENV=production
14-
15-
ARG LIBICONV_VERSION=1.15
16-
ARG LIBICONV_DOWNLOAD_SHA256=ccf536620a45458d26ba83887a983b96827001e92a13847b45e4925cc8913178
17-
18-
EXPOSE 3000 4000
19-
20-
WORKDIR /mastodon
21-
22-
COPY --from=node /usr/local/bin/node /usr/local/bin/node
23-
COPY --from=node /usr/local/lib/node_modules /usr/local/lib/node_modules
24-
COPY --from=node /usr/local/bin/npm /usr/local/bin/npm
25-
COPY --from=node /opt/yarn-* /opt/yarn
26-
27-
RUN apk add --no-cache -t build-dependencies \
28-
build-base \
29-
icu-dev \
30-
libidn-dev \
31-
openssl \
32-
libtool \
33-
libxml2-dev \
34-
libxslt-dev \
35-
postgresql-dev \
36-
protobuf-dev \
37-
python \
38-
&& apk add --no-cache \
39-
ca-certificates \
40-
ffmpeg \
41-
file \
42-
git \
43-
icu-libs \
44-
imagemagick \
45-
libidn \
46-
libpq \
47-
libxml2 \
48-
libxslt \
49-
protobuf \
50-
tini \
51-
tzdata \
52-
&& update-ca-certificates \
53-
&& ln -s /opt/yarn/bin/yarn /usr/local/bin/yarn \
54-
&& ln -s /opt/yarn/bin/yarnpkg /usr/local/bin/yarnpkg \
55-
&& mkdir -p /tmp/src /opt \
56-
&& wget -O libiconv.tar.gz "https://ftp.gnu.org/pub/gnu/libiconv/libiconv-$LIBICONV_VERSION.tar.gz" \
57-
&& echo "$LIBICONV_DOWNLOAD_SHA256 *libiconv.tar.gz" | sha256sum -c - \
58-
&& tar -xzf libiconv.tar.gz -C /tmp/src \
59-
&& rm libiconv.tar.gz \
60-
&& cd /tmp/src/libiconv-$LIBICONV_VERSION \
61-
&& ./configure --prefix=/usr/local \
62-
&& make -j$(getconf _NPROCESSORS_ONLN)\
63-
&& make install \
64-
&& libtool --finish /usr/local/lib \
65-
&& cd /mastodon \
66-
&& rm -rf /tmp/*
67-
68-
COPY Gemfile Gemfile.lock package.json yarn.lock .yarnclean /mastodon/
69-
70-
RUN bundle config build.nokogiri --use-system-libraries --with-iconv-lib=/usr/local/lib --with-iconv-include=/usr/local/include \
71-
&& bundle install -j$(getconf _NPROCESSORS_ONLN) --deployment --without test development \
72-
&& yarn install --pure-lockfile --ignore-engines \
73-
&& yarn cache clean
74-
75-
RUN addgroup -g ${GID} mastodon && adduser -h /mastodon -s /bin/sh -D -G mastodon -u ${UID} mastodon \
76-
&& mkdir -p /mastodon/public/system /mastodon/public/assets /mastodon/public/packs \
77-
&& chown -R mastodon:mastodon /mastodon/public
78-
79-
COPY . /mastodon
80-
81-
RUN chown -R mastodon:mastodon /mastodon
82-
83-
VOLUME /mastodon/public/system
84-
77+
RUN apt update && \
78+
echo "Etc/UTC" > /etc/localtime && \
79+
ln -s /opt/jemalloc/lib/* /usr/lib/ && \
80+
apt -y dist-upgrade && \
81+
apt install -y whois && \
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+
86+
# Copy over masto source from building and set permissions
87+
COPY --from=build-dep --chown=mastodon:mastodon /opt/mastodon /opt/mastodon
88+
89+
# Install masto runtime deps
90+
RUN apt -y --no-install-recommends install \
91+
libssl1.1 libpq5 imagemagick ffmpeg \
92+
libicu60 libprotobuf10 libidn11 libyaml-0-2 \
93+
file ca-certificates tzdata libreadline7 && \
94+
apt -y install gcc && \
95+
ln -s /opt/mastodon /mastodon && \
96+
gem install bundler
97+
98+
# Clean up more dirs
99+
RUN rm -rf /var/cache && \
100+
rm -rf /var/apt
101+
102+
# Add tini
103+
ENV TINI_VERSION="0.18.0"
104+
ENV TINI_SUM="12d20136605531b09a2c2dac02ccee85e1b874eb322ef6baf7561cd93f93c855"
105+
ADD https://github.com/krallin/tini/releases/download/v${TINI_VERSION}/tini /tini
106+
RUN echo "$TINI_SUM tini" | sha256sum -c -
107+
RUN chmod +x /tini
108+
109+
# Run masto services in prod mode
110+
ENV RAILS_ENV="production"
111+
ENV NODE_ENV="production"
112+
113+
# Tell rails to serve static files
114+
ENV RAILS_SERVE_STATIC_FILES="true"
115+
116+
# Set the run user
85117
USER mastodon
86118

87-
RUN OTP_SECRET=precompile_placeholder SECRET_KEY_BASE=precompile_placeholder bundle exec rails assets:precompile
119+
# Precompile assets
120+
RUN cd ~ && \
121+
OTP_SECRET=precompile_placeholder SECRET_KEY_BASE=precompile_placeholder rails assets:precompile && \
122+
yarn cache clean
88123

89-
ENTRYPOINT ["/sbin/tini", "--"]
124+
# Set the work dir and the container entry point
125+
WORKDIR /opt/mastodon
126+
ENTRYPOINT ["/tini", "--"]

0 commit comments

Comments
 (0)