diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c1351a3..01dc2a7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -23,5 +23,25 @@ jobs: with: ruby-version: ${{ matrix.ruby }} bundler-cache: true - - run: bin/setup - - run: bin/rake test + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Build dockerfile.vips + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile.vips + tags: vips:latest + cache-from: type=gha + cache-to: type=gha,mode=max + load: true + - run: docker run --rm vips:latest bundle exec rake test X=/image_magick/ + - name: Build dockerfile.imagemagick + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile.imagemagick + tags: imagemagick:latest + cache-from: type=gha + cache-to: type=gha,mode=max + load: true + - run: docker run --rm imagemagick:latest bundle exec rake test X=/vips/ diff --git a/Dockerfile.imagemagick b/Dockerfile.imagemagick new file mode 100644 index 0000000..f933044 --- /dev/null +++ b/Dockerfile.imagemagick @@ -0,0 +1,19 @@ +FROM ruby:3.3 + +# throw errors if Gemfile has been modified since Gemfile.lock +RUN bundle config --global frozen 1 + +RUN apt-get update && apt-get install -y \ + imagemagick \ + inkscape \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /usr/src/app + +COPY lib/favicon_factory/version.rb ./lib/favicon_factory/version.rb +COPY favicon_factory.gemspec Gemfile Gemfile.lock . +RUN bundle install + +COPY . . + +CMD ["bin/console"] diff --git a/Dockerfile.vips b/Dockerfile.vips new file mode 100644 index 0000000..30433ae --- /dev/null +++ b/Dockerfile.vips @@ -0,0 +1,20 @@ +FROM ruby:3.3 + +# throw errors if Gemfile has been modified since Gemfile.lock +RUN bundle config --global frozen 1 + +RUN apt-get update && apt-get install -y \ + libvips \ + libvips-tools \ + && rm -rf /var/lib/apt/lists/* +RUN apt-get remove -y --purge imagemagick + +WORKDIR /usr/src/app + +COPY lib/favicon_factory/version.rb ./lib/favicon_factory/version.rb +COPY favicon_factory.gemspec Gemfile Gemfile.lock . +RUN bundle install + +COPY . . + +CMD ["bin/console"] diff --git a/README.md b/README.md index bf5f8ff..f50034c 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,8 @@ brew install vips ``` ```bash -sudo apt install libvips +sudo apt-get install libvips +sudo apt-get install libvips-tools ``` ImageMagick and Inkscape: @@ -48,8 +49,8 @@ brew install inkscape ``` ```bash -sudo apt install imagemagick -sudo apt install inkscape +sudo apt-get install imagemagick +sudo apt-get install inkscape ``` Add `favicon_factory` to the Gemfile: diff --git a/bin/setup b/bin/setup index bad4eaf..091a47a 100755 --- a/bin/setup +++ b/bin/setup @@ -19,9 +19,10 @@ FileUtils.chdir GEM_ROOT do system! "brew install inkscape" system! "brew install vips" when "linux" - system! "sudo apt install imagemagick" - system! "sudo apt install inkscape" - system! "sudo apt install libvips" + system! "sudo apt-get install imagemagick" + system! "sudo apt-get install inkscape" + system! "sudo apt-get install libvips" + system! "sudo apt-get install libvips-tools" else raise "Unsupported platform: #{Gem::Platform.local.os}" end diff --git a/build.log b/build.log new file mode 100644 index 0000000..1f9e898 --- /dev/null +++ b/build.log @@ -0,0 +1,76 @@ +#1 [internal] load .dockerignore +#1 transferring context: 2B done +#1 DONE 0.0s + +#2 [internal] load build definition from Dockerfile +#2 transferring dockerfile: 317B done +#2 DONE 0.0s + +#3 [internal] load metadata for docker.io/library/ruby:3.3 +#3 DONE 1.4s + +#4 [1/7] FROM docker.io/library/ruby:3.3@sha256:797d68561a91415e05fd95178f467d86d77bce2d4f17f32683241a687cbd1705 +#4 DONE 0.0s + +#5 [internal] load build context +#5 transferring context: 50.74kB 0.1s done +#5 DONE 0.1s + +#6 [2/7] RUN bundle config --global frozen 1 +#6 CACHED + +#7 [3/7] WORKDIR /usr/src/app +#7 CACHED + +#8 [4/7] COPY lib/favicon_factory/version.rb favicon_factory.gemspec Gemfile Gemfile.lock ./ +#8 CACHED + +#9 [5/7] RUN ls +#9 CACHED + +#10 [6/7] RUN bundle install +#10 0.363 Bundler 2.5.9 is running, but your lockfile was generated with 2.5.4. Installing Bundler 2.5.4 and restarting using that version. +#10 2.280 Fetching gem metadata from https://rubygems.org/. +#10 2.374 Fetching bundler 2.5.4 +#10 2.716 Installing bundler 2.5.4 +#10 3.217 +#10 3.217 [!] There was an error parsing `Gemfile`: +#10 3.217 [!] There was an error while loading `favicon_factory.gemspec`: cannot load such file -- /usr/src/app/lib/favicon_factory/version. Bundler cannot continue. +#10 3.217 +#10 3.217 # from /usr/src/app/favicon_factory.gemspec:3 +#10 3.217 # ------------------------------------------- +#10 3.217 # +#10 3.217 > require_relative "lib/favicon_factory/version" +#10 3.217 # +#10 3.217 # ------------------------------------------- +#10 3.217 . Bundler cannot continue. +#10 3.217 +#10 3.217 # from /usr/src/app/Gemfile:6 +#10 3.217 # ------------------------------------------- +#10 3.217 # # Specify your gem's dependencies in favicon_factory.gemspec +#10 3.217 > gemspec +#10 3.217 # +#10 3.217 # ------------------------------------------- +#10 ERROR: process "/bin/sh -c bundle install" did not complete successfully: exit code: 14 +------ + > [6/7] RUN bundle install: +#10 3.217 # +#10 3.217 # ------------------------------------------- +#10 3.217 . Bundler cannot continue. +#10 3.217 +#10 3.217 # from /usr/src/app/Gemfile:6 +#10 3.217 # ------------------------------------------- +#10 3.217 # # Specify your gem's dependencies in favicon_factory.gemspec +#10 3.217 > gemspec +#10 3.217 # +#10 3.217 # ------------------------------------------- +------ +Dockerfile:10 +-------------------- + 8 | COPY lib/favicon_factory/version.rb favicon_factory.gemspec Gemfile Gemfile.lock ./ + 9 | RUN ls + 10 | >>> RUN bundle install + 11 | + 12 | COPY . . +-------------------- +ERROR: failed to solve: process "/bin/sh -c bundle install" did not complete successfully: exit code: 14 diff --git a/lib/favicon_factory.rb b/lib/favicon_factory.rb index a4bb919..852e2da 100644 --- a/lib/favicon_factory.rb +++ b/lib/favicon_factory.rb @@ -8,7 +8,7 @@ autoload(:Vips, "vips") module FaviconFactory - Params = Data.define(:favicon_svg, :background, :adapter) do + Params = Data.define(:favicon_svg, :background) do def dir File.dirname(favicon_svg) end @@ -50,16 +50,6 @@ class Command desc "Background hex color for apple-touch-icon.png" end - flag :vips do - long "--vips" - desc "Use Vips (default if installed)" - end - - flag :"image-magick" do - long "--image-magick" - desc "Use ImageMagick" - end - flag :help do short "-h" long "--help" @@ -82,7 +72,7 @@ def initialize(argv, stderr) def call params, status = parse(@argv) return status if status >= 0 - BaseAdapter.find(params.adapter).new(params, stderr).create_icons + BaseAdapter.find.new(params, stderr).create_icons 0 end @@ -104,8 +94,7 @@ def parse(argv) return exit_message(1, "Error: #{background} is not a valid color, use a hex value like #0099ff") end - adapter = params[:vips] ? VipsAdapter : params[:"image-magick"] ? ImageMagickAdapter : nil - [Params.new(favicon_svg: favicon_svg, background: background, adapter: adapter), -1] + [Params.new(favicon_svg: favicon_svg, background: background), -1] end def hex?(string) @@ -121,10 +110,8 @@ def exit_message(status, message) class BaseAdapter class << self - def find(adapter = nil) - return adapter if adapter - return VipsAdapter if TTY::Which.which("vips") - ImageMagickAdapter + def find + TTY::Which.which("vips") ? VipsAdapter : ImageMagickAdapter end end diff --git a/test/test_e2e.rb b/test/test_e2e.rb index 7636170..cbe5f2b 100644 --- a/test/test_e2e.rb +++ b/test/test_e2e.rb @@ -4,7 +4,7 @@ require "open3" class TestE2e < Minitest::Test - def test_e2e__with_no_adapter__with_existing_svg__it_succeeds + def test_e2e__with_existing_svg__it_succeeds with_svg do |dir, path| _, stderr, status = Open3.capture3("bundle exec exe/favicon_factory #{path}") @@ -17,32 +17,4 @@ def test_e2e__with_no_adapter__with_existing_svg__it_succeeds end end end - - def test_e2e__image_magick__with_existing_svg__it_succeeds - with_svg do |dir, path| - _, stderr, status = Open3.capture3("bundle exec exe/favicon_factory --image-magick #{path}") - - assert_equal 0, status.exitstatus - assert_match Regexp.new("Info: Add the following to the ``"), stderr - TARGETS.each do |name| - path = File.join(dir, name) - assert_match Regexp.new("Info: Generating #{path}"), stderr - assert_path_exists path - end - end - end - - def test_e2e__vips__with_existing_svg__it_succeeds - with_svg do |dir, path| - _, stderr, status = Open3.capture3("bundle exec exe/favicon_factory --vips #{path}") - - assert_equal 0, status.exitstatus - assert_match Regexp.new("Info: Add the following to the ``"), stderr - TARGETS.each do |name| - path = File.join(dir, name) - assert_match Regexp.new("Info: Generating #{path}"), stderr - assert_path_exists path - end - end - end end diff --git a/test/test_image_magick.rb b/test/test_image_magick.rb index 59870c2..7bbabf2 100644 --- a/test/test_image_magick.rb +++ b/test/test_image_magick.rb @@ -9,31 +9,12 @@ def setup remove_const(:SVG_DENSITY) const_set(:SVG_DENSITY, 1) # make tests faster end - - FaviconFactory::BaseAdapter.class_eval do - class << self - alias :find_ :find - - def find(*) - FaviconFactory::ImageMagickAdapter - end - end - end - end - - def teardown - FaviconFactory::BaseAdapter.class_eval do - class << self - remove_method(:find) - alias :find :find_ - end - end end def test__image_magick__with_existing_files__it_skips with_svg do |dir, path| TARGETS.each { FileUtils.touch(File.join(dir, _1)) } - args = ["--image-magick", path] + args = [path] stderr = StringIO.new status = FaviconFactory::Cli.new(args, stderr).call diff --git a/test/test_vips.rb b/test/test_vips.rb index 68300fc..9387e3f 100644 --- a/test/test_vips.rb +++ b/test/test_vips.rb @@ -4,31 +4,10 @@ require "stringio" class TestVips < Minitest::Test - def setup - FaviconFactory::BaseAdapter.class_eval do - class << self - alias :find_ :find - - def find(*) - FaviconFactory::VipsAdapter - end - end - end - end - - def teardown - FaviconFactory::BaseAdapter.class_eval do - class << self - remove_method(:find) - alias :find :find_ - end - end - end - def test__vips__with_existing_files__it_skips with_svg do |dir, path| TARGETS.each { FileUtils.touch(File.join(dir, _1)) } - args = ["--vips", path] + args = [path] stderr = StringIO.new status = FaviconFactory::Cli.new(args, stderr).call