Ajout batch

This commit is contained in:
Serge NOEL
2025-12-05 14:54:08 +01:00
parent d04d1748d3
commit 0d0d52c93c
2 changed files with 111 additions and 16 deletions

View File

@@ -34,20 +34,42 @@ fi
# Build and push multi-arch image # Build and push multi-arch image
echo "Building for platforms: ${PLATFORMS}..." echo "Building for platforms: ${PLATFORMS}..."
# Check if PUSH is set to true
if [ "${PUSH}" = "true" ]; then
echo "Building and pushing to registry..."
docker buildx build \ docker buildx build \
--platform "${PLATFORMS}" \ --platform "${PLATFORMS}" \
--tag "${IMAGE_NAME}:${IMAGE_TAG}" \ --tag "${IMAGE_NAME}:${IMAGE_TAG}" \
--push \ --push \
. .
echo "============================================"
echo "✅ Multi-arch image built and pushed!"
echo "============================================"
echo "Image: ${IMAGE_NAME}:${IMAGE_TAG}"
echo ""
echo "Verify architectures:"
echo " docker buildx imagetools inspect ${IMAGE_NAME}:${IMAGE_TAG}"
else
# For multi-arch, save to local registry cache
echo "Building locally (use PUSH=true to push to registry)..."
docker buildx build \
--platform "${PLATFORMS}" \
--tag "${IMAGE_NAME}:${IMAGE_TAG}" \
.
echo "============================================" echo "============================================"
echo "✅ Multi-arch image built successfully!" echo "✅ Multi-arch image built successfully!"
echo "============================================" echo "============================================"
echo "Image: ${IMAGE_NAME}:${IMAGE_TAG}" echo "Image: ${IMAGE_NAME}:${IMAGE_TAG}"
echo "" echo ""
echo "Test on different platforms:" echo "Note: Multi-arch images are in buildx cache."
echo " amd64 (x86_64): docker run --rm ${IMAGE_NAME}:${IMAGE_TAG} node --version" echo "To push to registry:"
echo " arm64 (RPi 4): docker run --rm ${IMAGE_NAME}:${IMAGE_TAG} node --version" echo " PUSH=true ./build-multiarch.sh"
echo "" echo ""
echo "Verify architectures:" echo "To load single arch locally:"
echo " docker buildx imagetools inspect ${IMAGE_NAME}:${IMAGE_TAG}" echo " docker buildx build --platform linux/amd64 -t ${IMAGE_NAME}:${IMAGE_TAG} --load ."
echo " or"
echo " docker buildx build --platform linux/arm64 -t ${IMAGE_NAME}:${IMAGE_TAG} --load ."
fi

73
web-gateway/transfer-to-rpi.sh Executable file
View File

@@ -0,0 +1,73 @@
#!/bin/bash
# Transfer Docker image to Raspberry Pi and load into K3s
set -e
IMAGE_NAME="${IMAGE_NAME:-easylinux/web-gateway}"
IMAGE_TAG="${IMAGE_TAG:-latest}"
RPI_HOST="${RPI_HOST:-}"
RPI_USER="${RPI_USER:-pi}"
if [ -z "$RPI_HOST" ]; then
echo "Error: RPI_HOST not set"
echo "Usage: RPI_HOST=192.168.1.100 ./transfer-to-rpi.sh"
echo " or: RPI_HOST=rpi4.local RPI_USER=myuser ./transfer-to-rpi.sh"
exit 1
fi
echo "============================================"
echo "Transfer Docker Image to Raspberry Pi"
echo "============================================"
echo "Image: ${IMAGE_NAME}:${IMAGE_TAG}"
echo "Target: ${RPI_USER}@${RPI_HOST}"
echo "============================================"
# Step 1: Build ARM64 image locally
echo "Step 1/4: Building ARM64 image..."
docker buildx build \
--platform linux/arm64 \
--tag "${IMAGE_NAME}:${IMAGE_TAG}" \
--load \
.
# Step 2: Save image to tar.gz
echo "Step 2/4: Saving image to tar.gz..."
docker save "${IMAGE_NAME}:${IMAGE_TAG}" | gzip > /tmp/web-gateway-arm64.tar.gz
echo "Saved to /tmp/web-gateway-arm64.tar.gz ($(du -h /tmp/web-gateway-arm64.tar.gz | cut -f1))"
# Step 3: Transfer to Raspberry Pi
echo "Step 3/4: Transferring to ${RPI_USER}@${RPI_HOST}..."
scp /tmp/web-gateway-arm64.tar.gz "${RPI_USER}@${RPI_HOST}:/tmp/"
# Step 4: Load image on Raspberry Pi
echo "Step 4/4: Loading image into K3s..."
ssh "${RPI_USER}@${RPI_HOST}" << EOF
echo "Loading image into Docker/K3s..."
gunzip -c /tmp/web-gateway-arm64.tar.gz | sudo k3s ctr images import -
# Alternative if using docker instead of containerd:
# gunzip -c /tmp/web-gateway-arm64.tar.gz | docker load
echo "Cleaning up..."
rm /tmp/web-gateway-arm64.tar.gz
echo "Verifying image..."
sudo k3s ctr images ls | grep web-gateway || echo "Image not found!"
EOF
# Cleanup local file
rm /tmp/web-gateway-arm64.tar.gz
echo "============================================"
echo "✅ Image transferred successfully!"
echo "============================================"
echo "Image is now available on ${RPI_HOST}"
echo ""
echo "Deploy with Helm:"
echo " helm install rdp-web-gateway ./chart/rdp-web-gateway \\"
echo " --namespace rdpbroker \\"
echo " --create-namespace \\"
echo " --set image.repository=${IMAGE_NAME} \\"
echo " --set image.tag=${IMAGE_TAG} \\"
echo " --set image.pullPolicy=IfNotPresent \\"
echo " -f chart/rdp-web-gateway/examples/rpi4-k3s.yaml"