From dfa90600b52683a6c8b208b34d483de961ac1d85 Mon Sep 17 00:00:00 2001 From: Noah Durbin <13364668+noahdurbin@users.noreply.github.com> Date: Mon, 26 Aug 2024 12:55:48 -0600 Subject: [PATCH] feat: dockerfile setup --- Dockerfile | 65 ++++++++---------------------------------------------- 1 file changed, 9 insertions(+), 56 deletions(-) diff --git a/Dockerfile b/Dockerfile index 11d58b9..fab82f2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,59 +1,12 @@ -# syntax = docker/dockerfile:1 +FROM ruby:3.2.2 -# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile -ARG RUBY_VERSION=3.2.2 -FROM registry.docker.com/library/ruby:$RUBY_VERSION-slim as base +RUN apt-get update -qq && apt-get install -y nodejs postgresql-client +WORKDIR /app +COPY Gemfile /app/Gemfile +COPY Gemfile.lock /app/Gemfile.lock +RUN bundle install +COPY . /app -# Rails app lives here -WORKDIR /rails +EXPOSE ${PORT:-3000} -# Set production environment -ENV RAILS_ENV="production" \ - BUNDLE_DEPLOYMENT="1" \ - BUNDLE_PATH="/usr/local/bundle" \ - BUNDLE_WITHOUT="development" - - -# Throw-away build stage to reduce size of final image -FROM base as build - -# Install packages needed to build gems -RUN apt-get update -qq && \ - apt-get install --no-install-recommends -y build-essential git libpq-dev libvips pkg-config - -# 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 - -# Copy application code -COPY . . - -# Precompile bootsnap code for faster boot times -RUN bundle exec bootsnap precompile app/ lib/ - - -# Final stage for app image -FROM base - -# Install packages needed for deployment -RUN apt-get update -qq && \ - apt-get install --no-install-recommends -y curl libvips postgresql-client && \ - rm -rf /var/lib/apt/lists /var/cache/apt/archives - -# 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 && \ - chown -R rails:rails db log storage tmp -USER rails:rails - -# Entrypoint prepares the database. -ENTRYPOINT ["/rails/bin/docker-entrypoint"] - -# Start the server by default, this can be overwritten at runtime -EXPOSE 3000 -CMD ["./bin/rails", "server"] +CMD ["rails", "server", "-b", "0.0.0.0"]