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

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

We support public and private Docker images including those hosted on Docker Hub, AWS, GCP, and self-hosted registries accessible on the internet. (Bitbucket Pipelines cannot currently access Docker images that cannot be accessed via the internet.)

概要

既定のビルド環境

ビルド環境として使用する 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

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

カスタムのビルド環境

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

ビルド イメージとしてこれらのイメージや Docker Hub 上の別のパブリック イメージを使用する場合、後述のパブリック ビルド イメージの使用のガイドをご参照ください。

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 でホストされるプライベート イメージ

セキュアな変数を使用してユーザー名やパスワードの変数を構成し、それらを次のように image の YAML 構成に含めることができます。

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

Alternatively, you can avoid storing AWS_ACCESS_KEY and AWS_SECRET_KEY in Bitbucket and make use of OpenID Connect functionality to allow your workspace builds to access your image only.

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>

Bitbucket OpenID Connect と統合するように AWS アカウントを設定する方法に関するステップ バイ ステップの手順については、OpenID Connect を使用して、Pipelines の AWS ECR イメージを使用するをご確認ください。

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

GCR のイメージをプルするには、GCP の管理コンソールで、Pipelines 用に "Viewer" アクセスを持つサービス アカウントを構成する必要があります。

生成された JSON 形式のプライベート キーをダウンロードし、Pipelines のセキュアな変数にコピー アンド ペーストします。構成した変数は次の例のように、YAML image 構成の password フィールドで直接使用できます。

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]

The Docker inspect command will return an error if the image is not available locally. Be sure to pull the image before running the command.

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

An image's default user can be overridden by specifying a user UID as the run-as-user. The specified user UID must be an existing user in the image with a valid home directory.

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

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

You can build your own Docker file, create a docker image out of it, push it to a registry of your choice, and use it as your build environment. This way, you can keep your build environment lightweight by only including the tools that you need in your build.

リソース

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

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