CodeBuild で Rails 5.2 * yarn


yarnまわりの設定でてこずったのでメモ。

ちなみに、bundlerバージョン回りがまだひっかかっている(Gemfile.lockに2.01 入るとアウト) ← 残TODO

version: 0.2

phases:
  install:
    commands:
      # Upgrade AWS CLI to the latest version
      - pip3 install --upgrade awscli

      # Setup for Yarn
      # https://qiita.com/t-koshi/items/a5de8f0ade08d00784bd
      - curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
      - sudo apt-get install -y nodejs
      - sudo apt-get update -y
      - 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

      # prepare env
      - cp .env.sample .env
      - sed -i -e 's/someone/build/' .env

      # Install Ruby dependencies from the Gemfile.
      # - bin/yarn
      - bundle install --path=vendor/bundle


  pre_build:
    commands:
      # Set the SECRET_KEY_BASE environment variable for running tests
      - export SECRET_KEY_BASE=$(rake secret)

      # Regenerate DB
      - bundle exec rails db:apply
      - bundle exec rails db:convert

      # Run the tests
      - bundle exec rubocop
      # - bundle exec rake test

  post_build:
    commands:
      - aws cloudformation package --template template.yml --s3-bucket $S3_BUCKET --output-template-file template-export.yml

      # Do not remove this statement. This command is required for AWS CodeStar projects.
      # Update the AWS Partition, AWS Region, account ID and project ID in the project ARN on template-configuration.json file so AWS CloudFormation can tag project resources.
      - sed -i.bak 's/\$PARTITION\$/'${PARTITION}'/g;s/\$AWS_REGION\$/'${AWS_REGION}'/g;s/\$ACCOUNT_ID\$/'${ACCOUNT_ID}'/g;s/\$PROJECT_ID\$/'${PROJECT_ID}'/g' template-configuration.json

artifacts:
  type: zip
  files:
    - template-export.yml
    - template-configuration.json

参考: https://qiita.com/t-koshi/items/a5de8f0ade08d00784bd