We report daily on twitter. Please Follow me if you like. https://twitter.com/engineer_ikuzou
There was a case where the RSpec test that worked well in the local environment became an error on CircleCI. This error is caused by the minimagick used for image shaping. The error log is as follows.
--carrierwave (gem for image upload) --minimagick (gem for image shaping)
Failure/Error: let(:food_record) { create(:food_record) }
ActiveRecord::RecordInvalid:
Validation failed:Please enter an image,Image MiniMagick was unable to process the file. Please check the image. Error message: You must have ImageMagick or GraphicsMagick installed
./spec/models/food_record_spec.rb:4:in `block (2 levels) in <top (required)>'
./spec/models/food_record_spec.rb:31:in `block (3 levels) in <top (required)>'
As mentioned in the error log, MiniMagick doesn't seem to work without installing ImageMagick. In the local environment, you installed ImageMagick before you knew it. Therefore, I installed the package with the build job of .circleci/config.yml.
.circleci/config.yml
(abridgement)
jobs:
build: # our first job, named "build"
docker:
- image: cimg/ruby:2.7-node # use a tailored CircleCI docker image.
steps:
- checkout # pull down our git code.
- ruby/install-deps # use the ruby orb to install dependencies
# use the node orb to install our packages
# specifying that we use `yarn` and to cache dependencies with `yarn.lock`
# learn more: https://circleci.com/docs/2.0/caching/
- node/install-packages:
pkg-manager: yarn
cache-key: "yarn.lock"
- run: sudo apt-get update
- run: sudo apt-get -y install imagemagick #<Added in the build job! !! >
(abridgement)
# We use workflows to orchestrate the jobs that we declared above.
workflows:
version: 2
build_and_test:
jobs:
- build
- test:
requires:
- build
There is no error, and even if you check the log, the installation seems to be successful, but it is the same as the previous error. In order to set up something ImageMagick, I may not have what I need at the time of the buildings job, so I took the following actions.
Install MagickImage in test job
.circleci/config.yml
(abridgement)
test: # our next job, called "test"
# we run "parallel job containers" to enable speeding up our tests;
# this splits our tests across multiple containers.
parallelism: 3
# here we set 3 docker images.
docker:
- image: cimg/ruby:2.7-node # this is our primary docker image, where step commands run.
- image: circleci/postgres
environment: # add POSTGRES environment variables.
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: test
name: db
- image: selenium/standalone-chrome
name: chrome
# environment variables specific to Ruby/Rails, applied to the primary container.
environment:
BUNDLE_JOBS: "3"
BUNDLE_RETRY: "3"
PGHOST: db
RAILS_ENV: test
SELENIUM_REMOTE_URL: http://chrome:4444/wd/hub
# A series of steps to run, some are similar to those in "build".
steps:
- checkout
- ruby/install-deps
- node/install-packages:
pkg-manager: yarn
cache-key: "yarn.lock"
- run: sudo apt-get update
- run: sudo apt-get -y install imagemagick #<Added in test job! !! >
(abridgement)
This workaround worked! I couldn't find out the details of the cause of the error, but I hope it helps those who are addicted to the same error. Also, if anyone knows the cause of this, I'm sorry to trouble you, but I would be very grateful if you could let me know in the comments.
See the pull request below to see how they actually struggle with errors. https://github.com/naokikubo2/cookinglife_app/pull/15
Recommended Posts