Bitbucket is getting a new navigation

We’re rolling out these changes, so the documentation may not match your experience in the Bitbucket Cloud app. Read about the new Bitbucket navigation

Docker イメージをビルド環境として使用する

Bitbucket Pipelines では、Docker コンテナでビルドを実行します。これらのコンテナでは、ビルド環境を定義する Docker イメージを実行します。Bitbucket が提供する 既定のイメージを使用するか、またはカスタムイメージを取得できます。

Docker Hub、AWS、GCP、およびインターネットで到達可能なセルフホスト型レジストリにホストされる、パブリックまたはプライベートの Docker イメージがサポートされます。(現在 Bitbucket Pipelines ではインターネット経由でアクセスできない Docker イメージにアクセスすることはできません)。

概要

既定のビルド環境

ビルド環境として使用する Docker イメージを指定しない場合、Bitbucket Pipelines はアトラシアンが一般的なツールで構築した初期設定のものを使用します。

The default image is atlassian/default-image:latest. You can also use a specific version if the tools available in the default image do not satisfy your requirements.

名前

プラットフォーム

すぐに使用可能なアプリ

atlassian/default-image:1

atlassian/default-image:latest

Ubuntu 14.04

  • wget

  • xvfb

  • curl

  • ssh

  • git: 1.9.1

  • mercurial: 2.8.2

  • java: 1.8u66

  • maven: 3.0.5

  • node: 4.2.1

  • npm: 2.14.7

  • nvm: 0.29.0

  • python: 2.7.6

  • gcc: 4.8.4

  • ant: 1.9.3

atlassian/default-image:2

Ubuntu 16.04

  • wget

  • xvfb

  • curl

  • ssh

  • git: 2.7.4

  • mercurial: 3.7.3

  • java: Open-JDK 1.8u151

  • maven: 3.3.9

  • node: 8.9.4

  • npm: 5.6.0

  • nvm: 0.33.8

  • python: 2.7.12

  • gcc: 5.4.0

  • ant: 1.9.6

atlassian/default-image:3

 

ubuntu 20.04 LTS

  • wget

  • xvfb

  • curl

  • ssh

  • ZIP

  • jq

  • tar

  • parallel

  • git: 2.25.1

  • node: 14.17.5

  • npm: 6.14.14

  • nvm: 0.39.2

  • python: 3.8.10

  • gcc: 9.3.0

  • ant: 1.10.7

atlassian/default-image:4

セルフホスト ランナーに推奨

ubuntu 22.04 LTS

  • wget

  • xvfb

  • curl

  • ssh

  • ZIP

  • jq

  • tar

  • parallel

  • git: 2.39.1

  • node: 18.13.0

  • npm: 8.19.3

  • nvm: 0.39.2

  • python: 3.10.6

  • gcc: 11.3.0

  • ant: 1.10.12

atlassian/default-image:5

クラウドホスト ランナーに推奨

ubuntu 24.04 LTS

  • wget

  • xvfb

  • curl

  • ssh

  • ZIP

  • jq

  • tar

  • parallel

  • git: 2.49.0

  • node: 22.15.0

  • npm: 10.9.2

  • nvm: 0.40.3

  • python: 3.12.3

  • gcc: 13.2.0

  • ant: 1.10.14

  • docker cli: 28.1.1

  • docker buildx: 0.23.0

  • docker-compose: 2.36.0

ベスト プラクティスのためのヒント: Pipelines の実行を確認したら、デフォルト イメージ以外に使用できるイメージを見つけることをおすすめします。デフォルト イメージは、利用するユーザーのための互換性を最大限に確保することを意図しており、更新頻度は高くありません。また、多数のツールが含まれているため、環境によっては不要な場合が考えられます。つまり、自身で見つけたサイズの小さいビルド イメージのほうが、バグの修正を迅速に反映し、ビルドもすばやく行える可能性があります。

カスタムのビルド環境

既定の環境がニーズに合わない場合、Docker Hub で利用可能なイメージに役立つものがないかどうかを確認することをおすすめします。Docker Hub で利用可能な公式イメージで、Atlassian が推奨し、セットアップ中に Pipelines で構成しているものに、次のような例があります。

To use these images or another public image on Docker Hub as your build image, see the guide for Using public build images below.

To use an existing Docker image from your own registry, see the guide for Using private build images below.

To build your own Docker images, see the guide for Creating a custom build environment below.


パブリック ビルド イメージの使用

Docker Hub、別のレジストリ、またはセルフホスト型のレジストリにホストされる既存のパブリック イメージを使用できます。インターネット経由でアクセスできるイメージのみを使用できます。 

