Bitbucket Pipelines でサービスとデータベースを使用する
パイプラインを構成する
- パイプラインを表示
- bitbucket-pipelines.yml を設定する
- アーティファクトをステップで使用する
- Docker イメージをビルド環境として使用する
- Bitbucket Pipelines で Docker コマンドを実行する
- ブランチ ワークフロー
- パイプラインの変数
- Bitbucket Pipelines で SSH キーを使用する
- リポジトリにプッシュして戻す
- Pipelines のビルドで依存性を指定する
- キャッシュの依存性
- Bitbucket Pipelines でサービスとデータベースを使用する
- Bitbucket Pipelines で一般的なデータベースを実行する方法
- Bitbucket Pipelines でデータベースを使用してテストする
- Bitbucket Pipelines でのクロスプラットフォーム テスト
- Bitbucket Pipelines の通知
このページの内容
関連コンテンツ
- 関連コンテンツがありません
Bitbucket Pipelines では、ビルド パイプラインから複数の Docker コンテナを実行できます。アプリケーションのテストと運用で、パイプラインで追加サービスが必要になる場合、追加のコンテナを起動する必要がある場合があります。この追加サービスには、データストア、コード分析ツール、およびスタブ Web サービスなどが含まれます。
You define these additional services (and other resources) in the definitions
section of the bitbucket-pipelines.yml file. These services can then be referenced in the configuration of any pipeline that needs them.
パイプラインの実行時、bitbucket-pipeline.yml のステップで参照されているサービスが、パイプライン ステップ内で実行されるようにスケジューリングされます。これらのサービスは、ビルド コンテナとネットワーク アダプタを共有するほか、localhost でオープンなポートを共有します。ポート マッピングやホスト名は不要です。たとえば、Postgres を使用している場合、localhost のポート 5432 に接続するだけでテストを行えます。デバッグを行う場合、Pipelines の UI でサービスのログを確認できます。
Pipelines では、ビルド ステップあたりのサービス コンテナは最大 5 つに制限されます。サービス コンテナへのメモリの割り当て方法については以下のセクションを参照してください。
Pipelines でのデータベースの使用例については、「Bitbucket Pipelines でデータベースを使用してテストする」を参照してください。
完全な例
この bitbucket-pipelines.yml のサンプル ファイルは、サービスの定義と、パイプライン ステップでのサービスの使用方法の両方を示します。動作のブレイクダウンを後述しています。
pipelines:
branches:
master:
- step:
image: redis
script:
- redis-cli -h localhost ping
services:
- redis
- mysql
definitions:
services:
redis:
image: redis:3.2
mysql:
image: mysql:5.7
variables:
MYSQL_DATABASE: my-db
MYSQL_ROOT_PASSWORD: $password
サービスの定義
Services are defined in the definitions
section of the bitbucket-pipelines.yml file.
For example, the following defines two services: one named redis
that uses the library image redis
from Docker Hub (version 3.2), and another named database
that uses the official Docker Hub MySQL image (version 5.7).
The variables section allows you define variables, either literal values or existing pipelines variables.
definitions:
services:
redis:
image: redis:3.2
mysql:
image: mysql:5.7
variables:
MYSQL_DATABASE: my-db
MYSQL_ROOT_PASSWORD: $password
サービス メモリの制限
Each service definition can also define a custom memory limit for the service container, by using the memory
keyword (in megabytes).
関連するメモリ制限および既定の割り当ては次のとおりです。
- Regular steps have 4096 MB of memory in total, large build steps (which you can define using
size: 2x
) have 8192 MB in total. - ビルド コンテナには合計 1024 MB のメモリが割り当てられ、これでビルド プロセスと一部の Pipelines オーバーヘッド (エージェント コンテナ、ログなど) が網羅されます。
- 各パイプライン ステップでのサービスの合計メモリは、残りのメモリ (1x / 2x ステップでそれぞれ 3072 / 7128 MB) を超えることはできません。
- サービス コンテナは既定で 1024 MB のメモリを取得しますが、128 MB とステップの最大値 (3072 / 7128 MB) の間で使用量を構成できます。
- The Docker-in-Docker daemon used for Docker operations in Pipelines is treated as a service container, and so has a default memory limit of 1024 MB. This can also be adjusted to any value between 128 MB and 3072/7128 MB by changing the memory setting on the built-in
docker
service in the definitions section.
以下の例は、ビルド コンテナに 2048 MB のメモリ制限があることを示しています。
- Docker が 512 MB
- Redis が 512 MB
- MySQL が既定のメモリ制限 (1024 MB) を使用
pipelines:
default:
- step:
services:
- redis
- mysql
- docker
script:
- echo "This step is only allowed to consume 2048 MB of memory"
- echo "Services are consuming the rest. docker 512 MB, redis 512 MB, mysql 1024 MB"
definitions:
services:
redis:
image: redis:3.2
memory: 512
docker:
memory: 512 # reduce memory for docker-in-docker from 1GB to 512MB
mysql:
image: mysql:5.7
# memory: 1024 # default value
variables:
MYSQL_DATABASE: my-db
MYSQL_ROOT_PASSWORD: $password
パイプラインでのサービスの使用
bitbucket-pipelines.yml ファイルの "definitions" セクションでサービスを定義したら、そのサービスを任意のパイプライン ステップで参照できます。
For example, the following causes the redis
service to run with the step:
pipelines:
default:
- step:
image: node
script:
- npm install
- npm test
services:
- redis
プライベート イメージの使用
アクセスを制限するサービスを次のように定義できます。
definitions:
services:
redis:
image:
name: redis:3.2
username: username@organisation.com
password: $DOCKER_PASSWORD
異なるレジストリやフォーマットの Docker イメージを使用するためのその他の例については、「Docker イメージをビルド環境として使用する」をご参照ください。
注意事項と制限事項
Pipelines のサービスには次の制限があります。
- 1 ステップあたり最大 5 サービス
- 上述のメモリ制限
- パイプライン結果のサービスやログにアクセスするための REST API は提供していません。
- サービスの起動を待機するためのメカニズムは提供していません。
小さなサービスを大量に実行したい場合、Docker run または docker-compose を使用することをおすすめします。
ポートの制限
予約済みの使用できないポートがあります。
29418
関連コンテンツ
- 関連コンテンツがありません