#!/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"