2022-11-17 12:01:16 +02:00
|
|
|
# syntax=docker/dockerfile:1.4
|
2022-11-17 13:56:14 +02:00
|
|
|
# This needs to be bullseye-slim because the Ruby image is built on bullseye-slim
|
2023-07-05 10:27:37 +03:00
|
|
|
ARG NODE_IMAGE=node:18.16-bullseye-slim
|
|
|
|
ARG RUBY_IMAGE=ghcr.io/moritzheiber/ruby-jemalloc:3.2.2-slim
|
2019-02-24 17:32:40 +02:00
|
|
|
|
2023-07-05 10:27:37 +03:00
|
|
|
FROM ${RUBY_IMAGE} as ruby
|
2023-07-06 09:56:06 +03:00
|
|
|
|
|
|
|
# build-base
|
2023-07-05 10:27:37 +03:00
|
|
|
FROM ${NODE_IMAGE} as build-base
|
2019-02-24 17:32:40 +02:00
|
|
|
|
2022-11-17 13:56:14 +02:00
|
|
|
COPY --link --from=ruby /opt/ruby /opt/ruby
|
2019-02-24 17:32:40 +02:00
|
|
|
|
2022-11-17 13:56:14 +02:00
|
|
|
ENV DEBIAN_FRONTEND="noninteractive" \
|
2023-07-06 09:56:06 +03:00
|
|
|
PATH="${PATH}:/opt/ruby/bin"
|
2019-02-24 17:32:40 +02:00
|
|
|
|
2022-11-17 13:56:14 +02:00
|
|
|
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
|
2019-02-24 17:32:40 +02:00
|
|
|
|
2022-11-17 13:56:14 +02:00
|
|
|
WORKDIR /opt/mastodon
|
2019-02-24 17:32:40 +02:00
|
|
|
|
2022-12-15 16:57:17 +02:00
|
|
|
# hadolint ignore=DL3008
|
2023-07-06 09:56:06 +03:00
|
|
|
RUN --mount=type=cache,id=apt,target=/var/cache/apt,sharing=private \
|
|
|
|
set -eux && \
|
|
|
|
rm -f /etc/apt/apt.conf.d/docker-clean && \
|
|
|
|
echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache && \
|
|
|
|
apt-get update && \
|
|
|
|
apt-get install -y --no-install-recommends \
|
|
|
|
build-essential \
|
2022-11-17 13:56:14 +02:00
|
|
|
ca-certificates \
|
|
|
|
git \
|
2023-07-06 09:56:06 +03:00
|
|
|
libgdbm-dev \
|
|
|
|
libgmp-dev \
|
2022-11-17 13:56:14 +02:00
|
|
|
libicu-dev \
|
|
|
|
libidn11-dev \
|
|
|
|
libjemalloc-dev \
|
2023-07-06 09:56:06 +03:00
|
|
|
libpq-dev \
|
|
|
|
libreadline8 \
|
2022-11-17 13:56:14 +02:00
|
|
|
libssl-dev \
|
|
|
|
libyaml-0-2 \
|
|
|
|
python3 \
|
2023-07-06 09:56:06 +03:00
|
|
|
shared-mime-info \
|
|
|
|
zlib1g-dev
|
2023-03-16 05:48:30 +02:00
|
|
|
|
|
|
|
COPY --link .yarn/releases/ /opt/mastodon/.yarn/releases/
|
|
|
|
COPY --link Gemfile* package.json yarn.lock .yarnrc.yml /opt/mastodon/
|
|
|
|
|
2023-07-06 09:56:06 +03:00
|
|
|
ENV NODE_OPTIONS=--openssl-legacy-provider \
|
|
|
|
YARN_GLOBAL_FOLDER=/opt/yarn \
|
|
|
|
YARN_ENABLE_GLOBAL_CACHE=1
|
|
|
|
|
|
|
|
RUN --mount=type=cache,id=bundle,target=/opt/bundle/cache,sharing=private \
|
|
|
|
--mount=type=cache,id=yarn,target=/opt/yarn/cache,sharing=private \
|
|
|
|
set -eux && \
|
|
|
|
bundle config set cache_path /opt/bundle/cache && \
|
|
|
|
bundle config set silence_root_warning 'true' && \
|
|
|
|
bundle cache --no-install && \
|
2022-11-17 13:56:14 +02:00
|
|
|
bundle config set --local deployment 'true' && \
|
2023-07-06 09:56:06 +03:00
|
|
|
bundle install --local -j"$(nproc)" && \
|
|
|
|
yarn install --immutable
|
2022-11-17 13:56:14 +02:00
|
|
|
|
2023-03-16 05:48:30 +02:00
|
|
|
# Precompile assets
|
|
|
|
# TODO(kouhai): we're currently patching node_modules because of emoji-mart.
|
|
|
|
# we should integrate our own fork instead.
|
2023-03-17 06:09:27 +02:00
|
|
|
COPY --link . /opt/mastodon
|
2023-04-22 10:14:40 +03:00
|
|
|
|
2023-07-06 09:56:06 +03:00
|
|
|
# build
|
2023-04-22 10:14:40 +03:00
|
|
|
FROM build-base AS build
|
|
|
|
|
|
|
|
ENV RAILS_ENV="production" \
|
|
|
|
NODE_ENV="production"
|
|
|
|
|
2023-07-06 09:56:06 +03:00
|
|
|
ENV NODE_OPTIONS=--openssl-legacy-provider \
|
|
|
|
YARN_GLOBAL_FOLDER=/opt/yarn \
|
|
|
|
YARN_ENABLE_GLOBAL_CACHE=1
|
|
|
|
|
2023-03-16 05:48:30 +02:00
|
|
|
ENV OTP_SECRET=precompile_placeholder \
|
|
|
|
SECRET_KEY_BASE=precompile_placeholder \
|
|
|
|
RAKE_NO_YARN_INSTALL_HACK=1
|
|
|
|
|
2023-07-07 08:33:17 +03:00
|
|
|
# override this at will
|
|
|
|
ENV BOOTSNAP_READONLY=1
|
2023-07-06 09:56:06 +03:00
|
|
|
|
|
|
|
RUN --mount=type=cache,id=yarn,target=/opt/yarn/cache,sharing=private \
|
|
|
|
--mount=type=cache,id=webpacker,target=/opt/webpacker/cache,sharing=private \
|
|
|
|
set -eux && \
|
|
|
|
mkdir -p tmp/cache && \
|
|
|
|
ln -sf /opt/webpacker/cache tmp/cache/webpacker && \
|
|
|
|
mv ./emoji_data/all.json ./node_modules/emoji-mart/data/all.json && \
|
|
|
|
yarn install && \
|
|
|
|
bundle exec rails assets:precompile
|
2023-03-16 05:48:30 +02:00
|
|
|
|
2023-07-06 09:56:06 +03:00
|
|
|
# final image
|
|
|
|
FROM ${NODE_IMAGE} as output
|
2022-11-17 13:56:14 +02:00
|
|
|
|
2023-05-04 22:33:32 +03:00
|
|
|
# Use those args to specify your own version flags & suffixes
|
2023-07-06 09:56:06 +03:00
|
|
|
ARG SOURCE_TAG=""
|
2023-05-04 22:33:32 +03:00
|
|
|
ARG MASTODON_VERSION_FLAGS=""
|
|
|
|
ARG MASTODON_VERSION_SUFFIX=""
|
|
|
|
|
2022-11-17 13:56:14 +02:00
|
|
|
ARG UID="991"
|
|
|
|
ARG GID="991"
|
|
|
|
|
2021-03-20 22:21:57 +02:00
|
|
|
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
|
2022-11-17 13:56:14 +02:00
|
|
|
|
|
|
|
ENV DEBIAN_FRONTEND="noninteractive" \
|
|
|
|
PATH="${PATH}:/opt/ruby/bin:/opt/mastodon/bin"
|
|
|
|
|
2023-05-19 18:13:29 +03:00
|
|
|
# Ignoring these here since we don't want to pin any versions and the Debian image removes apt-get content after use
|
2022-12-15 16:57:17 +02:00
|
|
|
# hadolint ignore=DL3008,DL3009
|
2023-07-06 09:56:06 +03:00
|
|
|
RUN --mount=type=cache,id=apt,target=/var/cache/apt,sharing=private \
|
|
|
|
set -eux && \
|
|
|
|
rm -f /etc/apt/apt.conf.d/docker-clean && \
|
|
|
|
echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache && \
|
|
|
|
apt-get update && \
|
2022-11-17 13:56:14 +02:00
|
|
|
echo "Etc/UTC" > /etc/localtime && \
|
|
|
|
groupadd -g "${GID}" mastodon && \
|
2022-12-15 16:57:17 +02:00
|
|
|
useradd -l -u "$UID" -g "${GID}" -m -d /opt/mastodon mastodon && \
|
2023-07-06 09:56:06 +03:00
|
|
|
apt-get -y --no-install-recommends install \
|
|
|
|
ca-certificates \
|
2022-11-17 13:56:14 +02:00
|
|
|
ffmpeg \
|
2023-07-06 09:56:06 +03:00
|
|
|
file \
|
|
|
|
imagemagick \
|
2022-11-17 13:56:14 +02:00
|
|
|
libicu67 \
|
|
|
|
libidn11 \
|
2023-07-06 09:56:06 +03:00
|
|
|
libjemalloc2 \
|
|
|
|
libpq5 \
|
|
|
|
libreadline8 \
|
|
|
|
libssl1.1 \
|
2022-11-17 13:56:14 +02:00
|
|
|
libyaml-0-2 \
|
2023-07-06 09:56:06 +03:00
|
|
|
procps \
|
|
|
|
tini \
|
2022-11-17 13:56:14 +02:00
|
|
|
tzdata \
|
2023-07-06 09:56:06 +03:00
|
|
|
wget \
|
|
|
|
whois \
|
|
|
|
&& ln -s /opt/mastodon /mastodon
|
2022-11-17 13:56:14 +02:00
|
|
|
|
|
|
|
# Note: no, cleaning here since Debian does this automatically
|
|
|
|
# See the file /etc/apt/apt.conf.d/docker-clean within the Docker image's filesystem
|
2019-03-08 17:12:48 +02:00
|
|
|
|
2023-07-06 09:56:06 +03:00
|
|
|
COPY --link --from=ruby /opt/ruby /opt/ruby
|
2023-03-16 05:48:30 +02:00
|
|
|
COPY --link --chown=mastodon:mastodon --from=build /opt/mastodon /opt/mastodon
|
2019-02-24 17:32:40 +02:00
|
|
|
|
2022-11-17 13:56:14 +02:00
|
|
|
ENV RAILS_ENV="production" \
|
|
|
|
NODE_ENV="production" \
|
|
|
|
RAILS_SERVE_STATIC_FILES="true" \
|
2023-03-17 06:09:27 +02:00
|
|
|
BIND="0.0.0.0" \
|
2023-05-12 03:19:02 +03:00
|
|
|
SOURCE_TAG="${SOURCE_TAG}" \
|
2023-05-04 14:45:39 +03:00
|
|
|
MASTODON_VERSION_FLAGS="${MASTODON_VERSION_FLAGS}" \
|
|
|
|
MASTODON_VERSION_SUFFIX="${MASTODON_VERSION_SUFFIX}"
|
2019-02-24 17:32:40 +02:00
|
|
|
|
2023-07-06 09:56:06 +03:00
|
|
|
# override this at will
|
|
|
|
ENV BOOTSNAP_READONLY=1
|
|
|
|
|
2019-02-24 17:32:40 +02:00
|
|
|
# Set the run user
|
2018-02-20 18:25:01 +02:00
|
|
|
USER mastodon
|
2022-11-17 13:56:14 +02:00
|
|
|
WORKDIR /opt/mastodon
|
2018-02-20 18:25:01 +02:00
|
|
|
|
2019-02-24 17:32:40 +02:00
|
|
|
# Set the work dir and the container entry point
|
2021-03-20 22:21:57 +02:00
|
|
|
ENTRYPOINT ["/usr/bin/tini", "--"]
|
2019-11-04 13:56:21 +02:00
|
|
|
EXPOSE 3000 4000
|