Make scripts more robust to handle various repository structures
This commit is contained in:
		
							
								
								
									
										79
									
								
								Dockerfile
									
									
									
									
									
								
							
							
						
						
									
										79
									
								
								Dockerfile
									
									
									
									
									
								
							| @@ -15,20 +15,70 @@ RUN corepack enable | ||||
| # Will be overridden at runtime with the actual server endpoint | ||||
| ENV NEXT_PUBLIC_ENTE_ENDPOINT="https://localhost:8080" | ||||
|  | ||||
| # Build all web apps | ||||
| RUN cd web && \ | ||||
|     yarn cache clean && \ | ||||
|     yarn install --network-timeout 1000000000 && \ | ||||
|     yarn build:photos && \ | ||||
|     yarn build:accounts && \ | ||||
|     yarn build:auth && \ | ||||
|     yarn build:cast | ||||
| # Debugging the repository structure | ||||
| RUN find . -type d -maxdepth 3 | sort | ||||
|  | ||||
| # Check if web directory exists with apps subdirectory | ||||
| RUN mkdir -p /build/web/photos /build/web/accounts /build/web/auth /build/web/cast && \ | ||||
|     if [ -d "web" ] && [ -d "web/apps" ]; then \ | ||||
|         echo "Found web/apps directory, building web apps"; \ | ||||
|         cd web && \ | ||||
|         yarn cache clean && \ | ||||
|         yarn install --network-timeout 1000000000 && \ | ||||
|         yarn build:photos && \ | ||||
|         yarn build:accounts && \ | ||||
|         yarn build:auth && \ | ||||
|         yarn build:cast && \ | ||||
|         if [ -d "apps/photos/out" ]; then \ | ||||
|             cp -r apps/photos/out/* /build/web/photos/; \ | ||||
|         fi && \ | ||||
|         if [ -d "apps/accounts/out" ]; then \ | ||||
|             cp -r apps/accounts/out/* /build/web/accounts/; \ | ||||
|         fi && \ | ||||
|         if [ -d "apps/auth/out" ]; then \ | ||||
|             cp -r apps/auth/out/* /build/web/auth/; \ | ||||
|         fi && \ | ||||
|         if [ -d "apps/cast/out" ]; then \ | ||||
|             cp -r apps/cast/out/* /build/web/cast/; \ | ||||
|         fi; \ | ||||
|     elif [ -d "web" ]; then \ | ||||
|         echo "Found web directory, looking for alternative structure"; \ | ||||
|         find web -type d | grep -v node_modules | sort; \ | ||||
|         if [ -d "web/photos" ]; then \ | ||||
|             echo "Building photos app"; \ | ||||
|             cd web/photos && yarn install && yarn build && \ | ||||
|             if [ -d "out" ]; then cp -r out/* /build/web/photos/; fi; \ | ||||
|         fi; \ | ||||
|         if [ -d "web/accounts" ]; then \ | ||||
|             echo "Building accounts app"; \ | ||||
|             cd web/accounts && yarn install && yarn build && \ | ||||
|             if [ -d "out" ]; then cp -r out/* /build/web/accounts/; fi; \ | ||||
|         fi; \ | ||||
|         if [ -d "web/auth" ]; then \ | ||||
|             echo "Building auth app"; \ | ||||
|             cd web/auth && yarn install && yarn build && \ | ||||
|             if [ -d "out" ]; then cp -r out/* /build/web/auth/; fi; \ | ||||
|         fi; \ | ||||
|         if [ -d "web/cast" ]; then \ | ||||
|             echo "Building cast app"; \ | ||||
|             cd web/cast && yarn install && yarn build && \ | ||||
|             if [ -d "out" ]; then cp -r out/* /build/web/cast/; fi; \ | ||||
|         fi; \ | ||||
|     else \ | ||||
|         echo "Web directory not found, creating placeholder web pages"; \ | ||||
|         # Create placeholder HTML files for each app \ | ||||
|         mkdir -p /build/web/photos /build/web/accounts /build/web/auth /build/web/cast; \ | ||||
|         echo "<html><body><h1>Ente Photos</h1><p>Web app not available. Please check the build logs.</p></body></html>" > /build/web/photos/index.html; \ | ||||
|         echo "<html><body><h1>Ente Accounts</h1><p>Web app not available. Please check the build logs.</p></body></html>" > /build/web/accounts/index.html; \ | ||||
|         echo "<html><body><h1>Ente Auth</h1><p>Web app not available. Please check the build logs.</p></body></html>" > /build/web/auth/index.html; \ | ||||
|         echo "<html><body><h1>Ente Cast</h1><p>Web app not available. Please check the build logs.</p></body></html>" > /build/web/cast/index.html; \ | ||||
|     fi | ||||
|  | ||||
| FROM cloudron/base:5.0.0@sha256:04fd70dbd8ad6149c19de39e35718e024417c3e01dc9c6637eaf4a41ec4e596c | ||||
|  | ||||
| # Install necessary packages for both Go and Node.js | ||||
| RUN apt-get update && \ | ||||
|     apt-get install -y curl git nodejs npm golang libsodium23 libsodium-dev pkg-config && \ | ||||
|     apt-get install -y curl git nodejs npm golang libsodium23 libsodium-dev pkg-config nginx && \ | ||||
|     npm install -g yarn serve && \ | ||||
|     apt-get clean && apt-get autoremove && \ | ||||
|     rm -rf /var/cache/apt /var/lib/apt/lists | ||||
| @@ -42,10 +92,10 @@ WORKDIR /app/code | ||||
| RUN git clone --depth=1 https://github.com/ente-io/ente.git . | ||||
|  | ||||
| # Copy the web app built files from the first stage | ||||
| COPY --from=web-builder /ente/web/apps/photos/out /app/web/photos | ||||
| COPY --from=web-builder /ente/web/apps/accounts/out /app/web/accounts | ||||
| COPY --from=web-builder /ente/web/apps/auth/out /app/web/auth | ||||
| COPY --from=web-builder /ente/web/apps/cast/out /app/web/cast | ||||
| COPY --from=web-builder /build/web/photos /app/web/photos | ||||
| COPY --from=web-builder /build/web/accounts /app/web/accounts | ||||
| COPY --from=web-builder /build/web/auth /app/web/auth | ||||
| COPY --from=web-builder /build/web/cast /app/web/cast | ||||
|  | ||||
| # Copy configuration and startup scripts | ||||
| ADD start.sh /app/pkg/ | ||||
| @@ -54,6 +104,9 @@ ADD config.template.yaml /app/pkg/ | ||||
| # Set proper permissions | ||||
| RUN chmod +x /app/pkg/start.sh | ||||
|  | ||||
| # Create NGINX directories | ||||
| RUN mkdir -p /etc/nginx/sites-available /etc/nginx/sites-enabled | ||||
|  | ||||
| # Expose the web port (Cloudron expects port 8080) | ||||
| EXPOSE 8080 | ||||
|  | ||||
|   | ||||
							
								
								
									
										176
									
								
								start.sh
									
									
									
									
									
								
							
							
						
						
									
										176
									
								
								start.sh
									
									
									
									
									
								
							| @@ -5,13 +5,27 @@ set -eu | ||||
| # Create necessary directories | ||||
| mkdir -p /app/data/config /app/data/storage | ||||
|  | ||||
| # Print debug information about repository structure | ||||
| echo "==> DEBUG: Repository structure at /app/code" | ||||
| find /app/code -type d -not -path "*/node_modules/*" -not -path "*/\.*" | sort | ||||
| echo "==> DEBUG: Full repository structure at /app/code" | ||||
| find /app/code -type d -maxdepth 3 -not -path "*/node_modules/*" -not -path "*/\.*" | sort | ||||
|  | ||||
| echo "==> DEBUG: Looking for Go files" | ||||
| find /app/code -name "*.go" | grep -v test | sort | head -10 | ||||
|  | ||||
| echo "==> DEBUG: Looking for server-related directories" | ||||
| find /app/code -type d -path "*/server*" -o -path "*/museum*" | sort | ||||
|  | ||||
| echo "==> DEBUG: All package.json files in repository" | ||||
| find /app/code -name "package.json" -not -path "*/node_modules/*" | sort | ||||
| echo "==> DEBUG: Web app directories" | ||||
| ls -la /app/web | ||||
|  | ||||
| echo "==> DEBUG: Looking for web app directories" | ||||
| find /app/code -type d -path "*/web*" | sort | ||||
|  | ||||
| echo "==> DEBUG: Web app directories in /app/web (if they exist)" | ||||
| if [ -d "/app/web" ]; then | ||||
|     ls -la /app/web | ||||
| else | ||||
|     echo "Web app directory not yet copied to /app/web" | ||||
| fi | ||||
|  | ||||
| # Create config template file on first run | ||||
| if [[ ! -f /app/data/config/config.yaml ]]; then | ||||
| @@ -91,10 +105,19 @@ sed -i \ | ||||
|     -e "s|%%S3_PREFIX%%|${S3_PREFIX:-ente/}|g" \ | ||||
|     /app/data/config/config.yaml | ||||
|  | ||||
| # Install or verify required packages | ||||
| echo "==> Checking for required packages" | ||||
| if ! command -v nginx &> /dev/null; then | ||||
|     echo "==> Installing NGINX" | ||||
|     apt-get update && apt-get install -y nginx | ||||
| fi | ||||
|  | ||||
| # Set up NGINX to serve the web apps and proxy to the Museum server | ||||
| echo "==> Setting up NGINX for web apps and API" | ||||
|  | ||||
| # Create NGINX configuration | ||||
| mkdir -p /etc/nginx/sites-available /etc/nginx/sites-enabled | ||||
|  | ||||
| cat > /etc/nginx/sites-available/ente <<EOT | ||||
| server { | ||||
|     listen 8080; | ||||
| @@ -140,51 +163,71 @@ ln -sf /etc/nginx/sites-available/ente /etc/nginx/sites-enabled/ente | ||||
|  | ||||
| # Start NGINX | ||||
| echo "==> Starting NGINX" | ||||
| service nginx restart | ||||
| if command -v service &> /dev/null; then | ||||
|     service nginx restart || echo "Failed to restart nginx with service command" | ||||
| else | ||||
|     /usr/sbin/nginx -s reload || /usr/sbin/nginx || echo "Failed to start nginx" | ||||
| fi | ||||
|  | ||||
| # Looking for Museum (Go server component) | ||||
| echo "==> Looking for Museum (Go server component)" | ||||
|  | ||||
| # Find the server directory | ||||
| # Find the server directory - expanded search | ||||
| SERVER_DIR="" | ||||
|  | ||||
| # Look in all the most likely places | ||||
| if [ -d "/app/code/server" ]; then | ||||
|     echo "==> Found server directory at /app/code/server" | ||||
|     SERVER_DIR="/app/code/server" | ||||
| else | ||||
|     echo "==> ERROR: Could not find server directory at /app/code/server" | ||||
|     echo "==> Looking for Museum executable or source in alternate locations" | ||||
| elif [ -d "/app/code/museum" ]; then | ||||
|     echo "==> Found server directory at /app/code/museum" | ||||
|     SERVER_DIR="/app/code/museum" | ||||
| fi | ||||
|  | ||||
| # If not found yet, try to find it based on Go files | ||||
| if [ -z "$SERVER_DIR" ]; then | ||||
|     echo "==> Searching for Go server files in the repository" | ||||
|      | ||||
|     # Search for Museum executable or Go source files | ||||
|     GO_FILES=$(find /app/code -name "*.go" -not -path "*/\.*" | sort) | ||||
|     if [ -n "$GO_FILES" ]; then | ||||
|         echo "==> Found Go files in repository:" | ||||
|         echo "$GO_FILES" | ||||
|          | ||||
|         # Check for museum in Go files path | ||||
|         if find /app/code -path "*/museum/*" -name "*.go" | grep -q .; then | ||||
|             MUSEUM_DIR=$(find /app/code -path "*/museum/*" -name "*.go" | head -1 | xargs dirname) | ||||
|             echo "==> Found Museum directory at $MUSEUM_DIR" | ||||
|         else | ||||
|             echo "==> No clear Museum directory found" | ||||
|             echo "==> Using first Go file directory as fallback" | ||||
|             FIRST_GO_FILE=$(echo "$GO_FILES" | head -1) | ||||
|             MUSEUM_DIR=$(dirname "$FIRST_GO_FILE") | ||||
|         fi | ||||
|          | ||||
|         # Check for cmd/museum pattern which is mentioned in docs | ||||
|         if [ -d "/app/code/server/cmd/museum" ]; then | ||||
|             MUSEUM_DIR="/app/code/server/cmd/museum" | ||||
|             echo "==> Found Museum main directory at $MUSEUM_DIR" | ||||
|         fi | ||||
|          | ||||
|     # Look for cmd/museum path which is mentioned in docs | ||||
|     if find /app/code -path "*/cmd/museum" -type d | grep -q .; then | ||||
|         MUSEUM_DIR=$(find /app/code -path "*/cmd/museum" -type d | head -1) | ||||
|         echo "==> Found Museum command directory at $MUSEUM_DIR" | ||||
|         SERVER_DIR=$(dirname $(dirname "$MUSEUM_DIR")) | ||||
|     else | ||||
|         echo "==> FATAL ERROR: Could not find Go files in repository" | ||||
|         echo "==> Repository structure:" | ||||
|         find /app/code -type d -maxdepth 3 | sort | ||||
|         exit 1 | ||||
|         echo "==> Setting server directory to $SERVER_DIR" | ||||
|     # Look for main.go files in areas that might be server-related | ||||
|     elif find /app/code -name "main.go" -path "*/server*" | grep -q .; then | ||||
|         MAIN_GO=$(find /app/code -name "main.go" -path "*/server*" | head -1) | ||||
|         SERVER_DIR=$(dirname "$MAIN_GO") | ||||
|         echo "==> Found main.go in $SERVER_DIR" | ||||
|     # Look for any Go files with "museum" in the path | ||||
|     elif find /app/code -name "*.go" -path "*/museum*" | grep -q .; then | ||||
|         MUSEUM_GO=$(find /app/code -name "*.go" -path "*/museum*" | head -1) | ||||
|         SERVER_DIR=$(dirname "$MUSEUM_GO") | ||||
|         echo "==> Found Go file in museum directory: $SERVER_DIR" | ||||
|     # Last resort - look for any main.go file | ||||
|     elif find /app/code -name "main.go" | grep -v "test" | grep -q .; then | ||||
|         MAIN_GO=$(find /app/code -name "main.go" | grep -v "test" | head -1) | ||||
|         SERVER_DIR=$(dirname "$MAIN_GO") | ||||
|         echo "==> Found main.go as fallback: $SERVER_DIR" | ||||
|     fi | ||||
| fi | ||||
|  | ||||
| # If still not found, check the 'cli' directory as it might be a client for the Museum | ||||
| if [ -z "$SERVER_DIR" ] && [ -d "/app/code/cli" ]; then | ||||
|     echo "==> Checking CLI directory for Museum server code" | ||||
|     if find /app/code/cli -name "*.go" | grep -q .; then | ||||
|         SERVER_DIR="/app/code/cli" | ||||
|         echo "==> Using CLI directory as fallback for server: $SERVER_DIR" | ||||
|     fi | ||||
| fi | ||||
|  | ||||
| # If all else fails, just use the root | ||||
| if [ -z "$SERVER_DIR" ]; then | ||||
|     echo "==> WARNING: Could not find server directory with Go files" | ||||
|     echo "==> Using repository root as fallback" | ||||
|     SERVER_DIR="/app/code" | ||||
| fi | ||||
|  | ||||
| echo "==> Selected server directory: $SERVER_DIR" | ||||
| echo "==> Contents of $SERVER_DIR:" | ||||
| ls -la "$SERVER_DIR" | ||||
| @@ -237,27 +280,68 @@ export REMOTE_STORAGE_PREFIX="${S3_PREFIX:-ente/}" | ||||
| chown -R cloudron:cloudron /app/data | ||||
|  | ||||
| # Start Museum server on port 8000 (different from the NGINX port 8080) | ||||
| if [ -x "$SERVER_DIR/museum" ]; then | ||||
|     echo "==> Found Museum binary, running it in the background" | ||||
|     /usr/local/bin/gosu cloudron:cloudron "$SERVER_DIR/museum" --port 8000 & | ||||
| echo "==> Starting Museum server" | ||||
|  | ||||
| # First check for pre-built Museum binary | ||||
| if find "$SERVER_DIR" -name "museum" -type f -executable | grep -q .; then | ||||
|     MUSEUM_BIN=$(find "$SERVER_DIR" -name "museum" -type f -executable | head -1) | ||||
|     echo "==> Found Museum binary at $MUSEUM_BIN" | ||||
|     /usr/local/bin/gosu cloudron:cloudron "$MUSEUM_BIN" --port 8000 & | ||||
|     SERVER_PID=$! | ||||
|     echo "==> Museum server started with PID $SERVER_PID" | ||||
| # Next check for cmd/museum directory pattern | ||||
| elif [ -d "$SERVER_DIR/cmd/museum" ]; then | ||||
|     echo "==> Found Museum source in cmd/museum, running with go run in the background" | ||||
|     echo "==> Found Museum source in cmd/museum, running with go run" | ||||
|     cd "$SERVER_DIR" | ||||
|     /usr/local/bin/gosu cloudron:cloudron go run cmd/museum/main.go --port 8000 & | ||||
|     SERVER_PID=$! | ||||
|     echo "==> Museum server started with PID $SERVER_PID" | ||||
| # Next try to find any main.go for the Museum | ||||
| else | ||||
|     # Fallback approach - find main.go files | ||||
|     MAIN_FILES=$(find "$SERVER_DIR" -name "main.go" | grep -v "test") | ||||
|     MAIN_FILES=$(find "$SERVER_DIR" -name "main.go" | grep -v "test" || echo "") | ||||
|     if [ -n "$MAIN_FILES" ]; then | ||||
|         MAIN_FILE=$(echo "$MAIN_FILES" | head -1) | ||||
|         MAIN_DIR=$(dirname "$MAIN_FILE") | ||||
|         echo "==> Using main.go file at $MAIN_FILE, running in the background" | ||||
|         echo "==> Using main.go file at $MAIN_FILE" | ||||
|         cd "$MAIN_DIR" | ||||
|         /usr/local/bin/gosu cloudron:cloudron go run main.go --port 8000 & | ||||
|         SERVER_PID=$! | ||||
|         echo "==> Museum server started with PID $SERVER_PID" | ||||
|     else | ||||
|         echo "==> FATAL ERROR: Could not find Museum binary or main.go source file" | ||||
|         echo "==> ERROR: Could not find Museum binary or main.go source file" | ||||
|         echo "==> Available Go files:" | ||||
|         find "$SERVER_DIR" -name "*.go" | sort | ||||
|         exit 1 | ||||
|          | ||||
|         # Last resort - create a temporary Go HTTP server that returns a meaningful error | ||||
|         echo "==> Creating a temporary HTTP server to show the error to users" | ||||
|         mkdir -p /tmp/mock-server | ||||
|         cat > /tmp/mock-server/main.go <<EOT | ||||
| package main | ||||
|  | ||||
| import ( | ||||
|     "fmt" | ||||
|     "log" | ||||
|     "net/http" | ||||
| ) | ||||
|  | ||||
| func main() { | ||||
|     http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | ||||
|         w.Header().Set("Content-Type", "text/html") | ||||
|         fmt.Fprintf(w, "<html><body><h1>Ente Museum Server Error</h1>") | ||||
|         fmt.Fprintf(w, "<p>The Ente Museum server could not be started because no suitable Go source files were found.</p>") | ||||
|         fmt.Fprintf(w, "<p>Please check the logs for more information.</p>") | ||||
|         fmt.Fprintf(w, "</body></html>") | ||||
|     }) | ||||
|      | ||||
|     log.Println("Starting mock server on port 8000") | ||||
|     log.Fatal(http.ListenAndServe(":8000", nil)) | ||||
| } | ||||
| EOT | ||||
|         cd /tmp/mock-server | ||||
|         go run main.go & | ||||
|         SERVER_PID=$! | ||||
|         echo "==> Mock server started with PID $SERVER_PID to show error message" | ||||
|     fi | ||||
| fi | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user