2022-11-17 10:01:16 +00:00
|
|
|
# syntax=docker/dockerfile:1.4
|
2022-11-17 11:56:14 +00:00
|
|
|
# This needs to be bullseye-slim because the Ruby image is built on bullseye-slim
|
2023-07-05 07:27:37 +00:00
|
|
|
ARG NODE_IMAGE=node:18.16-bullseye-slim
|
|
|
|
ARG RUBY_IMAGE=ghcr.io/moritzheiber/ruby-jemalloc:3.2.2-slim
|
2019-02-24 15:32:40 +00:00
|
|
|
|
2023-07-05 07:27:37 +00:00
|
|
|
FROM ${RUBY_IMAGE} as ruby
|
2023-07-06 06:56:06 +00:00
|
|
|
|
|
|
|
# build-base
|
2023-07-05 07:27:37 +00:00
|
|
|
FROM ${NODE_IMAGE} as build-base
|
2019-02-24 15:32:40 +00:00
|
|
|
|
2022-11-17 11:56:14 +00:00
|
|
|
COPY --link --from=ruby /opt/ruby /opt/ruby
|
2019-02-24 15:32:40 +00:00
|
|
|
|
2022-11-17 11:56:14 +00:00
|
|
|
ENV DEBIAN_FRONTEND="noninteractive" \
|
2023-07-06 06:56:06 +00:00
|
|
|
PATH="${PATH}:/opt/ruby/bin"
|
2019-02-24 15:32:40 +00:00
|
|
|
|
2022-11-17 11:56:14 +00:00
|
|
|
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
|
2019-02-24 15:32:40 +00:00
|
|
|
|
2022-11-17 11:56:14 +00:00
|
|
|
WORKDIR /opt/mastodon
|
2019-02-24 15:32:40 +00:00
|
|
|
|
2022-12-15 14:57:17 +00:00
|
|
|
# hadolint ignore=DL3008
|
2023-07-06 06:56:06 +00: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 11:56:14 +00:00
|
|
|
ca-certificates \
|
|
|
|
git \
|
2023-07-06 06:56:06 +00:00
|
|
|
libgdbm-dev \
|
|
|
|
libgmp-dev \
|
2022-11-17 11:56:14 +00:00
|
|
|
libicu-dev \
|
|
|
|
libidn11-dev \
|
|
|
|
libjemalloc-dev \
|
2023-07-06 06:56:06 +00:00
|
|
|
libpq-dev \
|
|
|
|
libreadline8 \
|
2022-11-17 11:56:14 +00:00
|
|
|
libssl-dev \
|
|
|
|
libyaml-0-2 \
|
|
|
|
python3 \
|
2023-07-06 06:56:06 +00:00
|
|
|
shared-mime-info \
|
|
|
|
zlib1g-dev
|
2023-03-16 03:48:30 +00:00
|
|
|
|
|
|
|
COPY --link .yarn/releases/ /opt/mastodon/.yarn/releases/
|
|
|
|
COPY --link Gemfile* package.json yarn.lock .yarnrc.yml /opt/mastodon/
|
|
|
|
|
2023-07-06 06:56:06 +00: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 11:56:14 +00:00
|
|
|
bundle config set --local deployment 'true' && \
|
2023-07-06 06:56:06 +00:00
|
|
|
bundle install --local -j"$(nproc)" && \
|
|
|
|
yarn install --immutable
|
2022-11-17 11:56:14 +00:00
|
|
|
|
2023-03-16 03:48:30 +00: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 04:09:27 +00:00
|
|
|
COPY --link . /opt/mastodon
|
2023-04-22 07:14:40 +00:00
|
|
|
|
2023-07-06 06:56:06 +00:00
|
|
|
# build
|
2023-04-22 07:14:40 +00:00
|
|
|
FROM build-base AS build
|
|
|
|
|
|
|
|
ENV RAILS_ENV="production" \
|
|
|
|
NODE_ENV="production"
|
|
|
|
|
2023-07-06 06:56:06 +00:00
|
|
|
ENV NODE_OPTIONS=--openssl-legacy-provider \
|
|
|
|
YARN_GLOBAL_FOLDER=/opt/yarn \
|
|
|
|
YARN_ENABLE_GLOBAL_CACHE=1
|
|
|
|
|
2023-03-16 03:48:30 +00:00
|
|
|
ENV OTP_SECRET=precompile_placeholder \
|
|
|
|
SECRET_KEY_BASE=precompile_placeholder \
|
|
|
|
RAKE_NO_YARN_INSTALL_HACK=1
|
|
|
|
|
2023-07-06 06:56:06 +00:00
|
|
|
ENV BOOTSNAP_CACHE_DIR=/opt/mastodon/bootsnap
|
|
|
|
|
|
|
|
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 03:48:30 +00:00
|
|
|
|
2023-07-06 06:56:06 +00:00
|
|
|
# final image
|
|
|
|
FROM ${NODE_IMAGE} as output
|
2022-11-17 11:56:14 +00:00
|
|
|
|
2023-05-04 19:33:32 +00:00
|
|
|
# Use those args to specify your own version flags & suffixes
|
2023-07-06 06:56:06 +00:00
|
|
|
ARG SOURCE_TAG=""
|
2023-05-04 19:33:32 +00:00
|
|
|
ARG MASTODON_VERSION_FLAGS=""
|
|
|
|
ARG MASTODON_VERSION_SUFFIX=""
|
|
|
|
|
2022-11-17 11:56:14 +00:00
|
|
|
ARG UID="991"
|
|
|
|
ARG GID="991"
|
|
|
|
|
2021-03-20 20:21:57 +00:00
|
|
|
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
|
2022-11-17 11:56:14 +00:00
|
|
|
|
|
|
|
ENV DEBIAN_FRONTEND="noninteractive" \
|
|
|
|
PATH="${PATH}:/opt/ruby/bin:/opt/mastodon/bin"
|
|
|
|
|
2023-05-19 15:13:29 +00: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 14:57:17 +00:00
|
|
|
# hadolint ignore=DL3008,DL3009
|
2023-07-06 06:56:06 +00: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 11:56:14 +00:00
|
|
|
echo "Etc/UTC" > /etc/localtime && \
|
|
|
|
groupadd -g "${GID}" mastodon && \
|
2022-12-15 14:57:17 +00:00
|
|
|
useradd -l -u "$UID" -g "${GID}" -m -d /opt/mastodon mastodon && \
|
2023-07-06 06:56:06 +00:00
|
|
|
apt-get -y --no-install-recommends install \
|
|
|
|
ca-certificates \
|
2022-11-17 11:56:14 +00:00
|
|
|
ffmpeg \
|
2023-07-06 06:56:06 +00:00
|
|
|
file \
|
|
|
|
imagemagick \
|
2022-11-17 11:56:14 +00:00
|
|
|
libicu67 \
|
|
|
|
libidn11 \
|
2023-07-06 06:56:06 +00:00
|
|
|
libjemalloc2 \
|
|
|
|
libpq5 \
|
|
|
|
libreadline8 \
|
|
|
|
libssl1.1 \
|
2022-11-17 11:56:14 +00:00
|
|
|
libyaml-0-2 \
|
2023-07-06 06:56:06 +00:00
|
|
|
procps \
|
|
|
|
tini \
|
2022-11-17 11:56:14 +00:00
|
|
|
tzdata \
|
2023-07-06 06:56:06 +00:00
|
|
|
wget \
|
|
|
|
whois \
|
|
|
|
&& ln -s /opt/mastodon /mastodon
|
2022-11-17 11:56:14 +00: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 15:12:48 +00:00
|
|
|
|
2023-07-06 06:56:06 +00:00
|
|
|
COPY --link --from=ruby /opt/ruby /opt/ruby
|
2023-03-16 03:48:30 +00:00
|
|
|
COPY --link --chown=mastodon:mastodon --from=build /opt/mastodon /opt/mastodon
|
2019-02-24 15:32:40 +00:00
|
|
|
|
2022-11-17 11:56:14 +00:00
|
|
|
ENV RAILS_ENV="production" \
|
|
|
|
NODE_ENV="production" \
|
|
|
|
RAILS_SERVE_STATIC_FILES="true" \
|
2023-03-17 04:09:27 +00:00
|
|
|
BIND="0.0.0.0" \
|
2023-05-12 00:19:02 +00:00
|
|
|
SOURCE_TAG="${SOURCE_TAG}" \
|
2023-05-04 11:45:39 +00:00
|
|
|
MASTODON_VERSION_FLAGS="${MASTODON_VERSION_FLAGS}" \
|
|
|
|
MASTODON_VERSION_SUFFIX="${MASTODON_VERSION_SUFFIX}"
|
2019-02-24 15:32:40 +00:00
|
|
|
|
2023-07-06 06:56:06 +00:00
|
|
|
ENV BOOTSNAP_CACHE_DIR=/opt/mastodon/bootsnap
|
|
|
|
|
|
|
|
# override this at will
|
|
|
|
ENV BOOTSNAP_READONLY=1
|
|
|
|
|
2019-02-24 15:32:40 +00:00
|
|
|
# Set the run user
|
2018-02-20 16:25:01 +00:00
|
|
|
USER mastodon
|
2022-11-17 11:56:14 +00:00
|
|
|
WORKDIR /opt/mastodon
|
2018-02-20 16:25:01 +00:00
|
|
|
|
2019-02-24 15:32:40 +00:00
|
|
|
# Set the work dir and the container entry point
|
2021-03-20 20:21:57 +00:00
|
|
|
ENTRYPOINT ["/usr/bin/tini", "--"]
|
2019-11-04 11:56:21 +00:00
|
|
|
EXPOSE 3000 4000
|