LoginSignup
0
0

More than 5 years have passed since last update.

Circle Ci + Node.js + Postgresql セットアップ

Posted at

Circle Ci 実行時の流れ

  1. Environment  : 環境変数を設定
  2. Container postgres : postgres コンテナを立てる
  3. Checkout code : github リポジトリからクローン
  4. Restoring Cache : キャッシュがあれば node_modules をリストア
  5. node -v : node.js のバージョン確認
  6. yarn --varsion : yarn のバージョン確認
  7. yarn install : node module の インストール, キャッシュがある場合はスキップ
  8. Saving Cache : キャッシュの保存

設定ファイルの解説

※の部分を解説していきます。

config.yml
version: 2
jobs:
  build:
    docker:
      - image: node:8.5.0 ※1
      # specify the version you desire here
      - image: postgres ※1
        environment: ※2
          POSTGRES_DB: root
          POSTGRES_PASSWORD: root
          POSTGRES_USER: root

    working_directory: /var/www/html  ※3

    steps:
      - checkout ※4
      # Download and cache dependencies
      - restore_cache: ※6
          keys:
          - v1-dependencies-{{ checksum "package.json" }}
          # fallback to using the latest cache if no exact match is found
          - v1-dependencies-

      - run: node -v
      - run: yarn --varsion
      - run: yarn install

      - save_cache:  ※5
          paths:
            - node_modules
          key: v1-dependencies-{{ checksum "package.json" }}

※1 docker image の取得

node.js のバージョン8.5.0と postgres のイメージを取得してコンテナを立ててくれます。

※2 環境変数の設定

アプリケーションが postgres にアクセスする時に必要な環境変数の設定 

※3 steps に書かれたコマンドを実行するディレクトリ

checkout や run その他のコマンドを working_directory に指定したディレクトリで Circle Ciが実行します。

※4 リポジトリをクローン

先ほど指定したworking_directoryにリポジトリをクローンしてきます。

※5 キャッシュの保存

paths に書いたフォルダをキャッシュします。(今回はnode_modules)
key はキャッシュ保存時の package.json を hash 化しています。
この key は ※6 で使います。

※6 キャッシュのリストア

先ほど設定した key と実行時の key が同じであれば、キャッシュされた node_modules を使用します。

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