From b46968519e073941a2b298ae80c49d945f74face Mon Sep 17 00:00:00 2001 From: kuwoyuki Date: Sun, 7 Dec 2025 16:53:33 +0600 Subject: [PATCH] make container persistent --- binhost.sh | 87 ++++++++++++++++++++++++++++++++---------------------- serve.sh | 28 ++++++++++++++++++ trigger.sh | 0 3 files changed, 80 insertions(+), 35 deletions(-) create mode 100755 serve.sh mode change 100644 => 100755 trigger.sh diff --git a/binhost.sh b/binhost.sh index f8892c5..dbc5b56 100755 --- a/binhost.sh +++ b/binhost.sh @@ -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 < 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." + diff --git a/serve.sh b/serve.sh new file mode 100755 index 0000000..6dda0a7 --- /dev/null +++ b/serve.sh @@ -0,0 +1,28 @@ +#!/bin/sh + +WEB_CONTAINER="gentoo_binhost_server" +WEB_PORT="8080" + +echo "Checking Web Server..." + +if ! podman container exists "$WEB_CONTAINER"; then + echo "Starting Nginx binhost server on port $WEB_PORT..." + + podman run -d \ + --name "$WEB_CONTAINER" \ + --restart always \ + -p "$WEB_PORT":80 \ + -v binpkgs:/usr/share/nginx/html:ro \ + nginx:alpine \ + /bin/sh -c ' + echo "server { + listen 80; + root /usr/share/nginx/html; + location / { + autoindex on; + } + }" > /etc/nginx/conf.d/default.conf && nginx -g "daemon off;"' +else + podman start "$WEB_CONTAINER" >/dev/null 2>&1 + echo "Server is running at http://localhost:$WEB_PORT" +fi diff --git a/trigger.sh b/trigger.sh old mode 100644 new mode 100755