You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

187 lines
7.1 KiB

#!/bin/bash
# Build script for next-orly v0.58.5 Docker image
set -e
# Check for Docker
DOCKER_CMD=""
if command -v docker >/dev/null 2>&1; then
DOCKER_CMD="docker"
elif command -v podman >/dev/null 2>&1; then
DOCKER_CMD="podman"
elif command -v docker.io >/dev/null 2>&1; then
DOCKER_CMD="docker.io"
else
echo "Error: Docker is not installed or not in PATH."
echo ""
echo "To install Docker on Ubuntu/Debian:"
echo " sudo apt install docker.io"
echo " sudo systemctl enable --now docker"
echo " sudo usermod -aG docker $USER"
echo " # Then log out and back in"
echo ""
echo "Or install Podman (Docker alternative):"
echo " sudo apt install podman"
echo ""
exit 1
fi
# Check if we're on the correct tag
CURRENT_TAG=$(git describe --tags --exact-match HEAD 2>/dev/null || echo "")
if [ "$CURRENT_TAG" != "v0.58.5" ]; then
echo "Warning: Not on v0.58.5 tag (current: $CURRENT_TAG)"
echo "Continuing anyway..."
fi
# Always rebuild web UI to ensure latest changes are included
# Remove old dist folder if it exists to force fresh build
if [ -d "app/web/dist" ]; then
echo "Removing old web UI build to force fresh rebuild..."
rm -rf app/web/dist
fi
# Create minimal placeholder for Go embed directive (needed for local development)
# Docker will replace this with the actual build
mkdir -p app/web/dist
echo "<!-- Placeholder - will be replaced by Docker build -->" > app/web/dist/index.html
echo "Using Dockerfile.with-web (will build web UI in Docker with latest changes)..."
DOCKERFILE="Dockerfile.with-web"
# Ensure dev proxy is disabled in Dockerfile to prevent 502 errors
echo "Ensuring dev proxy is disabled in Dockerfile..."
# Remove any existing ORLY_WEB lines to avoid duplicates
sed -i '/ORLY_WEB_DISABLE/d' "$DOCKERFILE"
sed -i '/ORLY_WEB_DEV_PROXY_URL/d' "$DOCKERFILE"
# Remove trailing backslash from ORLY_LOG_LEVEL if it exists (we'll add it back)
sed -i 's/^\( ORLY_LOG_LEVEL=info\) \\$/\1/' "$DOCKERFILE"
# Now add the new lines properly formatted
awk '/^ ORLY_LOG_LEVEL=info$/ {
print $0 " \\"
print " ORLY_WEB_DISABLE=false \\"
print " ORLY_WEB_DEV_PROXY_URL=\"\""
next
} 1' "$DOCKERFILE" > "$DOCKERFILE.tmp" && mv "$DOCKERFILE.tmp" "$DOCKERFILE"
echo "Added ORLY_WEB_DISABLE=false and ORLY_WEB_DEV_PROXY_URL=\"\" to Dockerfile"
# Check if local nostr clone exists and prepare it for Docker build
NOSTR_PATH="${NOSTR_PATH:-/home/firefly/Dokumente/repos/nostr}"
mkdir -p .docker-build-context
# Backup go.mod and go.sum before making changes
cp go.mod go.mod.backup
cp go.sum go.sum.backup 2>/dev/null || true
if [ -d "$NOSTR_PATH" ] && [ -f "$NOSTR_PATH/go.mod" ]; then
echo "Found local nostr clone at: $NOSTR_PATH"
# Remove any existing replace directive
sed -i '/^replace git.mleku.dev\/mleku\/nostr/d' go.mod
# First, use the actual local path for vendoring (absolute path)
echo "replace git.mleku.dev/mleku/nostr => $NOSTR_PATH" >> go.mod
echo "Using local nostr module for vendoring"
# Vendor all dependencies locally (using local network, not Docker's network)
echo "Vendoring all dependencies locally..."
go mod vendor || {
echo "Error: Failed to vendor dependencies. Make sure you have network access."
exit 1
}
# Copy nostr into build context for Docker
rm -rf .docker-build-context/nostr
cp -r "$NOSTR_PATH" .docker-build-context/nostr
# Now update go.mod to use Docker build context path
echo "Preparing for Docker build..."
sed -i '/^replace git.mleku.dev\/mleku\/nostr/d' go.mod
echo "replace git.mleku.dev/mleku/nostr => ./docker-build-context/nostr" >> go.mod
# Update vendor/modules.txt to match the new replace path
# The nostr code is already in vendor/, we just need to update the metadata
if [ -f vendor/modules.txt ]; then
# Replace the absolute path with the relative Docker build context path
sed -i "s|=> $NOSTR_PATH|=> ./docker-build-context/nostr|g" vendor/modules.txt
fi
echo "Using local nostr module from build context"
else
echo "Local nostr clone not found at $NOSTR_PATH"
echo "Will try to fetch from remote (may have DNS issues)..."
# Create empty directory so COPY doesn't fail
mkdir -p .docker-build-context/nostr
# Remove any existing replace directive
sed -i '/^replace git.mleku.dev\/mleku\/nostr/d' go.mod
# Vendor all dependencies locally
echo "Vendoring all dependencies locally..."
go mod vendor || {
echo "Error: Failed to vendor dependencies. Make sure you have network access."
exit 1
}
fi
# Function to restore go.mod and go.sum on exit
restore_gomod() {
if [ -f go.mod.backup ]; then
mv go.mod.backup go.mod
echo "Restored go.mod"
fi
if [ -f go.sum.backup ]; then
mv go.sum.backup go.sum
echo "Restored go.sum"
fi
# Clean up build context and vendor
rm -rf .docker-build-context
rm -rf vendor
}
trap restore_gomod EXIT
# Build the Docker image with both version and latest tags
# Local nostr clone (if found) is already copied into build context
echo "Building Docker image silberengel/next-orly:v0.58.5 using $DOCKER_CMD..."
if [ "$DOCKER_CMD" = "docker" ]; then
# Try using host network mode first (uses host DNS) - best for DNS issues
if docker build --help 2>/dev/null | grep -q "\-\-network"; then
echo "Using host network mode for better DNS resolution..."
$DOCKER_CMD build --network=host -t silberengel/next-orly:v0.58.5 -t silberengel/next-orly:latest -f "$DOCKERFILE" .
elif docker build --help 2>/dev/null | grep -q "\-\-dns"; then
# Fallback to DNS configuration
echo "Using DNS configuration (8.8.8.8, 8.8.4.4)..."
$DOCKER_CMD build --dns 8.8.8.8 --dns 8.8.4.4 -t silberengel/next-orly:v0.58.5 -t silberengel/next-orly:latest -f "$DOCKERFILE" .
else
# Last resort - no DNS config
echo "Warning: No DNS configuration available, build may fail..."
$DOCKER_CMD build -t silberengel/next-orly:v0.58.5 -t silberengel/next-orly:latest -f "$DOCKERFILE" .
fi
else
# buildx or other - try DNS if available
if docker buildx build --help 2>/dev/null | grep -q "\-\-dns"; then
$DOCKER_CMD build --dns 8.8.8.8 --dns 8.8.4.4 -t silberengel/next-orly:v0.58.5 -t silberengel/next-orly:latest -f "$DOCKERFILE" .
else
$DOCKER_CMD build -t silberengel/next-orly:v0.58.5 -t silberengel/next-orly:latest -f "$DOCKERFILE" .
fi
fi
echo ""
echo "Build complete! Image tags:"
echo " - silberengel/next-orly:v0.58.5"
echo " - silberengel/next-orly:latest"
echo ""
echo "To push to Docker Hub:"
echo " $DOCKER_CMD push silberengel/next-orly:v0.58.5"
echo " $DOCKER_CMD push silberengel/next-orly:latest"
echo ""
echo "Or run this script with --push to build and push automatically:"
echo " $0 --push"
# Push if requested
if [ "$1" == "--push" ]; then
echo ""
echo "Pushing images to Docker Hub..."
$DOCKER_CMD push silberengel/next-orly:v0.58.5
$DOCKER_CMD push silberengel/next-orly:latest
echo ""
echo "✅ Images pushed successfully!"
fi