Files
webssh/deployment/scripts/docker-build-and-push.sh
T

89 lines
2.1 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# Build and Push Script for WebSSH
# Builds Docker image and pushes to Docker Hub
set -e
# Configuration
IMAGE_NAME="danaildr/webssh"
VERSION="0.5.1"
PLATFORMS="linux/amd64,linux/arm64,linux/arm/v7"
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
echo -e "${BLUE}🐳 Docker Hub Build & Push Script${NC}"
echo -e "${BLUE}=================================${NC}"
ensure_buildx_builder() {
if ! docker buildx inspect >/dev/null 2>&1; then
docker buildx create --use --name webssh-builder >/dev/null
fi
docker buildx inspect --bootstrap >/dev/null
}
# Function to build and push to Docker Hub
build_and_push() {
# Check if user is logged in to Docker Hub
if ! docker info | grep -q "Username"; then
echo -e "${YELLOW}⚠️ You're not logged in to Docker Hub${NC}"
echo -e "${BLUE}ℹ️ Please run: docker login${NC}"
return 1
fi
ensure_buildx_builder
echo -e "${GREEN}🏗 Building & pushing multi-arch image ${IMAGE_NAME}:${VERSION} (${PLATFORMS})...${NC}"
docker buildx build \
--platform "${PLATFORMS}" \
--tag "${IMAGE_NAME}:${VERSION}" \
--tag "${IMAGE_NAME}:latest" \
--push \
--file deployment/Dockerfile \
.
echo -e "${GREEN}✅ Docker build & push successful${NC}"
echo ""
echo -e "${YELLOW}⚠️ Don't forget to create a GitHub release!${NC}"
}
# Function to show usage
show_usage() {
echo "Usage: $0 [options]"
echo ""
echo "Options:"
echo " -v, --version Show configured version tag"
echo " -b, --build Build and push to Docker Hub"
echo " -h, --help Show this help message"
echo ""
echo "Examples:"
echo " $0 --version # Show version tag"
echo " $0 --build # Build and push multi-arch image"
}
# Parse command line arguments
case "${1:-}" in
-v|--version)
echo "${VERSION}"
;;
-b|--build)
build_and_push
;;
-h|--help|"")
show_usage
;;
*)
echo -e "${RED}❌ Unknown option: $1${NC}"
show_usage
exit 1
;;
esac