Revamp
- Upgrade Alpine to 3.15 - Use packaged Ruby (3), Node and libiconv - Build in a different stage than runtime - Build from main branch instead of latest release because of Ruby 3 patches
This commit is contained in:
parent
1d7360e561
commit
c0d8a48691
1 changed files with 68 additions and 62 deletions
130
Dockerfile
130
Dockerfile
|
@ -1,25 +1,15 @@
|
||||||
# -------------- Build-time variables --------------
|
# -------------- Build-time variables --------------
|
||||||
ARG MASTODON_VERSION=3.4.4
|
ARG MASTODON_VERSION=main
|
||||||
ARG MASTODON_REPOSITORY=mastodon/mastodon
|
ARG MASTODON_REPOSITORY=mastodon/mastodon
|
||||||
|
|
||||||
ARG RUBY_VERSION=2.7
|
ARG ALPINE_VERSION=3.15
|
||||||
ARG NODE_VERSION=14
|
|
||||||
ARG ALPINE_VERSION=3.14
|
|
||||||
ARG HARDENED_MALLOC_VERSION=8
|
ARG HARDENED_MALLOC_VERSION=8
|
||||||
ARG LIBICONV_VERSION=1.16
|
|
||||||
|
|
||||||
ARG UID=991
|
ARG UID=991
|
||||||
ARG GID=991
|
ARG GID=991
|
||||||
# ---------------------------------------------------
|
# ---------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
### Build Mastodon stack base (Ruby + Node)
|
|
||||||
FROM node:${NODE_VERSION}-alpine${ALPINE_VERSION} as node
|
|
||||||
FROM ruby:${RUBY_VERSION}-alpine${ALPINE_VERSION} as node-ruby
|
|
||||||
COPY --from=node /usr/local /usr/local
|
|
||||||
COPY --from=node /opt /opt
|
|
||||||
|
|
||||||
|
|
||||||
### Build Hardened Malloc
|
### Build Hardened Malloc
|
||||||
ARG ALPINE_VERSION
|
ARG ALPINE_VERSION
|
||||||
FROM alpine:${ALPINE_VERSION} as build-malloc
|
FROM alpine:${ALPINE_VERSION} as build-malloc
|
||||||
|
@ -35,28 +25,59 @@ RUN apk --no-cache add build-base git gnupg && cd /tmp \
|
||||||
&& make CONFIG_NATIVE=${CONFIG_NATIVE}
|
&& make CONFIG_NATIVE=${CONFIG_NATIVE}
|
||||||
|
|
||||||
|
|
||||||
### Build GNU Libiconv (needed for nokogiri)
|
### Build Mastodon
|
||||||
ARG ALPINE_VERSION
|
ARG ALPINE_VERSION
|
||||||
FROM alpine:${ALPINE_VERSION} as build-gnulibiconv
|
|
||||||
|
|
||||||
ARG LIBICONV_VERSION
|
FROM alpine:${ALPINE_VERSION} as mastodon-build
|
||||||
|
|
||||||
RUN apk --no-cache add build-base \
|
|
||||||
&& wget -q https://ftp.gnu.org/pub/gnu/libiconv/libiconv-${LIBICONV_VERSION}.tar.gz \
|
|
||||||
&& mkdir /tmp/libiconv && tar xf libiconv-${LIBICONV_VERSION}.tar.gz -C /tmp/libiconv --strip-components 1 \
|
|
||||||
&& cd /tmp/libiconv && mkdir output && ./configure --prefix=$PWD/output \
|
|
||||||
&& make -j$(getconf _NPROCESSORS_ONLN) && make install
|
|
||||||
|
|
||||||
|
|
||||||
### Build Mastodon (production environment)
|
|
||||||
FROM node-ruby as mastodon
|
|
||||||
|
|
||||||
COPY --from=build-gnulibiconv /tmp/libiconv/output /usr/local
|
|
||||||
COPY --from=build-malloc /tmp/hardened_malloc/libhardened_malloc.so /usr/local/lib/
|
|
||||||
|
|
||||||
ARG MASTODON_VERSION
|
ARG MASTODON_VERSION
|
||||||
ARG MASTODON_REPOSITORY
|
ARG MASTODON_REPOSITORY
|
||||||
|
|
||||||
|
# Install build dependencies
|
||||||
|
RUN apk --no-cache add -t build-dependencies \
|
||||||
|
build-base \
|
||||||
|
gnu-libiconv-dev \
|
||||||
|
icu-dev \
|
||||||
|
libidn-dev \
|
||||||
|
libtool \
|
||||||
|
libxml2-dev \
|
||||||
|
libxslt-dev \
|
||||||
|
postgresql-dev \
|
||||||
|
protobuf-dev \
|
||||||
|
python3 \
|
||||||
|
ruby-dev \
|
||||||
|
imagemagick \
|
||||||
|
yarn \
|
||||||
|
ruby \
|
||||||
|
ruby-bundler
|
||||||
|
|
||||||
|
RUN adduser -g ${GID} -u ${UID} --disabled-password --gecos "" mastodon \
|
||||||
|
&& mkdir /mastodon \
|
||||||
|
&& chown mastodon:mastodon /mastodon
|
||||||
|
USER mastodon
|
||||||
|
WORKDIR /mastodon
|
||||||
|
|
||||||
|
RUN wget -qO- https://github.com/${MASTODON_REPOSITORY}/archive/refs/heads/${MASTODON_VERSION}.tar.gz | tar xz --strip 1
|
||||||
|
|
||||||
|
ENV RAILS_SERVE_STATIC_FILES=true \
|
||||||
|
RAILS_ENV=production \
|
||||||
|
NODE_ENV=production
|
||||||
|
|
||||||
|
RUN bundle config build.nokogiri --use-system-libraries \
|
||||||
|
&& bundle config set --local clean 'true' && bundle config set --local deployment 'true' \
|
||||||
|
&& bundle config set --local without 'test development' && bundle config set no-cache 'true' \
|
||||||
|
&& bundle install -j$(getconf _NPROCESSORS_ONLN)
|
||||||
|
|
||||||
|
RUN yarn install --pure-lockfile --ignore-engines \
|
||||||
|
&& OTP_SECRET=precompile_placeholder SECRET_KEY_BASE=precompile_placeholder bundle exec rails assets:precompile \
|
||||||
|
&& yarn cache clean
|
||||||
|
|
||||||
|
|
||||||
|
### Mastodon runtime
|
||||||
|
ARG ALPINE_VERSION
|
||||||
|
|
||||||
|
FROM alpine:${ALPINE_VERSION} as mastodon
|
||||||
|
|
||||||
ARG UID
|
ARG UID
|
||||||
ARG GID
|
ARG GID
|
||||||
|
|
||||||
|
@ -66,10 +87,7 @@ ENV RUN_DB_MIGRATIONS=true \
|
||||||
RAILS_SERVE_STATIC_FILES=true \
|
RAILS_SERVE_STATIC_FILES=true \
|
||||||
RAILS_ENV=production \
|
RAILS_ENV=production \
|
||||||
NODE_ENV=production \
|
NODE_ENV=production \
|
||||||
PATH="${PATH}:/mastodon/bin" \
|
PATH="${PATH}:/mastodon/bin"
|
||||||
LD_PRELOAD="/usr/local/lib/libhardened_malloc.so"
|
|
||||||
|
|
||||||
WORKDIR /mastodon
|
|
||||||
|
|
||||||
# Install runtime dependencies
|
# Install runtime dependencies
|
||||||
RUN apk --no-cache add \
|
RUN apk --no-cache add \
|
||||||
|
@ -90,38 +108,26 @@ RUN apk --no-cache add \
|
||||||
yaml \
|
yaml \
|
||||||
readline \
|
readline \
|
||||||
gcompat \
|
gcompat \
|
||||||
# Install build dependencies
|
gnu-libiconv \
|
||||||
&& apk --no-cache add -t build-dependencies \
|
nodejs \
|
||||||
build-base \
|
ruby \
|
||||||
icu-dev \
|
ruby-bundler \
|
||||||
libidn-dev \
|
# For hardened_malloc
|
||||||
libtool \
|
libgcc \
|
||||||
libxml2-dev \
|
libstdc++
|
||||||
libxslt-dev \
|
|
||||||
postgresql-dev \
|
|
||||||
protobuf-dev \
|
|
||||||
python3 \
|
|
||||||
imagemagick \
|
|
||||||
# Install Mastodon
|
|
||||||
&& wget -qO- https://github.com/${MASTODON_REPOSITORY}/archive/v${MASTODON_VERSION}.tar.gz | tar xz --strip 1 \
|
|
||||||
&& bundle config build.nokogiri --use-system-libraries --with-iconv-lib=/usr/local/lib --with-iconv-include=/usr/local/include \
|
|
||||||
&& bundle config set --local clean 'true' && bundle config set --local deployment 'true' \
|
|
||||||
&& bundle config set --local without 'test development' && bundle config set no-cache 'true' \
|
|
||||||
&& bundle install -j$(getconf _NPROCESSORS_ONLN) \
|
|
||||||
&& yarn install --pure-lockfile --ignore-engines \
|
|
||||||
&& OTP_SECRET=precompile_placeholder SECRET_KEY_BASE=precompile_placeholder bundle exec rails assets:precompile \
|
|
||||||
# Clean
|
|
||||||
&& npm -g --force cache clean && yarn cache clean \
|
|
||||||
&& apk del build-dependencies \
|
|
||||||
# Prepare mastodon user
|
|
||||||
&& adduser -g ${GID} -u ${UID} --disabled-password --gecos "" mastodon \
|
|
||||||
&& chown -R mastodon:mastodon /mastodon
|
|
||||||
|
|
||||||
COPY --chown=mastodon:mastodon rootfs /
|
|
||||||
|
|
||||||
RUN chmod +x /usr/local/bin/* /etc/s6.d/*/* /etc/s6.d/.s6-svscan/*
|
|
||||||
|
|
||||||
|
RUN adduser -g ${GID} -u ${UID} --disabled-password --gecos "" mastodon
|
||||||
USER mastodon
|
USER mastodon
|
||||||
|
WORKDIR /mastodon
|
||||||
|
|
||||||
|
COPY --chown=mastodon:mastodon --from=mastodon-build /mastodon /mastodon
|
||||||
|
|
||||||
|
ENV LD_PRELOAD="/usr/local/lib/libhardened_malloc.so"
|
||||||
|
COPY --from=build-malloc /tmp/hardened_malloc/libhardened_malloc.so /usr/local/lib/
|
||||||
|
|
||||||
|
COPY --chown=mastodon:mastodon rootfs/usr/local/bin/run /usr/local/bin/run
|
||||||
|
COPY --chown=mastodon:mastodon rootfs/etc/s6.d /etc/s6.d
|
||||||
|
RUN chmod +x /usr/local/bin/* /etc/s6.d/*/* /etc/s6.d/.s6-svscan/*
|
||||||
|
|
||||||
VOLUME /mastodon/public/system /mastodon/log
|
VOLUME /mastodon/public/system /mastodon/log
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue