From eabab653a0f105a23356f09ca49905288f3a9efc Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 13 Oct 2025 20:57:37 +0200 Subject: [PATCH] Add cross-arch buildscript --- .env | 8 ++++++- README.md | 34 +++++++++++++++++++++------ build-and-push.sh | 56 ++++++++++++++++++++++++++++++++++++++++++++ compose.runtime.yaml | 4 ++-- compose.yaml | 4 ++-- 5 files changed, 94 insertions(+), 12 deletions(-) create mode 100755 build-and-push.sh diff --git a/.env b/.env index 5f14e87..727d57f 100644 --- a/.env +++ b/.env @@ -16,4 +16,10 @@ XDG_RUNTIME_DIR=/run/user/1000 WAYLAND_DISPLAY=wayland-1 DISPLAY=:0 -DEBUG=1 \ No newline at end of file +DEBUG=1 + +# Container registry settings +LOCAL_IMAGE_NAME=spyder-conda +SPYDER_IMAGE=git.maxboeer.com/schmax/spyder-desktop-docker:latest +BUILDX_PLATFORMS=linux/amd64,linux/arm64 +BUILDX_BUILDER_NAME=spyder-buildx \ No newline at end of file diff --git a/README.md b/README.md index 8343d27..496e11e 100644 --- a/README.md +++ b/README.md @@ -22,21 +22,36 @@ Spyder exits when you close the IDE window. Stop the stack with `Ctrl+C`. ## Using a Prebuilt Image -Build the image locally, tag it, and push it to your registry of choice (example: `ghcr.io/your-account/spyder-wayland:latest`). +Publish a multi-arch image to your Gitea container registry, then consumers can pull it directly. + +### 1. Configure registry access ```bash -docker compose build -docker tag spyder-conda ghcr.io/your-account/spyder-wayland:latest -docker push ghcr.io/your-account/spyder-wayland:latest +docker login gitea.example.com ``` -Consumers can run the IDE without building locally using the provided `compose.runtime.yaml`: +Use your Gitea username and a personal access token with `write:packages` scope. + +### 2. Build and push + +`build-and-push.sh` wraps `docker buildx` to build Linux/amd64 and Linux/arm64 images and push them to the registry referenced by `SPYDER_IMAGE`. + +```bash +chmod +x build-and-push.sh +./build-and-push.sh +``` + +Adjust `SPYDER_IMAGE`, `BUILDX_PLATFORMS`, or `BUILDX_BUILDER_NAME` in `.env` to control the target registry, platforms, or builder instance. + +### 3. Let consumers run the image + +Distribute `compose.runtime.yaml` (or the example compose below). End users simply run: ```bash docker compose -f compose.runtime.yaml up ``` -Override the default image by exporting `SPYDER_IMAGE` in `.env`. +Set `SPYDER_IMAGE` in their `.env` file if they host the image under a different name. ## Environment Variables @@ -45,6 +60,8 @@ Key settings live in `.env`: - `UID`, `GID`, `HOST_USER`, `HOST_GROUP` – mirror the host user to preserve file ownership. - `SPYDER_HOME`, `SPYDER_WORKSPACE` – container paths for the Spyder home and project workspace. - `SPYDER_HOME_VOLUME`, `SPYDER_WORKSPACE_VOLUME` – host-side bind mounts for persistence (can be absolute or relative paths). +- `LOCAL_IMAGE_NAME` – tag applied to locally built images via `docker compose build`. +- `SPYDER_IMAGE`, `BUILDX_PLATFORMS`, `BUILDX_BUILDER_NAME` – registry target and buildx configuration used by `build-and-push.sh`. - `XDG_RUNTIME_DIR`, `WAYLAND_DISPLAY`, `DISPLAY` – display/socket paths exported from the host session. - `DEBUG` – placeholder for future debug toggles. @@ -64,7 +81,10 @@ SPYDER_WORKSPACE_VOLUME=./spyder-workspace XDG_RUNTIME_DIR=/run/user/1000 WAYLAND_DISPLAY=wayland-1 DISPLAY=:0 -SPYDER_IMAGE=ghcr.io/your-account/spyder-wayland:latest +LOCAL_IMAGE_NAME=spyder-conda +SPYDER_IMAGE=gitea.example.com/max/spyder-wayland:latest +BUILDX_PLATFORMS=linux/amd64,linux/arm64 +BUILDX_BUILDER_NAME=spyder-buildx DEBUG=0 ``` diff --git a/build-and-push.sh b/build-and-push.sh new file mode 100755 index 0000000..cb1b02c --- /dev/null +++ b/build-and-push.sh @@ -0,0 +1,56 @@ +#!/bin/bash +set -euo pipefail + +ROOT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +cd "$ROOT_DIR" + +if [ -f .env ]; then + while IFS= read -r line || [ -n "$line" ]; do + # Skip empty lines and comments (leading whitespace ignored). + [[ $line =~ ^[[:space:]]*# ]] && continue + [[ -z ${line//[[:space:]]/} ]] && continue + + if [[ $line =~ ^([A-Za-z_][A-Za-z0-9_]*)=(.*)$ ]]; then + key="${BASH_REMATCH[1]}" + value="${BASH_REMATCH[2]}" + + # Strip trailing comments and surrounding whitespace. + value="${value%%#*}" + value="${value%$'\r'}" + value="${value#${value%%[![:space:]]*}}" + value="${value%${value##*[![:space:]]}}" + + # Remove simple single or double quotes around the value. + if [[ $value =~ ^\".*\"$ || $value =~ ^\'.*\'$ ]]; then + value="${value:1:${#value}-2}" + fi + + case "$key" in + SPYDER_IMAGE|BUILDX_PLATFORMS|BUILDX_BUILDER_NAME|LOCAL_IMAGE_NAME) + export "$key"="$value" + ;; + esac + fi + done < .env +fi + +: "${SPYDER_IMAGE:?SPYDER_IMAGE must be set in .env or environment}" +PLATFORMS=${BUILDX_PLATFORMS:-linux/amd64,linux/arm64} +BUILDER=${BUILDX_BUILDER_NAME:-spyder-buildx} + +if ! docker buildx inspect "$BUILDER" >/dev/null 2>&1; then + docker buildx create --name "$BUILDER" --use +else + docker buildx use "$BUILDER" +fi + +echo "Building multi-arch image for $SPYDER_IMAGE on platforms: $PLATFORMS" + +docker buildx build \ + --platform "$PLATFORMS" \ + --tag "$SPYDER_IMAGE" \ + --push \ + --file Dockerfile \ + . + +echo "Image pushed: $SPYDER_IMAGE" diff --git a/compose.runtime.yaml b/compose.runtime.yaml index 5b07ee6..1d6adca 100644 --- a/compose.runtime.yaml +++ b/compose.runtime.yaml @@ -2,7 +2,7 @@ services: spyder-wayland: # Default Wayland session using the published image. - image: ${SPYDER_IMAGE:-ghcr.io/your-account/spyder-wayland:latest} + image: ${SPYDER_IMAGE:-gitea.example.com/max/spyder-wayland:latest} environment: UID: "${UID}" GID: "${GID}" @@ -30,7 +30,7 @@ services: spyder-x11: profiles: - "x11" - image: ${SPYDER_IMAGE:-ghcr.io/your-account/spyder-wayland:latest} + image: ${SPYDER_IMAGE:-gitea.example.com/max/spyder-wayland:latest} environment: UID: "${UID}" GID: "${GID}" diff --git a/compose.yaml b/compose.yaml index 8a9b959..d64ea64 100644 --- a/compose.yaml +++ b/compose.yaml @@ -5,7 +5,7 @@ services: build: context: . dockerfile: Dockerfile - image: spyder-conda + image: ${LOCAL_IMAGE_NAME:-spyder-conda} environment: UID: "${UID}" GID: "${GID}" @@ -37,7 +37,7 @@ services: build: context: . dockerfile: Dockerfile - image: spyder-conda + image: ${LOCAL_IMAGE_NAME:-spyder-conda} environment: UID: "${UID}" GID: "${GID}"