言語ガイド: Elixir
これは、単純な Phoenix Web アプリケーション用の注釈付き config.yml
で、https://github.com/CircleCI-Public/circleci-demo-elixir-phoenix から入手できます。
お急ぎの場合は、以下の構成をプロジェクトの root ディレクトリにある .circleci/config.yml
にコピーしてください。 お急ぎでなければ、全体に目を通し、十分に理解を深めることをお勧めします。
設定ファイルの例
version: 2.1
jobs: # basic units of work in a run
build: # runs not using Workflows must have a `build` job as entry point
parallelism: 1 # run only one instance of this job
docker: # run the steps with Docker
- image: cimg/elixir:1.13.1 # ...with this image as the primary container; this is where all `steps` will run
auth:
username: mydockerhub-user
password: $DOCKERHUB_PASSWORD # context / project UI env-var reference
environment: # environment variables for primary container
MIX_ENV: test
- image: cimg/postgres:10.1 # database image
auth:
username: mydockerhub-user
password: $DOCKERHUB_PASSWORD # context / project UI env-var reference
environment: # environment variables for database
POSTGRES_USER: postgres
POSTGRES_DB: app_test
POSTGRES_PASSWORD:
working_directory: ~/app # directory where steps will run
steps: # commands that comprise the `build` job
- checkout # check out source code to working directory
- run: mix local.hex --force # install Hex locally (without prompt)
- run: mix local.rebar --force # fetch a copy of rebar (without prompt)
- restore_cache: # restores saved mix cache
# Read about caching dependencies: {{site.baseurl}}/2.0/caching/
keys: # list of cache keys, in decreasing specificity
- v1-mix-cache-{{ .Branch }}-{{ checksum "mix.lock" }}
- v1-mix-cache-{{ .Branch }}
- v1-mix-cache
- restore_cache: # restores saved build cache
keys:
- v1-build-cache-{{ .Branch }}
- v1-build-cache
- run: mix do deps.get, compile # get updated dependencies & compile them
- save_cache: # generate and store mix cache
key: v1-mix-cache-{{ .Branch }}-{{ checksum "mix.lock" }}
paths: "deps"
- save_cache: # don't forget to save a *build* cache, too
key: v1-build-cache-{{ .Branch }}
paths: "_build"
- run: # special utility that stalls main process until DB is ready
name: Wait for DB
command: dockerize -wait tcp://localhost:5432 -timeout 1m
- run: mix test # run all tests in project
- store_test_results: # upload junit test results for display in Test Summary
# Read more: {{site.baseurl}}/2.0/collect-test-data/
path: _build/test/lib/REPLACE_WITH_YOUR_APP_NAME # Replace with the name of your :app
version: 2.1
jobs: # basic units of work in a run
build: # runs not using Workflows must have a `build` job as entry point
parallelism: 1 # run only one instance of this job
docker: # run the steps with Docker
- image: cimg/elixir:1.13.1 # ...with this image as the primary container; this is where all `steps` will run
auth:
username: mydockerhub-user
password: $DOCKERHUB_PASSWORD # context / project UI env-var reference
environment: # environment variables for primary container
MIX_ENV: test
- image: cimg/postgres:10.1 # database image
auth:
username: mydockerhub-user
password: $DOCKERHUB_PASSWORD # context / project UI env-var reference
environment: # environment variables for database
POSTGRES_USER: postgres
POSTGRES_DB: app_test
POSTGRES_PASSWORD:
working_directory: ~/app # directory where steps will run
steps: # commands that comprise the `build` job
- checkout # check out source code to working directory
- run: mix local.hex --force # install Hex locally (without prompt)
- run: mix local.rebar --force # fetch a copy of rebar (without prompt)
- restore_cache: # restores saved mix cache
# Read about caching dependencies: https://circleci.com/docs/2.0/caching/
keys: # list of cache keys, in decreasing specificity
- v1-mix-cache-{{ .Branch }}-{{ checksum "mix.lock" }}
- v1-mix-cache-{{ .Branch }}
- v1-mix-cache
- restore_cache: # restores saved build cache
keys:
- v1-build-cache-{{ .Branch }}
- v1-build-cache
- run: mix do deps.get, compile # get updated dependencies & compile them
- save_cache: # generate and store mix cache
key: v1-mix-cache-{{ .Branch }}-{{ checksum "mix.lock" }}
paths: "deps"
- save_cache: # don't forget to save a *build* cache, too
key: v1-build-cache-{{ .Branch }}
paths: "_build"
- run: # special utility that stalls main process until DB is ready
name: Wait for DB
command: dockerize -wait tcp://localhost:5432 -timeout 1m
- run: mix test # run all tests in project
- store_test_results: # upload junit test results for display in Test Summary
# Read more: https://circleci.com/docs/2.0/collect-test-data/
path: _build/test/lib/REPLACE_WITH_YOUR_APP_NAME # Replace with the name of your :app
version: 2
jobs: # basic units of work in a run
build: # runs not using Workflows must have a `build` job as entry point
parallelism: 1 # run only one instance of this job
docker: # run the steps with Docker
- image: cimg/elixir:1.13.1 # ...with this image as the primary container; this is where all `steps` will run
auth:
username: mydockerhub-user
password: $DOCKERHUB_PASSWORD # context / project UI env-var reference
environment: # environment variables for primary container
MIX_ENV: test
- image: cimg/postgres:10.1 # database image
auth:
username: mydockerhub-user
password: $DOCKERHUB_PASSWORD # context / project UI env-var reference
environment: # environment variables for database
POSTGRES_USER: postgres
POSTGRES_DB: app_test
POSTGRES_PASSWORD:
working_directory: ~/app # directory where steps will run
steps: # commands that comprise the `build` job
- checkout # check out source code to working directory
- run: mix local.hex --force # install Hex locally (without prompt)
- run: mix local.rebar --force # fetch a copy of rebar (without prompt)
- restore_cache: # restores saved mix cache
# Read about caching dependencies: https://circleci.com/docs/2.0/caching/
keys: # list of cache keys, in decreasing specificity
- v1-mix-cache-{{ .Branch }}-{{ checksum "mix.lock" }}
- v1-mix-cache-{{ .Branch }}
- v1-mix-cache
- restore_cache: # restores saved build cache
keys:
- v1-build-cache-{{ .Branch }}
- v1-build-cache
- run: mix do deps.get, compile # get updated dependencies & compile them
- save_cache: # generate and store mix cache
key: v1-mix-cache-{{ .Branch }}-{{ checksum "mix.lock" }}
paths: "deps"
- save_cache: # don't forget to save a *build* cache, too
key: v1-build-cache-{{ .Branch }}
paths: "_build"
- run: # special utility that stalls main process until DB is ready
name: Wait for DB
command: dockerize -wait tcp://localhost:5432 -timeout 1m
- run: mix test # run all tests in project
- store_test_results: # upload junit test results for display in Test Summary
# Read more: https://circleci.com/docs/2.0/collect-test-data/
path: _build/test/lib/REPLACE_WITH_YOUR_APP_NAME # Replace with the name of your :app
設定ファイルの詳細
config.yml
は必ず version
キーから始めます。 このキーは、互換性を損なう変更に関する警告を表示するために使用します。
version: 2.1
実行実行は 1 つ以上のジョブで構成されます。 この実行では ワークフローを使用しないため、build
ジョブを記述する必要があります。
working_directory
キーを使用して、ジョブの steps
を実行する場所を指定します。 working_directory
のデフォルトの値は ~/project
です (project
は文字列リテラル)。
ジョブの各ステップは Executor という仮想環境で実行されます。
この例では docker
Executor を使用して、カスタム Docker イメージを指定しています。 CircleCI 提供の Elixir Docker イメージを使用します。
jobs:
build:
parallelism: 1
docker:
- image: cimg/elixir:1.7.3
auth:
username: mydockerhub-user
password: $DOCKERHUB_PASSWORD # context / project UI env-var reference
environment:
MIX_ENV: test
- image: cimg/postgres:10.1
auth:
username: mydockerhub-user
password: $DOCKERHUB_PASSWORD # context / project UI env-var reference
environment:
POSTGRES_USER: postgres
POSTGRES_DB: app_test
POSTGRES_PASSWORD:
working_directory: ~/app
ジョブのコンテナを選択したら、いくつかのコマンドを実行する steps
を作成します。
checkout
ステップを使用して、ソースコードをチェックアウトします。 デフォルトでは、working_directory
で指定されたパスにソース コードがチェックアウトされます。
run
ステップを使用して、コマンドを実行します。 この例では Mix を使用して Elixir ツールをインストールします。
steps:
- checkout
- run: mix local.hex --force
- run: mix local.rebar --force
実行の間隔を短縮するには、依存関係またはソース コードのキャッシュを検討してください。
save_cache
ステップを使用して、いくつかのファイルまたはディレクトリをキャッシュします。 この例では、仮想環境とインストールされたパッケージがキャッシュされます。
restore_cache
ステップを使用して、キャッシュされたファイルまたはディレクトリを復元します。
- restore_cache:
keys:
- v1-mix-cache-{{ .Branch }}-{{ checksum "mix.lock" }}
- v1-mix-cache-{{ .Branch }}
- v1-mix-cache
- restore_cache:
keys:
- v1-build-cache-{{ .Branch }}
- v1-build-cache
- run: mix do deps.get, compile
- save_cache:
key: v1-mix-cache-{{ .Branch }}-{{ checksum "mix.lock" }}
paths: "deps"
- save_cache:
key: v1-build-cache-{{ .Branch }}
paths: "_build"
最後に、データベースがオンラインになるまで待ち、テスト スイートを実行します。 テストの実行後、CircleCI Web アプリで使用できるようにテスト結果をアップロードします。
- run:
name: DB の待機
command: dockerize -wait tcp://localhost:5432 -timeout 1m
- run: mix test
- store_test_results:
path: _build/test/lib/REPLACE_WITH_YOUR_APP_NAME
並列実行
Splitting by Timings
As of version 2.0, CircleCI requires users to upload their own JUnit XML test output. Currently the main/only Elixir library that produces that output is JUnitFormatter.
In order to allow CircleCI’s parallelization to use the --split-by=timings
strategy with the XML output, you need to configure JUnitFormatter with the include_filename?: true
option which will add the filename to the XML.
By default, JUnitFormatter saves the output to the _build/test/lib/<application name>
directory, so in your .circleci/config.yml
you will want to configure the store_test_results
step to point to that same directory:
- store_test_results:
path: _build/test/lib/<application name>
However, JUnitFormatter also allows you to configure the directory where the results are saved via the report_dir
setting, in which case, the path
value in your CircleCI config should match the relative path of wherever you’re storing the output.
関連項目
ドキュメントの改善にご協力ください
このガイドは、CircleCI の他のドキュメントと同様にオープンソースであり、GitHub でご利用いただけます。 ご協力いただき、ありがとうございます。
- このページの編集をご提案ください (最初に「コントリビューションガイド」をご覧ください)。
- ドキュメントの問題点を報告する、またはフィードバックやコメントを送信するには、GitHub で issue を作成してください。
- CircleCI は、ユーザーの皆様の弊社プラットフォームにおけるエクスペリエンスを向上させる方法を常に模索しています。 フィードバックをお寄せいただける場合は、リサーチコミュニティにご参加ください。
サポートが必要ですか?
CircleCI のサポートエンジニアによる、サービスに関する問題、請求およびアカウントについての質問への対応、設定の構築に関する問題解決のサポートを行っています。 サポートチケットを送信して、CircleCI のサポートエンジニアにお問い合わせください。日本語でお問い合わせいただけます。
または、サポートサイトから、サポート記事やコミュニティフォーラム、トレーニングリソースをご覧いただけます。

CircleCI Documentation by CircleCI is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.