Update to include both Museum server and web apps in single package

This commit is contained in:
Andreas Düren 2025-03-14 21:45:09 +01:00
parent cf41205607
commit 08fbcacb5c
2 changed files with 101 additions and 12 deletions

View File

@ -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

View File

@ -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 <<EOT
server {
listen 8080;
# Photos app - root path
location / {
root /app/web/photos;
try_files \$uri \$uri/ /index.html;
}
# Accounts app
location /accounts/ {
alias /app/web/accounts/;
try_files \$uri \$uri/ /accounts/index.html;
}
# Auth app
location /auth/ {
alias /app/web/auth/;
try_files \$uri \$uri/ /auth/index.html;
}
# Cast app
location /cast/ {
alias /app/web/cast/;
try_files \$uri \$uri/ /cast/index.html;
}
# API endpoints - proxy to Museum server
location /api/ {
proxy_pass http://localhost:8000;
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host \$host;
proxy_cache_bypass \$http_upgrade;
}
}
EOT
# Enable the site
ln -sf /etc/nginx/sites-available/ente /etc/nginx/sites-enabled/ente
# Start NGINX
echo "==> Starting NGINX"
service nginx restart
# Looking for Museum (Go server component)
echo "==> Looking for Museum (Go server component)"
@ -183,23 +236,23 @@ 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:"
@ -207,3 +260,7 @@ else
exit 1
fi
fi
# Serve the static web apps in the foreground
echo "==> Running NGINX in the foreground"
exec nginx -g "daemon off;"