Skip to content
Merged
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
7 changes: 3 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@ ARG TARGETPLATFORM
# Upgrade inherited packages even when their existing versions satisfy dependencies.
RUN set -xe; \
apk upgrade --no-cache; \
# Replace bundled gems, including the old default JSON implementation.
# Refresh bundled gems to the latest releases compatible with this Ruby.
apk add --no-cache --virtual .wodby-gem-build-deps build-base; \
system_gems="$(ruby -e 'print Gem.default_dir')"; \
gem install --install-dir "$system_gems" --no-document json -v '~> 2.19.9'; \
gem install --install-dir "$system_gems" --no-document net-imap -v '~> 0.5.15'; \
ruby -rjson -rnet/imap -e 'abort unless Gem.loaded_specs.fetch("json").version >= Gem::Version.new("2.19.9")'; \
gem install --install-dir "$system_gems" --no-document json net-imap; \
# Remove the replaced default JSON implementation as well as its gemspec. \
ruby -rrbconfig -rfileutils -e ' \
root = RbConfig::CONFIG.fetch("rubylibdir"); \
arch = RbConfig::CONFIG.fetch("archdir"); \
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ buildx-imagetools-create:
.PHONY: buildx-imagetools-create

test:
docker run --rm --network none --entrypoint ruby -v "$(CURDIR)/tests/system-gems.rb:/tmp/system-gems.rb:ro" $(REPO):$(TAG) /tmp/system-gems.rb
cd ./tests && IMAGE=$(REPO):$(TAG) bash ./workspace-contract.sh
ifneq ($(RUBY_DEV),)
cd ./tests && RUBY_IMAGE=$(REPO):$(TAG) ./run.sh
Expand Down
25 changes: 25 additions & 0 deletions tests/system-gems.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Verify refreshed system gems load after removing the inherited implementations.
require 'json'
require 'net/imap'
require 'rbconfig'

%w[json net-imap].each do |name|
spec = Gem.loaded_specs.fetch(name)
abort "#{name} was not installed in the system gem directory" unless spec.base_dir == Gem.default_dir
abort "Old #{name} versions remain installed" unless Gem::Specification.find_all_by_name(name).size == 1
puts "#{name}=#{spec.version}"
end

abort 'JSON round trip failed' unless JSON.parse(JSON.generate('ok' => true)).fetch('ok')
abort 'Net::IMAP did not load' unless defined?(Net::IMAP::ResponseParser)

# Default gems cannot be removed by gem cleanup; their files need explicit removal.
root = RbConfig::CONFIG.fetch('rubylibdir')
arch = RbConfig::CONFIG.fetch('archdir')
[File.join(root, 'json'), File.join(root, 'json.rb'), File.join(arch, 'json')].each do |path|
abort "Inherited JSON implementation remains at #{path}" if File.exist?(path)
end

# System gem updates must not create root-owned files in the application bundle.
abort 'System gem updates created an application Gemfile' if File.exist?(File.join(Gem.dir, 'Gemfile'))
abort 'System gem updates created an application lockfile' if File.exist?(File.join(Gem.dir, 'Gemfile.lock'))
Loading