worker: support kvm and mem limit

This commit is contained in:
2026-10-13 15:44:20 +08:00
parent 9d40e25625
commit e4be20e8c7
3 changed files with 35 additions and 3 deletions
+8 -2
View File
@@ -1,9 +1,9 @@
FROM docker.io/debian:testing
RUN sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list.d/debian.sources
RUN sed -i 's/deb.debian.org/mirrors.nju.edu.cn/g' /etc/apt/sources.list.d/debian.sources
RUN apt-get update && \
apt-get install -y \
apt-get install -y --no-install-recommends \
hostname \
iproute2 \
procps \
@@ -18,6 +18,9 @@ RUN apt-get update && \
perl \
libxml-parser-perl \
nftables \
libarchive-tools \
e2fsprogs \
qemu-system-riscv64 \
&& \
apt-get clean
@@ -27,6 +30,9 @@ ENTRYPOINT ["/obs/entrypoint.sh"]
ENV OBS_REPO_SERVER="http://localhost:5252"
ENV WORKER_ID=obsworker-xxxx
ENV WORKER_TYPE=CHROOT
ENV WORKER_RAM=""
ENV WORKER_VM_DISK_SIZE=16G
ENV WORKER_PORT=15252
ENV WORKER_JOBS=4
ENV WORKER_ARCH=riscv64
@@ -28,10 +28,26 @@ ln -s . XML
mkdir -p /srv/obsworker/root
mkdir -p /srv/obsworker/state
#mount -t tmpfs tmpfs -o size=80% /srv/obsworker/root
hostlabel_flags=""
for label in ${WORKER_HOSTLABEL}; do
if [ -n "${label}" ]; then
hostlabel_flags="${hostlabel_flags} --hostlabel ${label}"
fi
done
./bs_worker --reposerver "${OBS_REPO_SERVER}" --port "${WORKER_PORT}" --id "${WORKER_ID}" --arch "${WORKER_ARCH}" --jobs "${WORKER_JOBS}" ${hostlabel_flags} --root /srv/obsworker/root --statedir /srv/obsworker/state
vm_type_flags=""
if [ "${WORKER_TYPE}" = "KVM" ]; then
case "${WORKER_VM_DISK_SIZE}" in
*G) WORKER_VM_DISK_SIZE="$((${WORKER_VM_DISK_SIZE%G} * 1024))" ;;
*M) WORKER_VM_DISK_SIZE="${WORKER_VM_DISK_SIZE%M}" ;;
esac
vm_type_flags="--vm-type kvm --vmdisk-filesystem ext4 --vmdisk-rootsize ${WORKER_VM_DISK_SIZE}"
if [ -z "${WORKER_RAM}" ]; then
vm_type_flags="${vm_type_flags} --vm-memory $(awk '/^MemTotal:/{printf "%.0fG\n", $2/1048576}' /proc/meminfo)"
else
vm_type_flags="${vm_type_flags} --vm-memory ${WORKER_RAM}"
fi
fi
./bs_worker --reposerver "${OBS_REPO_SERVER}" --port "${WORKER_PORT}" --id "${WORKER_ID}" --arch "${WORKER_ARCH}" --jobs "${WORKER_JOBS}" ${hostlabel_flags} --root /srv/obsworker/root --statedir /srv/obsworker/state ${vm_type_flags}
@@ -5,16 +5,26 @@ services:
environment:
OBS_REPO_SERVER: http://{{ (groups['obs_repo'][0] | extract(hostvars))['ansible_host'] }}:{{ (groups['obs_repo'][0] | extract(hostvars))['PORT'] }}
WORKER_ID: {{ item.ID }}
WORKER_TYPE: {{ item.TYPE | default('CHROOT') }}
{% if (item.TYPE | default('CHROOT')) == 'KVM' %}
WORKER_VM_DISK_SIZE: {{ item.VM_DISK_SIZE | default('16G') }}
{% endif %}
WORKER_RAM: {{ item.RAM | default('') }}
WORKER_PORT: {{ item.PORT }}
WORKER_JOBS: {{ item.JOBS }}
WORKER_ARCH: {{ item.ARCH }}
WORKER_HOSTLABEL: {{ item.LABEL }}
{% if item.RESTRICT_NETWORK is defined %}
IP_ALLOW_LIST: "{{ (groups['obs_repo'][0] | extract(hostvars))['ansible_host']}} {{(groups['obs_source'][0] | extract(hostvars))['ansible_host']}}"
{% endif %}
{% if item.RAM is defined and (item.TYPE | default('CHROOT')) == 'CHROOT' %}
mem_limit: "{{ item.RAM }}"
{% endif %}
ports:
- 0.0.0.0:{{ item.PORT }}:{{ item.PORT }}
volumes:
# for KVM worker's /dev/loopX creation
- /dev:/dev:rw
- ./volume/worker:/srv/obsworker/state
restart: unless-stopped
privileged: true