Files
baclight/Dockerfile
T

75 lines
2.1 KiB
Docker
Raw Normal View History

2026-05-06 13:28:16 -04:00
# syntax = docker/dockerfile:1
2024-05-30 20:33:19 -07:00
2026-05-06 13:28:16 -04:00
# 1. Base Stage: Common dependencies
ARG RUBY_VERSION=3.4.8
FROM ruby:$RUBY_VERSION-slim as base
2023-03-24 11:50:11 -07:00
WORKDIR /rails
2026-05-06 13:28:16 -04:00
ENV RAILS_ENV="production" \
BUNDLE_DEPLOYMENT="1" \
BUNDLE_PATH="/usr/local/bundle" \
BUNDLE_WITHOUT="development:test"
# SUPERCRONIC_URL=https://github.com \
# SUPERCRONIC=supercronic-linux-amd64 \
# SUPERCRONIC_SHA1SUM=cd48d45327f3f3396734267468f707f43372c2fc
2026-05-06 13:28:16 -04:00
# Install base packages (libvips for Active Storage, curl for healthchecks)
2024-05-30 20:33:19 -07:00
RUN apt-get update -qq && \
2026-05-06 13:28:16 -04:00
apt-get install --no-install-recommends -y \
curl \
git \
libvips \
freetds-bin \
freetds-dev \
libpq-dev \
libyaml-dev \
cron \
libjemalloc2 \
dos2unix && \
2024-05-30 20:33:19 -07:00
rm -rf /var/lib/apt/lists /var/cache/apt/archives
2026-05-06 13:28:16 -04:00
# RUN curl -fsSLO "$SUPERCRONIC_URL" \
# && echo "${SUPERCRONIC_SHA1SUM} ${SUPERCRONIC}" | sha1sum -c - \
# && chmod +x "$SUPERCRONIC" \
# && mv "$SUPERCRONIC" /usr/local/bin/supercronic
2026-05-06 13:28:16 -04:00
# 2. Build Stage: Gems and Assets
FROM base as build
2026-05-06 13:28:16 -04:00
# Install packages needed to build gems and precompile assets
2024-05-30 20:33:19 -07:00
RUN apt-get update -qq && \
2026-05-06 13:28:16 -04:00
apt-get install --no-install-recommends -y build-essential pkg-config less && \
2024-05-30 20:33:19 -07:00
rm -rf /var/lib/apt/lists /var/cache/apt/archives
2021-09-26 14:32:21 -07:00
# Install application gems
2026-05-06 13:28:16 -04:00
RUN bundle config set --local frozen false
COPY Gemfile Gemfile.lock ./
RUN bundle install && \
2026-05-06 13:28:16 -04:00
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git
2022-02-15 12:58:42 -08:00
# Copy application code
COPY . .
2021-09-26 14:32:21 -07:00
2026-05-06 13:28:16 -04:00
# Precompile assets (Tailwind is triggered here via assets:precompile)
# SECRET_KEY_BASE_DUMMY allows precompilation without real secrets
RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile
2021-09-26 14:32:21 -07:00
2026-05-06 13:28:16 -04:00
# 3. Final Stage: Lean Runtime
FROM base
2026-05-06 13:28:16 -04:00
# Copy built artifacts: gems and precompiled assets
COPY --from=build /usr/local/bundle /usr/local/bundle
COPY --from=build /rails /rails
2026-05-06 13:28:16 -04:00
# Run as a non-privileged user for security
RUN useradd -ms /bin/bash rails
RUN chown -R rails:rails /rails
USER rails:rails
# Entrypoint prepares the database.
ENTRYPOINT ["/rails/bin/docker-entrypoint"]
2026-05-06 13:28:16 -04:00
# Start the server
EXPOSE 3002
2024-06-09 09:42:10 -07:00
CMD ["bundle", "exec", "puma", "-C", "config/puma.rb"]