mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-12-14 04:55:27 +00:00
Draft Docker optimation
This commit is contained in:
138
Dockerfile
138
Dockerfile
@@ -1,60 +1,132 @@
|
|||||||
FROM archlinux:latest
|
# ------------------------------------------------------------
|
||||||
|
# Infinito dev container (multi-distro)
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
ARG BASE_IMAGE=archlinux:latest
|
||||||
|
FROM ${BASE_IMAGE}
|
||||||
|
|
||||||
# 1) Pakete inkl. docker (damit docker CLI im Container vorhanden ist)
|
# ------------------------------------------------------------
|
||||||
RUN pacman -Syu --noconfirm \
|
# Base dependencies per distro
|
||||||
|
# - git, python, venv tooling
|
||||||
|
# - docker CLI (best-effort)
|
||||||
|
# - rsync, build tools, CA certificates
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
RUN set -e; \
|
||||||
|
if [ -f /etc/os-release ]; then \
|
||||||
|
. /etc/os-release; \
|
||||||
|
else \
|
||||||
|
echo "ERROR: /etc/os-release not found, cannot detect distro."; \
|
||||||
|
exit 1; \
|
||||||
|
fi; \
|
||||||
|
echo "[infinito] Detected base distro: ${ID:-unknown}"; \
|
||||||
|
case "${ID}" in \
|
||||||
|
arch) \
|
||||||
|
pacman -Syu --noconfirm \
|
||||||
base-devel \
|
base-devel \
|
||||||
git \
|
git \
|
||||||
python \
|
python \
|
||||||
python-pip \
|
python-pip \
|
||||||
python-setuptools \
|
python-setuptools \
|
||||||
|
rsync \
|
||||||
alsa-lib \
|
alsa-lib \
|
||||||
go \
|
go \
|
||||||
rsync \
|
|
||||||
docker \
|
docker \
|
||||||
&& pacman -Scc --noconfirm
|
curl \
|
||||||
|
ca-certificates; \
|
||||||
|
pacman -Scc --noconfirm; \
|
||||||
|
# Ensure python3 exists (Arch only ships 'python' by default) \
|
||||||
|
if [ ! -x /usr/bin/python3 ]; then \
|
||||||
|
ln -sf /usr/bin/python /usr/bin/python3; \
|
||||||
|
fi; \
|
||||||
|
# Stub systemctl and yay to avoid side effects in containers \
|
||||||
|
printf '#!/bin/sh\nexit 0\n' > /usr/bin/systemctl; \
|
||||||
|
chmod +x /usr/bin/systemctl; \
|
||||||
|
printf '#!/bin/sh\nexit 0\n' > /usr/bin/yay; \
|
||||||
|
chmod +x /usr/bin/yay; \
|
||||||
|
;; \
|
||||||
|
debian|ubuntu) \
|
||||||
|
apt-get update; \
|
||||||
|
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
|
||||||
|
build-essential \
|
||||||
|
git \
|
||||||
|
python3 \
|
||||||
|
python3-venv \
|
||||||
|
python3-pip \
|
||||||
|
python3-setuptools \
|
||||||
|
rsync \
|
||||||
|
libasound2 \
|
||||||
|
docker.io \
|
||||||
|
curl \
|
||||||
|
ca-certificates; \
|
||||||
|
rm -rf /var/lib/apt/lists/*; \
|
||||||
|
;; \
|
||||||
|
fedora|rhel|centos) \
|
||||||
|
dnf -y update; \
|
||||||
|
dnf -y install \
|
||||||
|
git \
|
||||||
|
python3 \
|
||||||
|
python3-pip \
|
||||||
|
python3-setuptools \
|
||||||
|
make \
|
||||||
|
gcc \
|
||||||
|
rsync \
|
||||||
|
alsa-lib \
|
||||||
|
docker \
|
||||||
|
curl \
|
||||||
|
ca-certificates \
|
||||||
|
xz; \
|
||||||
|
dnf clean all; \
|
||||||
|
;; \
|
||||||
|
*) \
|
||||||
|
echo "ERROR: Unsupported base distro '${ID}'."; \
|
||||||
|
exit 1; \
|
||||||
|
;; \
|
||||||
|
esac
|
||||||
|
|
||||||
# 2) systemctl & yay stubben
|
# ------------------------------------------------------------
|
||||||
RUN printf '#!/bin/sh\nexit 0\n' > /usr/bin/systemctl \
|
# pkgmgr via Python venv (distro-agnostic)
|
||||||
&& chmod +x /usr/bin/systemctl \
|
# ------------------------------------------------------------
|
||||||
&& printf '#!/bin/sh\nexit 0\n' > /usr/bin/yay \
|
|
||||||
&& chmod +x /usr/bin/yay
|
|
||||||
|
|
||||||
# 3) python-simpleaudio aus AUR
|
|
||||||
RUN useradd -m aur_builder \
|
|
||||||
&& su aur_builder -c "git clone https://aur.archlinux.org/python-simpleaudio.git /home/aur_builder/psa && \
|
|
||||||
cd /home/aur_builder/psa && \
|
|
||||||
makepkg --noconfirm --skippgpcheck" \
|
|
||||||
&& pacman -U --noconfirm /home/aur_builder/psa/*.pkg.tar.zst \
|
|
||||||
&& rm -rf /home/aur_builder/psa
|
|
||||||
|
|
||||||
# 4) pkgmgr + venv
|
|
||||||
ENV PKGMGR_REPO=/opt/package-manager \
|
ENV PKGMGR_REPO=/opt/package-manager \
|
||||||
PKGMGR_VENV=/root/.venvs/pkgmgr
|
PKGMGR_VENV=/root/.venvs/pkgmgr
|
||||||
|
|
||||||
RUN git clone https://github.com/kevinveenbirkenbach/package-manager.git $PKGMGR_REPO \
|
RUN git clone https://github.com/kevinveenbirkenbach/package-manager.git "$PKGMGR_REPO" \
|
||||||
&& python -m venv $PKGMGR_VENV \
|
&& python3 -m venv "$PKGMGR_VENV" \
|
||||||
&& $PKGMGR_VENV/bin/pip install --upgrade pip \
|
&& "$PKGMGR_VENV/bin/pip" install --upgrade pip \
|
||||||
&& $PKGMGR_VENV/bin/pip install --no-cache-dir -r $PKGMGR_REPO/requirements.txt ansible \
|
&& "$PKGMGR_VENV/bin/pip" install --no-cache-dir \
|
||||||
|
-r "$PKGMGR_REPO/requirements.txt" \
|
||||||
|
ansible \
|
||||||
|
simpleaudio \
|
||||||
&& printf '#!/bin/sh\n. %s/bin/activate\nexec python %s/main.py "$@"\n' \
|
&& printf '#!/bin/sh\n. %s/bin/activate\nexec python %s/main.py "$@"\n' \
|
||||||
"$PKGMGR_VENV" "$PKGMGR_REPO" > /usr/local/bin/pkgmgr \
|
"$PKGMGR_VENV" "$PKGMGR_REPO" > /usr/local/bin/pkgmgr \
|
||||||
&& chmod +x /usr/local/bin/pkgmgr
|
&& chmod +x /usr/local/bin/pkgmgr
|
||||||
|
|
||||||
ENV PATH="$PKGMGR_VENV/bin:/root/.local/bin:${PATH}"
|
ENV PATH="$PKGMGR_VENV/bin:/root/.local/bin:${PATH}"
|
||||||
|
|
||||||
# 6) Infinito.Nexus Quelle rein
|
# ------------------------------------------------------------
|
||||||
|
# Copy local Infinito source into the image
|
||||||
|
# ------------------------------------------------------------
|
||||||
COPY . /opt/infinito-src
|
COPY . /opt/infinito-src
|
||||||
|
|
||||||
# 7) Infinito via pkgmgr (shallow)
|
# ------------------------------------------------------------
|
||||||
|
# Install Infinito via pkgmgr (shallow clone)
|
||||||
|
# ------------------------------------------------------------
|
||||||
RUN pkgmgr install infinito --clone-mode shallow
|
RUN pkgmgr install infinito --clone-mode shallow
|
||||||
|
|
||||||
# 8) Override mit lokaler Quelle
|
# ------------------------------------------------------------
|
||||||
RUN INFINITO_PATH=$(pkgmgr path infinito) && \
|
# Override installed Infinito with local source
|
||||||
rm -rf "$INFINITO_PATH"/* && \
|
# (keeps pkgmgr metadata, but code comes from /opt/infinito-src)
|
||||||
rsync -a --delete --exclude='.git' /opt/infinito-src/ "$INFINITO_PATH"/
|
# ------------------------------------------------------------
|
||||||
|
RUN INFINITO_PATH="$(pkgmgr path infinito)" && \
|
||||||
|
rm -rf "${INFINITO_PATH:?}"/* && \
|
||||||
|
rsync -a --delete --exclude='.git' /opt/infinito-src/ "${INFINITO_PATH}/"
|
||||||
|
|
||||||
# 9) Symlink
|
# ------------------------------------------------------------
|
||||||
RUN INFINITO_PATH=$(pkgmgr path infinito) && \
|
# Symlink infinito CLI into PATH
|
||||||
ln -sf "$INFINITO_PATH"/main.py /usr/local/bin/infinito && \
|
# ------------------------------------------------------------
|
||||||
|
RUN INFINITO_PATH="$(pkgmgr path infinito)" && \
|
||||||
|
ln -sf "${INFINITO_PATH}/main.py" /usr/local/bin/infinito && \
|
||||||
chmod +x /usr/local/bin/infinito
|
chmod +x /usr/local/bin/infinito
|
||||||
|
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
# Default command: show help and keep container running
|
||||||
|
# ------------------------------------------------------------
|
||||||
CMD sh -c "infinito --help && exec tail -f /dev/null"
|
CMD sh -c "infinito --help && exec tail -f /dev/null"
|
||||||
|
|||||||
95
Makefile
95
Makefile
@@ -1,3 +1,24 @@
|
|||||||
|
# ------------------------------------------------------------
|
||||||
|
# Multi-distro Docker build configuration (similar to pkgmgr)
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
DISTROS := arch debian ubuntu fedora centos
|
||||||
|
BASE_IMAGE_ARCH := archlinux:latest
|
||||||
|
BASE_IMAGE_DEBIAN := debian:stable-slim
|
||||||
|
BASE_IMAGE_UBUNTU := ubuntu:latest
|
||||||
|
BASE_IMAGE_FEDORA := fedora:latest
|
||||||
|
BASE_IMAGE_CENTOS := quay.io/centos/centos:stream9
|
||||||
|
|
||||||
|
# Make them available to scripts (if you later add resolve-base-image.sh, etc.)
|
||||||
|
export DISTROS
|
||||||
|
export BASE_IMAGE_ARCH
|
||||||
|
export BASE_IMAGE_DEBIAN
|
||||||
|
export BASE_IMAGE_UBUNTU
|
||||||
|
export BASE_IMAGE_FEDORA
|
||||||
|
export BASE_IMAGE_CENTOS
|
||||||
|
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
# Infinito roles/config generation
|
||||||
|
# ------------------------------------------------------------
|
||||||
ROLES_DIR := ./roles
|
ROLES_DIR := ./roles
|
||||||
APPLICATIONS_OUT := ./group_vars/all/04_applications.yml
|
APPLICATIONS_OUT := ./group_vars/all/04_applications.yml
|
||||||
APPLICATIONS_SCRIPT := ./cli/build/defaults/applications.py
|
APPLICATIONS_SCRIPT := ./cli/build/defaults/applications.py
|
||||||
@@ -19,29 +40,34 @@ RESERVED_USERNAMES := $(shell \
|
|||||||
| paste -sd, - \
|
| paste -sd, - \
|
||||||
)
|
)
|
||||||
|
|
||||||
.PHONY: build install test
|
.PHONY: build install test clean clean-keep-logs list tree mig dockerignore \
|
||||||
|
messy-build messy-test \
|
||||||
|
docker-build docker-build-no-cache
|
||||||
|
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
# Core project targets
|
||||||
|
# ------------------------------------------------------------
|
||||||
clean-keep-logs:
|
clean-keep-logs:
|
||||||
@echo "🧹 Cleaning ignored files but keeping logs/…"
|
@echo "🧹 Cleaning ignored files but keeping logs/…"
|
||||||
git clean -fdX -- ':!logs' ':!logs/**'
|
git clean -fdX -- ':!logs' ':!logs/**'
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@echo "Removing ignored git files"
|
@echo "🧹 Removing ignored git files…"
|
||||||
git clean -fdX
|
git clean -fdX
|
||||||
|
|
||||||
list:
|
list:
|
||||||
@echo Generating the roles list
|
@echo "📦 Generating the roles list…"
|
||||||
python3 main.py build roles_list
|
python3 main.py build roles_list
|
||||||
|
|
||||||
tree:
|
tree:
|
||||||
@echo Generating Tree
|
@echo "🌳 Generating roles tree…"
|
||||||
python3 main.py build tree -D 2 --no-signal
|
python3 main.py build tree -D 2 --no-signal
|
||||||
|
|
||||||
mig: list tree
|
mig: list tree
|
||||||
@echo Creating meta data for meta infinity graph
|
@echo "🔗 Creating meta data for meta infinity graph…"
|
||||||
|
|
||||||
dockerignore:
|
dockerignore:
|
||||||
@echo Create dockerignore
|
@echo "📝 Creating .dockerignore from .gitignore…"
|
||||||
cat .gitignore > .dockerignore
|
cat .gitignore > .dockerignore
|
||||||
echo ".git" >> .dockerignore
|
echo ".git" >> .dockerignore
|
||||||
|
|
||||||
@@ -79,7 +105,60 @@ install: build
|
|||||||
@echo "⚙️ Install complete."
|
@echo "⚙️ Install complete."
|
||||||
|
|
||||||
build: clean messy-build
|
build: clean messy-build
|
||||||
@echo "Full build with cleanup before was executed."
|
@echo "✅ Full build (with cleanup) finished."
|
||||||
|
|
||||||
test: build messy-test
|
test: build messy-test
|
||||||
@echo "Full test with build before was executed."
|
@echo "✅ Full test (with build) finished."
|
||||||
|
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
# Docker: multi-distro dev containers for Infinito
|
||||||
|
# Uses the multi-distro Dockerfile with ARG BASE_IMAGE
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
|
||||||
|
# Helper to map distro → BASE_IMAGE_* variable
|
||||||
|
define _infinito_base_image
|
||||||
|
$(if $(filter $(1),arch),$(BASE_IMAGE_ARCH),\
|
||||||
|
$(if $(filter $(1),debian),$(BASE_IMAGE_DEBIAN),\
|
||||||
|
$(if $(filter $(1),ubuntu),$(BASE_IMAGE_UBUNTU),\
|
||||||
|
$(if $(filter $(1),fedora),$(BASE_IMAGE_FEDORA),\
|
||||||
|
$(if $(filter $(1),centos),$(BASE_IMAGE_CENTOS),)))))
|
||||||
|
endef
|
||||||
|
|
||||||
|
docker-build:
|
||||||
|
@echo "============================================================"
|
||||||
|
@echo ">>> Building Infinito dev containers for: $(DISTROS)"
|
||||||
|
@echo "============================================================"
|
||||||
|
@for distro in $(DISTROS); do \
|
||||||
|
base_image="$(call _infinito_base_image,$$distro)"; \
|
||||||
|
image_name="infinito-dev-$$distro"; \
|
||||||
|
echo; \
|
||||||
|
echo "------------------------------------------------------------"; \
|
||||||
|
echo ">>> Building $$image_name (BASE_IMAGE=$$base_image)…"; \
|
||||||
|
echo "------------------------------------------------------------"; \
|
||||||
|
docker build \
|
||||||
|
--build-arg BASE_IMAGE="$$base_image" \
|
||||||
|
-t "$$image_name" \
|
||||||
|
. || exit $$?; \
|
||||||
|
done
|
||||||
|
@echo
|
||||||
|
@echo "✅ All Infinito dev images built."
|
||||||
|
|
||||||
|
docker-build-no-cache:
|
||||||
|
@echo "============================================================"
|
||||||
|
@echo ">>> Building Infinito dev containers (NO CACHE) for: $(DISTROS)"
|
||||||
|
@echo "============================================================"
|
||||||
|
@for distro in $(DISTROS); do \
|
||||||
|
base_image="$(call _infinito_base_image,$$distro)"; \
|
||||||
|
image_name="infinito-dev-$$distro"; \
|
||||||
|
echo; \
|
||||||
|
echo "------------------------------------------------------------"; \
|
||||||
|
echo ">>> Building $$image_name with NO CACHE (BASE_IMAGE=$$base_image)…"; \
|
||||||
|
echo "------------------------------------------------------------"; \
|
||||||
|
docker build \
|
||||||
|
--no-cache \
|
||||||
|
--build-arg BASE_IMAGE="$$base_image" \
|
||||||
|
-t "$$image_name" \
|
||||||
|
. || exit $$?; \
|
||||||
|
done
|
||||||
|
@echo
|
||||||
|
@echo "✅ All Infinito dev images built (no cache)."
|
||||||
|
|||||||
Reference in New Issue
Block a user