post-processors 블록

post-processors 블록

이 주제에서는 post-processors 블록에 대한 참조 정보를 다뤄요.

출처: Packer 공식 문서

본문

설명 (Description)

빌드 블록에 post-processors 블록을 추가해서 포스트-프로세서 구성 목록을 포함시킬 수 있어요. Packer는 각 빌드 후 아티팩트에 대해 포스트-프로세서를 실행해요.

# builds.pkr.hcl
build {
  # ...
  post-processors {
    post-processor "shell-local" { # create an artifice.txt file containing "hello"
      inline = [ "echo hello > artifice.txt" ]
    }
    post-processor "artifice" { # tell packer this is now the new artifact
      files = ["artifice.txt"]
    }
    post-processor "checksum" { # checksum artifice.txt
      checksum_types = [ "md5", "sha512" ] # checksum the artifact
      keep_input_artifact = true           # keep the artifact
    }
  }

}

post-processors 블록은 각 빌드의 아티팩트에서 실행할 여러 포스트-프로세서를 정의할 수 있게 해 줘요. 포스트-프로세서를 사용하는 방법은 포스트-프로세서 문서를 참고하세요.

post-processor와 post-processors 블록의 차이점 (Difference between a post-processor and a post-processors block)

다음 두 템플릿은 같은 일을 해요:

# builds.pkr.hcl
build {
  # ... build image
  post-processor "checksum" { # checksum image
    checksum_types = [ "md5", "sha512" ] # checksum the artifact
  }

  post-processor "amazon-import" { # upload image to AWS
  }

  post-processor "googlecompute-import" { # upload image to GCP
  }
}
# builds.pkr.hcl
build {
  # ... build image
  post-processors {
    post-processor "checksum" { # checksum image
      checksum_types = [ "md5", "sha512" ] # checksum the artifact
    }
  }

  post-processors {
    post-processor "amazon-import" { # upload image to AWS
    }
  }

  post-processors {
    post-processor "googlecompute-import" { # upload image to GCP
    }
  }
}

각 포스트-프로세서는 각 빌드 후에 시작돼요. 즉 각 소스에서 각 프로비저닝 단계가 실행된 뒤에 시작돼요. 모든 경우에 소스 이미지는 삭제될 거예요.