Joe Kiernan
Joe Kiernan

Reputation: 41

Ruby version conflicting on AWS Codebuild

I have a rails project I am trying to build via AWS codedeploy and having some issues specifying the ruby version. Using AWS codedeploy standard image (aws/codebuild/standard:2.0). I also attempted a build where I put "runtime-versions: ruby: 2.6.3" in the buildspec but that threw the following error: "Phase context status code: YAML_FILE_ERROR Message: Unknown runtime version named '2.6.3' of ruby. This build image has the following versions: 2.6"

Here is the error I am getting when building:

[Container] 2020/05/04 19:02:30 Waiting for agent ping
[Container] 2020/05/04 19:02:32 Waiting for DOWNLOAD_SOURCE
[Container] 2020/05/04 19:02:34 Phase is DOWNLOAD_SOURCE
[Container] 2020/05/04 19:02:34 CODEBUILD_SRC_DIR=/codebuild/output/src627814628/src/git-codecommit.us-east-2.amazonaws.com/v1/repos/floppyhats
[Container] 2020/05/04 19:02:34 YAML location is /codebuild/output/src627814628/src/git-codecommit.us-east-2.amazonaws.com/v1/repos/floppyhats/buildspec.yml
[Container] 2020/05/04 19:02:34 Processing environment variables
[Container] 2020/05/04 19:02:34 Selecting 'ruby' runtime version '2.6' based on manual selections...
[Container] 2020/05/04 19:02:34 Running command echo "Installing Ruby version 2.6 ..."
Installing Ruby version 2.6 ...

[Container] 2020/05/04 19:02:34 Running command rbenv global $RUBY_26_VERSION

[Container] 2020/05/04 19:02:34 Moving to directory /codebuild/output/src627814628/src/git-codecommit.us-east-2.amazonaws.com/v1/repos/floppyhats
[Container] 2020/05/04 19:02:34 Registering with agent
[Container] 2020/05/04 19:02:34 Phases found in YAML: 3
[Container] 2020/05/04 19:02:34  INSTALL: 3 commands
[Container] 2020/05/04 19:02:34  PRE_BUILD: 3 commands
[Container] 2020/05/04 19:02:34  BUILD: 2 commands
[Container] 2020/05/04 19:02:34 Phase complete: DOWNLOAD_SOURCE State: SUCCEEDED
[Container] 2020/05/04 19:02:34 Phase context status code:  Message: 
[Container] 2020/05/04 19:02:34 Entering phase INSTALL
[Container] 2020/05/04 19:02:34 Running command echo Installing Bundler...
Installing Bundler...

[Container] 2020/05/04 19:02:34 Running command gem install bundler
rbenv: version `ruby-2.6.3' is not installed (set by /codebuild/output/src627814628/src/git-codecommit.us-east-2.amazonaws.com/v1/repos/floppyhats/.ruby-version)

[Container] 2020/05/04 19:02:34 Command did not exit successfully gem install bundler exit status 1
[Container] 2020/05/04 19:02:34 Phase complete: INSTALL State: FAILED
[Container] 2020/05/04 19:02:34 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: gem install bundler. Reason: exit status 1

Here is my buildspec file:

version: 0.2
phases:
  install:
    runtime-versions:
        ruby: 2.6
    commands:
      - echo Installing Bundler...
      - gem install bundler
      - bundle install
  pre_build:
    commands:
      - echo Preparing database to run tests...
      - RAILS_ENV=test rails db:setup
      - RAILS_ENV=test rails db:migrate
  build:
    commands:
      - echo Running tests...
      - rails test

And the relevant piece of my gemfile

source 'https://rubygems.org'

ruby '2.6.3'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0.2', '>= 6.0.2.2'

Thanks for the help!

Upvotes: 4

Views: 1613

Answers (1)

Zhen Li
Zhen Li

Reputation: 171

Currently, we have ruby 2.6.5 installed in our aws/codebuild/standard:2.0 image. Repo .ruby-version and Gemfile need to use ruby 2.6.5. Thanks.

Upvotes: 2

Related Questions