2
2

More than 5 years have passed since last update.

rails5.0のRSpecをAWS CodeBuildで実行するためにnode, MySQL5.7, yarnをインストールしたときのメモ

Last updated at Posted at 2018-06-09

buildspec.ymlファイルに以下を記述

buildspec.yml
version: 0.2

env:
  variables:
    RAILS_ENV: "test"
    DB_ROOT_PASSWORD: "password"
    DB_HOST: "localhost"
    DB_PASSWORD: "password"
    DB_SOCKET: "/var/run/mysqld/mysqld.sock"

phases:
  install:
    commands:
      - rm -rf db/seeds/test
      - cp -rf db/seeds/development db/seeds/test
      - gem install bundler
      - bundle install
      - curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
      - sudo apt-get install -y nodejs
      - apt-get install -y gnupg procps
      - export DEBIAN_FRONTEND=noninteractive
      - echo "mysql-server mysql-server/root_password password ${DB_ROOT_PASSWORD}" |debconf-set-selections
      - echo "mysql-server mysql-server/root_password_again password ${DB_ROOT_PASSWORD}" |debconf-set-selections
      - apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys 5072E1F5
      - echo "deb http://repo.mysql.com/apt/ubuntu/ trusty mysql-5.7" | tee /etc/apt/sources.list.d/mysql.list
      - sudo apt-get update -y
      - sudo apt-get install -y mysql-server
      - service mysql start
      - mysql --version
      - mysql -hlocalhost -uroot -ppassword -P3306 -e "show databases;"
      - mysql -hlocalhost -uroot -ppassword -P3306 -e "show variables like '%sock%';"
      - mysql -hlocalhost -uroot -ppassword -P3306 -e "GRANT ALL PRIVILEGES on *.* to 'root'@'localhost' IDENTIFIED BY '${DB_ROOT_PASSWORD}'; FLUSH PRIVILEGES;"
      - curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
      - echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
      - sudo apt-get update && sudo apt-get install yarn
      - yarn install
  pre_build:
    commands:
      - bundle exec rails db:setup
  build:
    commands:
      - bundle exec rspec
  post_build:
    commands:
      - echo 'Test completed!'

artifacts:
  files:
    - '**/*'

参考URL
- https://dev.mysql.com/doc/mysql-apt-repo-quick-guide/en/#repo-qg-apt-repo-manual-setup
- http://inokara.hateblo.jp/entry/2017/09/12/080818

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