modified build process to clone the quartz repo to /quartz; this is copied into the build container, any files Ive customized are overlayed and then the site is built
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
# .gitignore
|
# .gitignore
|
||||||
|
quartz/
|
||||||
|
|
||||||
# Node
|
# Node
|
||||||
node_modules/
|
node_modules/
|
||||||
@@ -13,6 +14,7 @@ public/
|
|||||||
content/ # If the script creates it and doesn't always clean it up
|
content/ # If the script creates it and doesn't always clean it up
|
||||||
.last_build_content_timestamp
|
.last_build_content_timestamp
|
||||||
cron_quartz_update.log
|
cron_quartz_update.log
|
||||||
|
update_quartz_docker.log
|
||||||
update_quartz_docker.log # Or whatever your script log file is named
|
update_quartz_docker.log # Or whatever your script log file is named
|
||||||
compose_down_output.tmp # If you kept temporary files for compose output
|
compose_down_output.tmp # If you kept temporary files for compose output
|
||||||
compose_up_output.tmp # If you kept temporary files for compose output
|
compose_up_output.tmp # If you kept temporary files for compose output
|
||||||
|
|||||||
+48
-23
@@ -1,43 +1,68 @@
|
|||||||
|
# Dockerfile
|
||||||
|
|
||||||
# Stage 1: Build the Quartz site
|
# Stage 1: Build the Quartz site
|
||||||
FROM node:lts-slim AS builder
|
FROM node:lts-slim AS builder
|
||||||
|
|
||||||
WORKDIR /app
|
# Create a non-root user to own files and run npm commands
|
||||||
|
USER node
|
||||||
|
WORKDIR /home/node/app
|
||||||
|
|
||||||
# Copy package.json and package-lock.json (or yarn.lock)
|
# Copy the locally cloned Quartz source code from the build context
|
||||||
COPY package*.json ./
|
# This 'quartz_framework_source' dir is expected to be in the build context root,
|
||||||
|
# prepared by the update_quartz_docker.sh script.
|
||||||
|
COPY --chown=node:node quartz/ .
|
||||||
|
# Now /home/node/app contains the full cloned Quartz repo structure,
|
||||||
|
# including its package.json, its quartz/ directory with bootstrap-cli.mjs, etc.
|
||||||
|
|
||||||
# Install dependencies
|
# Install dependencies based on the cloned Quartz source's package.json
|
||||||
RUN npm i
|
RUN npm ci
|
||||||
|
# This will also make ./node_modules/.bin/quartz available, pointing to ./quartz/bootstrap-cli.mjs
|
||||||
|
|
||||||
# Copy the rest of the Quartz project files
|
# Now, copy your specific custom configuration files and the prepared content
|
||||||
COPY . .
|
# from the root of your deployment repo (the build context's root)
|
||||||
|
# into the current WORKDIR (/home/node/app), overwriting any placeholders
|
||||||
|
# from the cloned Quartz source if they share the same names/paths.
|
||||||
|
COPY --chown=node:node quartz.config.ts ./quartz.config.ts
|
||||||
|
COPY --chown=node:node quartz.layout.ts ./quartz.layout.ts
|
||||||
|
# If you have other custom files/dirs at the root of your deployment repo that Quartz needs:
|
||||||
|
# e.g., custom assets not part of Obsidian content, or custom components to overlay
|
||||||
|
# COPY --chown=node:node assets/ ./assets/
|
||||||
|
# COPY --chown=node:node components/ ./components/
|
||||||
|
|
||||||
# Build the Quartz site (adjust if your build command is different)
|
# Copy the Obsidian content prepared by the host script into ./content
|
||||||
# This usually outputs to a 'public' directory
|
COPY --chown=node:node content/ ./content/
|
||||||
|
|
||||||
|
# Now run the build command.
|
||||||
|
# `npx quartz build` should work because:
|
||||||
|
# 1. `npm ci` (based on the framework's package.json) made node_modules/.bin/quartz available,
|
||||||
|
# pointing to the local ./quartz/bootstrap-cli.mjs.
|
||||||
|
# 2. It will use your custom quartz.config.ts, quartz.layout.ts, and ./content.
|
||||||
RUN npx quartz build
|
RUN npx quartz build
|
||||||
|
# Output is expected in /home/node/app/public
|
||||||
|
|
||||||
# ---- START DEBUG ----
|
# ---- START DEBUG (Optional) ----
|
||||||
RUN echo "Listing contents of /app/public after build:" && ls -lA /app/public
|
# USER root # If you need root to ls everything for debug
|
||||||
RUN echo "Checking for /app/public/index.html:" && \
|
# RUN echo "Listing contents of /home/node/app after all copies:" && ls -lA /home/node/app
|
||||||
if [ -f /app/public/index.html ]; then \
|
# RUN echo "Listing contents of /home/node/app/content:" && ls -lA /home/node/app/content
|
||||||
echo "index.html found. First few lines:"; \
|
# RUN echo "Listing contents of /home/node/app/public after build:" && ls -lA /home/node/app/public
|
||||||
head -n 10 /app/public/index.html; \
|
# RUN echo "Checking for /home/node/app/public/index.html:" && \
|
||||||
else \
|
# if [ -f /home/node/app/public/index.html ]; then \
|
||||||
echo "index.html NOT FOUND in /app/public!"; \
|
# echo "index.html found. First few lines:"; \
|
||||||
fi
|
# head -n 10 /home/node/app/public/index.html; \
|
||||||
|
# else \
|
||||||
|
# echo "index.html NOT FOUND in /home/node/app/public!"; \
|
||||||
|
# fi
|
||||||
|
# USER node # Switch back if you changed it
|
||||||
# ---- END DEBUG ----
|
# ---- END DEBUG ----
|
||||||
|
|
||||||
# Stage 2: Serve the static files with NGINX
|
# Stage 2: Serve the static files with NGINX
|
||||||
FROM nginx:alpine
|
FROM nginx:alpine
|
||||||
|
|
||||||
# Remove default NGINX configuration
|
|
||||||
RUN rm /etc/nginx/conf.d/default.conf
|
RUN rm /etc/nginx/conf.d/default.conf
|
||||||
|
|
||||||
# Copy custom NGINX configuration from your project
|
|
||||||
COPY custom_nginx.conf /etc/nginx/conf.d/default.conf
|
COPY custom_nginx.conf /etc/nginx/conf.d/default.conf
|
||||||
|
|
||||||
# Copy only the built static files from the 'builder' stage's 'public' folder
|
# Adjust source path for public files from the builder stage
|
||||||
COPY --from=builder /app/public /usr/share/nginx/html
|
COPY --from=builder /home/node/app/public /usr/share/nginx/html
|
||||||
|
|
||||||
EXPOSE 80
|
EXPOSE 80
|
||||||
CMD ["nginx", "-g", "daemon off;"]
|
CMD ["nginx", "-g", "daemon off;"]
|
||||||
Generated
-7145
File diff suppressed because it is too large
Load Diff
-115
@@ -1,115 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "@jackyzha0/quartz",
|
|
||||||
"description": "🌱 publish your digital garden and notes as a website",
|
|
||||||
"private": true,
|
|
||||||
"version": "4.5.1",
|
|
||||||
"type": "module",
|
|
||||||
"author": "jackyzha0 <j.zhao2k19@gmail.com>",
|
|
||||||
"license": "MIT",
|
|
||||||
"homepage": "https://quartz.jzhao.xyz",
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://github.com/jackyzha0/quartz.git"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"quartz": "./quartz/bootstrap-cli.mjs",
|
|
||||||
"docs": "npx quartz build --serve -d docs",
|
|
||||||
"check": "tsc --noEmit && npx prettier . --check",
|
|
||||||
"format": "npx prettier . --write",
|
|
||||||
"test": "tsx --test",
|
|
||||||
"profile": "0x -D prof ./quartz/bootstrap-cli.mjs build --concurrency=1"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"npm": ">=10.9.2",
|
|
||||||
"node": ">=22"
|
|
||||||
},
|
|
||||||
"keywords": [
|
|
||||||
"site generator",
|
|
||||||
"ssg",
|
|
||||||
"digital-garden",
|
|
||||||
"markdown",
|
|
||||||
"blog",
|
|
||||||
"quartz"
|
|
||||||
],
|
|
||||||
"bin": {
|
|
||||||
"quartz": "./quartz/bootstrap-cli.mjs"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"@clack/prompts": "^0.11.0",
|
|
||||||
"@floating-ui/dom": "^1.7.0",
|
|
||||||
"@myriaddreamin/rehype-typst": "^0.6.0",
|
|
||||||
"@napi-rs/simple-git": "0.1.19",
|
|
||||||
"@tweenjs/tween.js": "^25.0.0",
|
|
||||||
"@webgpu/types": "^0.1.61",
|
|
||||||
"ansi-truncate": "^1.2.0",
|
|
||||||
"async-mutex": "^0.5.0",
|
|
||||||
"chokidar": "^4.0.3",
|
|
||||||
"cli-spinner": "^0.2.10",
|
|
||||||
"d3": "^7.9.0",
|
|
||||||
"esbuild-sass-plugin": "^3.3.1",
|
|
||||||
"flexsearch": "0.7.43",
|
|
||||||
"github-slugger": "^2.0.0",
|
|
||||||
"globby": "^14.1.0",
|
|
||||||
"gray-matter": "^4.0.3",
|
|
||||||
"hast-util-to-html": "^9.0.5",
|
|
||||||
"hast-util-to-jsx-runtime": "^2.3.6",
|
|
||||||
"hast-util-to-string": "^3.0.1",
|
|
||||||
"is-absolute-url": "^4.0.1",
|
|
||||||
"js-yaml": "^4.1.0",
|
|
||||||
"lightningcss": "^1.30.1",
|
|
||||||
"mdast-util-find-and-replace": "^3.0.2",
|
|
||||||
"mdast-util-to-hast": "^13.2.0",
|
|
||||||
"mdast-util-to-string": "^4.0.0",
|
|
||||||
"micromorph": "^0.4.5",
|
|
||||||
"minimatch": "^10.0.1",
|
|
||||||
"pixi.js": "^8.9.2",
|
|
||||||
"preact": "^10.26.7",
|
|
||||||
"preact-render-to-string": "^6.5.13",
|
|
||||||
"pretty-bytes": "^7.0.0",
|
|
||||||
"pretty-time": "^1.1.0",
|
|
||||||
"reading-time": "^1.5.0",
|
|
||||||
"rehype-autolink-headings": "^7.1.0",
|
|
||||||
"rehype-citation": "^2.3.1",
|
|
||||||
"rehype-katex": "^7.0.1",
|
|
||||||
"rehype-mathjax": "^7.1.0",
|
|
||||||
"rehype-pretty-code": "^0.14.1",
|
|
||||||
"rehype-raw": "^7.0.0",
|
|
||||||
"rehype-slug": "^6.0.0",
|
|
||||||
"remark": "^15.0.1",
|
|
||||||
"remark-breaks": "^4.0.0",
|
|
||||||
"remark-frontmatter": "^5.0.0",
|
|
||||||
"remark-gfm": "^4.0.1",
|
|
||||||
"remark-math": "^6.0.0",
|
|
||||||
"remark-parse": "^11.0.0",
|
|
||||||
"remark-rehype": "^11.1.2",
|
|
||||||
"remark-smartypants": "^3.0.2",
|
|
||||||
"rfdc": "^1.4.1",
|
|
||||||
"satori": "^0.13.1",
|
|
||||||
"serve-handler": "^6.1.6",
|
|
||||||
"sharp": "^0.34.2",
|
|
||||||
"shiki": "^1.26.2",
|
|
||||||
"source-map-support": "^0.5.21",
|
|
||||||
"to-vfile": "^8.0.0",
|
|
||||||
"toml": "^3.0.0",
|
|
||||||
"unified": "^11.0.5",
|
|
||||||
"unist-util-visit": "^5.0.0",
|
|
||||||
"vfile": "^6.0.3",
|
|
||||||
"workerpool": "^9.2.0",
|
|
||||||
"ws": "^8.18.2",
|
|
||||||
"yargs": "^18.0.0"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"@types/d3": "^7.4.3",
|
|
||||||
"@types/hast": "^3.0.4",
|
|
||||||
"@types/js-yaml": "^4.0.9",
|
|
||||||
"@types/node": "^22.15.23",
|
|
||||||
"@types/pretty-time": "^1.1.5",
|
|
||||||
"@types/source-map-support": "^0.5.10",
|
|
||||||
"@types/ws": "^8.18.1",
|
|
||||||
"@types/yargs": "^17.0.33",
|
|
||||||
"esbuild": "^0.25.5",
|
|
||||||
"prettier": "^3.5.3",
|
|
||||||
"tsx": "^4.19.4",
|
|
||||||
"typescript": "^5.8.3"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+72
-110
@@ -1,156 +1,118 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# --- Configuration ---
|
# --- Configuration ---
|
||||||
# IMPORTANT: Set this to the ABSOLUTE path of your Quartz project directory on the host
|
QUARTZ_PROJECT_DIR="/home/hoid/projects/digital_garden" # Path to your my-quartz-deployment repo
|
||||||
QUARTZ_PROJECT_DIR="/home/hoid/projects/portfolio/quartz"
|
|
||||||
|
|
||||||
# IMPORTANT: Set this to the ABSOLUTE path of the ACTUAL FOLDER in your Obsidian vault
|
|
||||||
# that contains the Markdown files and assets for your Quartz site.
|
|
||||||
# This is the SOURCE of your content.
|
|
||||||
OBSIDIAN_CONTENT_SOURCE="/home/hoid/docker/obsidian/vaults/weeslahw_coppermind/Digital_Garden"
|
OBSIDIAN_CONTENT_SOURCE="/home/hoid/docker/obsidian/vaults/weeslahw_coppermind/Digital_Garden"
|
||||||
|
LOCAL_CONTENT_TARGET_DIR_NAME="content" # Temp dir for Obsidian content within QUARTZ_PROJECT_DIR
|
||||||
# Directory name within your QUARTZ_PROJECT_DIR that Quartz uses for content
|
|
||||||
# This is where the script will temporarily place the real content for the Docker build.
|
|
||||||
# The Dockerfile's `COPY . .` will then pick this up.
|
|
||||||
LOCAL_CONTENT_TARGET_DIR_NAME="content"
|
|
||||||
|
|
||||||
# Timestamp file to track the last successful build's content state
|
|
||||||
# This file will be created in the QUARTZ_PROJECT_DIR
|
|
||||||
LAST_BUILD_TIMESTAMP_FILE=".last_build_content_timestamp"
|
LAST_BUILD_TIMESTAMP_FILE=".last_build_content_timestamp"
|
||||||
|
|
||||||
# Log file for this script's output (recommended when run by cron)
|
|
||||||
LOG_FILE="${QUARTZ_PROJECT_DIR}/update_quartz_docker.log"
|
LOG_FILE="${QUARTZ_PROJECT_DIR}/update_quartz_docker.log"
|
||||||
|
|
||||||
|
# Quartz Framework Source Configuration
|
||||||
|
QUARTZ_FRAMEWORK_DIR_NAME="quartz" # Dir name within QUARTZ_PROJECT_DIR
|
||||||
|
QUARTZ_FRAMEWORK_REPO_URL="https://github.com/jackyzha0/quartz.git"
|
||||||
|
QUARTZ_FRAMEWORK_BRANCH="v4" # Or "main", or a specific tag like "v4.2.5"
|
||||||
|
|
||||||
|
DOCKER_COMPOSE_CMD="/usr/local/bin/docker-compose"
|
||||||
|
|
||||||
# --- Script Logic ---
|
# --- Script Logic ---
|
||||||
|
log_message() { echo "[$(date '+%Y-%m-%d %H:%M:%S')] - $1" | tee -a "$LOG_FILE"; }
|
||||||
# Function for logging
|
cd "$QUARTZ_PROJECT_DIR" || { log_message "FATAL: Failed to cd to project directory: ${QUARTZ_PROJECT_DIR}"; exit 1; }
|
||||||
log_message() {
|
|
||||||
echo "[$(date '+%Y-%m-%d %H:%M:%S')] - $1" | tee -a "$LOG_FILE"
|
|
||||||
}
|
|
||||||
|
|
||||||
cd "$QUARTZ_PROJECT_DIR" || {
|
|
||||||
log_message "FATAL: Failed to cd to project directory: ${QUARTZ_PROJECT_DIR}"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
log_message "--- Quartz Docker Update Script Started ---"
|
log_message "--- Quartz Docker Update Script Started ---"
|
||||||
|
|
||||||
# --- Change Detection ---
|
# --- Step 1: Ensure Quartz Framework Source is Present and Updated ---
|
||||||
NEEDS_REBUILD=false
|
FRAMEWORK_FULL_PATH="${QUARTZ_PROJECT_DIR}/${QUARTZ_FRAMEWORK_DIR_NAME}"
|
||||||
if [ ! -d "$OBSIDIAN_CONTENT_SOURCE" ]; then
|
if [ -d "${FRAMEWORK_FULL_PATH}/.git" ]; then
|
||||||
log_message "ERROR: Obsidian content source directory does not exist: ${OBSIDIAN_CONTENT_SOURCE}"
|
log_message "Attempting to update Quartz framework source in ./${QUARTZ_FRAMEWORK_DIR_NAME}..."
|
||||||
NEEDS_REBUILD=false # Or set to true if you want to try building with an empty content dir
|
(cd "$FRAMEWORK_FULL_PATH" && git checkout "$QUARTZ_FRAMEWORK_BRANCH" && git fetch origin && git reset --hard "origin/${QUARTZ_FRAMEWORK_BRANCH}")
|
||||||
elif [ ! -f "$LAST_BUILD_TIMESTAMP_FILE" ]; then
|
if [ $? -ne 0 ]; then
|
||||||
log_message "No last build timestamp found at ${LAST_BUILD_TIMESTAMP_FILE}. Triggering initial rebuild."
|
log_message "WARNING: Failed to update Quartz framework source. Using existing version. Consider deleting ./${QUARTZ_FRAMEWORK_DIR_NAME} to force fresh clone."
|
||||||
NEEDS_REBUILD=true
|
|
||||||
else
|
else
|
||||||
# Efficiently check if any file within OBSIDIAN_CONTENT_SOURCE is newer than the timestamp file
|
log_message "Quartz framework source updated successfully to branch/tag ${QUARTZ_FRAMEWORK_BRANCH}."
|
||||||
if find "$OBSIDIAN_CONTENT_SOURCE" -type f -newer "$LAST_BUILD_TIMESTAMP_FILE" -print -quit | grep -q .; then
|
fi
|
||||||
log_message "Changes detected in Obsidian content directory (${OBSIDIAN_CONTENT_SOURCE}) since last build. Triggering rebuild."
|
|
||||||
NEEDS_REBUILD=true
|
|
||||||
else
|
else
|
||||||
log_message "No changes detected in Obsidian content directory since last build."
|
log_message "Cloning Quartz framework (branch/tag: ${QUARTZ_FRAMEWORK_BRANCH}) into ./${QUARTZ_FRAMEWORK_DIR_NAME}..."
|
||||||
|
rm -rf "$FRAMEWORK_FULL_PATH" # Remove if it's a broken/incomplete dir
|
||||||
|
git clone --depth 1 --branch "$QUARTZ_FRAMEWORK_BRANCH" "$QUARTZ_FRAMEWORK_REPO_URL" "$FRAMEWORK_FULL_PATH"
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
log_message "ERROR: Failed to clone Quartz framework source from ${QUARTZ_FRAMEWORK_REPO_URL} (branch: ${QUARTZ_FRAMEWORK_BRANCH})."
|
||||||
|
log_message "--- Script Finished (Error) ---"
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# --- Step 2: Change Detection for Obsidian Content ---
|
||||||
|
NEEDS_REBUILD=false
|
||||||
|
# ... (Your existing change detection logic for OBSIDIAN_CONTENT_SOURCE vs LAST_BUILD_TIMESTAMP_FILE) ...
|
||||||
|
# (Make sure this logic is sound and sets NEEDS_REBUILD=true correctly)
|
||||||
|
if [ ! -d "$OBSIDIAN_CONTENT_SOURCE" ]; then
|
||||||
|
log_message "ERROR: Obsidian content source directory does not exist: ${OBSIDIAN_CONTENT_SOURCE}"
|
||||||
|
NEEDS_REBUILD=false
|
||||||
|
elif [ ! -f "$LAST_BUILD_TIMESTAMP_FILE" ]; then
|
||||||
|
log_message "No last build timestamp found. Triggering initial rebuild."
|
||||||
|
NEEDS_REBUILD=true
|
||||||
|
else
|
||||||
|
if find "$OBSIDIAN_CONTENT_SOURCE" -type f -newer "$LAST_BUILD_TIMESTAMP_FILE" -print -quit | grep -q .; then
|
||||||
|
log_message "Changes detected in Obsidian content. Triggering rebuild."
|
||||||
|
NEEDS_REBUILD=true
|
||||||
|
else
|
||||||
|
log_message "No changes detected in Obsidian content since last build."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
if [ "$NEEDS_REBUILD" = false ]; then
|
if [ "$NEEDS_REBUILD" = false ]; then
|
||||||
log_message "Skipping Docker rebuild and deploy."
|
log_message "Skipping Docker rebuild and deploy as no content changes were detected."
|
||||||
log_message "--- Script Finished (No Changes) ---"
|
log_message "--- Script Finished (No Changes) ---"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# --- Prepare Content for Docker Build ---
|
# --- Step 3: Prepare Content Directory for Docker Build ---
|
||||||
LOCAL_CONTENT_FULL_PATH="${QUARTZ_PROJECT_DIR}/${LOCAL_CONTENT_TARGET_DIR_NAME}"
|
LOCAL_CONTENT_FULL_PATH="${QUARTZ_PROJECT_DIR}/${LOCAL_CONTENT_TARGET_DIR_NAME}"
|
||||||
|
log_message "Preparing content directory for Docker build: ${LOCAL_CONTENT_FULL_PATH}"
|
||||||
|
rm -rf "${LOCAL_CONTENT_FULL_PATH}" # Remove old temporary content
|
||||||
|
mkdir "${LOCAL_CONTENT_FULL_PATH}" || { log_message "ERROR: Failed to create local content directory."; exit 1; }
|
||||||
|
rsync -a --delete "${OBSIDIAN_CONTENT_SOURCE}/" "${LOCAL_CONTENT_FULL_PATH}/" || { log_message "ERROR: Failed to rsync Obsidian content."; exit 1; }
|
||||||
|
log_message "Obsidian content prepared successfully."
|
||||||
|
|
||||||
log_message "Preparing content directory: ${LOCAL_CONTENT_FULL_PATH}"
|
# --- Step 4: Docker Build & Deploy using Docker Compose ---
|
||||||
|
# ... (Your existing docker-compose down and docker-compose up sections using $DOCKER_COMPOSE_CMD) ...
|
||||||
# Remove existing local content directory/symlink in project dir (if any)
|
# (The Dockerfile will now use the ./quartz_framework_source/ and ./content/ directories)
|
||||||
if [ -L "${LOCAL_CONTENT_FULL_PATH}" ] || [ -d "${LOCAL_CONTENT_FULL_PATH}" ]; then
|
log_message "Tearing down existing Docker Compose services (if any)..."
|
||||||
log_message "Removing existing ./${LOCAL_CONTENT_TARGET_DIR_NAME}"
|
|
||||||
rm -rf "${LOCAL_CONTENT_FULL_PATH}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
log_message "Creating new ./${LOCAL_CONTENT_TARGET_DIR_NAME} directory"
|
|
||||||
mkdir "${LOCAL_CONTENT_FULL_PATH}"
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
log_message "ERROR: Failed to create local content directory: ${LOCAL_CONTENT_FULL_PATH}"
|
|
||||||
log_message "--- Script Finished (Error) ---"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
log_message "Copying content from ${OBSIDIAN_CONTENT_SOURCE} to ${LOCAL_CONTENT_FULL_PATH}"
|
|
||||||
|
|
||||||
# Using rsync for efficient copying; ensure it's installed (sudo apt install rsync)
|
|
||||||
# The trailing slash on OBSIDIAN_CONTENT_SOURCE/ is important for rsync
|
|
||||||
rsync -a --delete "${OBSIDIAN_CONTENT_SOURCE}/" "${LOCAL_CONTENT_FULL_PATH}/"
|
|
||||||
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
log_message "ERROR: Failed to copy content from Obsidian source to local content directory."
|
|
||||||
log_message "--- Script Finished (Error) ---"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
log_message "Content prepared successfully for Docker build."
|
|
||||||
|
|
||||||
# --- Docker Build & Deploy using Docker Compose ---
|
|
||||||
# Use absolute path for docker-compose for robustness in cron
|
|
||||||
DOCKER_COMPOSE_CMD="/usr/local/bin/docker-compose"
|
|
||||||
|
|
||||||
log_message "Tearing down existing Docker Compose services (if any) for a clean deployment..."
|
|
||||||
# Create a temporary file to capture output from 'docker-compose down'
|
|
||||||
COMPOSE_DOWN_OUTPUT_FILE="${QUARTZ_PROJECT_DIR}/compose_down_output.tmp"
|
COMPOSE_DOWN_OUTPUT_FILE="${QUARTZ_PROJECT_DIR}/compose_down_output.tmp"
|
||||||
|
|
||||||
# Execute 'docker-compose down' and capture all its output
|
|
||||||
$DOCKER_COMPOSE_CMD down --remove-orphans --volumes > "$COMPOSE_DOWN_OUTPUT_FILE" 2>&1
|
$DOCKER_COMPOSE_CMD down --remove-orphans --volumes > "$COMPOSE_DOWN_OUTPUT_FILE" 2>&1
|
||||||
DOWN_EXIT_CODE=$?
|
DOWN_EXIT_CODE=$?
|
||||||
|
|
||||||
if [ $DOWN_EXIT_CODE -ne 0 ]; then
|
if [ $DOWN_EXIT_CODE -ne 0 ]; then
|
||||||
log_message "WARNING: '$DOCKER_COMPOSE_CMD down' failed with exit code $DOWN_EXIT_CODE. Output from command:"
|
log_message "WARNING: '$DOCKER_COMPOSE_CMD down' failed with exit code $DOWN_EXIT_CODE. Output:"
|
||||||
# Append the captured output from docker-compose down to the main log
|
echo "" >> "$LOG_FILE"; cat "$COMPOSE_DOWN_OUTPUT_FILE" >> "$LOG_FILE"; echo "" >> "$LOG_FILE"
|
||||||
# Ensure there's a newline before catting, in case log_message doesn't add one after its prefix
|
log_message "Attempting to proceed..."
|
||||||
echo "" >> "$LOG_FILE"
|
|
||||||
cat "$COMPOSE_DOWN_OUTPUT_FILE" >> "$LOG_FILE"
|
|
||||||
echo "" >> "$LOG_FILE" # Add a newline after the output
|
|
||||||
log_message "(End of '$DOCKER_COMPOSE_CMD down' output for this attempt)"
|
|
||||||
log_message "Attempting to proceed with 'up' command despite 'down' issues..." # This was your script's original logic
|
|
||||||
else
|
else
|
||||||
log_message "'$DOCKER_COMPOSE_CMD down' executed successfully."
|
log_message "'$DOCKER_COMPOSE_CMD down' executed successfully."
|
||||||
fi
|
fi
|
||||||
rm -f "$COMPOSE_DOWN_OUTPUT_FILE" # Clean up the temporary file
|
rm -f "$COMPOSE_DOWN_OUTPUT_FILE"
|
||||||
|
|
||||||
log_message "Building and deploying with Docker Compose..."
|
log_message "Building and deploying with Docker Compose..."
|
||||||
# Create a temporary file to capture output from 'docker-compose up'
|
|
||||||
COMPOSE_UP_OUTPUT_FILE="${QUARTZ_PROJECT_DIR}/compose_up_output.tmp"
|
COMPOSE_UP_OUTPUT_FILE="${QUARTZ_PROJECT_DIR}/compose_up_output.tmp"
|
||||||
|
|
||||||
$DOCKER_COMPOSE_CMD up -d --build --remove-orphans > "$COMPOSE_UP_OUTPUT_FILE" 2>&1
|
$DOCKER_COMPOSE_CMD up -d --build --remove-orphans > "$COMPOSE_UP_OUTPUT_FILE" 2>&1
|
||||||
UP_EXIT_CODE=$?
|
UP_EXIT_CODE=$?
|
||||||
|
|
||||||
if [ $UP_EXIT_CODE -ne 0 ]; then
|
if [ $UP_EXIT_CODE -ne 0 ]; then
|
||||||
log_message "ERROR: '$DOCKER_COMPOSE_CMD up -d --build --remove-orphans' failed with exit code $UP_EXIT_CODE! Output from command:"
|
log_message "ERROR: '$DOCKER_COMPOSE_CMD up -d --build --remove-orphans' failed with exit code $UP_EXIT_CODE! Output:"
|
||||||
echo "" >> "$LOG_FILE"
|
echo "" >> "$LOG_FILE"; cat "$COMPOSE_UP_OUTPUT_FILE" >> "$LOG_FILE"; echo "" >> "$LOG_FILE"
|
||||||
cat "$COMPOSE_UP_OUTPUT_FILE" >> "$LOG_FILE"
|
|
||||||
echo "" >> "$LOG_FILE"
|
|
||||||
log_message "(End of '$DOCKER_COMPOSE_CMD up' output for this attempt)"
|
|
||||||
log_message "--- Script Finished (Error) ---"
|
log_message "--- Script Finished (Error) ---"
|
||||||
rm -f "$COMPOSE_UP_OUTPUT_FILE" # Clean up
|
rm -f "$COMPOSE_UP_OUTPUT_FILE"; exit 1
|
||||||
exit 1
|
|
||||||
else
|
else
|
||||||
log_message "'$DOCKER_COMPOSE_CMD up -d --build --remove-orphans' executed successfully."
|
log_message "'$DOCKER_COMPOSE_CMD up -d --build --remove-orphans' executed successfully."
|
||||||
fi
|
fi
|
||||||
rm -f "$COMPOSE_UP_OUTPUT_FILE" # Clean up
|
rm -f "$COMPOSE_UP_OUTPUT_FILE"
|
||||||
|
|
||||||
# Update the timestamp file on successful deployment
|
|
||||||
|
# --- Step 5: Update Timestamp & Cleanup ---
|
||||||
touch "$LAST_BUILD_TIMESTAMP_FILE"
|
touch "$LAST_BUILD_TIMESTAMP_FILE"
|
||||||
log_message "Updated last build timestamp: ${LAST_BUILD_TIMESTAMP_FILE}"
|
log_message "Updated last build timestamp."
|
||||||
|
|
||||||
# Optional: Clean up by removing the copied content and restoring symlink if needed for local dev
|
log_message "Cleaning up temporary local content directory ./${LOCAL_CONTENT_TARGET_DIR_NAME}..."
|
||||||
# This is useful if your local Quartz dev workflow relies on the symlink.
|
|
||||||
# If the cron job is the ONLY way this is built, cleanup might not be strictly necessary,
|
|
||||||
# but it keeps the project dir clean of copied data between runs.
|
|
||||||
log_message "Cleaning up temporary local content directory..."
|
|
||||||
rm -rf "${LOCAL_CONTENT_FULL_PATH}"
|
rm -rf "${LOCAL_CONTENT_FULL_PATH}"
|
||||||
|
# Note: We are NOT cleaning up ./${QUARTZ_FRAMEWORK_DIR_NAME} here as we want to keep it for the next run to `git pull`.
|
||||||
# If you use a symlink for local dev, uncomment and adjust to restore it:
|
# It's in .gitignore of your `my-quartz-deployment` repo.
|
||||||
#ln -s "${OBSIDIAN_CONTENT_SOURCE}" "${LOCAL_CONTENT_FULL_PATH}"
|
|
||||||
log_message "Local content directory cleaned up."
|
|
||||||
|
|
||||||
log_message "--- Script Finished Successfully ---"
|
log_message "--- Script Finished Successfully ---"
|
||||||
Reference in New Issue
Block a user