[RAILS] [When using MiniMagick] A memorandum because I stumbled in the CircleCI test environment.

We report daily on twitter. Please Follow me if you like. https://twitter.com/engineer_ikuzou

Status

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.

Development environment

Technology used

--carrierwave (gem for image upload) --minimagick (gem for image shaping)

Error log (CircleCI test job)

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)>'

Countermeasure ① ⇨ Failure

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.

Countermeasure ② ⇨ Success

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)

Finally

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.

Reference material

See the pull request below to see how they actually struggle with errors. https://github.com/naokikubo2/cookinglife_app/pull/15

Recommended Posts

[When using MiniMagick] A memorandum because I stumbled in the CircleCI test environment.
I stumbled when I tried using neo4j in the jenv environment, so make a note
Build a browser test environment using Capybara in the Docker development environment
What I stumbled upon in the ActiveModel :: Serializer test
I was confused because there was a split in the Array
I summarized the points to note when using resources and resources in combination
A story I was addicted to when testing the API using MockMVC
Creating a Servlet in the Liberty environment
(Capistrano) After deploying, I get a We're sorry… error in the production environment.
I made a primality test program in Java
Build a test flow on CircleCI using Jib
I wrote a primality test program in Java
Rspec: I want to test the post-execution state when I set a method on subject
Error memorandum that occurred when creating a CI / CD environment [Rails + CircleCI + Capistrano + AWS]
A memorandum because I was addicted to the setting of the Android project of IntelliJ IDEA
I tried using a database connection in Android development
I get Mysql2 :: Error :: ConnectionError in the production environment
Unsupported major.minor version 52.0 A memorandum when I got hooked
I read the "Object-Oriented Practical Guide", so a memorandum
[Java] When writing the source ... A memorandum of understanding ①
What I learned when building a server in Java
I tried using Docker because I don't want to pollute the local environment in Microsoft Teams tab development of MS Learn
Differences in code when using the length system in Java
[Ruby] Get in the habit of using the dup method when making a copy of a string variable
When I switched to IntelliJ, I got a lot of differences in the encoding of the properties file.
Template creation program when using the reminder function in slack
Create a MySQL test environment (+ millions of test data) in 5 minutes
A memorandum of the environment variable "JAVA_HOME" path setting procedure
Review because I used the collection_check_boxes method in the Ralis portfolio
I tried using the GitHub repository as a library server
I want to find a relative path in a situation using Path
Resolve CreateProcess error = 206 when running Java in a Windows environment
What I did when I stumbled on IntelliJ gradle 2.2 → 2.6 environment migration
I tried to build the environment little by little using docker
I have a question because the gradle setup doesn't work
Easily monitor the indoor environment-⑦ Summarize in a simple tool-
I wrote a C parser (like) using PEG in Ruby
After learning Progate, I tried to make an SNS application using Rails in the local environment