例では、次のようになっています。

  • アカウント名は、イメージを所有するアカウントの名前です。

  • ユーザー名、パスワード、およびメール アドレスは、レジストリに対する個人の認証情報です。

Docker Hub でホストされるパブリック イメージ

関連する dockerhub ページに一覧表示されている pull コマンド (1) からイメージ名を見つけることができます。

タグを指定しない場合、Docker では latest バージョン タグを使用します。

image: openjdk

Docker Hub のイメージ バージョンとアカウントの両方を指定した場合の例は次のようになります。

image: account-name/openjdk:8

Docker Hub の外部でホストされるパブリック イメージ

Docker 以外が提供している、プライベート レジストリでホストされているイメージの場合、URL にイメージ名を含めます。

image: docker.someprovider.com/account-name/openjdk:8

プライベート ビルド イメージの使用

セルフホスト型のレジストリや、Docker Hub、Amazon ECR、Google GCR のプライベート イメージなどの、プライベートな Docker レジストリを認証する場合、YAML ファイル内でイメージ構成の一部としてユーザー名とパスワードを提供する必要があります。プロバイダによってはメール アドレスが要求される場合があるため。これを任意で含めることもできます。

Docker Hub でホストされるプライベート イメージ

You can use secure variables to configure username and password variables, then add them to the image YAML configuration as shown below:

image: name: account-name/openjdk:8 username: $DOCKER_HUB_USERNAME password: $DOCKER_HUB_PASSWORD email: $DOCKER_HUB_EMAIL

AWS ECR (EC2 コンテナ レジストリ) でホストされるプライベート イメージ

If the image is hosted by ECR, you can provide the access key and secret key via secure variables under an additional aws section in your YAML image configuration:

image: name: <aws_account_id>.dkr.ecr.<region>.amazonaws.com/openjdk:8 aws: access-key: $AWS_ACCESS_KEY secret-key: $AWS_SECRET_KEY

または、AWS_ACCESS_KEYAWS_SECRET_KEY を Bitbucket に保存しないようにして、OpenID Connect 機能を利用してワークスペース ビルドが画像のみにアクセスできるようにできます。

image: name: <aws_account_id>.dkr.ecr.<region>.amazonaws.com/openjdk:8 aws: oidc-role: arn:aws:iam::<aws_account_id>:role/<your_role_name>

For step-by-step instruction on how to configure your AWS Account to work with Bitbucket OpenID Connect, check out the following: Use AWS ECR images in Pipelines with OpenID Connect.

Google Container Registry (GCR) でホストされるプライベート イメージ

To pull an image from GCR, you need to configure a service account for Pipelines with "Viewer" access in your GCP admin console.

Download the generated JSON private key, and copy/paste it into a secure variable in Pipelines. The configured variable can then be used directly in the password field in your YAML image configuration as shown below:

image: name: <region>.gcr.io/<project>/image:latest username: _json_key password: '$GCR_JSON_KEY'

その他のレジストリでホストされるイメージ

You can use secure variables to configure username and password variables, then add them to the image YAML configuration as shown below:

image: name: docker.your-company-name.com/account-name/openjdk:8 username: $USERNAME password: $PASSWORD email: $EMAIL

イメージのダイジェストの保存

確実に同じイメージを取得するには、イメージのハッシュ値またはダイジェスト値を参照します。ダイジェストは暗号化されたハッシュ値であり、イメージの内容が変更されるとダイジェストも変更されます。イメージのダイジェストを保存することで、変更が行われていない同じイメージを確実に参照できます。

イメージのダイジェストの使用

image: name: ubuntu@sha256:a0ee7647e24c8494f1cf6b94f1a3cd127f423268293c25d924fbe18fd82db5a4

イメージのダイジェストの検索

> docker inspect --format='{{.RepoDigests}}' ubuntu [ubuntu@sha256:a0ee7647e24c8494f1cf6b94f1a3cd127f423268293c25d924fbe18fd82db5a4]

イメージがローカルで利用できない場合、Docker inspect コマンドはエラーを返します。コマンドを実行する前に、必ずイメージをプルしてください。

既定ユーザーのオーバーライド

run-as-user としてユーザー UID を指定することで、イメージの既定ユーザーをオーバーライドできます。指定するユーザー UID は、有効なホーム ディレクトリを持つ、イメージ内に存在するものである必要があります。

image: name: atlassian/default-image:3 run-as-user: 1000

カスタム ビルド環境の作成

独自の Docker ファイルを構築し、そこから Docker イメージを作成し、それを任意のレジストリにプッシュしてビルド環境として使用できます。この方法では、ビルドで必要なツールのみを含めることで、ビルド環境を非常に軽量に保つことができます。

リソース

さらにヘルプが必要ですか?

アトラシアン コミュニティをご利用ください。