Add cross-arch buildscript

This commit is contained in:
Max
2025-10-13 20:57:37 +02:00
parent 8aae094348
commit eabab653a0
5 changed files with 94 additions and 12 deletions

8
.env
View File

@@ -16,4 +16,10 @@ XDG_RUNTIME_DIR=/run/user/1000
WAYLAND_DISPLAY=wayland-1
DISPLAY=:0
DEBUG=1
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

View File

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

56
build-and-push.sh Executable file
View File

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

View File

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

View File

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