Skip to content

Commit 198525a

Browse files
committed
fix(docker): prevent bundler from loading dev/test gems in production builds
Containers were failing to start because Bundler was attempting to resolve and load development/test gems even though they weren't installed (due to `bundle install --without development test`). This occurred because Bundler parses the entire Gemfile and tries to resolve all gem groups, regardless of the --without flag. Changes: - Wrap dev/test gem groups in conditional `unless ENV['SKIP_DEV_GEMS']` to completely exclude them from Bundler's view during production builds - Set `ENV SKIP_DEV_GEMS=1` in all Dockerfiles before bundle install - Add explicit `gem "anycable", "~> 1.5"` to fix missing anycable RPC command - Update deprecated platform syntax from `:mingw, :x64_mingw` to `:windows` - Add `.bundle/` to .dockerignore to prevent local bundler config from overwriting Docker build config - Make RAILS_ENV configurable via .env with production as default (`RAILS_ENV: "${RAILS_ENV:-production}"` in compose.yaml) The conditional logic preserves local development functionality - when SKIP_DEV_GEMS is not set, dev/test gems are defined and installed normally. Fixes: Container startup failures with "Could not find gem 'byebug' in locally installed gems" error despite using --without development test
1 parent 9d51575 commit 198525a

File tree

9 files changed

+42
-96
lines changed

9 files changed

+42
-96
lines changed

