Files

85 lines
2.7 KiB
Docker
Raw Permalink 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"
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
# 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 16:29:07 -04:00
apt-get install --no-install-recommends -y build-essential pkg-config less && \
# mkdir -p /etc/apt/keyrings && \
# curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \
# echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" > /etc/apt/sources.list.d/nodesource.list && \
# apt-get update && \
# apt-get install nodejs -y && \
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
2026-05-06 16:29:07 -04:00
# RUN apt-get install -y npm
# RUN npm install -g yarn
2026-05-06 16:11:02 -04: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-06-17 23:23:36 -04:00
RUN ./bin/rails stimulus:manifest:update
RUN ./bin/importmap pin .
2026-05-06 17:08:48 -04:00
# RUN bundle exec ./bin/rails rails_icons:sync
RUN ./bin/rails generate rails_icons:sync --libraries=lucide
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
2026-06-17 23:23:36 -04:00
# RUN bundle exec rails assets:clobber assets:precompile RAILS_ENV=production SECRET_KEY_BASE_DUMMY=1
RUN bundle exec rails assets:precompile RAILS_ENV=production SECRET_KEY_BASE_DUMMY=1
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
2026-06-17 23:23:36 -04:00
# COPY --from=build /rails/public /rails/public
# COPY --from=build /rails/app/javascript /rails/app/javascript
# COPY --from=build /rails/config/importmap.rb /rails/config/importmap.rb
2026-05-06 13:28:16 -04:00
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"]