diff --git a/Dockerfile b/Dockerfile index f6fb53d..8bc4906 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,20 +1,52 @@ +FROM node:20-bookworm-slim as web-builder + +WORKDIR /ente + +# Clone the repository for web app building +RUN apt-get update && apt-get install -y git && \ + git clone --depth=1 https://github.com/ente-io/ente.git . && \ + apt-get clean && apt-get autoremove && \ + rm -rf /var/cache/apt /var/lib/apt/lists + +# Will help default to yarn version 1.22.22 +RUN corepack enable + +# Set environment variables for web app build +# 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 + 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 && \ - npm install -g yarn && \ + npm install -g yarn serve && \ apt-get clean && apt-get autoremove && \ rm -rf /var/cache/apt /var/lib/apt/lists # Set up directory structure -RUN mkdir -p /app/code /app/data/config +RUN mkdir -p /app/code /app/data/config /app/web WORKDIR /app/code -# Clone the ente repository during build (not from local source) +# Clone the ente repository during build (for the Museum server) 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 configuration and startup scripts ADD start.sh /app/pkg/ ADD config.template.yaml /app/pkg/ @@ -22,7 +54,7 @@ ADD config.template.yaml /app/pkg/ # Set proper permissions RUN chmod +x /app/pkg/start.sh -# Expose the web port +# Expose the web port (Cloudron expects port 8080) EXPOSE 8080 # Start the application diff --git a/start.sh b/start.sh index c3cf6f4..faed159 100644 --- a/start.sh +++ b/start.sh @@ -10,6 +10,8 @@ echo "==> DEBUG: Repository structure at /app/code" find /app/code -type d -not -path "*/node_modules/*" -not -path "*/\.*" | 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 # Create config template file on first run if [[ ! -f /app/data/config/config.yaml ]]; then @@ -89,6 +91,57 @@ sed -i \ -e "s|%%S3_PREFIX%%|${S3_PREFIX:-ente/}|g" \ /app/data/config/config.yaml +# 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 +cat > /etc/nginx/sites-available/ente < Starting NGINX" +service nginx restart + # Looking for Museum (Go server component) echo "==> Looking for Museum (Go server component)" @@ -183,27 +236,31 @@ export REMOTE_STORAGE_PREFIX="${S3_PREFIX:-ente/}" # Change ownership to cloudron user chown -R cloudron:cloudron /app/data -# Look for Museum binary first +# Start Museum server on port 8000 (different from the NGINX port 8080) if [ -x "$SERVER_DIR/museum" ]; then - echo "==> Found Museum binary, running it directly" - exec /usr/local/bin/gosu cloudron:cloudron "$SERVER_DIR/museum" + echo "==> Found Museum binary, running it in the background" + /usr/local/bin/gosu cloudron:cloudron "$SERVER_DIR/museum" --port 8000 & elif [ -d "$SERVER_DIR/cmd/museum" ]; then - echo "==> Found Museum source in cmd/museum, running with go run" + echo "==> Found Museum source in cmd/museum, running with go run in the background" cd "$SERVER_DIR" - exec /usr/local/bin/gosu cloudron:cloudron go run cmd/museum/main.go + /usr/local/bin/gosu cloudron:cloudron go run cmd/museum/main.go --port 8000 & else # Fallback approach - find main.go files MAIN_FILES=$(find "$SERVER_DIR" -name "main.go" | grep -v "test") 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" + echo "==> Using main.go file at $MAIN_FILE, running in the background" cd "$MAIN_DIR" - exec /usr/local/bin/gosu cloudron:cloudron go run main.go + /usr/local/bin/gosu cloudron:cloudron go run main.go --port 8000 & else echo "==> FATAL ERROR: Could not find Museum binary or main.go source file" echo "==> Available Go files:" find "$SERVER_DIR" -name "*.go" | sort exit 1 fi -fi \ No newline at end of file +fi + +# Serve the static web apps in the foreground +echo "==> Running NGINX in the foreground" +exec nginx -g "daemon off;" \ No newline at end of file