μ  ν‚¨μŠ€μ—μ„œ Docker Plugin 을 μ‚¬μš©ν•΄μ„œ Dockerfile을 톡해 μ‰½κ²Œ 도컀 이미지λ₯Ό λΉŒλ“œν•  수 μžˆλ‹€. μ•„λ§ˆμ‘΄ μ›Ή μ„œλΉ„μŠ€μ™€ 같은 ν΄λΌμš°λ“œ μ„œλΉ„μŠ€μ—μ„œλŠ” x86_64(AMD64) μ•„ν‚€ν…μ²˜ 뿐만 μ•„λ‹ˆλΌ ARM64 μ•„ν‚€ν…μ²˜ 기반의 더 μ €λ ΄ν•˜κ³  μ„±λŠ₯이 쒋은 μ„œλ²„λ₯Ό ν™œμš©ν•  수 μžˆλ‹€. 기본적인 도컀 이미지 λΉŒλ“œ λͺ…λ Ήμ–΄λŠ” λΉŒλ“œλ₯Ό μ‹œλ„ν•˜λŠ” μ„œλ²„μ™€ λ™μΌν•œ μ•„ν‚€ν…μ²˜μ— λŒ€ν•œ μ΄λ―Έμ§€λ§Œ λ§Œλ“€ 수 μžˆμœΌλ―€λ‘œ λ©€ν‹° ν”Œλž«νΌ 이미지λ₯Ό λ§Œλ“€κΈ° μœ„ν•΄μ„œλŠ” Buildkit을 μ΄μš©ν•΄μ•Όν•œλ‹€.

Jenkins μ‚¬μš©μž 도컀 그룹에 μΆ”κ°€

μ  ν‚¨μŠ€κ°€ μ„€μΉ˜λœ μ„œλ²„μ— μ‹€ν–‰λ˜μ–΄μžˆλŠ” 도컀 μ—”μ§„μœΌλ‘œ λΉŒλ“œν•  수 μžˆλ„λ‘ 도컀 그룹에 μ  ν‚¨μŠ€ μ‚¬μš©μžλ₯Ό ν¬ν•¨μ‹œμΌœμ•Όν•œλ‹€. μ  ν‚¨μŠ€ μ‚¬μš©μžλ₯Ό 도컀 그룹에 μΆ”κ°€ν•˜κ³ λ‚˜μ„œλŠ” 도컀와 μ  ν‚¨μŠ€ λͺ¨λ‘ μž¬μ‹€ν–‰μ„ μˆ˜ν–‰ν•˜μ—¬μ•Ό ν•œλ‹€.

sudo usermod -aG docker jenkins
sudo systemctl restart jenkins
sudo systemctl restart docker

QEMU μ„€μΉ˜

μœˆλ„μš°μ™€ λ§₯ ν™˜κ²½μ—μ„œ μ‚¬μš©ν•˜λŠ” 도컀 λ°μŠ€ν¬νƒ‘μ—λŠ” QEMU 을 ν¬ν•¨ν•˜κ³  μžˆμ–΄ μ‰½κ²Œ λ©€ν‹° ν”Œλž«νΌ 이미지λ₯Ό λΉŒλ“œν•  수 μžˆλ‹€. ν•˜μ§€λ§Œ, 일반적으둜 μ  ν‚¨μŠ€λ₯Ό μ„€μΉ˜ν•˜λŠ” λ¦¬λˆ…μŠ€ μ„œλ²„μ—μ„œλŠ” QEMU의 도움을 λ°›κΈ° μœ„ν•΄μ„œ 직접 μ„€μΉ˜ν•΄μ•Όν•œλ‹€.

docker run --privileged --rm tonistiigi/binfmt --install all

Docker Build Cloud λ₯Ό λΉŒλ”λ‘œ μ΄μš©ν•˜κΈ°

Docker Build Cloudλ₯Ό μ΄μš©ν•˜μ—¬ λΉŒλ“œν•˜κΈ° μœ„ν•΄μ„œλŠ” cloud λ“œλΌμ΄λ²„λ₯Ό μ§€μ›ν•˜λŠ” buildx 버전을 μ„€μΉ˜ν•΄μ•Όν•œλ‹€. buildx-desktop μ—μ„œ λ¦¬λˆ…μŠ€ μ„œλ²„μ— λ§žλŠ” λ°”μ΄λ„ˆλ¦¬ νŒŒμΌμ„ λ‹€μš΄λ°›μ•„μ„œ μ  ν‚¨μŠ€ κ³„μ •μ—μ„œ λ°”λΌλ³΄λŠ” 도컀 κ²½λ‘œμ— docker-buildx ν”ŒλŸ¬κ·ΈμΈμœΌλ‘œ μΆ”κ°€ν•˜μž.

# μ  ν‚¨μŠ€ μ‚¬μš©μžλ‘œ μ „ν™˜
sudo su jenkins -s /bin/bash

