

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# 를 사용한 예약 용량 샘플 AWS CodeBuild
<a name="reserved-capacity-samples"></a>

이 샘플은 CodeBuild 내 예약 용량 플릿을 실험하는 데 사용할 수 있습니다.

**Topics**
+ [예약 용량 샘플을 사용한 캐싱](#reserved-capacity-samples.caching)

## 예약 용량 샘플을 사용한 캐싱
<a name="reserved-capacity-samples.caching"></a>

캐시는 빌드 환경에서 재사용할 수 있는 정보를 저장하여 여러 빌드에 사용할 수 있습니다. 이 샘플은 예약 용량을 사용하여 빌드 프로젝트 내에서 캐싱을 활성화하는 방법을 보여주었습니다. 자세한 내용은 [성능을 개선하기 위한 캐시 빌드](build-caching.md) 단원을 참조하십시오.

프로젝트 설정에서 하나 이상의 캐시 모드를 지정하여 시작할 수 있습니다.

```
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'
```