본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

구성 파일 패치

원문 보기 위키 갱신

구성 파일 패치 (deck file patch)

deck file patch 명령어를 사용하면 선언형 구성 파일에서 값을 추가하거나 수정, 삭제할 수 있어요. 패치는 수정할 객체를 선택하는 selector와 새로 지정할 value의 조합으로 이루어지고, 값의 데이터 타입에 따라 스칼라 값은 덮어쓰고 배열에는 항목이 추가돼요. 간단한 변경은 명령줄 인수로, 더 복잡한 패치는 YAML 패치 파일로 지정할 수 있고 결과는 기본적으로 stdout에 출력되지만 -o 옵션으로 파일에 저장할 수도 있어요

출처: 문서

본문

deck file patch 명령어를 사용하면 선언형 구성 파일에서 값을 추가, 업데이트 또는 제거할 수 있어요. 패치는 파일에서 어떤 객체를 패치할지 선택하는 selector와 사용할 새 값을 담고 있는 value의 조합이에요.

selector가 가리키는 속성의 데이터 타입이 병합 동작을 결정해요:

  • 스칼라 값(문자열, 정수, 불리언)의 경우 기존 값이 덮어써져요.
  • 배열의 경우, 셀렉터가 배열이면 제공된 값이 기존 배열에 추가돼요.

변경 사항은 커맨드 라인 인자로 지정하거나, deck file patch 명령어에 전달되는 패치 파일로 제공할 수 있어요.

deck file patch 명령어는 기본적으로 패치된 파일을 stdout으로 출력해요. -o ./config.yaml처럼 파일 경로를 지정하면 업데이트된 구성을 디스크의 파일에 쓸 수 있어요.

커맨드 라인 인자

커맨드 라인으로 값을 패치하려면 --selector와 --value 인자를 전달하세요.

다음 예제는 deck file patch -s ./kong.yaml --selector <S> --value <V> 형식으로 실행할 수 있어요.

# set field "read_timeout" to a numeric value of 10000
--selector="$..services[*]" --value="read_timeout:10000"

# set field "_comment" to a string value
--selector="$..services[*]" --value='_comment:"comment injected by patching"'

# set field "_ignore" to an array of strings
--selector="$..services[*]" --value='_ignore:["ignore1","ignore2"]'

# remove fields "_ignore" and "_comment" from the object
--selector="$..services[*]" --value='_ignore:' --value='_comment:'

# append entries to the methods array of all route objects
--selector="$..routes[*].methods" --value='["OPTIONS"]'

패치 파일

더 복잡한 패치 작업이 필요하다면 패치를 YAML 파일에 저장할 수 있어요. YAML 파일에는 selectors와 values가 들어가고, 값을 삭제하기 위한 명시적인 remove 키도 포함돼요.

patches:
  - selectors:
      - $..services[*]
    values:
      read_timeout: 10000
      _comment: comment injected by patching
    remove:
      - _ignore
      - _comment

위 파일을 적용하려면 deck file patch -s ./config.yaml patch1.yaml patch2.yaml를 실행하세요. 여러 개의 패치 파일을 한 번에 제공할 수도 있어요.

커맨드 사용법

Usage:
  deck file patch [flags] [...patch-files]

Examples:
# update the read-timeout on all services
cat kong.yml | deck file patch --selector="$..services[*]" --value="read_timeout:10000"

Flags:
      --format string          Output format: yaml or json. (default "yaml")
  -h, --help                   help for patch
  -o, --output-file string     Output file to write. Use - to write to stdout. (default "-")
      --selector stringArray   json-pointer identifying element to patch. Repeat for multiple selectors.)
  -s, --state string           decK file to process. Use - to read from stdin. (default "-")
      --value stringArray      A value to set in the selected entry in <key:value> format. Can be specified multiple times.

관련 리소스

더 알아보기 (Learn more)

  • decK 파일에 플러그인을 추가하는 다른 파일 조작 명령어도 함께 살펴봐요 — deck file add-plugins