Bazel Docker 컨테이너 시작하기

문제 신고 소스 보기

이 페이지에서는 Bazel 컨테이너의 콘텐츠, 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/...

AddressSanitizer (asan), ThreadSanitizer (tsan) 또는 MemorySanitizer (msan)를 적절히 선택하는 --config=asan|tsan|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