Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Production docker image built without test gems #334

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 34 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ RUN \
ENV APP_HOME /srv/app
ENV DEPS_HOME /deps

ARG RAILS_ENV
ENV RAILS_ENV ${RAILS_ENV:-production}
ENV NODE_ENV ${RAILS_ENV:-production}
ENV RAILS_ENV=production
ENV NODE_ENV=production

# ------------------------------------------------------------------------------
# Dependencies
Expand All @@ -42,26 +41,20 @@ RUN gem update --system 3.3.5
RUN gem install bundler -v 2.3.5
RUN bundle config set frozen "true"
RUN bundle config set no-cache "true"
RUN bundle config set with "${BUNDLE_GEM_GROUPS}"
RUN bundle config set without development test
RUN bundle install --retry=10 --jobs=4
# End

# Install Javascript dependencies
COPY yarn.lock ${DEPS_HOME}/yarn.lock
COPY package.json ${DEPS_HOME}/package.json

RUN \
if [ ${RAILS_ENV} = "production" ]; then \
yarn install --frozen-lockfile --production; \
else \
yarn install --frozen-lockfile; \
fi
# End
RUN yarn install --frozen-lockfile --production

# ------------------------------------------------------------------------------
# Web
# Production
# ------------------------------------------------------------------------------
FROM base AS web
FROM base AS production

WORKDIR ${APP_HOME}

Expand Down Expand Up @@ -119,10 +112,32 @@ EXPOSE 3000

CMD ["bundle", "exec", "rails", "server"]

# ------------------------------------------------------------------------------
# Development
# ------------------------------------------------------------------------------
FROM production as development

ENV RAILS_ENV=development
ENV NODE_ENV=development

RUN bundle config unset without
RUN bundle config set with development
RUN bundle install --retry=10 --jobs=4

# Define the runtime command in docker-compose.yml
tahb marked this conversation as resolved.
Show resolved Hide resolved
CMD ["bundle", "exec", "rails", "console"]

# ------------------------------------------------------------------------------
# Test
# ------------------------------------------------------------------------------
FROM web as test
FROM production as test

ENV RAILS_ENV=test
ENV NODE_ENV=test

RUN bundle config unset without
tahb marked this conversation as resolved.
Show resolved Hide resolved
RUN bundle config set with test
RUN bundle install --retry=10 --jobs=4

RUN \
apt-get update && \
Expand All @@ -139,3 +154,8 @@ COPY .stylelintignore ${APP_HOME}/.stylelintignore

COPY .rspec ${APP_HOME}/.rspec
COPY spec ${APP_HOME}/spec

RUN yarn install --frozen-lockfile

# Define the runtime command in docker-compose.test.yml
tahb marked this conversation as resolved.
Show resolved Hide resolved
CMD ["bundle", "exec", "rake"]
6 changes: 4 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ require_relative "config/application"

Rails.application.load_tasks

desc "Run all the tests"
task default: %i[spec standard]
if Rails.env.development? || Rails.env.test?
desc "Run all the tests"
task default: %i[spec standard]
end
2 changes: 1 addition & 1 deletion config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present?

# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
config.assets.js_compressor = Uglifier.new(harmony: true)
lozette marked this conversation as resolved.
Show resolved Hide resolved
# Set a css_compressor so sassc-rails does not overwrite the compressor when running the tests
config.assets.css_compressor = nil

Expand Down
2 changes: 0 additions & 2 deletions docker-compose.ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ services:
build:
context: .
target: test
args:
RAILS_ENV: "test"
cache_from:
- app_test:latest
image: app_test
Expand Down
2 changes: 0 additions & 2 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ services:
build:
context: .
target: test
args:
RAILS_ENV: "test"
command: bundle exec rake
ports:
- "3000:3000"
Expand Down
4 changes: 1 addition & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ services:
web:
build:
context: .
target: web
args:
RAILS_ENV: "development"
target: development
command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
ports:
- "3000:3000"
Expand Down
Loading