0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

How to Set Configuration Only for the CI Environment

Last updated at Posted at 2025-02-15

Overview

This post report a way to set configuration only for the CI Envirionment. Rails application flequently use RSpec in CI/CD pipeline. Like many others I also follow this approach in Rails application development.

One day, I found numerous logs displayed in the GitHub Actions output during the RSpec process.Following error code is diplayed in real.

log writing failed. "\xE4" from ASCII-8BIT to UTF-8
log writing failed. "\xE4" from ASCII-8BIT to UTF-8
・
・
・

I researched reason why this error occurred. As a result, I found that the process of handling CSV in RSpec caused this error. However, I couldn't stop using the existing RSpec. So I tried resolve this error.

What is the reason?

I investigated the output when running RSpec in my local development environment and found that the above error occurred when Rails attempted to write execution logs to the local storage of the Docker container. Both my local and CI environments used UTF-8 encoding. However, RSpec attempted to write logs in ASCII-8BIT while handling CSV files.

Resolving each error one by one would require significant effort. Therefore, I decided to disable log writing to log/development.log in local storage. At first glance, this decision may seem like an act of laziness or an attempt to avoid solving the problem. However, it not only resolves the previously mentioned issue but also helps reduce CI execution time.

RSpec runs inside a Docker container as defined in the CI.yml file. Logs written inside the container during CI execution cannot be viewed unless they are transferred to another environment. However, this is hardly a problem.

How to make Rails identify CI environment

Simply add the following code to the appropriate configuration file:

 if ENV['CI']
    config.logger = ActiveSupport::TaggedLogging.new(Logger.new(nil))
 end

ENV['CI'] is set by CI/CD tools by default.

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?