- Run
docker compose run web bundle && docker compose build
to update your Gemfile.lock before building the image - Gemfile.dev should be nearly identical to Gemfile but also contain development gems such as 'debug' and 'solargraph-rails'
- Dockerfile.dev should be nearly identical to Dockerfile, except for the
FROM
image version,COPY Gemfile.dev Gemfile
,COPY Gemfile.lock Gemfile.lock
, and possibly using the root user - Remember to revert your Gemfile.lock before committing, e.g.
git checkout develop -- Gemfile.lock
Created
September 1, 2023 07:24
-
-
Save sephraim/4b982568e326fefec6b082f1c7f4effd to your computer and use it in GitHub Desktop.
[Override Dockerfile / Gemfile for local development] # Add the following files to your project root
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Use Dockerfile.dev to upgrade Ruby and Gemfile.dev to add local dev gems such as 'debug' and 'solargraph-rails' | |
services: | |
web: | |
build: | |
context: . | |
dockerfile: Dockerfile.dev | |
volumes: | |
- .:/app | |
- ./Gemfile.dev:/app/Gemfile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ! DEV ONLY - UPGRADE RUBY | |
ARG RUBY_VERSION=2.7.8 | |
# Server setup | |
FROM ruby:${RUBY_VERSION} as base | |
WORKDIR /app | |
RUN apt-get update -qq | |
RUN apt-get install --no-install-recommends -y --allow-downgrades \ | |
build-essential \ | |
libpq-dev \ | |
netcat \ | |
less | |
RUN apt-get purge -y --auto-remove | |
RUN rm -rf /var/lib/apt/lists/* | |
# Prep for gem installation | |
# NOTE: The following `gem update` command is necessary to avoid a RubyGems warning. | |
# Also Bundler v2.3.26 is the last version that works with Ruby 2.5. | |
# When Ruby gets upgraded, the following command can change to: `RUN gem install bundler` | |
RUN gem update --system 3.2.3 && gem install bundler -v 2.3.26 | |
# App build | |
FROM base as gemset | |
# ! DEV ONLY - USE Gemfile.dev TO INSTALL DEBUGGER | |
COPY Gemfile.dev Gemfile | |
COPY Gemfile.lock Gemfile.lock | |
RUN bundle update --bundler && bundle install | |
# App env setup | |
FROM base | |
ENV LANG=C.UTF-8 LC_ALL=C.UTF-8 | |
ENV RACK_ENV=development | |
COPY --from=gemset /usr/local/bundle /usr/local/bundle | |
COPY . . | |
EXPOSE 3000/tcp | |
CMD ["bundle", "exec", "rails", "s", "-p", "3000", "-b", "0.0.0.0"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
source 'https://rubygems.org' | |
git_source(:github) { |repo| "https://github.com/#{repo}.git" } | |
ruby '3.1.2' | |
# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main" | |
gem 'rails', '~> 7.0.4' | |
# Use mysql as the database for Active Record | |
gem 'mysql2', '~> 0.5' | |
# Use the Puma web server [https://github.com/puma/puma] | |
gem 'puma', '~> 5.0' | |
# Build JSON APIs with ease [https://github.com/rails/jbuilder] | |
# gem "jbuilder" | |
# Use Redis adapter to run Action Cable in production | |
# gem "redis", "~> 4.0" | |
# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis] | |
# gem "kredis" | |
# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword] | |
# gem "bcrypt", "~> 3.1.7" | |
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem | |
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby] | |
# Reduces boot times through caching; required in config/boot.rb | |
gem 'bootsnap', require: false | |
# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images] | |
# gem "image_processing", "~> 1.2" | |
# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible | |
# gem "rack-cors" | |
# Enable JSON API serialization | |
gem 'active_model_serializers' | |
group :development, :test do | |
gem 'byebug' | |
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem | |
gem 'debug', platforms: %i[mri mingw x64_mingw] # ! DEV ONLY | |
gem 'rspec-rails' | |
gem 'rubocop-rails' | |
end | |
group :development do | |
gem 'solargraph-rails' # ! DEV ONLY | |
# Speed up commands on slow machines / big apps [https://github.com/rails/spring] | |
# gem "spring" | |
end | |
group :test do | |
gem 'factory_bot_rails' | |
gem 'faker' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment