Files
danbooru/config/docker/Dockerfile.danbooru
evazion 3a05b7e832 docker: add less and tini to base image.
Add `less` to the Docker image to fix an issue with running `bin/rails console`.
The console uses Pry[1], which has an issue where it pipes long output
through `less`, but it tries to use the -X option, which is only
supported by GNU less, not Busybox less. There's a open bug about this
in the Pry repo dating back to 2014[2].

Add `tini` and use it as the Docker entrypoint to ensure we forward
signals to child processes and reap zombie children properly. This fixes
an issue where if you ran something like:

  docker run ghcr.io/danbooru/danbooru bash -c 'bin/rails db:test:prepare && bin/rails test'

Then you couldn't use control-C to stop the container. This was because
bash wasn't forwarding signals to its children, and because by default,
programs running as PID 1 ignore SIGINT and SIGTERM. See [3][4] for details.

1: https://github.com/pry/pry
2: https://github.com/pry/pry/issues.1248
3: https://github.com/krallin/tini/issues.8
4: https://gist.github.com/StevenACoffman/41fee08e8782b411a4a26b9700ad7af5#dont-run-pid-1
2021-09-22 02:52:36 -05:00

71 lines
1.6 KiB
Docker

FROM ubuntu:20.10 AS base
WORKDIR /danbooru
ENV PATH="/root/.asdf/bin:/root/.asdf/shims:$PATH"
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 .yarn package.json yarn.lock ./
RUN yarn install
COPY . .
ARG SOURCE_COMMIT
RUN echo "$SOURCE_COMMIT" > REVISION
FROM development AS assets
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 && \
asdf uninstall nodejs && \
ln -s /tmp tmp
FROM base as production
COPY --from=development /root /root
COPY --from=assets /danbooru /danbooru
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