Add wip lab 3
This commit is contained in:
8
utilities/pdf_make/Dockerfile
Normal file
8
utilities/pdf_make/Dockerfile
Normal file
@ -0,0 +1,8 @@
|
||||
# pdf_make/Dockerfile
|
||||
FROM pandoc/latex:2.19
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# IMPORTANT: Copy your script into the container
|
||||
COPY generate_reports.sh /app/generate_reports.sh
|
||||
RUN chmod +x /app/generate_reports.sh
|
||||
39
utilities/pdf_make/generate_reports.sh
Executable file
39
utilities/pdf_make/generate_reports.sh
Executable file
@ -0,0 +1,39 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "Starting report generation..."
|
||||
|
||||
# Navigate to the /labs directory within the container
|
||||
# This is crucial because we're mounting the host's /labs into the container's /labs
|
||||
cd /labs || { echo "Error: /labs directory not found in container. Exiting."; exit 1; }
|
||||
|
||||
# Find all directories prefixed with "lab-"
|
||||
find . -maxdepth 1 -type d -name "lab-*" | while read lab_dir; do
|
||||
echo "Processing directory: $lab_dir"
|
||||
markdown_file="$lab_dir/LAB-REPORT.md"
|
||||
pdf_file="$lab_dir/LAB-REPORT.pdf"
|
||||
|
||||
# Check if LAB-REPORT.md exists
|
||||
if [ -f "$markdown_file" ]; then
|
||||
echo "Found $markdown_file"
|
||||
# Check if LAB-REPORT.pdf does not exist
|
||||
if [ ! -f "$pdf_file" ]; then
|
||||
echo "LAB-REPORT.pdf not found. Generating PDF from markdown..."
|
||||
# Generate PDF using pandoc
|
||||
# Make sure 'pandoc' command is available in the image, which it is for pandoc/latex
|
||||
image_dir="$lab_dir"
|
||||
pandoc "$markdown_file" -s -o "$pdf_file" --pdf-engine=pdflatex --resource-path "$image_dir"
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Successfully generated $pdf_file"
|
||||
else
|
||||
echo "Error generating $pdf_file"
|
||||
fi
|
||||
else
|
||||
echo "LAB-REPORT.pdf already exists. Skipping generation."
|
||||
fi
|
||||
else
|
||||
echo "LAB-REPORT.md not found in $lab_dir. Skipping."
|
||||
fi
|
||||
done
|
||||
|
||||
echo "Report generation complete."
|
||||
52
utilities/pdf_make/labs.sh
Executable file
52
utilities/pdf_make/labs.sh
Executable file
@ -0,0 +1,52 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Define image name
|
||||
IMAGE_NAME="pandoc-report-generator"
|
||||
PDF_MAKE_DIR="." # Path to your Dockerfile and generate_reports.sh
|
||||
LABS_DIR="../.." # Path to your labs directory
|
||||
WORKING_DIRECTORY=$(dirname "$0")
|
||||
|
||||
echo "--- Debug Info ---"
|
||||
echo "Directory name: $(dirname "$0")"
|
||||
echo "Current Working Directory: ${WORKING_DIRECTORY}"
|
||||
echo "Image Name (variable): '$IMAGE_NAME'"
|
||||
echo "PDF Make Directory (variable): '$PDF_MAKE_DIR'"
|
||||
echo "Labs Directory (variable): '$LABS_DIR'"
|
||||
echo "Absolute Labs Mount Path: '${WORKING_DIRECTORY}/$LABS_DIR'"
|
||||
echo "--------------------"
|
||||
|
||||
echo "--- Building Docker image: $IMAGE_NAME ---"
|
||||
# Build the Docker image from the pdf_make directory
|
||||
docker build -t "$IMAGE_NAME" "$WORKING_DIRECTORY/$PDF_MAKE_DIR"
|
||||
BUILD_STATUS=$?
|
||||
echo "Build command exited with status: $BUILD_STATUS"
|
||||
|
||||
if [ $BUILD_STATUS -ne 0 ]; then
|
||||
echo "ERROR: Docker image build failed. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "--- Running report generation inside Docker container ---"
|
||||
# This single-line docker run command is the most robust way to avoid shell parsing issues.
|
||||
# It explicitly sets the entrypoint and mounts the /labs directory.
|
||||
docker run --rm --entrypoint /bin/sh -v "${WORKING_DIRECTORY}/$LABS_DIR:/labs" "$IMAGE_NAME" /app/generate_reports.sh
|
||||
|
||||
RUN_STATUS=$?
|
||||
echo "Run command exited with status: $RUN_STATUS"
|
||||
|
||||
if [ $RUN_STATUS -ne 0 ]; then
|
||||
echo "ERROR: Report generation failed inside Docker container."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "--- All operations completed successfully. ---"
|
||||
|
||||
# --- New Step: Verify Output on Host ---
|
||||
echo "--- Verifying generated PDFs on host ---"
|
||||
find "${WORKING_DIRECTORY}/$LABS_DIR" -type f -name "LAB-REPORT.pdf"
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "PDFs should now be available in your '$LABS_DIR' directory."
|
||||
else
|
||||
echo "No PDFs found or an error occurred during verification."
|
||||
fi
|
||||
Reference in New Issue
Block a user