Files
baclight/production.Dockerfile
T

87 lines
2.7 KiB
Docker
Raw Normal View History

2023-03-24 11:50:11 -07:00
# syntax=docker/dockerfile:1
2022-04-24 22:52:31 -07:00
# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile
2023-05-04 14:01:39 -07:00
ARG RUBY_VERSION=3.2.2
FROM registry.docker.com/library/ruby:$RUBY_VERSION-slim as base
2023-03-24 12:47:07 -07:00
WORKDIR /rails
# Set production environment
2023-09-30 19:44:40 -07:00
ENV RAILS_ENV="production" \
2023-09-30 19:46:35 -07:00
BUNDLE_DEPLOYMENT="1" \
BUNDLE_JOBS="4" \
BUNDLE_WITHOUT="development,test" \
2023-09-30 19:44:40 -07:00
BUNDLE_PATH="/usr/local/bundle"
2023-03-24 12:47:07 -07:00
# Throw-away build stage to reduce size of final image
FROM base as build
# Install packages needed to build gems
# NOTE: This example project intentionally does not require or install node.js
2023-03-24 12:47:07 -07:00
2023-05-06 10:59:57 -07:00
RUN --mount=type=cache,target=/var/cache/apt \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
--mount=type=tmpfs,target=/var/log \
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 -qq \
&& apt-get install -yq --no-install-recommends \
2022-04-24 22:52:31 -07:00
build-essential \
gnupg2 \
less \
git \
2023-09-30 09:57:54 -07:00
libpq-dev \
libvips \
pkg-config
2022-04-24 22:52:31 -07:00
2023-03-24 12:47:07 -07:00
# Install application gems
COPY Gemfile Gemfile.lock ./
RUN bundle install && \
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \
bundle exec bootsnap precompile --gemfile
2022-04-24 22:52:31 -07:00
2023-03-24 12:47:07 -07:00
# Copy application code
2022-04-24 22:52:31 -07:00
COPY . .
2023-03-24 12:47:07 -07:00
# Precompile bootsnap code for faster boot times
RUN bundle exec bootsnap precompile app/ lib/
# Precompiling assets for production without requiring secret RAILS_MASTER_KEY
2023-09-30 09:57:54 -07:00
RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile
2023-03-24 12:47:07 -07:00
2023-03-24 12:47:07 -07:00
# Final stage for app image
FROM base
# Install packages needed for deployment
2023-05-06 11:06:37 -07:00
RUN --mount=type=cache,target=/var/cache/apt \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
--mount=type=tmpfs,target=/var/log \
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 -qq \
&& apt-get install -yq --no-install-recommends \
curl \
postgresql-client \
libvips
2023-03-24 12:47:07 -07:00
# Copy built artifacts: gems, application
COPY --from=build /usr/local/bundle /usr/local/bundle
COPY --from=build /rails /rails
# Run and own only the runtime files as a non-root user for security
RUN useradd rails --create-home --shell /bin/bash && \
2023-03-24 12:47:07 -07:00
chown -R rails:rails db log storage tmp
USER rails:rails
# Entrypoint prepares the database.
ENTRYPOINT ["/rails/bin/docker-entrypoint-production"]
2022-09-10 17:24:59 -07:00
2023-09-30 19:36:08 -07:00
HEALTHCHECK --interval=15s --timeout=3s --start-period=0s --start-interval=5s --retries=3 \
2023-09-30 11:46:38 -07:00
CMD curl -f http://localhost:3000/up || exit 1
# Start the server by default, this can be overwritten at runtime
2022-04-24 22:52:31 -07:00
EXPOSE 3000
2023-09-30 20:11:14 -07:00
CMD ["bundle", "exec", "puma", "-C", "config/puma.rb"]