- Multi-architecture Docker image (ARM64 + AMD64) - Kubernetes manifests for 3-replica deployment - Traefik ingress configuration - NGINX Proxy Manager integration - ConfigMap-based configuration - Automated build and deployment scripts - Session monitoring tools
147 lines
3.9 KiB
Bash
Executable File
147 lines
3.9 KiB
Bash
Executable File
#!/bin/bash
|
|
set -e
|
|
|
|
# Colors for output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Configuration
|
|
GITEA_HOST="192.168.1.208:3002"
|
|
IMAGE_NAME="socktop-webterm"
|
|
CARGO_TOML="Cargo.toml"
|
|
|
|
echo -e "${GREEN}=== Socktop WebTerm - Multi-Architecture Build & Publish ===${NC}"
|
|
echo ""
|
|
echo "This script builds for both AMD64 (x86_64) and ARM64 (Raspberry Pi)"
|
|
echo ""
|
|
|
|
# Check if buildx is available
|
|
if ! docker buildx version &> /dev/null; then
|
|
echo -e "${RED}Error: docker buildx is not available${NC}"
|
|
echo ""
|
|
echo "Install buildx:"
|
|
echo " Docker Desktop: Already included"
|
|
echo " Docker Engine: https://docs.docker.com/buildx/working-with-buildx/"
|
|
exit 1
|
|
fi
|
|
|
|
echo -e "${GREEN}✓ Docker buildx is available${NC}"
|
|
echo ""
|
|
|
|
# Extract version from Cargo.toml
|
|
if [ ! -f "$CARGO_TOML" ]; then
|
|
echo -e "${RED}Error: Cargo.toml not found!${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
VERSION=$(grep '^version = ' "$CARGO_TOML" | head -1 | sed 's/version = "\(.*\)"/\1/')
|
|
|
|
if [ -z "$VERSION" ]; then
|
|
echo -e "${RED}Error: Could not extract version from Cargo.toml${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
echo -e "${YELLOW}Version detected:${NC} $VERSION"
|
|
echo -e "${YELLOW}Gitea Host:${NC} $GITEA_HOST"
|
|
echo ""
|
|
|
|
# Prompt for Gitea username
|
|
read -p "Enter Gitea username: " GITEA_USER
|
|
|
|
if [ -z "$GITEA_USER" ]; then
|
|
echo -e "${RED}Error: Username cannot be empty${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
# Prompt for Gitea password (hidden input)
|
|
read -s -p "Enter Gitea password: " GITEA_PASSWORD
|
|
echo ""
|
|
|
|
if [ -z "$GITEA_PASSWORD" ]; then
|
|
echo -e "${RED}Error: Password cannot be empty${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
echo ""
|
|
|
|
# Docker login to Gitea registry
|
|
echo -e "${YELLOW}Logging in to Gitea Docker registry...${NC}"
|
|
echo "$GITEA_PASSWORD" | docker login "$GITEA_HOST" -u "$GITEA_USER" --password-stdin
|
|
|
|
if [ $? -ne 0 ]; then
|
|
echo -e "${RED}Error: Docker login failed${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
echo -e "${GREEN}✓ Login successful${NC}"
|
|
echo ""
|
|
|
|
# Create or use existing buildx builder
|
|
BUILDER_NAME="multiarch-builder"
|
|
echo -e "${YELLOW}Setting up buildx builder...${NC}"
|
|
|
|
if ! docker buildx inspect "$BUILDER_NAME" &> /dev/null; then
|
|
echo "Creating new buildx builder: $BUILDER_NAME"
|
|
docker buildx create --name "$BUILDER_NAME" --use
|
|
else
|
|
echo "Using existing buildx builder: $BUILDER_NAME"
|
|
docker buildx use "$BUILDER_NAME"
|
|
fi
|
|
|
|
# Bootstrap the builder
|
|
docker buildx inspect --bootstrap
|
|
|
|
echo -e "${GREEN}✓ Builder ready${NC}"
|
|
echo ""
|
|
|
|
# Build and push multi-architecture image
|
|
echo -e "${YELLOW}Building multi-architecture image...${NC}"
|
|
echo "Target platforms: linux/amd64, linux/arm64"
|
|
echo ""
|
|
echo "This will take several minutes as it builds for both architectures..."
|
|
echo ""
|
|
|
|
docker buildx build \
|
|
--platform linux/amd64,linux/arm64 \
|
|
--tag "${GITEA_HOST}/${GITEA_USER}/${IMAGE_NAME}:${VERSION}" \
|
|
--tag "${GITEA_HOST}/${GITEA_USER}/${IMAGE_NAME}:latest" \
|
|
--push \
|
|
.
|
|
|
|
if [ $? -ne 0 ]; then
|
|
echo -e "${RED}Error: Build failed${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
echo ""
|
|
echo -e "${GREEN}✓ Build and push successful${NC}"
|
|
echo ""
|
|
|
|
# Summary
|
|
echo -e "${GREEN}=== Publication Complete ===${NC}"
|
|
echo ""
|
|
echo "Multi-architecture images published to Gitea registry:"
|
|
echo -e " ${GREEN}${GITEA_HOST}/${GITEA_USER}/${IMAGE_NAME}:${VERSION}${NC}"
|
|
echo -e " ${GREEN}${GITEA_HOST}/${GITEA_USER}/${IMAGE_NAME}:latest${NC}"
|
|
echo ""
|
|
echo "Architectures:"
|
|
echo " - linux/amd64 (x86_64)"
|
|
echo " - linux/arm64 (Raspberry Pi, ARM servers)"
|
|
echo ""
|
|
echo "To pull on your k3s cluster (will automatically use correct architecture):"
|
|
echo -e " ${YELLOW}docker pull ${GITEA_HOST}/${GITEA_USER}/${IMAGE_NAME}:${VERSION}${NC}"
|
|
echo -e " ${YELLOW}docker pull ${GITEA_HOST}/${GITEA_USER}/${IMAGE_NAME}:latest${NC}"
|
|
echo ""
|
|
echo "For Kubernetes, use image:"
|
|
echo -e " ${YELLOW}image: ${GITEA_HOST}/${GITEA_USER}/${IMAGE_NAME}:${VERSION}${NC}"
|
|
echo ""
|
|
|
|
# Logout
|
|
echo -e "${YELLOW}Logging out from Gitea registry...${NC}"
|
|
docker logout "$GITEA_HOST"
|
|
echo -e "${GREEN}✓ Logged out${NC}"
|
|
echo ""
|
|
echo -e "${GREEN}Done!${NC}"
|