From 1ef17c650dc9a75961fb72633050ef67bc3f8fd9 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 21 Sep 2025 14:49:21 +1200 Subject: [PATCH] multiarch! --- .gitea/workflows/buiildpublish.yaml | 24 --------- .gitea/workflows/buildpublish.yaml | 82 +++++++++++++++++++++++++++++ Dockerfile.accelerated_base | 29 +++++++--- publish.sh | 34 ++++++++---- 4 files changed, 128 insertions(+), 41 deletions(-) delete mode 100644 .gitea/workflows/buiildpublish.yaml create mode 100644 .gitea/workflows/buildpublish.yaml diff --git a/.gitea/workflows/buiildpublish.yaml b/.gitea/workflows/buiildpublish.yaml deleted file mode 100644 index a5a1b2f..0000000 --- a/.gitea/workflows/buiildpublish.yaml +++ /dev/null @@ -1,24 +0,0 @@ -name: Gitea Actions Demo -run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀 -on: [push] - -jobs: - Build: - runs-on: ubuntu-latest - steps: - - name: Check out repository code - uses: actions/checkout@v4 - - name: Build the project - run: | - ./build.sh - - name: Login to Gitea - uses: docker/login-action@v3 - with: - registry: gitea.jde.nz - username: DoesntMatter - password: ${{ secrets.DOCKER_PUSH_TOKEN }} - - name: Publish - run: | - ./publish.sh - - diff --git a/.gitea/workflows/buildpublish.yaml b/.gitea/workflows/buildpublish.yaml new file mode 100644 index 0000000..41a7584 --- /dev/null +++ b/.gitea/workflows/buildpublish.yaml @@ -0,0 +1,82 @@ +name: Build-Publish-Multi-Arch +run-name: Build and publish multi-architecture Docker images + +on: [push] + +defaults: + run: + shell: bash + +jobs: + build: + strategy: + matrix: + platform: + - linux/amd64 + - linux/arm64 + runs-on: ${{ matrix.platform }} + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Login to Gitea + uses: docker/login-action@v3 + with: + registry: gitea.jde.nz + username: DoesntMatter + password: ${{ secrets.DOCKER_PUSH_TOKEN }} + + - name: Build Images + run: | + ./build.sh + + - name: Publish as Architecture-Specific + run: | + # Only publish on main branch + if [ "$GITHUB_REF" = "refs/heads/main" ]; then + DOCKER_PUSH_TOKEN=${{ secrets.DOCKER_PUSH_TOKEN }} \ + ./publish.sh + fi + + create-manifest: + needs: [build] + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Login to Gitea + uses: docker/login-action@v3 + with: + registry: gitea.jde.nz + username: DoesntMatter + password: ${{ secrets.DOCKER_PUSH_TOKEN }} + + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y jq + + - name: Create and push manifest lists + run: | + # Only create manifest on main branch + if [ "$GITHUB_REF" = "refs/heads/main" ]; then + # Get list of all Dockerfile.* files to determine image names + for dockerfile in Dockerfile.*; do + image_name="${dockerfile//Dockerfile./}" + + echo "Creating manifest for ${image_name}..." + + # Create the manifest list using the architecture-specific digests + docker manifest create gitea.jde.nz/public/${image_name}:latest \ + --amend gitea.jde.nz/public/${image_name}:latest-x86_64 \ + --amend gitea.jde.nz/public/${image_name}:latest-aarch64 + + # Push the manifest list + docker manifest push gitea.jde.nz/public/${image_name}:latest + + echo "Manifest list for ${image_name} created and pushed successfully" + done + + echo "All manifest lists created and pushed successfully" + fi \ No newline at end of file diff --git a/Dockerfile.accelerated_base b/Dockerfile.accelerated_base index 04f677e..c57bac2 100644 --- a/Dockerfile.accelerated_base +++ b/Dockerfile.accelerated_base @@ -24,13 +24,11 @@ RUN apt-get update && apt-get install -y \ python3.11-venv \ # FFmpeg with hardware acceleration support ffmpeg \ - # Intel QuickSync / VAAPI dependencies - intel-media-va-driver-non-free \ + # VAAPI dependencies (generic, works on both x86_64 and arm64) vainfo \ libva-drm2 \ libva-dev \ libva2 \ - i965-va-driver \ # OpenGL/Graphics libraries libgl1 \ libglib2.0-0 \ @@ -71,6 +69,14 @@ RUN apt-get update && apt-get install -y \ gfortran \ && rm -rf /var/lib/apt/lists/* +# Install architecture-specific Intel drivers (only on x86_64) +RUN if [ "$(dpkg --print-architecture)" = "amd64" ]; then \ + apt-get update && apt-get install -y \ + intel-media-va-driver-non-free \ + i965-va-driver \ + && rm -rf /var/lib/apt/lists/*; \ + fi + # Set Python 3.11 as default RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.11 1 && \ update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 1 && \ @@ -94,13 +100,12 @@ RUN pip install --no-cache-dir \ requests # Install PyTorch CPU version (can be overridden in derived images for CUDA) +# Note: PyTorch provides different wheels for different architectures RUN pip install --no-cache-dir \ torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu # Set environment variables for hardware acceleration -# Intel QuickSync / VAAPI -ENV LIBVA_DRIVER_NAME=iHD -ENV LIBVA_DRIVERS_PATH=/usr/lib/x86_64-linux-gnu/dri +# VAAPI driver configuration (paths will be set at runtime via entrypoint) # Python environment ENV PYTHONUNBUFFERED=1 @@ -124,6 +129,15 @@ RUN useradd -m -s /bin/bash -u 1000 appuser && \ RUN mkdir -p /app /data /models && \ chown -R appuser:appuser /app /data /models +# Create entrypoint script to set architecture-specific environment variables +RUN echo '#!/bin/bash\n\ +export LIBVA_DRIVERS_PATH=/usr/lib/$(uname -m)-linux-gnu/dri\n\ +if [ "$(uname -m)" = "x86_64" ]; then\n\ + export LIBVA_DRIVER_NAME=iHD\n\ +fi\n\ +exec "$@"' > /entrypoint.sh && \ + chmod +x /entrypoint.sh + # Set working directory WORKDIR /app @@ -134,5 +148,8 @@ HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ # Default to non-root user (can be overridden in derived images) USER appuser +# Set entrypoint +ENTRYPOINT ["/entrypoint.sh"] + # Default command - can be overridden in derived images CMD ["/bin/bash"] \ No newline at end of file diff --git a/publish.sh b/publish.sh index 88159c6..5b7ceb2 100755 --- a/publish.sh +++ b/publish.sh @@ -3,22 +3,34 @@ set -euo pipefail SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +ARCH=$(uname -m) -# get date/time in local timezone, format YYYY.MMDD.HHMMSS -DATETIME=$(date +%Y.%m%d.%H%M%S) +echo "Publishing generic-docker-images to gitea.jde.nz/public/:latest-${ARCH}" -"${SCRIPTDIR}/build.sh" +function die() { + echo "error: $1" + exit 1 +} -# iterate through the docker files in format Dockerfile.IMAGE_NAME +# Build all images +"${SCRIPTDIR}/build.sh" || die "Build failed" + +# Iterate through the docker files in format Dockerfile.IMAGE_NAME for dockerfile in Dockerfile.* do - # get the image name from the dockerfile + # Get the image name from the dockerfile image_name="${dockerfile//Dockerfile./}" - # tag the image with the latest tag - docker tag "$image_name:latest" "gitea.jde.nz/public/$image_name:latest" - docker tag "$image_name:latest" "gitea.jde.nz/public/$image_name:$DATETIME" - # push the image to the local docker registry - docker push -a "gitea.jde.nz/public/$image_name" + + # Create and push the arch-specific docker image + IMAGE_NAME="gitea.jde.nz/public/${image_name}:latest-${ARCH}" + + # Tag the locally built image with arch-specific tag + docker tag "${image_name}:latest" "${IMAGE_NAME}" + + # Push the arch-specific image + docker push "${IMAGE_NAME}" + + echo "Pushed ${IMAGE_NAME}" done - +echo "All architecture-specific images pushed successfully" \ No newline at end of file