CodeDeploy で yarn build したときの buildspec.yml

Published: 2018/5/23


Code Deploy を利用する際の設定で、 yarn を用いてビルドを行っている記事がなかったので、それの自分用のまとめ。

を参考に、 node_modules ディレクトリは .tar 形式にして保存している。

また、 yarn 自体のインストールについては、 yarn の公式サイトに載っていた、 ubuntu でのインストール方法を参考にした。

できあがるものは以下で、これを基本的に使いまわせば良い。

version: 0.2

phases:
  install:
    commands:
      - sudo apt-get update && sudo apt-get install apt-transport-https
      - 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

  pre_build:
    commands:
      - if [ -e /tmp/node_modules.tar ]; then tar xf /tmp/node_modules.tar; fi
      - yarn install

  build:
    commands:
      - yarn run build

  post_build:
    commands:
      - tar cf /tmp/node_modules.tar node_modules

artifacts:
  files: [ '**/*' ]
  base-directory: build

cache:
  paths:
    - /tmp/node_modules.tar

Tags: aws-code-deployyarn