반응형

안녕하세요. 
오늘은 AWS의 CodeDeploy을 통해 소스를 배포할 때 파일 중복으로 실패하는 경우에 어떤 방법으로 해결하면 되는지 적어보겠습니다. 

CodeDeploy 실패가 발생하면 가장 먼저 확인하는 부분은 "이벤트 세부 정보"의 내용 확인입니다. 
아마, 아래와 같은 에러가 발생했다면 파일 중복으로 인한 실패로 판단하시면 됩니다. 

The deployment failed because a specified file already exsist at this localtion : <path>

이를 해결하는 방법은 2가지가 존재합니다. 
2가지 방법을 보고 우리 환경에 맞는 방법을 사용하면 됩니다. 

방법 1. file_exists_behavior: OVERWRITE

appspec.yaml 파일에 "file_exists_behavior: OVERWRITE"의 내용을 추가합니다. 

version: 0.0
os: linux
files:
  - source: /
    destination: <path>
    file_exists_behavior: OVERWRITE
permissions:
  - object: <path>
    pattern: "**"
    owner: tomcat
    mode: 755
    type:
      - file
  - object: <path>
    owner: tomcat
    mode: 755
    type:
      - directory
 
hooks:
  AfterInstall:
    - location: scripts/install.sh
      timeout: 60
 
  ApplicationStop:
    - location: scripts/stopApp.sh
 
  ApplicationStart:
    - location: scripts/startApp.sh
      timeout: 60
      runas: tomcat
 
  ValidateService:
    - location: scripts/healthCheck.sh
      timeout: 120

방법 2. BeforeInstall 스크립트 추가

방법 1. appspec.yml의 hooks 부분을 보시면 AfterInstall 부터 시작되는 것을 보실 수 있습니다. 
방법 2. 에서는 hooks 부분에 "BeforInstall" 을 추가하고 기존 Deploy 파일을 삭제하는 스크립트를 생성해 동작하도록 내용을 추가합니다.

version: 0.0
os: linux
files:
  - source: /
    destination: <path>
    방법 1. 에 작성된 내용은 필요 없어서 삭제
permissions:
  - object: <path>
    pattern: "**"
    owner: tomcat
    mode: 755
    type:
      - file
  - object: <path>
    owner: tomcat
    mode: 755
    type:
      - directory
 
hooks:
  BeforInstall: <- 내용 추가
    - location: scripts/init.sh
        timeout: 60
         
  AfterInstall:
    - location: scripts/install.sh
      timeout: 60
 
  ApplicationStop:
    - location: scripts/stopApp.sh
 
  ApplicationStart:
    - location: scripts/startApp.sh
      timeout: 60
      runas: tomcat
 
  ValidateService:
    - location: scripts/healthCheck.sh
      timeout: 120
반응형

+ Recent posts