Fix Go build environment and frontend URLs
This commit is contained in:
parent
d69ab22967
commit
4081e89fdd
449
start.sh
449
start.sh
@ -16,7 +16,7 @@ echo "==> Environment: Internal IP=$(hostname -I)"
|
|||||||
# Ensure required utilities are installed
|
# Ensure required utilities are installed
|
||||||
echo "==> Ensuring required utilities are installed"
|
echo "==> Ensuring required utilities are installed"
|
||||||
apt-get update || echo "Warning: apt-get update failed, continuing with existing packages"
|
apt-get update || echo "Warning: apt-get update failed, continuing with existing packages"
|
||||||
apt-get install -y file unzip wget curl || echo "Warning: apt-get install failed, continuing with existing utilities"
|
apt-get install -y git golang-go curl wget file unzip pkg-config gcc libsodium-dev || echo "Warning: apt-get install failed, continuing with existing utilities"
|
||||||
echo "==> Utilities installed"
|
echo "==> Utilities installed"
|
||||||
|
|
||||||
# Create necessary directories
|
# Create necessary directories
|
||||||
@ -27,6 +27,10 @@ mkdir -p /app/data/web/photos
|
|||||||
mkdir -p /app/data/web/accounts
|
mkdir -p /app/data/web/accounts
|
||||||
mkdir -p /app/data/web/auth
|
mkdir -p /app/data/web/auth
|
||||||
mkdir -p /app/data/web/cast
|
mkdir -p /app/data/web/cast
|
||||||
|
# Create Go directories
|
||||||
|
mkdir -p /app/data/go/pkg
|
||||||
|
mkdir -p /app/data/go/bin
|
||||||
|
mkdir -p /app/data/go/src
|
||||||
echo "==> Created all necessary directories"
|
echo "==> Created all necessary directories"
|
||||||
|
|
||||||
# Directory listings for debugging
|
# Directory listings for debugging
|
||||||
@ -37,108 +41,156 @@ ls -la /app/data/web
|
|||||||
echo "==> Directory listing of /app/data/ente:"
|
echo "==> Directory listing of /app/data/ente:"
|
||||||
ls -la /app/data/ente
|
ls -la /app/data/ente
|
||||||
|
|
||||||
# Define server directory
|
# Clone Ente repository if it doesn't exist
|
||||||
SERVER_DIR="/app/data/ente/server"
|
ENTE_DIR="/app/data/ente/repository"
|
||||||
echo "==> Using server directory: ${SERVER_DIR}"
|
if [ ! -d "$ENTE_DIR" ]; then
|
||||||
|
echo "==> Cloning Ente repository"
|
||||||
# Download Museum server
|
mkdir -p "$ENTE_DIR"
|
||||||
echo "==> Downloading Ente Museum server..."
|
git clone https://github.com/ente-io/ente "$ENTE_DIR"
|
||||||
cd ${SERVER_DIR}
|
echo "==> Ente repository cloned successfully"
|
||||||
|
|
||||||
# Check if museum binary already exists and is executable
|
|
||||||
if [ -f "${SERVER_DIR}/museum" ] && [ -x "${SERVER_DIR}/museum" ]; then
|
|
||||||
echo "==> Museum server binary already exists"
|
|
||||||
else
|
else
|
||||||
echo "==> Downloading from GitHub releases..."
|
echo "==> Ente repository already exists, pulling latest changes"
|
||||||
|
cd "$ENTE_DIR"
|
||||||
|
git pull
|
||||||
|
fi
|
||||||
|
|
||||||
# Try multiple release URLs
|
# Set up S3 config
|
||||||
DOWNLOAD_URLS=(
|
if [ ! -f "/app/data/s3.env" ]; then
|
||||||
"https://github.com/ente-io/museum/releases/latest/download/museum-linux-amd64"
|
echo "==> Creating default S3 environment file"
|
||||||
"https://github.com/ente-io/museum/releases/download/v1.0.0/museum-linux-amd64"
|
cat > /app/data/s3.env << 'EOF'
|
||||||
"https://github.com/ente-io/museum/releases/download/latest/museum-linux-amd64"
|
S3_ACCESS_KEY=your-access-key
|
||||||
)
|
S3_SECRET_KEY=your-secret-key
|
||||||
|
S3_ENDPOINT=your-s3-endpoint
|
||||||
|
S3_REGION=your-region
|
||||||
|
S3_BUCKET=your-bucket
|
||||||
|
EOF
|
||||||
|
chmod 600 /app/data/s3.env
|
||||||
|
echo "==> Created S3 environment file at /app/data/s3.env"
|
||||||
|
echo "==> IMPORTANT: Please edit this file with your actual S3 credentials"
|
||||||
|
else
|
||||||
|
echo "==> S3 environment file already exists"
|
||||||
|
fi
|
||||||
|
|
||||||
DOWNLOAD_SUCCESS=false
|
# Load S3 config
|
||||||
|
if [ -f "/app/data/s3.env" ]; then
|
||||||
|
source /app/data/s3.env
|
||||||
|
echo "==> Loaded S3 configuration"
|
||||||
|
fi
|
||||||
|
|
||||||
for URL in "${DOWNLOAD_URLS[@]}"; do
|
# Create museum.yaml config
|
||||||
echo "==> Trying download from: $URL"
|
MUSEUM_CONFIG="/app/data/ente/server/museum.yaml"
|
||||||
if curl -L -o museum "$URL" 2>/app/data/logs/curl.log; then
|
if [ ! -f "$MUSEUM_CONFIG" ]; then
|
||||||
# Check if downloaded file is a valid binary
|
echo "==> Creating museum.yaml configuration"
|
||||||
if file museum | grep -q "ELF"; then
|
cat > "$MUSEUM_CONFIG" << EOF
|
||||||
chmod +x museum
|
port: 3080
|
||||||
DOWNLOAD_SUCCESS=true
|
host: 0.0.0.0
|
||||||
echo "==> Successfully downloaded museum binary from $URL"
|
db:
|
||||||
|
driver: postgres
|
||||||
|
source: "postgres://${CLOUDRON_POSTGRESQL_USERNAME}:${CLOUDRON_POSTGRESQL_PASSWORD}@${CLOUDRON_POSTGRESQL_HOST}:${CLOUDRON_POSTGRESQL_PORT}/${CLOUDRON_POSTGRESQL_DATABASE}?sslmode=disable"
|
||||||
|
max_conns: 10
|
||||||
|
max_idle: 5
|
||||||
|
log_level: info
|
||||||
|
cors:
|
||||||
|
allow_origins:
|
||||||
|
- "*"
|
||||||
|
s3:
|
||||||
|
endpoint: "${S3_ENDPOINT:-s3.amazonaws.com}"
|
||||||
|
region: "${S3_REGION:-us-east-1}"
|
||||||
|
access_key: "${S3_ACCESS_KEY}"
|
||||||
|
secret_key: "${S3_SECRET_KEY}"
|
||||||
|
bucket: "${S3_BUCKET}"
|
||||||
|
public_url: "https://${CLOUDRON_APP_FQDN}/photos"
|
||||||
|
email:
|
||||||
|
enabled: true
|
||||||
|
host: "${CLOUDRON_SMTP_SERVER:-localhost}"
|
||||||
|
port: ${CLOUDRON_SMTP_PORT:-25}
|
||||||
|
username: "${CLOUDRON_SMTP_USERNAME:-""}"
|
||||||
|
password: "${CLOUDRON_SMTP_PASSWORD:-""}"
|
||||||
|
from: "Ente <${CLOUDRON_MAIL_FROM:-no-reply@${CLOUDRON_APP_DOMAIN}}>"
|
||||||
|
EOF
|
||||||
|
chmod 600 "$MUSEUM_CONFIG"
|
||||||
|
echo "==> Created museum.yaml configuration"
|
||||||
|
else
|
||||||
|
echo "==> museum.yaml configuration already exists"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Test PostgreSQL connectivity
|
||||||
|
echo "==> Testing PostgreSQL connectivity..."
|
||||||
|
if ! PGPASSWORD="$CLOUDRON_POSTGRESQL_PASSWORD" psql -h "$CLOUDRON_POSTGRESQL_HOST" -p "$CLOUDRON_POSTGRESQL_PORT" -U "$CLOUDRON_POSTGRESQL_USERNAME" -d "$CLOUDRON_POSTGRESQL_DATABASE" -c "SELECT 1;" > /dev/null 2>&1; then
|
||||||
|
echo "==> ERROR: Failed to connect to PostgreSQL"
|
||||||
|
echo "==> Connection details:"
|
||||||
|
echo "==> Host: $CLOUDRON_POSTGRESQL_HOST"
|
||||||
|
echo "==> Port: $CLOUDRON_POSTGRESQL_PORT"
|
||||||
|
echo "==> User: $CLOUDRON_POSTGRESQL_USERNAME"
|
||||||
|
echo "==> Database: $CLOUDRON_POSTGRESQL_DATABASE"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo "==> PostgreSQL connection successful"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Build Ente Museum server
|
||||||
|
echo "==> Building Ente Museum server..."
|
||||||
|
cd "$ENTE_DIR/server"
|
||||||
|
|
||||||
|
# Set Go environment variables
|
||||||
|
export GOPATH="/app/data/go"
|
||||||
|
export GOBIN="/app/data/go/bin"
|
||||||
|
export GO111MODULE=on
|
||||||
|
export GOCACHE="/app/data/go/cache"
|
||||||
|
mkdir -p $GOCACHE
|
||||||
|
|
||||||
|
# Set required environment variables
|
||||||
|
export ENTE_DB_USER="$CLOUDRON_POSTGRESQL_USERNAME"
|
||||||
|
export ENTE_DB_PASSWORD="$CLOUDRON_POSTGRESQL_PASSWORD"
|
||||||
|
export ENTE_DB_HOST="$CLOUDRON_POSTGRESQL_HOST"
|
||||||
|
export ENTE_DB_PORT="$CLOUDRON_POSTGRESQL_PORT"
|
||||||
|
export ENTE_DB_NAME="$CLOUDRON_POSTGRESQL_DATABASE"
|
||||||
|
export ENTE_CONFIG_FILE="/app/data/ente/server/museum.yaml"
|
||||||
|
|
||||||
|
# Build museum binary
|
||||||
|
echo "==> Building museum binary..."
|
||||||
|
go mod download
|
||||||
|
go build -o /app/data/ente/server/museum cmd/museum/main.go
|
||||||
|
|
||||||
|
# Check if build was successful
|
||||||
|
if [ ! -f "/app/data/ente/server/museum" ]; then
|
||||||
|
echo "==> ERROR: Failed to build museum server, will try to download pre-built binary"
|
||||||
|
|
||||||
|
# Try to download pre-built binary
|
||||||
|
ARCH=$(uname -m)
|
||||||
|
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
|
||||||
|
|
||||||
|
if [ "$ARCH" = "x86_64" ]; then
|
||||||
|
ARCH="amd64"
|
||||||
|
elif [ "$ARCH" = "aarch64" ]; then
|
||||||
|
ARCH="arm64"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "==> Detected architecture: $OS-$ARCH"
|
||||||
|
|
||||||
|
# Try different release URLs
|
||||||
|
for RELEASE_URL in \
|
||||||
|
"https://github.com/ente-io/ente/releases/latest/download/museum-$OS-$ARCH" \
|
||||||
|
"https://github.com/ente-io/ente/releases/download/latest/museum-$OS-$ARCH" \
|
||||||
|
"https://github.com/ente-io/museum/releases/latest/download/museum-$OS-$ARCH" \
|
||||||
|
"https://github.com/ente-io/museum/releases/download/latest/museum-$OS-$ARCH"
|
||||||
|
do
|
||||||
|
echo "==> Trying to download from: $RELEASE_URL"
|
||||||
|
if curl -L -o "/app/data/ente/server/museum" "$RELEASE_URL" && [ -s "/app/data/ente/server/museum" ]; then
|
||||||
|
chmod +x "/app/data/ente/server/museum"
|
||||||
|
echo "==> Successfully downloaded museum binary from $RELEASE_URL"
|
||||||
break
|
break
|
||||||
else
|
else
|
||||||
echo "==> Downloaded file is not a valid binary: $(file museum)"
|
echo "==> Download failed from $RELEASE_URL"
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo "==> Download failed from $URL"
|
|
||||||
cat /app/data/logs/curl.log || echo "No curl logs available"
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# If direct binary download fails, try downloading the source code and build
|
# Check if we have a working binary
|
||||||
if [ "$DOWNLOAD_SUCCESS" = false ]; then
|
if [ ! -f "/app/data/ente/server/museum" ] || [ ! -s "/app/data/ente/server/museum" ]; then
|
||||||
echo "==> Trying to download source code..."
|
echo "==> ERROR: Failed to obtain museum binary. Creating a placeholder Node.js server."
|
||||||
|
|
||||||
SOURCE_URLS=(
|
# Create Node.js placeholder server
|
||||||
"https://github.com/ente-io/museum/archive/refs/heads/main.zip"
|
cat > /app/data/ente/server/server.js << 'EOF'
|
||||||
"https://github.com/ente-io/ente/archive/refs/heads/main.zip"
|
|
||||||
"https://api.github.com/repos/ente-io/museum/zipball/main"
|
|
||||||
)
|
|
||||||
|
|
||||||
for URL in "${SOURCE_URLS[@]}"; do
|
|
||||||
echo "==> Trying source download from: $URL"
|
|
||||||
if curl -L -o museum.zip "$URL" 2>/app/data/logs/curl.log; then
|
|
||||||
echo "==> Checking downloaded file..."
|
|
||||||
file museum.zip
|
|
||||||
|
|
||||||
# Check if we have a valid zip file
|
|
||||||
if file museum.zip | grep -q "Zip archive data"; then
|
|
||||||
echo "==> Valid zip file downloaded"
|
|
||||||
unzip -o museum.zip
|
|
||||||
|
|
||||||
# Find the extracted directory
|
|
||||||
EXTRACTED_DIR=$(find . -maxdepth 1 -type d -name "museum-*" -o -name "ente-io-museum-*" | head -1)
|
|
||||||
|
|
||||||
if [ -n "$EXTRACTED_DIR" ]; then
|
|
||||||
echo "==> Found extracted directory: $EXTRACTED_DIR"
|
|
||||||
cd "$EXTRACTED_DIR"
|
|
||||||
|
|
||||||
# Try to build if go is available
|
|
||||||
if command -v go &> /dev/null; then
|
|
||||||
echo "==> Building museum server with Go..."
|
|
||||||
go build -o museum cmd/museum/main.go && DOWNLOAD_SUCCESS=true
|
|
||||||
|
|
||||||
if [ -f "museum" ]; then
|
|
||||||
chmod +x museum
|
|
||||||
mv museum ${SERVER_DIR}/
|
|
||||||
echo "==> Successfully built museum binary"
|
|
||||||
cd ${SERVER_DIR}
|
|
||||||
DOWNLOAD_SUCCESS=true
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo "==> Could not find extracted directory"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo "==> Downloaded file is not a valid zip file: $(file museum.zip)"
|
|
||||||
cat museum.zip
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo "==> Source download failed from $URL"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
# If all download attempts fail, create a placeholder server
|
|
||||||
if [ "$DOWNLOAD_SUCCESS" = false ]; then
|
|
||||||
echo "==> All download attempts failed, creating a placeholder server..."
|
|
||||||
|
|
||||||
# Creating a placeholder server with Node.js
|
|
||||||
cat > ${SERVER_DIR}/server.js << 'EOF'
|
|
||||||
const http = require('http');
|
const http = require('http');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
@ -200,83 +252,21 @@ server.on('error', (error) => {
|
|||||||
// Log startup
|
// Log startup
|
||||||
log('Museum placeholder server starting up');
|
log('Museum placeholder server starting up');
|
||||||
EOF
|
EOF
|
||||||
|
echo "==> Created Node.js placeholder server"
|
||||||
# Mark the failure but continue with the placeholder
|
|
||||||
echo "==> Created Node.js placeholder server at ${SERVER_DIR}/server.js"
|
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
|
|
||||||
# Set up S3 config
|
|
||||||
if [ ! -f "/app/data/s3.env" ]; then
|
|
||||||
echo "==> Creating default S3 environment file"
|
|
||||||
cat > /app/data/s3.env << 'EOF'
|
|
||||||
S3_ACCESS_KEY=your-access-key
|
|
||||||
S3_SECRET_KEY=your-secret-key
|
|
||||||
S3_ENDPOINT=your-s3-endpoint
|
|
||||||
S3_REGION=your-region
|
|
||||||
S3_BUCKET=your-bucket
|
|
||||||
EOF
|
|
||||||
chmod 600 /app/data/s3.env
|
|
||||||
echo "==> Created S3 environment file at /app/data/s3.env"
|
|
||||||
echo "==> IMPORTANT: Please edit this file with your actual S3 credentials"
|
|
||||||
else
|
else
|
||||||
echo "==> S3 environment file already exists"
|
echo "==> Successfully built museum binary"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Load S3 config
|
# Make museum binary executable
|
||||||
if [ -f "/app/data/s3.env" ]; then
|
chmod +x /app/data/ente/server/museum 2>/dev/null || true
|
||||||
source /app/data/s3.env
|
|
||||||
echo "==> Loaded S3 configuration"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Create museum.yaml config
|
|
||||||
if [ ! -f "${SERVER_DIR}/museum.yaml" ]; then
|
|
||||||
echo "==> Creating museum.yaml configuration"
|
|
||||||
cat > ${SERVER_DIR}/museum.yaml << EOF
|
|
||||||
port: 3080
|
|
||||||
host: 0.0.0.0
|
|
||||||
db:
|
|
||||||
driver: postgres
|
|
||||||
source: "postgres://${CLOUDRON_POSTGRESQL_USERNAME}:${CLOUDRON_POSTGRESQL_PASSWORD}@${CLOUDRON_POSTGRESQL_HOST}:${CLOUDRON_POSTGRESQL_PORT}/${CLOUDRON_POSTGRESQL_DATABASE}?sslmode=disable"
|
|
||||||
max_conns: 10
|
|
||||||
max_idle: 5
|
|
||||||
log_level: info
|
|
||||||
cors:
|
|
||||||
allow_origins:
|
|
||||||
- "*"
|
|
||||||
s3:
|
|
||||||
endpoint: "${S3_ENDPOINT:-s3.amazonaws.com}"
|
|
||||||
region: "${S3_REGION:-us-east-1}"
|
|
||||||
access_key: "${S3_ACCESS_KEY}"
|
|
||||||
secret_key: "${S3_SECRET_KEY}"
|
|
||||||
bucket: "${S3_BUCKET}"
|
|
||||||
public_url: "https://${CLOUDRON_APP_FQDN}/photos"
|
|
||||||
EOF
|
|
||||||
chmod 600 ${SERVER_DIR}/museum.yaml
|
|
||||||
echo "==> Created museum.yaml configuration"
|
|
||||||
else
|
|
||||||
echo "==> museum.yaml configuration already exists"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Test PostgreSQL connectivity
|
|
||||||
echo "==> Testing PostgreSQL connectivity..."
|
|
||||||
if ! PGPASSWORD="$CLOUDRON_POSTGRESQL_PASSWORD" psql -h "$CLOUDRON_POSTGRESQL_HOST" -p "$CLOUDRON_POSTGRESQL_PORT" -U "$CLOUDRON_POSTGRESQL_USERNAME" -d "$CLOUDRON_POSTGRESQL_DATABASE" -c "SELECT 1;" > /dev/null 2>&1; then
|
|
||||||
echo "==> ERROR: Failed to connect to PostgreSQL"
|
|
||||||
echo "==> Connection details:"
|
|
||||||
echo "==> Host: $CLOUDRON_POSTGRESQL_HOST"
|
|
||||||
echo "==> Port: $CLOUDRON_POSTGRESQL_PORT"
|
|
||||||
echo "==> User: $CLOUDRON_POSTGRESQL_USERNAME"
|
|
||||||
echo "==> Database: $CLOUDRON_POSTGRESQL_DATABASE"
|
|
||||||
else
|
|
||||||
echo "==> PostgreSQL connection successful"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Download and set up web app
|
# Download and set up web app
|
||||||
echo "==> Setting up Ente web app..."
|
echo "==> Setting up Ente web app..."
|
||||||
WEB_DIR="/app/data/ente/web"
|
WEB_DIR="/app/data/ente/web"
|
||||||
|
|
||||||
if [ ! -d "${WEB_DIR}/photos" ] || [ ! -f "${WEB_DIR}/photos/index.html" ]; then
|
if [ ! -d "${WEB_DIR}/photos" ] || [ ! -f "${WEB_DIR}/photos/index.html" ]; then
|
||||||
# Create placeholder HTML
|
echo "==> Downloading pre-built web app..."
|
||||||
echo "==> Downloading Ente web app..."
|
|
||||||
|
|
||||||
# Try to download web app
|
# Try to download web app
|
||||||
if curl -L -o /tmp/web.zip "https://github.com/ente-io/ente/releases/latest/download/web.zip" 2>/app/data/logs/curl_web.log; then
|
if curl -L -o /tmp/web.zip "https://github.com/ente-io/ente/releases/latest/download/web.zip" 2>/app/data/logs/curl_web.log; then
|
||||||
@ -288,7 +278,7 @@ if [ ! -d "${WEB_DIR}/photos" ] || [ ! -f "${WEB_DIR}/photos/index.html" ]; then
|
|||||||
# Check if extraction was successful
|
# Check if extraction was successful
|
||||||
if [ -d "/tmp/web" ]; then
|
if [ -d "/tmp/web" ]; then
|
||||||
# Copy contents to the web directory
|
# Copy contents to the web directory
|
||||||
cp -r /tmp/web/* ${WEB_DIR}/
|
cp -r /tmp/web/* ${WEB_DIR}/ || echo "Failed to copy web files"
|
||||||
echo "==> Web app extracted and installed"
|
echo "==> Web app extracted and installed"
|
||||||
else
|
else
|
||||||
echo "==> Failed to extract web app"
|
echo "==> Failed to extract web app"
|
||||||
@ -305,7 +295,7 @@ if [ ! -d "${WEB_DIR}/photos" ] || [ ! -f "${WEB_DIR}/photos/index.html" ]; then
|
|||||||
mkdir -p /tmp/web
|
mkdir -p /tmp/web
|
||||||
unzip -o /tmp/web.zip -d /tmp/web
|
unzip -o /tmp/web.zip -d /tmp/web
|
||||||
# Copy contents to the web directory
|
# Copy contents to the web directory
|
||||||
cp -r /tmp/web/* ${WEB_DIR}/
|
cp -r /tmp/web/* ${WEB_DIR}/ || echo "Failed to copy web files"
|
||||||
echo "==> Web app extracted and installed"
|
echo "==> Web app extracted and installed"
|
||||||
else
|
else
|
||||||
echo "==> Downloaded file is not a valid zip file: $(file /tmp/web.zip)"
|
echo "==> Downloaded file is not a valid zip file: $(file /tmp/web.zip)"
|
||||||
@ -315,7 +305,31 @@ if [ ! -d "${WEB_DIR}/photos" ] || [ ! -f "${WEB_DIR}/photos/index.html" ]; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Create placeholder HTML if download failed
|
# If download failed, try to manually copy from repository
|
||||||
|
if [ ! -f "${WEB_DIR}/photos/index.html" ] && [ -d "$ENTE_DIR/web/apps/photos/out" ]; then
|
||||||
|
echo "==> Copying pre-built web apps from repository..."
|
||||||
|
mkdir -p "${WEB_DIR}/photos"
|
||||||
|
cp -r "$ENTE_DIR/web/apps/photos/out/"* "${WEB_DIR}/photos/" || echo "Failed to copy photos app"
|
||||||
|
|
||||||
|
if [ -d "$ENTE_DIR/web/apps/accounts/out" ]; then
|
||||||
|
mkdir -p "${WEB_DIR}/accounts"
|
||||||
|
cp -r "$ENTE_DIR/web/apps/accounts/out/"* "${WEB_DIR}/accounts/" || echo "Failed to copy accounts app"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -d "$ENTE_DIR/web/apps/auth/out" ]; then
|
||||||
|
mkdir -p "${WEB_DIR}/auth"
|
||||||
|
cp -r "$ENTE_DIR/web/apps/auth/out/"* "${WEB_DIR}/auth/" || echo "Failed to copy auth app"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -d "$ENTE_DIR/web/apps/cast/out" ]; then
|
||||||
|
mkdir -p "${WEB_DIR}/cast"
|
||||||
|
cp -r "$ENTE_DIR/web/apps/cast/out/"* "${WEB_DIR}/cast/" || echo "Failed to copy cast app"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "==> Copied web apps from repository"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Create placeholder HTML if download and build both failed
|
||||||
if [ ! -f "${WEB_DIR}/photos/index.html" ]; then
|
if [ ! -f "${WEB_DIR}/photos/index.html" ]; then
|
||||||
echo "==> Creating placeholder HTML files..."
|
echo "==> Creating placeholder HTML files..."
|
||||||
mkdir -p ${WEB_DIR}/photos
|
mkdir -p ${WEB_DIR}/photos
|
||||||
@ -337,6 +351,7 @@ if [ ! -d "${WEB_DIR}/photos" ] || [ ! -f "${WEB_DIR}/photos/index.html" ]; then
|
|||||||
<div class="container">
|
<div class="container">
|
||||||
<h1>Ente Photos</h1>
|
<h1>Ente Photos</h1>
|
||||||
<p>This is a placeholder for the Ente Photos application. The actual app is being set up.</p>
|
<p>This is a placeholder for the Ente Photos application. The actual app is being set up.</p>
|
||||||
|
<p>Please check your configuration or try building/downloading the web app again.</p>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@ -363,16 +378,20 @@ fi
|
|||||||
# Copy web files to /app/data/web
|
# Copy web files to /app/data/web
|
||||||
echo "==> Copying web files to /app/data/web..."
|
echo "==> Copying web files to /app/data/web..."
|
||||||
if [ -d "${WEB_DIR}/photos" ]; then
|
if [ -d "${WEB_DIR}/photos" ]; then
|
||||||
cp -r ${WEB_DIR}/photos/* /app/data/web/photos/ || echo "==> Warning: Failed to copy photos files"
|
mkdir -p /app/data/web/photos
|
||||||
|
cp -rf ${WEB_DIR}/photos/* /app/data/web/photos/ || echo "==> Warning: Failed to copy photos files"
|
||||||
fi
|
fi
|
||||||
if [ -d "${WEB_DIR}/accounts" ]; then
|
if [ -d "${WEB_DIR}/accounts" ]; then
|
||||||
cp -r ${WEB_DIR}/accounts/* /app/data/web/accounts/ || echo "==> Warning: Failed to copy accounts files"
|
mkdir -p /app/data/web/accounts
|
||||||
|
cp -rf ${WEB_DIR}/accounts/* /app/data/web/accounts/ || echo "==> Warning: Failed to copy accounts files"
|
||||||
fi
|
fi
|
||||||
if [ -d "${WEB_DIR}/auth" ]; then
|
if [ -d "${WEB_DIR}/auth" ]; then
|
||||||
cp -r ${WEB_DIR}/auth/* /app/data/web/auth/ || echo "==> Warning: Failed to copy auth files"
|
mkdir -p /app/data/web/auth
|
||||||
|
cp -rf ${WEB_DIR}/auth/* /app/data/web/auth/ || echo "==> Warning: Failed to copy auth files"
|
||||||
fi
|
fi
|
||||||
if [ -d "${WEB_DIR}/cast" ]; then
|
if [ -d "${WEB_DIR}/cast" ]; then
|
||||||
cp -r ${WEB_DIR}/cast/* /app/data/web/cast/ || echo "==> Warning: Failed to copy cast files"
|
mkdir -p /app/data/web/cast
|
||||||
|
cp -rf ${WEB_DIR}/cast/* /app/data/web/cast/ || echo "==> Warning: Failed to copy cast files"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Create runtime config for web app
|
# Create runtime config for web app
|
||||||
@ -382,8 +401,8 @@ for APP in photos accounts auth cast; do
|
|||||||
mkdir -p "${CONFIG_DIR}"
|
mkdir -p "${CONFIG_DIR}"
|
||||||
cat > "${CONFIG_DIR}/runtime-config.js" << EOF
|
cat > "${CONFIG_DIR}/runtime-config.js" << EOF
|
||||||
window.RUNTIME_CONFIG = {
|
window.RUNTIME_CONFIG = {
|
||||||
API_URL: "https://${CLOUDRON_APP_FQDN}/api",
|
API_URL: "/api",
|
||||||
PUBLIC_ALBUMS_URL: "https://${CLOUDRON_APP_FQDN}/public",
|
PUBLIC_ALBUMS_URL: "/public",
|
||||||
DEBUG: true
|
DEBUG: true
|
||||||
};
|
};
|
||||||
console.log("Loaded runtime config:", window.RUNTIME_CONFIG);
|
console.log("Loaded runtime config:", window.RUNTIME_CONFIG);
|
||||||
@ -394,7 +413,7 @@ done
|
|||||||
# Set up Caddy web server
|
# Set up Caddy web server
|
||||||
echo "==> Setting up Caddy web server..."
|
echo "==> Setting up Caddy web server..."
|
||||||
cat > /app/data/Caddyfile << EOF
|
cat > /app/data/Caddyfile << EOF
|
||||||
:3080 {
|
:80 {
|
||||||
log {
|
log {
|
||||||
output file /app/data/logs/caddy.log
|
output file /app/data/logs/caddy.log
|
||||||
}
|
}
|
||||||
@ -442,12 +461,15 @@ cat > /app/data/Caddyfile << EOF
|
|||||||
EOF
|
EOF
|
||||||
echo "==> Created Caddy configuration"
|
echo "==> Created Caddy configuration"
|
||||||
|
|
||||||
# Start museum server or placeholder
|
# Start museum server
|
||||||
cd ${SERVER_DIR}
|
cd /app/data/ente/server
|
||||||
if [ -f "${SERVER_DIR}/museum" ] && [ -x "${SERVER_DIR}/museum" ]; then
|
|
||||||
echo "==> Starting Museum server..."
|
echo "==> Starting Museum server..."
|
||||||
mkdir -p /app/data/logs
|
mkdir -p /app/data/logs
|
||||||
./museum serve --config museum.yaml > /app/data/logs/museum.log 2>&1 &
|
|
||||||
|
# Check if we have the museum binary or need to use Node.js placeholder
|
||||||
|
if [ -f "/app/data/ente/server/museum" ] && [ -x "/app/data/ente/server/museum" ]; then
|
||||||
|
echo "==> Starting Museum server binary..."
|
||||||
|
/app/data/ente/server/museum serve --config museum.yaml > /app/data/logs/museum.log 2>&1 &
|
||||||
|
|
||||||
# Wait for server to start
|
# Wait for server to start
|
||||||
MAX_ATTEMPTS=30
|
MAX_ATTEMPTS=30
|
||||||
@ -466,80 +488,19 @@ if [ -f "${SERVER_DIR}/museum" ] && [ -x "${SERVER_DIR}/museum" ]; then
|
|||||||
echo "==> ERROR: Museum server failed to start within $MAX_ATTEMPTS seconds"
|
echo "==> ERROR: Museum server failed to start within $MAX_ATTEMPTS seconds"
|
||||||
echo "==> Last few lines of museum.log:"
|
echo "==> Last few lines of museum.log:"
|
||||||
tail -n 20 /app/data/logs/museum.log || echo "==> No log file found"
|
tail -n 20 /app/data/logs/museum.log || echo "==> No log file found"
|
||||||
|
echo "==> Starting Node.js placeholder server instead..."
|
||||||
|
|
||||||
# Fall back to Node.js server if available
|
if [ -f "/app/data/ente/server/server.js" ]; then
|
||||||
if [ -f "${SERVER_DIR}/server.js" ]; then
|
node /app/data/ente/server/server.js > /app/data/logs/museum.log 2>&1 &
|
||||||
echo "==> Starting Node.js placeholder server..."
|
echo "==> Node.js placeholder server started"
|
||||||
node ${SERVER_DIR}/server.js >> /app/data/logs/museum.log 2>&1 &
|
|
||||||
|
|
||||||
# Wait for server to start
|
|
||||||
MAX_ATTEMPTS=10
|
|
||||||
ATTEMPT=0
|
|
||||||
while [ $ATTEMPT -lt $MAX_ATTEMPTS ]; do
|
|
||||||
if curl -s http://localhost:3080/health > /dev/null; then
|
|
||||||
echo "==> Node.js placeholder server started successfully"
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
ATTEMPT=$((ATTEMPT+1))
|
|
||||||
echo "==> Waiting for Node.js server to start (attempt $ATTEMPT/$MAX_ATTEMPTS)..."
|
|
||||||
sleep 1
|
|
||||||
done
|
|
||||||
|
|
||||||
if [ $ATTEMPT -eq $MAX_ATTEMPTS ]; then
|
|
||||||
echo "==> ERROR: Node.js server failed to start within $MAX_ATTEMPTS seconds"
|
|
||||||
echo "==> The application will have limited API functionality"
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
echo "==> No fallback server available. Creating one on the fly..."
|
echo "==> ERROR: No server executable found"
|
||||||
# Create a minimal Node.js server
|
exit 1
|
||||||
cat > ${SERVER_DIR}/server.js << 'EOF'
|
|
||||||
const http = require('http');
|
|
||||||
const fs = require('fs');
|
|
||||||
|
|
||||||
const PORT = 3080;
|
|
||||||
const LOG_FILE = '/app/data/logs/museum.log';
|
|
||||||
|
|
||||||
// Ensure log directory exists
|
|
||||||
if (!fs.existsSync('/app/data/logs')) {
|
|
||||||
fs.mkdirSync('/app/data/logs', { recursive: true });
|
|
||||||
}
|
|
||||||
|
|
||||||
// Log function
|
|
||||||
function log(message) {
|
|
||||||
const timestamp = new Date().toISOString();
|
|
||||||
const logMessage = `${timestamp} - ${message}\n`;
|
|
||||||
console.log(logMessage);
|
|
||||||
fs.appendFileSync(LOG_FILE, logMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create server
|
|
||||||
const server = http.createServer((req, res) => {
|
|
||||||
log(`Request received: ${req.method} ${req.url}`);
|
|
||||||
|
|
||||||
// Health check endpoint
|
|
||||||
if (req.url === '/health' || req.url === '/api/health') {
|
|
||||||
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
||||||
res.end(JSON.stringify({ status: 'OK', server: 'Museum Placeholder' }));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Default response for any other endpoint
|
|
||||||
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
||||||
res.end(JSON.stringify({ message: 'Placeholder Museum Server' }));
|
|
||||||
});
|
|
||||||
|
|
||||||
// Start server
|
|
||||||
server.listen(PORT, '0.0.0.0', () => {
|
|
||||||
log(`Minimal museum placeholder server running on port ${PORT}`);
|
|
||||||
});
|
|
||||||
EOF
|
|
||||||
node ${SERVER_DIR}/server.js >> /app/data/logs/museum.log 2>&1 &
|
|
||||||
echo "==> Started minimal Node.js placeholder server"
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
elif [ -f "${SERVER_DIR}/server.js" ]; then
|
elif [ -f "/app/data/ente/server/server.js" ]; then
|
||||||
echo "==> Starting Node.js placeholder server..."
|
echo "==> Starting Node.js placeholder server..."
|
||||||
node ${SERVER_DIR}/server.js > /app/data/logs/museum.log 2>&1 &
|
node /app/data/ente/server/server.js > /app/data/logs/museum.log 2>&1 &
|
||||||
echo "==> Node.js placeholder server started"
|
echo "==> Node.js placeholder server started"
|
||||||
else
|
else
|
||||||
echo "==> ERROR: No server executable found"
|
echo "==> ERROR: No server executable found"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user