make container persistent

This commit is contained in:
2025-12-07 16:53:33 +06:00
parent b6f1a545fe
commit 1100e753f0
2 changed files with 79 additions and 35 deletions

View File

@@ -49,56 +49,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 "> Installing git"
emerge -1vn dev-vcs/git
echo "> Syncing overlays"
echo "Syncing..."
if [[ -d /var/db/repos/gentoo/.git ]]; then
emaint sync -a
else
emerge-webrsync -q
fi
echo "> Setting Profile..."
eselect profile set "$PROFILE"
echo "Building world.."
echo "> Building World..."
emerge --verbose --usepkg --buildpkg --update --deep --newuse --changed-use --with-bdeps=y --keep-going @world
emerge --verbose --usepkg --buildpkg \
--update --deep --changed-use \
--with-bdeps=y --binpkg-respect-use=y --binpkg-changed-deps=y \
--keep-going @world
echo "> Cleaning up..."
echo "Cleaning up.."
emerge --depclean
emaint binhost --fix
EOF
echo "Build complete."

28
serve.sh Normal file
View File

@@ -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