これらのサンプルを使用して、CodeBuild のリザーブドキャパシティフリートを試すことができます。
リザーブドキャパシティのサンプルを使用したキャッシュ
キャッシュでは、ビルド環境の再利用可能な部分が保存され、複数のビルドでそれらを使用することができます。このサンプルでは、リザーブドキャパシティを使用してビルドプロジェクト内のキャッシュを有効にする方法を示しました。詳細については、「パフォーマンスを向上させるためのキャッシュビルド」を参照してください。
プロジェクト設定で 1 つ以上のキャッシュモードを指定することから開始できます。
Cache:
Type: LOCAL
Modes:
- LOCAL_CUSTOM_CACHE
- LOCAL_DOCKER_LAYER_CACHE
- LOCAL_SOURCE_CACHE
注記
Docker レイヤーキャッシュを使用するには、必ず特権モードを有効にしてください。
プロジェクトの buildspec 設定は以下のようになります。
version: 0.2
phases:
build:
commands:
- echo testing local source cache
- touch /codebuild/cache/workspace/foobar.txt
- git checkout -b cached_branch
- echo testing local docker layer cache
- docker run alpine:3.14 2>&1 | grep 'Pulling from' || exit 1
- echo testing local custom cache
- touch foo
- mkdir bar && ln -s foo bar/foo2
- mkdir bar/bar && touch bar/bar/foo3 && touch bar/bar/foo4
- "[ -f foo ] || exit 1"
- "[ -L bar/foo2 ] || exit 1"
- "[ -f bar/bar/foo3 ] || exit 1"
- "[ -f bar/bar/foo4 ] || exit 1"
cache:
paths:
- './foo'
- './bar/**/*'
- './bar/bar/foo3'
新しいプロジェクトでビルドを実行してキャッシュをシードすることから開始できます。それが完了したら、次のように buildspec を上書きして別のビルドを開始する必要があります。
version: 0.2
phases:
build:
commands:
- echo testing local source cache
- git branch | if grep 'cached_branch'; then (exit 0); else (exit 1); fi
- ls /codebuild/cache/workspace | if grep 'foobar.txt'; then (exit 0); else (exit 1); fi
- echo testing local docker layer cache
- docker run alpine:3.14 2>&1 | if grep 'Pulling from'; then (exit 1); else (exit 0); fi
- echo testing local custom cache
- "[ -f foo ] || exit 1"
- "[ -L bar/foo2 ] || exit 1"
- "[ -f bar/bar/foo3 ] || exit 1"
- "[ -f bar/bar/foo4 ] || exit 1"
cache:
paths:
- './foo'
- './bar/**/*'
- './bar/bar/foo3'