th: optimize dockerfile (attempt was made)

pull/59/head
kouhai dev 2023-03-15 20:48:30 -07:00
parent 236f063dd3
commit 0382d1efe7
1 changed files with 22 additions and 12 deletions

View File

@ -13,7 +13,6 @@ ENV DEBIAN_FRONTEND="noninteractive" \
SHELL ["/bin/bash", "-o", "pipefail", "-c"] SHELL ["/bin/bash", "-o", "pipefail", "-c"]
WORKDIR /opt/mastodon WORKDIR /opt/mastodon
COPY Gemfile* package.json yarn.lock /opt/mastodon/
# hadolint ignore=DL3008 # hadolint ignore=DL3008
RUN apt-get update && \ RUN apt-get update && \
@ -32,14 +31,32 @@ RUN apt-get update && \
ca-certificates \ ca-certificates \
libreadline8 \ libreadline8 \
python3 \ python3 \
shared-mime-info && \ shared-mime-info
COPY --link .yarn/releases/ /opt/mastodon/.yarn/releases/
COPY --link Gemfile* package.json yarn.lock .yarnrc.yml /opt/mastodon/
RUN \
bundle config set --local deployment 'true' && \ bundle config set --local deployment 'true' && \
bundle config set --local without 'development test' && \ bundle config set --local without 'development test' && \
bundle config set silence_root_warning true && \ bundle config set silence_root_warning true && \
bundle install -j"$(nproc)" && \ bundle install -j"$(nproc)" && \
yarn install --pure-lockfile --network-timeout 600000 && \ yarn install --immutable && \
yarn cache clean yarn cache clean
ENV RAILS_ENV="production" \
NODE_ENV="production"
# Precompile assets
# TODO(kouhai): we're currently patching node_modules because of emoji-mart.
# we should integrate our own fork instead.
COPY ./emoji_data/all.json ./node_modules/emoji-mart/data/all.json
ENV OTP_SECRET=precompile_placeholder \
SECRET_KEY_BASE=precompile_placeholder \
RAKE_NO_YARN_INSTALL_HACK=1
RUN bundle exec rails assets:precompile
FROM node:${NODE_VERSION} FROM node:${NODE_VERSION}
ARG UID="991" ARG UID="991"
@ -79,8 +96,8 @@ RUN apt-get update && \
# Note: no, cleaning here since Debian does this automatically # 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 # See the file /etc/apt/apt.conf.d/docker-clean within the Docker image's filesystem
COPY --chown=mastodon:mastodon . /opt/mastodon COPY --link --chown=mastodon:mastodon . /opt/mastodon
COPY --chown=mastodon:mastodon --from=build /opt/mastodon /opt/mastodon COPY --link --chown=mastodon:mastodon --from=build /opt/mastodon /opt/mastodon
ENV RAILS_ENV="production" \ ENV RAILS_ENV="production" \
NODE_ENV="production" \ NODE_ENV="production" \
@ -91,13 +108,6 @@ ENV RAILS_ENV="production" \
USER mastodon USER mastodon
WORKDIR /opt/mastodon WORKDIR /opt/mastodon
# Precompile assets
# TODO(kaniini): Yarn install is invoked to allow us to pre-patch emoji-mart
# we should set up a deviation instead.
RUN yarn install && cp ./emoji_data/all.json ./node_modules/emoji-mart/data/all.json && \
OTP_SECRET=precompile_placeholder SECRET_KEY_BASE=precompile_placeholder rails assets:precompile && \
yarn cache clean
# Set the work dir and the container entry point # Set the work dir and the container entry point
ENTRYPOINT ["/usr/bin/tini", "--"] ENTRYPOINT ["/usr/bin/tini", "--"]
EXPOSE 3000 4000 EXPOSE 3000 4000