openc3-cosmos-cmd-tlm-api/.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Gemfile.lock
88
coverage/
99
spec/
1010
test/
11+
.bundle/
1112
# Keep the directories but no contents
1213
log/*
1314
tmp/*

openc3-cosmos-cmd-tlm-api/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ COPY Gemfile Gemfile.lock* ./
1010

1111
USER root
1212

13+
ENV SKIP_DEV_GEMS=1
1314
RUN bundle config set --local without 'development test' \
1415
&& bundle install --quiet \
1516
&& rm -rf /usr/lib/ruby/gems/*/cache/* \

openc3-cosmos-cmd-tlm-api/Dockerfile-ubi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ COPY Gemfile Gemfile.lock* ./
1010

1111
USER root
1212

13+
ENV SKIP_DEV_GEMS=1
1314
RUN bundle config set --local without 'development test' \
1415
&& bundle install --quiet \
1516
&& rm -rf /usr/lib/ruby/gems/*/cache/* \

openc3-cosmos-cmd-tlm-api/Gemfile

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ gem 'rails', '~> 7.2.0'
99

1010
# Use anycable instead of actioncable
1111
gem "anycable-rails", "~> 1.5"
12+
gem "anycable", "~> 1.5"
1213

1314
# The following gems are installed in the OpenC3 base container openc3-base
1415
# which this Dockerfile depends on: puma, redis, nokogiri
@@ -32,19 +33,23 @@ gem "rails_semantic_logger", '~> 4.17'
3233
# For downloading files to the server (e.g. plugin install from the app store)
3334
gem 'down', '~> 5.4', '>= 5.4.2'
3435

35-
group :development, :test do
36-
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
37-
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
38-
gem 'rspec-rails', '~> 7.0'
39-
gem 'simplecov', '~> 0.22'
40-
gem 'simplecov-cobertura', '~> 3.0'
41-
gem 'rexml', '~> 3.4'
42-
# simplecov_json_formatter formatter supports SonarQube
43-
# gem 'simplecov_json_formatter', '~> 0.1'
44-
end
36+
# Only define development/test gems if not in production build
37+
# Set SKIP_DEV_GEMS=1 in Dockerfile to exclude these groups entirely
38+
unless ENV['SKIP_DEV_GEMS']
39+
group :development, :test do
40+
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
41+
gem 'byebug', platforms: [:mri, :windows]
42+
gem 'rspec-rails', '~> 7.0'
43+
gem 'simplecov', '~> 0.22'
44+
gem 'simplecov-cobertura', '~> 3.0'
45+
gem 'rexml', '~> 3.4'
46+
# simplecov_json_formatter formatter supports SonarQube
47+
# gem 'simplecov_json_formatter', '~> 0.1'
48+
end
4549

46-
group :test do
47-
gem 'mock_redis', '~> 0.47'
50+
group :test do
51+
gem 'mock_redis', '~> 0.47'
52+
end
4853
end
4954

5055
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem

openc3-cosmos-script-runner-api/.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Gemfile.lock
88
coverage/
99
spec/
1010
test/
11+
.bundle/
1112
# Keep the directories but no contents
1213
log/*
1314
tmp/*

openc3-cosmos-script-runner-api/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ COPY Gemfile Gemfile.lock* ./
1010

1111
USER root
1212

13+
ENV SKIP_DEV_GEMS=1
1314
RUN bundle config set --local without 'development test' \
1415
&& bundle install --quiet \
1516
&& rm -rf /usr/lib/ruby/gems/*/cache/* \

openc3-cosmos-script-runner-api/Dockerfile-ubi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ COPY Gemfile Gemfile.lock* ./
1010

1111
USER root
1212

13+
ENV SKIP_DEV_GEMS=1
1314
RUN bundle config set --local without 'development test' \
1415
&& bundle install --quiet \
1516
&& rm -rf /usr/lib/ruby/gems/*/cache/* \

openc3-cosmos-script-runner-api/Gemfile

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ gem 'rails', '~> 7.2.0'
99

1010
# Use anycable instead of actioncable
1111
gem "anycable-rails", "~> 1.5"
12+
gem "anycable", "~> 1.5"
1213

1314
# The following gems are installed in the OpenC3 base container openc3-base
1415
# which this Dockerfile depends on: puma, redis, nokogiri
@@ -29,20 +30,24 @@ gem 'rack-cors', '~> 3.0'
2930
# Use gem to get JSON logs
3031
gem "rails_semantic_logger", '~> 4.17'
3132

32-
group :development, :test do
33-
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
34-
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
35-
gem 'rspec-rails', '~> 7.0'
36-
gem 'rspec'
37-
gem 'simplecov', '~> 0.22'
38-
gem 'simplecov-cobertura', '~> 3.0'
39-
gem 'rexml', '~> 3.4'
40-
# simplecov_json_formatter formatter supports SonarQube
41-
# gem 'simplecov_json_formatter', '~> 0.1'
42-
end
43-
44-
group :test do
45-
gem 'mock_redis', '~> 0.47'
33+
# Only define development/test gems if not in production build
34+
# Set SKIP_DEV_GEMS=1 in Dockerfile to exclude these groups entirely
35+
unless ENV['SKIP_DEV_GEMS']
36+
group :development, :test do
37+
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
38+
gem 'byebug', platforms: [:mri, :windows]
39+
gem 'rspec-rails', '~> 7.0'
40+
gem 'rspec'
41+
gem 'simplecov', '~> 0.22'
42+
gem 'simplecov-cobertura', '~> 3.0'
43+
gem 'rexml', '~> 3.4'
44+
# simplecov_json_formatter formatter supports SonarQube
45+
# gem 'simplecov_json_formatter', '~> 0.1'
46+
end
47+
48+
group :test do
49+
gem 'mock_redis', '~> 0.47'
50+
end
4651
end
4752

4853
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem

scripts/linux/openc3_build_ubi.sh

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -144,58 +144,6 @@ record_build() {
144144
BUILD_TIMES+=("$duration")
145145
}
146146

147-
# Helper function to prepare Ruby services for air-gapped builds
148-
# This generates a Gemfile.lock without development/test gems to avoid
149-
# dependency resolution failures in air-gapped environments
150-
prepare_ruby_service() {
151-
local service_dir="$1"
152-
local abs_service_dir="${SCRIPT_DIR}/${service_dir}"
153-
echo " Preparing Gemfile.lock for air-gapped build..."
154-
155-
# Check if Gemfile exists
156-
if [ ! -f "$abs_service_dir/Gemfile" ]; then
157-
echo " No Gemfile found, skipping preparation"
158-
return 0
159-
fi
160-
161-
# Generate Gemfile.lock without dev/test gems
162-
# Set bundler version to match what's installed in openc3-ruby-ubi
163-
(cd "$abs_service_dir" && \
164-
bundle config set --local without 'development test' && \
165-
bundle lock --conservative --bundler=2.5.22 2>/dev/null || bundle lock --bundler=2.5.22) && \
166-
echo " Generated Gemfile.lock without development/test gems"
167-
168-
# Temporarily modify .dockerignore to include Gemfile.lock
169-
if [ -f "$abs_service_dir/.dockerignore" ]; then
170-
if grep -q "^Gemfile\.lock$" "$abs_service_dir/.dockerignore"; then
171-
cp "$abs_service_dir/.dockerignore" "$abs_service_dir/.dockerignore.bak"
172-
sed -i.tmp '/^Gemfile\.lock$/d' "$abs_service_dir/.dockerignore" && rm -f "$abs_service_dir/.dockerignore.tmp"
173-
echo " Modified .dockerignore to include Gemfile.lock in build"
174-
fi
175-
fi
176-
}
177-
178-
# Cleanup function for Ruby service preparation
179-
cleanup_ruby_service() {
180-
local service_dir="$1"
181-
local abs_service_dir="${SCRIPT_DIR}/${service_dir}"
182-
183-
# Restore .dockerignore if we backed it up
184-
if [ -f "$abs_service_dir/.dockerignore.bak" ]; then
185-
mv "$abs_service_dir/.dockerignore.bak" "$abs_service_dir/.dockerignore"
186-
echo " Restored .dockerignore"
187-
fi
188-
189-
# Remove generated Gemfile.lock
190-
if [ -f "$abs_service_dir/Gemfile.lock" ]; then
191-
rm -f "$abs_service_dir/Gemfile.lock"
192-
echo " Removed generated Gemfile.lock"
193-
fi
194-
195-
# Clean up bundle config
196-
(cd "$abs_service_dir" && bundle config unset without 2>/dev/null || true)
197-
}
198-
199147
if should_build "openc3-ruby-ubi"; then
200148
echo "Building openc3-ruby-ubi..."
201149
START_TIME=$SECONDS
@@ -221,12 +169,6 @@ if should_build "openc3-base-ubi"; then
221169
echo "Building openc3-base-ubi..."
222170
START_TIME=$SECONDS
223171

224-
# Prepare Gemfile.lock for air-gapped build
225-
prepare_ruby_service "openc3"
226-
227-
# Set trap to ensure cleanup even on error
228-
trap "cleanup_ruby_service 'openc3'" EXIT
229-
230172
cd openc3
231173
docker build \
232174
-f Dockerfile-ubi \
@@ -329,12 +271,6 @@ if should_build "openc3-cosmos-cmd-tlm-api-ubi"; then
329271
echo "Building openc3-cosmos-cmd-tlm-api-ubi..."
330272
START_TIME=$SECONDS
331273

332-
# Prepare Gemfile.lock for air-gapped build
333-
prepare_ruby_service "openc3-cosmos-cmd-tlm-api"
334-
335-
# Set trap to ensure cleanup even on error
336-
trap "cleanup_ruby_service 'openc3-cosmos-cmd-tlm-api'" EXIT
337-
338274
cd openc3-cosmos-cmd-tlm-api
339275
docker build \
340276
-f Dockerfile-ubi \
@@ -361,12 +297,6 @@ if should_build "openc3-cosmos-script-runner-api-ubi"; then
361297
echo "Building openc3-cosmos-script-runner-api-ubi..."
362298
START_TIME=$SECONDS
363299

364-
# Prepare Gemfile.lock for air-gapped build
365-
prepare_ruby_service "openc3-cosmos-script-runner-api"
366-
367-
# Set trap to ensure cleanup even on error
368-
trap "cleanup_ruby_service 'openc3-cosmos-script-runner-api'" EXIT
369-
370300
cd openc3-cosmos-script-runner-api
371301
docker build \
372302
-f Dockerfile-ubi \

0 commit comments

Comments
 (0)