Bake 원격 정의

Bake 원격 정의 (Remote Bake file definition)

Bake 파일을 원격 Git 저장소나 HTTPS URL에서 직접 불러와 빌드할 수 있어요. 구성 정의를 코드로 공유하고 싶을 때 유용하답니다.

출처: 문서

본문

예를 들어 docker/cli Git 저장소의 v20.10.11 태그에서 Bake 정의를 직접 가져와 빌드할 수 있어요:

$ docker buildx bake "https://github.com/docker/cli.git#v20.10.11" --print
#1 [internal] load git source https://github.com/docker/cli.git#v20.10.11
#1 0.745 e8f1871b077b64bcb4a13334b7146492773769f7       refs/tags/v20.10.11
#1 2.022 From https://github.com/docker/cli
#1 2.022  * [new tag]         v20.10.11  -> v20.10.11
#1 DONE 2.9s

--print로 해석된 정의를 확인하면 이렇게 돼요:

{
  "group": {
    "default": {
      "targets": ["binary"]
    }
  },
  "target": {
    "binary": {
      "context": "https://github.com/docker/cli.git#v20.10.11",
      "dockerfile": "Dockerfile",
      "args": {
        "BASE_VARIANT": "alpine",
        "GO_STRIP": "",
        "VERSION": ""
      },
      "target": "binary",
      "platforms": ["local"],
      "output": ["build"]
    }
  }
}

원격 정의에서 로컬 컨텍스트 사용하기 (Use the local context with a remote definition)

cwd:// 접두어를 쓰면 원격 정의를 빌드할 때 로컬(현재 작업 디렉터리)을 컨텍스트로 사용할 수 있어요:

target "default" {
  context = "cwd://"
  dockerfile-inline = <<EOT
FROM alpine
WORKDIR /src
COPY . .
RUN ls -l && stop
EOT
}
$ touch foo bar
$ docker buildx bake "https://github.com/dvdksn/buildx.git#bake-remote-example"
...
 > [4/4] RUN ls -l && stop:
#8 0.101 total 0
#8 0.102 -rw-r--r--    1 root     root             0 Jul 27 18:47 bar
#8 0.102 -rw-r--r--    1 root     root             0 Jul 27 18:47 foo
#8 0.102 /bin/sh: stop: not found

특정 로컬 디렉터리를 컨텍스트로 쓰려면 경로를 지정하면 돼요. 단, 그 경로는 명령이 실행되는 작업 디렉터리 안에 있어야 해요. 절대 경로나 작업 디렉터리 밖으로 나가는 상대 경로를 쓰면 Bake는 오류를 던져요.

로컬 명명 컨텍스트 (Local named contexts)

cwd:// 접두어로 Bake 실행 컨텍스트 안의 로컬 디렉터리를 명명 컨텍스트(named context)로 정의할 수도 있어요. 자세한 내용은 Bake의 컨텍스트 문서를 참고해요.

더 알아보기 (Learn more)