2022-11-17 10:01:16 +00:00
|
|
|
# syntax=docker/dockerfile:1.4
|
2023-09-05 16:19:59 +00:00
|
|
|
# This needs to be bookworm-slim because the Ruby image is built on bookworm-slim
|
2023-10-22 23:18:41 +00:00
|
|
|
ARG NODE_IMAGE="node:20.8-bookworm-slim"
|
2023-07-05 07:27:37 +00:00
|
|
|
ARG RUBY_IMAGE=ghcr.io/moritzheiber/ruby-jemalloc:3.2.2-slim
|
2019-02-24 15:32:40 +00:00
|
|
|
|
2023-07-07 05:46:49 +00:00
|
|
|
# hadolint ignore=DL3006
|
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-07 05:46:49 +00:00
|
|
|
# hadolint ignore=DL3006
|
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
|
|
|
|
2023-07-07 05:46:49 +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 && \
|
2023-09-14 21:11:36 +00:00
|
|
|
apt-get -yq dist-upgrade && \
|
2023-07-06 06:56:06 +00:00
|
|
|
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 \
|
2023-09-05 16:19:59 +00:00
|
|
|
libidn-dev \
|
2022-11-17 11:56:14 +00:00
|
|
|
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
|
|
|
|
|
2023-07-07 05:46:49 +00:00
|
|
|
# hadolint ignore=DL3060
|
2023-07-06 06:56:06 +00:00
|
|
|
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 && \
|
2023-09-17 03:35:31 +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
|
|
|
|
|
2023-09-17 03:35:31 +00:00
|
|
|
ENV RAILS_ENV=production \
|
|
|
|
NODE_ENV=production
|
2023-04-22 07:14:40 +00:00
|
|
|
|
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-07 05:33:17 +00:00
|
|
|
# override this at will
|
|
|
|
ENV BOOTSNAP_READONLY=1
|
2023-07-06 06:56:06 +00: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 03:48:30 +00:00
|
|
|
|
2023-07-06 06:56:06 +00:00
|
|
|
# final image
|
2023-07-07 05:46:49 +00:00
|
|
|
# hadolint ignore=DL3006
|
|
|
|
FROM ${NODE_IMAGE} as output-base
|
2022-11-17 11:56:14 +00:00
|
|
|
|
2023-07-07 05:46:49 +00:00
|
|
|
ENV DEBIAN_FRONTEND="noninteractive"
|
2022-11-17 11:56:14 +00:00
|
|
|
|
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 && \
|
2022-11-17 11:56:14 +00:00
|
|
|
echo "Etc/UTC" > /etc/localtime && \
|
2023-07-07 05:46:49 +00:00
|
|
|
apt-get update && \
|
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 \
|
2023-09-05 16:19:59 +00:00
|
|
|
libicu72 \
|
|
|
|
libidn12 \
|
2023-07-06 06:56:06 +00:00
|
|
|
libjemalloc2 \
|
|
|
|
libpq5 \
|
|
|
|
libreadline8 \
|
2023-09-17 03:35:31 +00:00
|
|
|
libssl3 \
|
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 \
|
2023-07-07 05:46:49 +00:00
|
|
|
whois
|
|
|
|
|
|
|
|
# final image
|
|
|
|
FROM output-base as output
|
|
|
|
|
|
|
|
# Use those args to specify your own version flags & suffixes
|
|
|
|
ARG SOURCE_TAG=""
|
2023-09-17 03:35:31 +00:00
|
|
|
ARG MASTODON_VERSION_PRERELEASE=""
|
|
|
|
ARG MASTODON_VERSION_METADATA=""
|
2023-07-07 05:46:49 +00:00
|
|
|
|
|
|
|
ARG UID="991"
|
|
|
|
ARG GID="991"
|
|
|
|
|
|
|
|
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
|
|
|
|
|
|
|
|
ENV PATH="${PATH}:/opt/ruby/bin:/opt/mastodon/bin"
|
|
|
|
|
|
|
|
# Ignoring these here since we don't want to pin any versions and the Debian image removes apt-get content after use
|
|
|
|
# hadolint ignore=DL3008,DL3009
|
|
|
|
RUN groupadd -g "${GID}" mastodon && \
|
2023-09-17 03:35:31 +00:00
|
|
|
useradd -l -u "${UID}" -g "${GID}" -m -d /opt/mastodon mastodon && \
|
2023-07-07 05:46:49 +00:00
|
|
|
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-08-25 16:26:44 +00:00
|
|
|
MASTODON_VERSION_PRERELEASE="${MASTODON_VERSION_PRERELEASE}" \
|
|
|
|
MASTODON_VERSION_METADATA="${MASTODON_VERSION_METADATA}"
|
2019-02-24 15:32:40 +00:00
|
|
|
|
2023-07-06 06:56:06 +00:00
|
|
|
# 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
|