make container persistent

This commit is contained in:
2025-12-07 16:53:33 +06:00
parent b6f1a545fe
commit b46968519e
3 changed files with 80 additions and 35 deletions

View File

@@ -7,6 +7,7 @@ REPO="${WORK_DIR}/repo"
CTX="${WORK_DIR}/ctx"
IMAGE="docker.io/gentoo/stage3:amd64-desktop-openrc"
CONTAINER_NAME="gentoo_builder"
PROFILE="default/linux/amd64/23.0/desktop"
if [[ ! -d "$REPO/.git" ]]; then
@@ -49,56 +50,72 @@ done
# generate world union
cat "$REPO"/hosts/*/world 2>/dev/null | sort -u | sed '/^#/d;/^$/d' > "$CTX/var/lib/portage/world"
echo "Packages to build: $(wc -l < "$CTX/var/lib/portage/world")"
echo "Packages in aggregated world file: $(wc -l < "$CTX/var/lib/portage/world")"
# make.conf
mkdir -p "$CTX/etc/portage"
cp "$REPO/binhost/make.conf" "$CTX/etc/portage/make.conf"
init_container() {
echo "Creating new builder container..."
podman run -d \
--name "$CONTAINER_NAME" \
--cap-add=SYS_PTRACE \
-v portage_db:/var/db/repos/gentoo \
-v distfiles:/var/cache/distfiles \
-v binpkgs:/var/cache/binpkgs \
--tmpfs /var/tmp/portage:rw,size=48G,mode=1777 \
"$IMAGE" \
bin/bash -c "sleep infinity"
echo "Running setup..."
podman exec "$CONTAINER_NAME" bash -c "
emerge-webrsync -q
emerge -1vn --usepkg --buildpkg dev-vcs/git app-eselect/eselect-repository
eselect profile set '$PROFILE'
"
}
if ! podman container exists "$CONTAINER_NAME"; then
init_container
else
if ! podman container inspect -f '{{.State.Running}}' "$CONTAINER_NAME" >/dev/null 2>&1; then
echo "Starting existing container..."
podman start "$CONTAINER_NAME"
fi
fi
echo "Injecting current config..."
podman cp "$CTX/etc/portage/" "$CONTAINER_NAME":/etc/
podman cp "$CTX/var/lib/portage/world" "$CONTAINER_NAME":/var/lib/portage/world
echo "Starting Builder..."
VOLUMES=(
-v portage_db:/var/db/repos/gentoo
-v distfiles:/var/cache/distfiles
-v binpkgs:/var/cache/binpkgs
-v "$CTX/etc/portage/make.conf:/etc/portage/make.conf"
-v "$CTX/var/lib/portage:/tmp/incoming_world:ro"
)
# add config dirs to volumes
for type in "${CONFIGS[@]}"; do
VOLUMES+=(-v "$CTX/etc/portage/$type:/etc/portage/$type")
done
# start cooking
podman run --rm -i \
--name "gentoo_builder" \
--cap-add=SYS_PTRACE \
"${VOLUMES[@]}" \
--tmpfs /var/tmp/portage:rw,size=48G,mode=1777 \
"$IMAGE" /bin/bash <<EOF
podman exec -i "$CONTAINER_NAME" /bin/bash <<EOF
set -e
source /etc/profile
cp /tmp/incoming_world/world /var/lib/portage/world
chown -R portage:portage /etc/portage /var/lib/portage/world
echo "> Syncing tree..."
emerge-webrsync -q
echo "Syncing..."
if [[ -d /var/db/repos/gentoo/.git ]]; then
emaint sync -a
else
emerge-webrsync -q
fi
echo "> Installing git"
emerge -1vn dev-vcs/git
echo "Building world.."
echo "> Syncing overlays"
emaint sync -a
emerge --verbose --usepkg --buildpkg \
--update --deep --changed-use \
--with-bdeps=y --binpkg-respect-use=y --binpkg-changed-deps=y \
--keep-going @world
echo "> Setting Profile..."
eselect profile set "$PROFILE"
echo "> Building World..."
emerge --verbose --usepkg --buildpkg --update --deep --newuse --changed-use --with-bdeps=y --keep-going @world
echo "> Cleaning up..."
echo "Cleaning up.."
emerge --depclean
emaint binhost --fix
EOF
echo "Build complete."