Skip to main content

Bazel のリモート ビルド キャッシュ

Bazel のリモート キャッシュを正常に使用するには、 bitrise.bazelrc このファイルには、Bazel プロジェクトのリモート ビルド キャッシュを有効にするために必要な構成が含まれています。リモート キャッシュは、ローカル マシン上で実行されるビルド、または CI 環境で実行されるビルドに使用できます。

Bitrise CI 環境での Bazel のリモート キャッシュの構成

Bazel のリモート キャッシュの構成には、以下が含まれます。

Workflow Editor

bitrise.yml

  1. でアプリを開きます ビットライズ

  2. クリック ワークフロー メインページのボタン。

  3. ワークフローとパイプライン ページで、必要なワークフローを見つけます。

    workflow-and-pipelines.png
  4. Add the Activate Bitrise Build Cache for Bazel Step to your Workflow.

    The Step requires no configuration.

  • Open the bitrise.yml file and add the activate-build-cache-for-bazel Step to your Workflow.

    The Step requires no configuration.

    your-workflow:
      steps:
        - git-clone: {}
        - activate-build-cache-for-bazel:
    

During your first build, outputs will be saved to cache. We recommend running a couple of builds to ensure the cache is warmed up.

Configuring remote cache for Bazel in other CI environments

The Bitrise Build Cache does not require using the Bitrise CI. You can use other CI/CD services and still take advantage of remote caching to improve your Bazel build times.

これを行うには、ビルド中に Bitrise Build Cache CLI をダウンロードし、CLI を実行して Bitrise Build Cache を有効にするように CI 環境を構成する必要があります。

  1. Bitrise でパーソナル アクセス トークンを生成します。 パーソナルアクセストークンの作成

    プロセス中に必要になるため、トークンの値をコピーします。

  2. あなたの ワークスペース ID。これを行うには、ワークスペースのページに移動し、URL で ID を見つけます。

    workspace-id.png
  3. Set the following Environment Variables in your CI configuration:

    • BITRISE_BUILD_CACHE_AUTH_TOKEN: The value should be your Personal Access Token.

    • BITRISE_BUILD_CACHE_WORKSPACE_ID: The value should be the Bitrise Workspace slug.

  4. Add the following script to your CI configuration before the step you want to speed up:

    Environment

    Make sure to run the script in the same environment as the Bazel command you want to speed up. For example, if you use multiple Docker containers throughout the build, make sure that the Bitrise Build Cache CLI runs in the same Docker container as the Bazel command.

    #!/usr/bin/env bash
    set -euxo pipefail
    
    # download Bitrise Build Cache CLI
    curl -sSfL 'https://raw.githubusercontent.com/bitrise-io/bitrise-build-cache-cli/main/install/installer.sh' | sh -s -- -b /tmp/bin -d
    
    # run the CLI to enable Bitrise build cache for Bazel
    /tmp/bin/bitrise-build-cache enable-for bazel