Files
danbooru/config/docker/Dockerfile.danbooru
evazion c1a37d9577 docker: set MALLOC_ARENA_MAX=2.
Setting MALLOC_ARENA_MAX=2 is claimed to reduce memory bloat caused by
fragmentation. Jemalloc 3.x is also claimed to reduce memory bloat, but
modern distros only ship Jemalloc 5.x, and supposedly only 3.x works.

https://devcenter.heroku.com/articles/tuning-glibc-memory-behavior
https://bugs.ruby-lang.org/issues/14718
https://www.speedshop.co/2017/12/04/malloc-doubles-ruby-memory.html
https://www.joyfulbikeshedding.com/blog/2019-03-14-what-causes-ruby-memory-bloat.html
2021-11-28 22:45:50 -06:00

80 lines
2.1 KiB
Docker

FROM ubuntu:21.04 AS base
WORKDIR /danbooru
ENV PATH="/root/.asdf/bin:/root/.asdf/shims:$PATH:/usr/lib/postgresql/14/bin"
# Reduces memory usage at the cost of higher thread contention.
# https://bugs.ruby-lang.org/issues/14718
ENV MALLOC_ARENA_MAX=2
COPY config/docker/build-base-image.sh .
RUN \
./build-base-image.sh && \
chmod go+rx /root && \
useradd --home-dir /root --user-group danbooru && \
rm build-base-image.sh
FROM base AS development
ARG NODE_VERSION=14.15.5
RUN \
apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
build-essential libpq-dev libvips-dev zlib1g-dev \
curl ca-certificates dirmngr git gpg && \
rm -rf /var/lib/apt/lists/*
RUN \
asdf plugin add nodejs && \
asdf install nodejs "$NODE_VERSION" && \
asdf global nodejs "$NODE_VERSION" && \
npm install --unsafe-perm=true -g yarn
COPY Gemfile Gemfile.lock ./
RUN \
bundle install --jobs "$(nproc)" && \
rm -rf "$(gem environment gemdir)/cache" && \
find "$(gem environment gemdir)" -name "*.o" -delete
COPY .yarnrc.yml package.json yarn.lock ./
COPY .yarn/ ./.yarn/
RUN yarn install
COPY postcss.config.js Rakefile ./
COPY bin/rails bin/webpack ./bin/
COPY config/application.rb config/boot.rb config/danbooru_default_config.rb config/webpacker.yml ./config/
COPY config/webpack/ ./config/webpack/
COPY public/images ./public/images
COPY public/fonts ./public/fonts
COPY app/components/ ./app/components/
COPY app/javascript/ ./app/javascript/
RUN \
bin/rails assets:precompile && \
rm -rf \
node_modules .yarn/cache tmp /usr/local/share/.cache/yarn \
/root/.yarn/berry/cache /root/.bundle/cache /root/.npm && \
ln -s /tmp tmp && \
ln -s packs public/packs-test
FROM base as production
COPY --from=development /root /root
COPY --from=development /danbooru /danbooru
COPY . .
ARG SOURCE_COMMIT
RUN echo "$SOURCE_COMMIT" > REVISION
USER danbooru
ENTRYPOINT ["tini", "--"]
CMD ["bin/rails", "server"]
# https://github.com/opencontainers/image-spec/blob/main/annotations.md
LABEL org.opencontainers.image.source https://github.com/danbooru/danbooru