# syntax = docker/dockerfile:1 # Make sure it matches the Ruby version in .ruby-version and Gemfile ARG RUBY_VERSION=<%= Gem.ruby_version %> FROM ruby:$RUBY_VERSION-slim as base # Rails app lives here WORKDIR /rails # Set production environment ENV RAILS_ENV="production" \ BUNDLE_PATH="vendor/bundle" \ BUNDLE_WITHOUT="development:test" # Throw-away build stage to reduce size of final image FROM base as build # Install packages need to build gems<%= using_node? ? " and node modules" : "" %> RUN apt-get update -qq && \ apt-get install -y <%= build_packages.join(" ") %> <% if using_node? -%> # Install JavaScript dependencies ARG NODE_VERSION=<%= node_version %> ARG YARN_VERSION=<%= yarn_version %> ENV VOLTA_HOME="/usr/local" RUN curl https://get.volta.sh | bash && \ volta install node@$NODE_VERSION yarn@$YARN_VERSION <% end -%> # Install application gems COPY Gemfile Gemfile.lock ./ RUN bundle install <% if using_node? -%> # Install node modules COPY package.json yarn.lock ./ RUN yarn install <% end -%> # Copy application code COPY . . <% if depend_on_bootsnap? -%> # Precompile bootsnap code for faster boot times RUN bundle exec bootsnap precompile --gemfile app/ lib/ <% end -%> <% unless binfile_fixups.empty? -%> # Adjust binfiles to be executable on Linux <%= "RUN " + binfile_fixups.join(" && \\\n ") %> <% end -%> <% unless api_only? -%> # Precompiling assets for production without requiring secret RAILS_MASTER_KEY RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile <% end -%> # Final stage for app image FROM base # Install packages need for deployment RUN apt-get update -qq && \ apt-get install --no-install-recommends -y <%= deploy_packages.join(" ") %> && \ rm -rf /var/lib/apt/lists /var/cache/apt/archives # Copy built application from second stage COPY --from=build /rails /rails # Deployment options ENV RAILS_LOG_TO_STDOUT="1" \ RAILS_SERVE_STATIC_FILES="true" # 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"]