Bazel Docker 컨테이너 시작하기

문제 신고 <ph type="x-smartling-placeholder"></ph> 소스 보기 1박 · 7.2 · 7.1 · 7.0 · 6.5 · 6.4

이 페이지에서는 Bazel 컨테이너의 콘텐츠, 빌드 방법을 자세히 설명합니다. Bazel을 사용한 abseil-cpp 프로젝트 이 프로젝트를 직접 빌드하는 방법을 Bazel 컨테이너를 사용하여 호스트 머신에서 가져옵니다.

디렉터리 마운트를 사용하여 호스트 머신에서 Abseil 프로젝트 빌드

이 섹션의 안내에 따라 Bazel 컨테이너를 사용하여 빌드할 수 있습니다. 호스트 환경에서 체크아웃된 소스와 연결합니다. 컨테이너가 시작될 때 빌드 명령어마다 다릅니다 빌드 결과가 호스트에 캐시됩니다. 빌드 간에 재사용할 수 있습니다

프로젝트를 호스트 머신의 디렉터리에 클론합니다.

git clone --depth 1 --branch 20220623.1 https://github.com/abseil/abseil-cpp.git /src/workspace

빌드 간에 공유할 캐시된 결과가 있는 폴더를 만듭니다.

mkdir -p /tmp/build_output/

Bazel 컨테이너를 사용하여 프로젝트 빌드 및 빌드 만들기 호스트 머신의 출력 폴더에서 사용 가능한 출력을 예측할 수 있습니다

docker run \
  -e USER="$(id -u)" \
  -u="$(id -u)" \
  -v /src/workspace:/src/workspace \
  -v /tmp/build_output:/tmp/build_output \
  -w /src/workspace \
  gcr.io/bazel-public/bazel:latest \
  --output_user_root=/tmp/build_output \
  build //absl/...

--config=asan|tsan|msan 빌드를 추가하여 새니타이저로 프로젝트를 빌드합니다. AddressSanitizer (asan), ThreadSanitizer (tsan) 또는 MemorySanitizer (msan)를 적절하게 업데이트합니다.

docker run \
  -e USER="$(id -u)" \
  -u="$(id -u)" \
  -v /src/workspace:/src/workspace \
  -v /tmp/build_output:/tmp/build_output \
  -w /src/workspace \
  gcr.io/bazel-public/bazel:latest \
  --output_user_root=/tmp/build_output \
  build --config={asan | tsan | msan} -- //absl/... -//absl/types:variant_test

컨테이너 내부에서 Abseil 프로젝트 빌드

이 섹션의 안내에 따라 Bazel 컨테이너를 사용하여 빌드할 수 있습니다. 컨테이너 내부의 소스와 연결합니다 컨테이너를 처음 시작할 때 워크플로우를 파악하고 워크플로우에 변경사항을 적용하여 빌드 결과가 캐시됩니다

Bazel 컨테이너에서 셸을 시작합니다.

docker run --interactive --entrypoint=/bin/bash gcr.io/bazel-public/bazel:latest

각 컨테이너 ID는 고유합니다. 아래 안내에서 컨테이너는 5a99103747c6입니다.

프로젝트를 클론합니다.

ubuntu@5a99103747c6:~$ git clone --depth 1 --branch 20220623.1 https://github.com/abseil/abseil-cpp.git && cd abseil-cpp/

일반 빌드를 수행합니다.

ubuntu@5a99103747c6:~/abseil-cpp$ bazel build //absl/...

--config=asan|tsan|msan를 추가하여 새니타이저로 프로젝트를 빌드합니다. AddressSanitizer (asan), ThreadSanitizer (tsan)를 선택하거나 MemorySanitizer (msan)를 적절하게 업데이트합니다.

ubuntu@5a99103747c6:~/abseil-cpp$ bazel build --config={asan | tsan | msan} -- //absl/... -//absl/types:variant_test

Bazel 컨테이너 살펴보기

아직 하지 않았다면 Bazel 컨테이너 내에서 대화형 셸을 시작합니다.

docker run -it --entrypoint=/bin/bash gcr.io/bazel-public/bazel:latest
ubuntu@5a99103747c6:~$

컨테이너 콘텐츠를 살펴봅니다.

ubuntu@5a99103747c6:~$ gcc --version
gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
ubuntu@5a99103747c6:~$ java -version
openjdk version "1.8.0_362"
OpenJDK Runtime Environment (build 1.8.0_362-8u372-ga~us1-0ubuntu1~20.04-b09)
OpenJDK 64-Bit Server VM (build 25.362-b09, mixed mode)
ubuntu@5a99103747c6:~$ python -V
Python 3.8.10
ubuntu@5a99103747c6:~$ bazel version
WARNING: Invoking Bazel in batch mode since it is not invoked from within a workspace (below a directory having a WORKSPACE file).
Extracting Bazel installation...
Build label: 6.2.1
Build target: bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Fri Jun 2 16:59:58 2023 (1685725198)
Build timestamp: 1685725198
Build timestamp as int: 1685725198