feat: Move Notion import to runtime (container startup)
Browse files- Remove Notion import from build time (secrets not available)
- Create entrypoint.sh that imports at container startup
- Keep Node.js in final image (install nginx in build stage)
- Secrets are now available at runtime
- First startup will take 5-10 min for import+rebuild
- Subsequent starts use cached content unless triggered
- Dockerfile +14 -30
- entrypoint.sh +42 -0
- nginx.conf +1 -1
Dockerfile
CHANGED
|
@@ -32,23 +32,8 @@ RUN if [ "$ENABLE_LATEX_CONVERSION" = "true" ]; then \
|
|
| 32 |
echo "βοΈ LaTeX importer disabled - skipping..."; \
|
| 33 |
fi
|
| 34 |
|
| 35 |
-
#
|
| 36 |
-
|
| 37 |
-
ARG NOTION_TOKEN
|
| 38 |
-
ARG NOTION_PAGE_ID
|
| 39 |
-
# Convert ARG to ENV so they're available to Node.js
|
| 40 |
-
ENV NOTION_TOKEN=$NOTION_TOKEN
|
| 41 |
-
ENV NOTION_PAGE_ID=$NOTION_PAGE_ID
|
| 42 |
-
# Debug: show if variables are set
|
| 43 |
-
RUN echo "π Debug: ENABLE_NOTION_IMPORT=$ENABLE_NOTION_IMPORT"
|
| 44 |
-
RUN echo "π Debug: NOTION_TOKEN=${NOTION_TOKEN:+SET (${#NOTION_TOKEN} chars)}${NOTION_TOKEN:-NOT SET}"
|
| 45 |
-
RUN echo "π Debug: NOTION_PAGE_ID=${NOTION_PAGE_ID:+SET}${NOTION_PAGE_ID:-NOT SET}"
|
| 46 |
-
RUN if [ "$ENABLE_NOTION_IMPORT" = "true" ]; then \
|
| 47 |
-
echo "π Notion importer enabled - running notion:import..."; \
|
| 48 |
-
npm run notion:import; \
|
| 49 |
-
else \
|
| 50 |
-
echo "βοΈ Notion importer disabled - skipping..."; \
|
| 51 |
-
fi
|
| 52 |
|
| 53 |
# Ensure `public/data` is a real directory with real files (not a symlink)
|
| 54 |
# This handles the case where `public/data` is a symlink in the repo, which
|
|
@@ -66,24 +51,23 @@ RUN npm run build
|
|
| 66 |
# Generate the PDF (light theme, full wait)
|
| 67 |
RUN npm run export:pdf -- --theme=light --wait=full
|
| 68 |
|
| 69 |
-
#
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
# Copy the built application from the build stage
|
| 73 |
-
COPY --from=build /app/dist /usr/share/nginx/html
|
| 74 |
|
| 75 |
-
# Copy
|
| 76 |
COPY nginx.conf /etc/nginx/nginx.conf
|
| 77 |
|
| 78 |
-
#
|
| 79 |
-
|
| 80 |
-
|
| 81 |
|
| 82 |
-
#
|
| 83 |
-
|
|
|
|
|
|
|
| 84 |
|
| 85 |
# Expose port 8080
|
| 86 |
EXPOSE 8080
|
| 87 |
|
| 88 |
-
#
|
| 89 |
-
|
|
|
|
| 32 |
echo "βοΈ LaTeX importer disabled - skipping..."; \
|
| 33 |
fi
|
| 34 |
|
| 35 |
+
# Note: Notion import is done at RUNTIME (not build time) to access secrets
|
| 36 |
+
# See entrypoint.sh for the import logic
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
# Ensure `public/data` is a real directory with real files (not a symlink)
|
| 39 |
# This handles the case where `public/data` is a symlink in the repo, which
|
|
|
|
| 51 |
# Generate the PDF (light theme, full wait)
|
| 52 |
RUN npm run export:pdf -- --theme=light --wait=full
|
| 53 |
|
| 54 |
+
# Install nginx in the build stage (we'll use this image as final to keep Node.js)
|
| 55 |
+
RUN apt-get update && apt-get install -y nginx && apt-get clean && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
+
# Copy nginx configuration
|
| 58 |
COPY nginx.conf /etc/nginx/nginx.conf
|
| 59 |
|
| 60 |
+
# Copy entrypoint script
|
| 61 |
+
COPY entrypoint.sh /entrypoint.sh
|
| 62 |
+
RUN chmod +x /entrypoint.sh
|
| 63 |
|
| 64 |
+
# Create necessary directories and set permissions for nginx
|
| 65 |
+
RUN mkdir -p /var/cache/nginx /var/run /var/log/nginx && \
|
| 66 |
+
chmod -R 777 /var/cache/nginx /var/run /var/log/nginx /etc/nginx/nginx.conf && \
|
| 67 |
+
chmod -R 755 /app/dist
|
| 68 |
|
| 69 |
# Expose port 8080
|
| 70 |
EXPOSE 8080
|
| 71 |
|
| 72 |
+
# Use entrypoint script that handles Notion import if enabled
|
| 73 |
+
ENTRYPOINT ["/entrypoint.sh"]
|
entrypoint.sh
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -e
|
| 3 |
+
|
| 4 |
+
echo "π Starting Hugging Face Space..."
|
| 5 |
+
|
| 6 |
+
# Check if Notion import is enabled and token is available
|
| 7 |
+
if [ "${ENABLE_NOTION_IMPORT:-false}" = "true" ] && [ -n "$NOTION_TOKEN" ] && [ -n "$NOTION_PAGE_ID" ]; then
|
| 8 |
+
echo "π Notion import enabled - fetching content from Notion..."
|
| 9 |
+
echo " Page ID: $NOTION_PAGE_ID"
|
| 10 |
+
|
| 11 |
+
cd /app
|
| 12 |
+
|
| 13 |
+
# Run notion import
|
| 14 |
+
if npm run notion:import 2>&1; then
|
| 15 |
+
echo "β
Notion import completed successfully!"
|
| 16 |
+
|
| 17 |
+
# Rebuild the site with new content
|
| 18 |
+
echo "π¨ Rebuilding site with Notion content..."
|
| 19 |
+
npm run build 2>&1
|
| 20 |
+
|
| 21 |
+
# Generate PDF
|
| 22 |
+
echo "π Generating PDF..."
|
| 23 |
+
npm run export:pdf -- --theme=light --wait=full 2>&1 || echo "β οΈ PDF generation failed (non-critical)"
|
| 24 |
+
|
| 25 |
+
echo "β
Site rebuilt and ready!"
|
| 26 |
+
else
|
| 27 |
+
echo "β οΈ Notion import failed - using pre-built content from build time"
|
| 28 |
+
fi
|
| 29 |
+
else
|
| 30 |
+
if [ "${ENABLE_NOTION_IMPORT:-false}" = "true" ]; then
|
| 31 |
+
echo "β οΈ Notion import enabled but NOTION_TOKEN or NOTION_PAGE_ID not found"
|
| 32 |
+
echo " NOTION_TOKEN: ${NOTION_TOKEN:+SET}${NOTION_TOKEN:-NOT SET}"
|
| 33 |
+
echo " NOTION_PAGE_ID: ${NOTION_PAGE_ID:+SET}${NOTION_PAGE_ID:-NOT SET}"
|
| 34 |
+
echo " β Using pre-built content from build time"
|
| 35 |
+
else
|
| 36 |
+
echo "βοΈ Notion import disabled - using pre-built content from build time"
|
| 37 |
+
fi
|
| 38 |
+
fi
|
| 39 |
+
|
| 40 |
+
# Start nginx
|
| 41 |
+
echo "π Starting nginx on port 8080..."
|
| 42 |
+
exec nginx -g 'daemon off;'
|
nginx.conf
CHANGED
|
@@ -36,7 +36,7 @@ http {
|
|
| 36 |
listen 8080;
|
| 37 |
server_name localhost;
|
| 38 |
|
| 39 |
-
root /
|
| 40 |
index index.html;
|
| 41 |
|
| 42 |
# Health check endpoint
|
|
|
|
| 36 |
listen 8080;
|
| 37 |
server_name localhost;
|
| 38 |
|
| 39 |
+
root /app/dist;
|
| 40 |
index index.html;
|
| 41 |
|
| 42 |
# Health check endpoint
|