การเริ่มต้นใช้งานคอนเทนเนอร์ Bazel Docker

หน้านี้จะให้รายละเอียดเกี่ยวกับเนื้อหาของคอนเทนเนอร์ Bazel วิธีสร้างโปรเจ็กต์ abseil-cpp โดยใช้ Bazel ภายในคอนเทนเนอร์ Bazel และวิธีสร้างโปรเจ็กต์นี้โดยตรงจากเครื่องโฮสต์โดยใช้คอนเทนเนอร์ Bazel ที่มีการติดตั้งไดเรกทอรี

สร้างโปรเจ็กต์ Abseil จากเครื่องโฮสต์ด้วยการติดตั้งไดเรกทอรี

วิธีการในส่วนนี้จะช่วยให้คุณสร้างโดยใช้คอนเทนเนอร์ Bazel พร้อมกับแหล่งที่มาที่เช็คเอาต์ในสภาพแวดล้อมโฮสต์ ระบบจะเริ่มต้นคอนเทนเนอร์ สำหรับคำสั่งบิลด์แต่ละรายการที่คุณเรียกใช้ ระบบจะแคชผลลัพธ์ของบิลด์ในสภาพแวดล้อมโฮสต์เพื่อให้สามารถนำไปใช้ซ้ำในบิลด์ต่างๆ ได้

โคลนโปรเจ็กต์ไปยังไดเรกทอรีในเครื่องโฮสต์

git clone 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 \
  l.gcr.io/google/bazel:latest \
  --output_user_root=/tmp/build_output \
  build //absl/...

สร้างโปรเจ็กต์ด้วย Sanitizer โดยเพิ่ม--config=asan|tsan|msan build flag เพื่อเลือก 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 \
  l.gcr.io/google/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 l.gcr.io/google/bazel:latest

รหัสคอนเทนเนอร์แต่ละรายการจะไม่ซ้ำกัน ในวิธีการด้านล่าง คอนเทนเนอร์คือ 5a99103747c6

โคลนโปรเจ็กต์

root@5a99103747c6:~# git clone https://github.com/abseil/abseil-cpp.git && cd abseil-cpp/

สร้างอย่างสม่ำเสมอ

root@5a99103747c6:~/abseil-cpp# bazel build //absl/...

สร้างโปรเจ็กต์ด้วย Sanitizer โดยเพิ่ม--config=asan|tsan|msan แฟล็กบิลด์เพื่อเลือก AddressSanitizer (asan), ThreadSanitizer (tsan) หรือ MemorySanitizer (msan) ตามความเหมาะสม

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

สำรวจคอนเทนเนอร์ Bazel

หากยังไม่ได้ดำเนินการ ให้เริ่มเชลล์แบบอินเทอร์แอกทีฟภายในคอนเทนเนอร์ Bazel

docker run -it --entrypoint=/bin/bash l.gcr.io/google/bazel:latest
root@5a99103747c6:/#

สำรวจเนื้อหาของคอนเทนเนอร์

root@5a99103747c6:/# clang --version
clang version 8.0.0 (trunk 340178)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/bin
root@5a99103747c6:/# java -version
openjdk version "1.8.0_181"
OpenJDK Runtime Environment (build 1.8.0_181-8u181-b13-0ubuntu0.16.04.1-b13)
OpenJDK 64-Bit Server VM (build 25.181-b13, mixed mode)
root@5a99103747c6:/# python -V
Python 2.7.12
root@5a99103747c6:/# python3 -V
Python 3.6.6
root@5a99103747c6:/# bazel version
Extracting Bazel installation...
Build label: 0.17.1
Build target: bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Fri Sep 14 10:39:25 2018 (1536921565)
Build timestamp: 1536921565
Build timestamp as int: 1536921565