# cloud λ“œλΌμ΄λ²„λ₯Ό μ§€μ›ν•˜λŠ” Buildx μ„€μΉ˜
wget https://github.com/docker/buildx-desktop/releases/download/v0.14.0-desktop.1/buildx-v0.14.0-desktop.1.linux-amd64
mv buildx-v0.14.0-desktop.1.linux-amd64 ~/docker/cli-plugins/docker-buildx
chmod a+x ~/.docker/cli-plugins/docker-buildx

# Buildx 버전 확인
docker buildx version
github.com/docker/buildx v0.14.0-desktop.1 7b0470cffd54ccbf42976d2f75febc4532c85073

# Docker Build Cloud λΉŒλ” μΆ”κ°€
docker buildx create --driver xxxinc/builder --use
docker buildx ls
NAME/NODE               DRIVER/ENDPOINT                          STATUS    BUILDKIT       PLATFORMS
cloud-eipgridinc-ddd*   cloud
 \_ linux-amd64          \_ cloud://xxxinc/builder_linux-amd64   running   v0.13.1        linux/amd64*, linux/amd64/v2, linux/amd64/v3, linux/amd64/v4, linux/386
 \_ linux-arm64          \_ cloud://xxxinc/builder_linux-arm64   running   v0.13.1        linux/arm64*, linux/arm64/v6, linux/arm64/v7
default                 docker
 \_ default              \_ default                              running   v0.8+unknown   linux/amd64, linux/arm64, linux/riscv64, linux/ppc64le, linux/s390x, linux/386, linux/arm/v7, linux/arm/v6

Docker Build Cloud ν™˜κ²½μ—μ„œ λΉŒλ“œν•˜λ―€λ‘œ –bootstrap μ˜΅μ…˜μœΌλ‘œ λΉŒλ” μ΄ˆκΈ°ν™”λ₯Ό μˆ˜ν–‰ν•  ν•„μš”κ°€ μ—†μŠ΅λ‹ˆλ‹€.

Jenkins μ—μ„œ λΉŒλ“œν•˜κΈ°

Docker Plugin μ—μ„œλŠ” buildx λͺ…λ Ήμ–΄λ₯Ό 선택할 수 μ—†κΈ° λ•Œλ¬Έμ— Execute Shell 을 μ„ νƒν•΄μ„œ 직접 buildx λͺ…λ Ήμ–΄λ₯Ό μ‚¬μš©ν•˜λŠ” 슀크립트λ₯Ό μž‘μ„±ν•΄μ•Όν•œλ‹€. μ•„λž˜μ˜ μŠ€ν¬λ¦½νŠΈμ—μ„œ 도컀 계정에 λ‘œκ·ΈμΈν•˜κΈ° μœ„ν•΄μ„œ μ  ν‚¨μŠ€ μ‚¬μš©μžμ˜ config.json 을 μ΄μš©ν•˜κ²Œ ν–ˆλ‹€.

# Log in to Docker Hub
echo "Logging into Docker Hub..."
docker login

BUILDER_NAME="cloud-xxxinc-builder"

# Check if the builder already exists
BUILDER_EXISTS=$(docker buildx ls | grep "$BUILDER_NAME" || true)

if [[ -z "$BUILDER_EXISTS" ]]; then
  echo "Creating new builder instance..."
  docker buildx create --name "$BUILDER_NAME" --driver cloud xxxinc/builder --use
else
  echo "Using existing builder instance..."
  docker buildx use "$BUILDER_NAME"
fi

# List the builder instances
docker buildx ls

# Install QEMU emulators for building multi-architecture images
docker run --rm --privileged tonistiigi/binfmt --install all

# build
echo "Building Docker image using Buildx with Docker Build Cloud..."
docker buildx build --platform linux/amd64,linux/arm64 -t xxxinc/testapp:${version}-buildx --push .

(Optional) HDF5 for ARM64

ARM64 μ•„ν‚€ν…μ²˜λ‘œ λΉŒλ“œν•˜λŠ” κ²½μš°μ—λ§Œ ValueError: did not find HDF5 headers κ°€ λ°œμƒν•˜λŠ” 것을 κ²½ν—˜ν–ˆλ‹€. 검색 κ²°κ³Ό μ•„λž˜μ˜ μ„Έκ°œμ˜ νŒ¨ν‚€μ§€λ₯Ό μ„€μΉ˜ν•˜λŠ” κ²ƒμœΌλ‘œ 해결이 λ˜μ—ˆλ‹€.

  • libhdf5-serial-dev
  • netcdf-bin
  • libnetcdf-dev
Dockerfile
FROM python:3.8-slim-buster RUN apt-get update && apt-get install -y \ gcc \ libpq-dev \ libhdf5-serial-dev \ netcdf-bin \ libnetcdf-dev

문제 해결에 도움이 된 κΈ€