add source code and readme
This commit is contained in:
125
build/bookwyrm/build.sh
Executable file
125
build/bookwyrm/build.sh
Executable file
@@ -0,0 +1,125 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "🚀 Building Production-Optimized BookWyrm Containers..."
|
||||
echo "Optimized build targeting ~400MB final image size"
|
||||
|
||||
# Exit on any error
|
||||
set -e
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Function to print colored output
|
||||
print_status() {
|
||||
echo -e "${GREEN}✓${NC} $1"
|
||||
}
|
||||
|
||||
print_warning() {
|
||||
echo -e "${YELLOW}⚠${NC} $1"
|
||||
}
|
||||
|
||||
print_error() {
|
||||
echo -e "${RED}✗${NC} $1"
|
||||
}
|
||||
|
||||
# Check if Docker is running
|
||||
if ! docker info >/dev/null 2>&1; then
|
||||
print_error "Docker is not running. Please start Docker and try again."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Building optimized containers for ARM64 architecture..."
|
||||
echo "This will build:"
|
||||
echo -e " • ${YELLOW}bookwyrm-base${NC} - Shared base image (~400MB)"
|
||||
echo -e " • ${YELLOW}bookwyrm-web${NC} - Web server (Nginx + Django/Gunicorn, ~450MB)"
|
||||
echo -e " • ${YELLOW}bookwyrm-worker${NC} - Background workers (Celery + Beat, ~450MB)"
|
||||
echo ""
|
||||
|
||||
# Step 1: Build optimized base image
|
||||
echo "Step 1/3: Building optimized base image..."
|
||||
cd bookwyrm-base
|
||||
if docker build --platform linux/arm64 -t bookwyrm-base:latest .; then
|
||||
print_status "Base image built successfully!"
|
||||
else
|
||||
print_error "Failed to build base image"
|
||||
exit 1
|
||||
fi
|
||||
cd ..
|
||||
|
||||
# Step 2: Build optimized web container
|
||||
echo ""
|
||||
echo "Step 2/3: Building optimized web container..."
|
||||
cd bookwyrm-web
|
||||
if docker build --platform linux/arm64 -t <YOUR_REGISTRY_URL>/library/bookwyrm-web:latest .; then
|
||||
print_status "Web container built successfully!"
|
||||
else
|
||||
print_error "Failed to build web container"
|
||||
exit 1
|
||||
fi
|
||||
cd ..
|
||||
|
||||
# Step 3: Build optimized worker container
|
||||
echo ""
|
||||
echo "Step 3/3: Building optimized worker container..."
|
||||
cd bookwyrm-worker
|
||||
if docker build --platform linux/arm64 -t <YOUR_REGISTRY_URL>/library/bookwyrm-worker:latest .; then
|
||||
print_status "Worker container built successfully!"
|
||||
else
|
||||
print_error "Failed to build worker container"
|
||||
exit 1
|
||||
fi
|
||||
cd ..
|
||||
|
||||
echo ""
|
||||
echo "🎉 All containers built successfully!"
|
||||
|
||||
# Show image sizes
|
||||
echo ""
|
||||
echo "📊 Built image sizes:"
|
||||
docker images --format "table {{.Repository}}\t{{.Tag}}\t{{.Size}}" | grep -E "(bookwyrm-base|bookwyrm-web|bookwyrm-worker)" | grep -v optimized
|
||||
|
||||
echo ""
|
||||
echo "Built containers:"
|
||||
echo " • <YOUR_REGISTRY_URL>/library/bookwyrm-web:latest"
|
||||
echo " • <YOUR_REGISTRY_URL>/library/bookwyrm-worker:latest"
|
||||
|
||||
# Ask if user wants to push
|
||||
echo ""
|
||||
read -p "Push containers to Harbor registry? (y/N): " -n 1 -r
|
||||
echo
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
echo ""
|
||||
echo "🚀 Pushing containers to registry..."
|
||||
|
||||
# Login check
|
||||
if ! docker info 2>/dev/null | grep -q "<YOUR_REGISTRY_URL>"; then
|
||||
print_warning "You may need to login to Harbor registry first:"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
echo "Pushing web container..."
|
||||
if docker push <YOUR_REGISTRY_URL>/library/bookwyrm-web:latest; then
|
||||
print_status "Web container pushed successfully!"
|
||||
else
|
||||
print_error "Failed to push web container"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Pushing worker container..."
|
||||
if docker push <YOUR_REGISTRY_URL>/library/bookwyrm-worker:latest; then
|
||||
print_status "Worker container pushed successfully!"
|
||||
else
|
||||
print_error "Failed to push worker container"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
print_status "All containers pushed to Harbor registry!"
|
||||
else
|
||||
echo "Skipping push. You can push later with:"
|
||||
echo " docker push <YOUR_REGISTRY_URL>/library/bookwyrm-web:latest"
|
||||
echo " docker push <YOUR_REGISTRY_URL>/library/bookwyrm-worker:latest"
|
||||
fi
|
||||
Reference in New Issue
Block a user