make container persistent
This commit is contained in:
84
binhost.sh
84
binhost.sh
@@ -49,56 +49,72 @@ done
|
|||||||
|
|
||||||
# generate world union
|
# generate world union
|
||||||
cat "$REPO"/hosts/*/world 2>/dev/null | sort -u | sed '/^#/d;/^$/d' > "$CTX/var/lib/portage/world"
|
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
|
# make.conf
|
||||||
mkdir -p "$CTX/etc/portage"
|
mkdir -p "$CTX/etc/portage"
|
||||||
cp "$REPO/binhost/make.conf" "$CTX/etc/portage/make.conf"
|
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..."
|
echo "Starting Builder..."
|
||||||
|
|
||||||
VOLUMES=(
|
podman exec -i "$CONTAINER_NAME" /bin/bash <<EOF
|
||||||
-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
|
|
||||||
set -e
|
set -e
|
||||||
source /etc/profile
|
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..."
|
echo "Syncing..."
|
||||||
emerge-webrsync -q
|
if [[ -d /var/db/repos/gentoo/.git ]]; then
|
||||||
|
|
||||||
echo "> Installing git"
|
|
||||||
emerge -1vn dev-vcs/git
|
|
||||||
|
|
||||||
echo "> Syncing overlays"
|
|
||||||
emaint sync -a
|
emaint sync -a
|
||||||
|
else
|
||||||
|
emerge-webrsync -q
|
||||||
|
fi
|
||||||
|
|
||||||
echo "> Setting Profile..."
|
echo "Building world.."
|
||||||
eselect profile set "$PROFILE"
|
|
||||||
|
|
||||||
echo "> Building World..."
|
emerge --verbose --usepkg --buildpkg \
|
||||||
emerge --verbose --usepkg --buildpkg --update --deep --newuse --changed-use --with-bdeps=y --keep-going @world
|
--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
|
emerge --depclean
|
||||||
emaint binhost --fix
|
emaint binhost --fix
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
echo "Build complete."
|
||||||
|
|
||||||
|
|||||||
28
serve.sh
Normal file
28
serve.sh
Normal 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
|
||||||
Reference in New Issue
Block a user