2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【CircleCI】Start Buildingでハマった話

Posted at

#前提

CircleCI初心者です。

Rails 6.0.3.1
ruby 2.6.3
Bundler version 2.1.4


以下の記事を参照して、githubと連携しオリジナルアプリにcircleCIを導入しようとしていました。
【circleCI】Railsアプリでgithubと連携してrubocopとrspecテストを走らせる
すると以下のエラーが、、、

#!/bin/bash -eo pipefail 
bundle -v 
Traceback (most recent call last):
 
	2: from /usr/local/bin/bundle:23:in `<main>'
 
	1: from /usr/local/lib/ruby/2.6.0/rubygems.rb:302:in `activate_bin_path'
 
/usr/local/lib/ruby/2.6.0/rubygems.rb:283:in `find_spec_for_exe': Could not find 'bundler' (2.1.4) required by your /home/circleci/project/Gemfile.lock. (Gem::GemNotFoundException)
 
To update to the latest version installed on your system, run `bundle update --bundler`.
 
To install the missing version, run `gem install bundler:2.1.4`
 
 
Exited with code exit status 1 
CircleCI received exit code 1 

とりあえず、.circleci/config.ymlの中身をみてみる。

.circleci/config.yml
version: 2.1
orbs:
  ruby: circleci/ruby@0.1.2 

jobs:
  build:
    docker:
      - image: circleci/ruby:2.6.3-stretch-node
    executor: ruby/default
    steps:
      - checkout
      - run:
          name: Which bundler?
          command: bundle -v
      - ruby/bundle-install

あれ、dockerブランチで設定した内容と違う....
きちんとmergeしていなかった。
凡ミス。
きちんと書き直してから、再度
Set Up PrijectStart Buildingしてみる!

ちなみに、config.ymlの書き方は以下の記事を参考にさせていただきました。
 既存のRails6アプリをDocker化しつつCircleCIでシステムスペックも実行できる環境を作る

.circleci/config.yml
version: 2
jobs:
  build:
    working_directory: ~/my-app
    docker:
      - image: circleci/ruby:2.6.3-node-browsers
        environment:
          BUNDLE_RETRY: 3
          BUNDLE_PATH: vendor/bundle
          BUNDLER_VERSION: 2.1.4  
          DATABASE_URL: postgres://postgres:password@localhost:5432/myapp_test
          RAILS_ENV: test
      - image: circleci/postgres:11-alpine
    steps:
      - checkout
      - restore_cache:
          keys:
            - my-app-bundle-v1-{{ checksum "Gemfile.lock" }}
            - my-app-bundle-v1-
      - run:
          name: Bundler install
          command: |
            gem update --system
            gem install bundler -v 2.1.4
      - run:
          name: Bundle Install
          command: bundle check || bundle install
      - save_cache:
          key: my-app-bundle-v1-{{ checksum "Gemfile.lock" }}
          paths:
            - vendor/bundle
      - restore_cache:
          keys:
            - rails-demo-yarn-{{ checksum "yarn.lock" }}
            - rails-demo-yarn-
      - run:
          name: Yarnをinstall
          command: yarn install --cache-folder ~/.cache/yarn
      - run:
          name: Wait for DB
          command: dockerize -wait tcp://127.0.0.1:5432 -timeout 1m
      - run:
          name: Database setup
          command: bin/rails db:create db:schema:load --trace
      - run: bundle exec bin/webpack
      - run:
          name: execute rspec
          command: bundle exec rspec
      - store_test_results:
          path: /tmp/test-results

注意点としては、**bundle2.0.1以上であるとbundle installに失敗するみたいなので、環境に明示的に指定する必要がある。
以下抜粋。

.circleci/config.yml

# 省略
docker:
      - image: circleci/ruby:2.6.3-node-browsers
        environment:
          BUNDLE_RETRY: 3
          BUNDLE_PATH: vendor/bundle
          #バージョン指定する
          BUNDLER_VERSION: 2.1.4  
          DATABASE_URL: postgres://postgres:password@localhost:5432/myapp_test
          RAILS_ENV: test
#省略

それに伴い牡蠣でもバージョンを指定する

.circleci/config.yml
 - run:
          name: Bundler install
          command: |
            gem update --system
            gem install bundler -v 2.1.4

上記で無事Successになりました。

参考記事

[CircleCI] "You must use Bundler 2 or greater with this lockfile."というエラー
【circleCI】Railsアプリでgithubと連携してrubocopとrspecテストを走らせる
【CircleCI】CircleCI 2.0からはじめる個人での簡単なCI導入方法 - githubとの連携まで

2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?