In a Dev category discussion titled ‘Online update succeeds, but rebuild fails,’ merefield reports that while online updates succeed, CLI rebuilds fail when installing the rmagick gem due to missing ImageMagick compile-time libraries. The issue stems from a recent Docker image update (5ed07ecc) that removed these libraries to reduce image size. featheredtoast suggests either installing libmagickwand-dev via a hook or removing the rmagick dependency, noting that Discourse’s image optimization already uses ImageMagick binaries directly. merefield expresses disappointment, preferring rmagick’s API over clunky system calls. featheredtoast provides a hook example to install dependencies, clarifying that the base image doesn’t block installations — just omits the libraries. Jagster attempts the fix but reports failure, possibly due to tmux scroll limitations — later clarified by pfaffman. Ultimately, merefield resolves the issue by replacing rmagick with direct ImageMagick CLI calls, calling it a regrettable but necessary workaround.
Came across a curious issue which may highlight another difference between online updates and command line updates.
If I perform an online update with a plugin with the rmagick gem, it succeeds.
However, it fails with a cli rebuild with:
ERROR: Error installing rmagick:
ERROR: Failed to build gem native extension.
current directory: /var/www/discourse/plugins/discourse-topic-previews-sidecar/gems/3.3.6/gems/rmagick-6.0.1/ext/RMagick
/usr/local/bin/ruby extconf.rb
checking for brew... no
checking for pacman... no
checking for Ruby version >= 3.0.0... yes
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include=${opt-dir}/include
--without-opt-include
--with-opt-lib=${opt-dir}/lib
--without-opt-lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/usr/local/bin/$(RUBY_BASE_NAME)
--with-pkg-config
--without-pkg-config
--with-override-variables
--without-override-variables
/var/www/discourse/plugins/discourse-topic-previews-sidecar/gems/3.3.6/gems/pkg-config-1.5.6/lib/pkg-config.rb:504:in `parse_pc': .pc doesn't exist: <MagickCore> (PackageConfig::NotFoundError)
Are gems only built during a full build? Or could it be there has been a Ruby version increment which is only performed on a full rebuild? (which then forces a remake of the gem?)
We’ve updated our image so we’re compiling imagemagick separately and only including the final imagemagick binary, so we are no longer including compile-time libs for imagemagick in the image in an effort to reduce the size of our base images.
You could simply add an install script to install imagemagick libs, but I’d recommend removing the plugin’s dependency on the rmagick gem - I’m not sure I see where that gem is being called as it looks like it’s extending core Discourse’s optimize image calls, which just calls out to the imagemagick binary directly.
Even if I’m able to find a worklaround, it would be a real shame to block the use of rmagick gem as the alternative is messing with system calls to ImageMagick, which is a bit … clunky … and much less developer friendly as opposed to using a convenient API in language.