Docker: Use precompiled jemalloc, format, apply hadolint suggestions (#10823)
* Format, apply hadolint suggestions, little nitpicks * Use pre compiled jemalloc * Use tini from package repositoryshrike
parent
876840e9ef
commit
46d3d3169e
71
Dockerfile
71
Dockerfile
|
@ -1,7 +1,7 @@
|
||||||
FROM ubuntu:20.04 as build-dep
|
FROM ubuntu:20.04 as build-dep
|
||||||
|
|
||||||
# Use bash for the shell
|
# Use bash for the shell
|
||||||
SHELL ["/usr/bin/bash", "-c"]
|
SHELL ["/bin/bash", "-c"]
|
||||||
|
|
||||||
# Install Node v12 (LTS)
|
# Install Node v12 (LTS)
|
||||||
ENV NODE_VER="12.21.0"
|
ENV NODE_VER="12.21.0"
|
||||||
|
@ -17,35 +17,19 @@ RUN ARCH= && \
|
||||||
*) echo "unsupported architecture"; exit 1 ;; \
|
*) echo "unsupported architecture"; exit 1 ;; \
|
||||||
esac && \
|
esac && \
|
||||||
echo "Etc/UTC" > /etc/localtime && \
|
echo "Etc/UTC" > /etc/localtime && \
|
||||||
apt update && \
|
apt-get update && \
|
||||||
apt -y install wget python && \
|
apt-get install -y --no-install-recommends ca-certificates wget python && \
|
||||||
cd ~ && \
|
cd ~ && \
|
||||||
wget https://nodejs.org/download/release/v$NODE_VER/node-v$NODE_VER-linux-$ARCH.tar.gz && \
|
wget -q https://nodejs.org/download/release/v$NODE_VER/node-v$NODE_VER-linux-$ARCH.tar.gz && \
|
||||||
tar xf node-v$NODE_VER-linux-$ARCH.tar.gz && \
|
tar xf node-v$NODE_VER-linux-$ARCH.tar.gz && \
|
||||||
rm node-v$NODE_VER-linux-$ARCH.tar.gz && \
|
rm node-v$NODE_VER-linux-$ARCH.tar.gz && \
|
||||||
mv node-v$NODE_VER-linux-$ARCH /opt/node
|
mv node-v$NODE_VER-linux-$ARCH /opt/node
|
||||||
|
|
||||||
# Install jemalloc
|
|
||||||
ENV JE_VER="5.2.1"
|
|
||||||
RUN apt update && \
|
|
||||||
apt -y install make autoconf gcc g++ && \
|
|
||||||
cd ~ && \
|
|
||||||
wget https://github.com/jemalloc/jemalloc/archive/$JE_VER.tar.gz && \
|
|
||||||
tar xf $JE_VER.tar.gz && \
|
|
||||||
cd jemalloc-$JE_VER && \
|
|
||||||
./autogen.sh && \
|
|
||||||
./configure --prefix=/opt/jemalloc && \
|
|
||||||
make -j$(nproc) > /dev/null && \
|
|
||||||
make install_bin install_include install_lib && \
|
|
||||||
cd .. && rm -rf jemalloc-$JE_VER $JE_VER.tar.gz
|
|
||||||
|
|
||||||
# Install Ruby
|
# Install Ruby
|
||||||
ENV RUBY_VER="2.7.2"
|
ENV RUBY_VER="2.7.2"
|
||||||
ENV CPPFLAGS="-I/opt/jemalloc/include"
|
RUN apt-get update && \
|
||||||
ENV LDFLAGS="-L/opt/jemalloc/lib/"
|
apt-get install -y --no-install-recommends build-essential \
|
||||||
RUN apt update && \
|
bison libyaml-dev libgdbm-dev libreadline-dev libjemalloc-dev \
|
||||||
apt -y install build-essential \
|
|
||||||
bison libyaml-dev libgdbm-dev libreadline-dev \
|
|
||||||
libncurses5-dev libffi-dev zlib1g-dev libssl-dev && \
|
libncurses5-dev libffi-dev zlib1g-dev libssl-dev && \
|
||||||
cd ~ && \
|
cd ~ && \
|
||||||
wget https://cache.ruby-lang.org/pub/ruby/${RUBY_VER%.*}/ruby-$RUBY_VER.tar.gz && \
|
wget https://cache.ruby-lang.org/pub/ruby/${RUBY_VER%.*}/ruby-$RUBY_VER.tar.gz && \
|
||||||
|
@ -55,17 +39,16 @@ RUN apt update && \
|
||||||
--with-jemalloc \
|
--with-jemalloc \
|
||||||
--with-shared \
|
--with-shared \
|
||||||
--disable-install-doc && \
|
--disable-install-doc && \
|
||||||
ln -s /opt/jemalloc/lib/* /usr/lib/ && \
|
make -j"$(nproc)" > /dev/null && \
|
||||||
make -j$(nproc) > /dev/null && \
|
|
||||||
make install && \
|
make install && \
|
||||||
cd .. && rm -rf ruby-$RUBY_VER.tar.gz ruby-$RUBY_VER
|
rm -rf ../ruby-$RUBY_VER.tar.gz ../ruby-$RUBY_VER
|
||||||
|
|
||||||
ENV PATH="${PATH}:/opt/ruby/bin:/opt/node/bin"
|
ENV PATH="${PATH}:/opt/ruby/bin:/opt/node/bin"
|
||||||
|
|
||||||
RUN npm install -g yarn && \
|
RUN npm install -g yarn && \
|
||||||
gem install bundler && \
|
gem install bundler && \
|
||||||
apt update && \
|
apt-get update && \
|
||||||
apt -y install git libicu-dev libidn11-dev \
|
apt-get install -y --no-install-recommends git libicu-dev libidn11-dev \
|
||||||
libpq-dev libprotobuf-dev protobuf-compiler
|
libpq-dev libprotobuf-dev protobuf-compiler
|
||||||
|
|
||||||
COPY Gemfile* package.json yarn.lock /opt/mastodon/
|
COPY Gemfile* package.json yarn.lock /opt/mastodon/
|
||||||
|
@ -73,7 +56,7 @@ COPY Gemfile* package.json yarn.lock /opt/mastodon/
|
||||||
RUN cd /opt/mastodon && \
|
RUN cd /opt/mastodon && \
|
||||||
bundle config set deployment 'true' && \
|
bundle config set deployment 'true' && \
|
||||||
bundle config set without 'development test' && \
|
bundle config set without 'development test' && \
|
||||||
bundle install -j$(nproc) && \
|
bundle install -j"$(nproc)" && \
|
||||||
yarn install --pure-lockfile
|
yarn install --pure-lockfile
|
||||||
|
|
||||||
FROM ubuntu:20.04
|
FROM ubuntu:20.04
|
||||||
|
@ -81,7 +64,6 @@ FROM ubuntu:20.04
|
||||||
# Copy over all the langs needed for runtime
|
# Copy over all the langs needed for runtime
|
||||||
COPY --from=build-dep /opt/node /opt/node
|
COPY --from=build-dep /opt/node /opt/node
|
||||||
COPY --from=build-dep /opt/ruby /opt/ruby
|
COPY --from=build-dep /opt/ruby /opt/ruby
|
||||||
COPY --from=build-dep /opt/jemalloc /opt/jemalloc
|
|
||||||
|
|
||||||
# Add more PATHs to the PATH
|
# Add more PATHs to the PATH
|
||||||
ENV PATH="${PATH}:/opt/ruby/bin:/opt/node/bin:/opt/mastodon/bin"
|
ENV PATH="${PATH}:/opt/ruby/bin:/opt/node/bin:/opt/mastodon/bin"
|
||||||
|
@ -89,35 +71,26 @@ ENV PATH="${PATH}:/opt/ruby/bin:/opt/node/bin:/opt/mastodon/bin"
|
||||||
# Create the mastodon user
|
# Create the mastodon user
|
||||||
ARG UID=991
|
ARG UID=991
|
||||||
ARG GID=991
|
ARG GID=991
|
||||||
RUN apt update && \
|
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
|
||||||
|
RUN apt-get update && \
|
||||||
echo "Etc/UTC" > /etc/localtime && \
|
echo "Etc/UTC" > /etc/localtime && \
|
||||||
ln -s /opt/jemalloc/lib/* /usr/lib/ && \
|
apt-get install -y --no-install-recommends whois wget && \
|
||||||
apt install -y whois wget && \
|
|
||||||
addgroup --gid $GID mastodon && \
|
addgroup --gid $GID mastodon && \
|
||||||
useradd -m -u $UID -g $GID -d /opt/mastodon mastodon && \
|
useradd -m -u $UID -g $GID -d /opt/mastodon mastodon && \
|
||||||
echo "mastodon:`head /dev/urandom | tr -dc A-Za-z0-9 | head -c 24 | mkpasswd -s -m sha-256`" | chpasswd
|
echo "mastodon:$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 24 | mkpasswd -s -m sha-256)" | chpasswd && \
|
||||||
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# Install mastodon runtime deps
|
# Install mastodon runtime deps
|
||||||
RUN apt -y --no-install-recommends install \
|
RUN apt-get update && \
|
||||||
libssl1.1 libpq5 imagemagick ffmpeg \
|
apt-get -y --no-install-recommends install \
|
||||||
|
libssl1.1 libpq5 imagemagick ffmpeg libjemalloc2 \
|
||||||
libicu66 libprotobuf17 libidn11 libyaml-0-2 \
|
libicu66 libprotobuf17 libidn11 libyaml-0-2 \
|
||||||
file ca-certificates tzdata libreadline8 && \
|
file ca-certificates tzdata libreadline8 gcc tini && \
|
||||||
apt -y install gcc && \
|
|
||||||
ln -s /opt/mastodon /mastodon && \
|
ln -s /opt/mastodon /mastodon && \
|
||||||
gem install bundler && \
|
gem install bundler && \
|
||||||
rm -rf /var/cache && \
|
rm -rf /var/cache && \
|
||||||
rm -rf /var/lib/apt/lists/*
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# Add tini
|
|
||||||
ENV TINI_VERSION="0.19.0"
|
|
||||||
RUN dpkgArch="$(dpkg --print-architecture)" && \
|
|
||||||
ARCH=$dpkgArch && \
|
|
||||||
wget https://github.com/krallin/tini/releases/download/v${TINI_VERSION}/tini-$ARCH \
|
|
||||||
https://github.com/krallin/tini/releases/download/v${TINI_VERSION}/tini-$ARCH.sha256sum && \
|
|
||||||
cat tini-$ARCH.sha256sum | sha256sum -c - && \
|
|
||||||
mv tini-$ARCH /tini && rm tini-$ARCH.sha256sum && \
|
|
||||||
chmod +x /tini
|
|
||||||
|
|
||||||
# Copy over mastodon source, and dependencies from building, and set permissions
|
# Copy over mastodon source, and dependencies from building, and set permissions
|
||||||
COPY --chown=mastodon:mastodon . /opt/mastodon
|
COPY --chown=mastodon:mastodon . /opt/mastodon
|
||||||
COPY --from=build-dep --chown=mastodon:mastodon /opt/mastodon /opt/mastodon
|
COPY --from=build-dep --chown=mastodon:mastodon /opt/mastodon /opt/mastodon
|
||||||
|
@ -140,5 +113,5 @@ RUN cd ~ && \
|
||||||
|
|
||||||
# Set the work dir and the container entry point
|
# Set the work dir and the container entry point
|
||||||
WORKDIR /opt/mastodon
|
WORKDIR /opt/mastodon
|
||||||
ENTRYPOINT ["/tini", "--"]
|
ENTRYPOINT ["/usr/bin/tini", "--"]
|
||||||
EXPOSE 3000 4000
|
EXPOSE 3000 4000
|
||||||
|
|
Loading…
Reference in New Issue