Added Docker support
This commit is contained in:
parent
12e71a4245
commit
3f865d15bf
99
DOCKER_THESIS_DEFENSE_LATEX.sh
Normal file
99
DOCKER_THESIS_DEFENSE_LATEX.sh
Normal file
@ -0,0 +1,99 @@
|
||||
#!/bin/bash
|
||||
#Variable to indicate if a docker image should be saved (user choice)
|
||||
#If it is passed in as yes or no from a script use than. Otherwise use a input
|
||||
if [ ! -n "$SAVE" ]
|
||||
then
|
||||
echo "Do you want to save a new docker image as a backup?"
|
||||
read -p " Yes/No: " SAVE
|
||||
fi
|
||||
#Convert to upper case.
|
||||
SAVE=${SAVE^^}
|
||||
#Exit if not valid
|
||||
if [ ! $SAVE = YES ] && [ ! $SAVE = NO ] ; then
|
||||
echo "The option to save the docker image must be set to Yes or No. Exiting."
|
||||
exit
|
||||
fi
|
||||
|
||||
DOCKER_CONTAINER_NAME="beamer_container"
|
||||
DOCKER_IMAGE_NAME="acg/thesis_defense_latex:1.0"
|
||||
|
||||
#If the docker image to run beamer LaTex doesn't exist make it
|
||||
if [ -z "$(docker images -q $DOCKER_IMAGE_NAME 2> /dev/null)" ]; then
|
||||
echo "Building a LaTex docker image, for the thesis."
|
||||
#Move to the directory with the Dockerfile used to run the regression analysis, and create result figures.
|
||||
cd ./Docker_Make/
|
||||
#Move back tot he main working directory
|
||||
docker build -t $DOCKER_IMAGE_NAME .
|
||||
cd ../
|
||||
echo "Docker LaTex image built"
|
||||
fi
|
||||
#Check if a docker container of the image is running, and if an exited container blocks, removed if before running a new one.
|
||||
if [ "$(docker ps -a -q -f name=${DOCKER_CONTAINER_NAME})" ]; then
|
||||
echo "Removing existing container of thesis image."
|
||||
if [ "$(docker ps -aq -f status=exited -f name=${DOCKER_CONTAINER_NAME})" ]; then
|
||||
# cleanup
|
||||
docker rm ${DOCKER_CONTAINER_NAME}
|
||||
# run the container
|
||||
echo "Running docker image as a container"
|
||||
docker run -d -t --name "$DOCKER_CONTAINER_NAME" "$DOCKER_IMAGE_NAME"
|
||||
|
||||
fi
|
||||
else
|
||||
# run the container
|
||||
echo "Running docker image as a container"
|
||||
docker run -d -t --name "$DOCKER_CONTAINER_NAME" "$DOCKER_IMAGE_NAME"
|
||||
fi
|
||||
|
||||
|
||||
|
||||
#Save a image snapshot with all LaTex code. The SAVE variable is made to be lower case.
|
||||
if [ $SAVE = YES ]
|
||||
then
|
||||
timestamp=$(date +%Y-%m-%d)
|
||||
SAVE_DIR="ACG_DEFENSE_BEAMER_DOCKER_${timestamp}"
|
||||
SAVE_DIR_PATH="Saved_Images/${SAVE_DIR}"
|
||||
echo "Making Save Location ${SAVE_DIR_PATH}"
|
||||
mkdir -p ${SAVE_DIR_PATH}
|
||||
echo "Copying LaTex Code to ${SAVE_DIR_PATH}"
|
||||
cp -r ./LATEX/* ${SAVE_DIR_PATH}
|
||||
cd ${SAVE_DIR_PATH}
|
||||
#Run the cleaning script to remove any files that do not need to be upload to the docker container.
|
||||
bash clean.sh
|
||||
mkdir -p DOCKER_IMAGE
|
||||
echo "Writing script file to run the Docker LaTex code"
|
||||
echo '#If the image does not exist make it' > DOCKER_RUN.sh
|
||||
echo "if [ ! \"\$(docker images -q ${DOCKER_IMAGE_NAME} 2> /dev/null)\" ]; then" >> DOCKER_RUN.sh
|
||||
echo " docker load -i DOCKER_IMAGE/LATEX_DOCKER.tar" >> DOCKER_RUN.sh
|
||||
echo "fi" >> DOCKER_RUN.sh
|
||||
echo "#If container is stoped remove." >> DOCKER_RUN.sh
|
||||
echo "if [ \"\$(docker ps -aq -f status=exited -f name=${DOCKER_CONTAINER_NAME})\" ]; then" >> DOCKER_RUN.sh
|
||||
echo " docker rm ${DOCKER_CONTAINER_NAME}" >> DOCKER_RUN.sh
|
||||
echo " docker run -d -t --name ${DOCKER_CONTAINER_NAME} ${DOCKER_IMAGE_NAME}" >> DOCKER_RUN.sh
|
||||
echo "fi" >> DOCKER_RUN.sh
|
||||
echo "#If container does not exists make it" >> DOCKER_RUN.sh
|
||||
echo "if [ ! \"\$(docker ps -a -q -f name=${DOCKER_CONTAINER_NAME})\" ]; then" >> DOCKER_RUN.sh
|
||||
echo " docker run -d -t --name ${DOCKER_CONTAINER_NAME} ${DOCKER_IMAGE_NAME}" >> DOCKER_RUN.sh
|
||||
echo "fi" >> DOCKER_RUN.sh >> DOCKER_RUN.sh
|
||||
echo "#Run LaTex Docker on the build files, export the pdf, and exit" >> DOCKER_RUN.sh
|
||||
echo "mv DOCKER_IMAGE/ ../" >> DOCKER_RUN.sh
|
||||
|
||||
echo "docker cp ./ ${DOCKER_CONTAINER_NAME}:/LaTex" >> DOCKER_RUN.sh
|
||||
echo "docker exec ${DOCKER_CONTAINER_NAME} bash /LaTex/build.sh" >> DOCKER_RUN.sh
|
||||
echo "docker cp ${DOCKER_CONTAINER_NAME}:/LaTex/Mines_Thesis.pdf ./" >> DOCKER_RUN.sh
|
||||
echo "mv ../DOCKER_IMAGE/ ./" >> DOCKER_RUN.sh
|
||||
|
||||
echo "docker stop ${DOCKER_CONTAINER_NAME}" >> DOCKER_RUN.sh
|
||||
echo "docker remove ${DOCKER_CONTAINER_NAME}" >> DOCKER_RUN.sh
|
||||
|
||||
cd DOCKER_IMAGE
|
||||
echo "Creating Docker Image Saved to ${SAVE_DIR_PATH}/DOCKER_IMAGE/LATEX_DOCKER.tar"
|
||||
docker save "${DOCKER_IMAGE_NAME}" > LATEX_DOCKER.tar
|
||||
cd ../../
|
||||
echo "Creating a compressed tar.gz file of all contents of ${SAVE_DIR_PATH}"
|
||||
tar -czf "${SAVE_DIR}.tar.gz" "${SAVE_DIR}"
|
||||
echo "Removing original contents of ${SAVE_DIR_PATH} to save space"
|
||||
rm -r ${SAVE_DIR}
|
||||
echo "Snapshot saved!"
|
||||
fi
|
||||
|
||||
|
||||
12
Docker_Make/Dockerfile
Normal file
12
Docker_Make/Dockerfile
Normal file
@ -0,0 +1,12 @@
|
||||
#Date Created: October 4th 2024
|
||||
#Author Alex Gebben <agebben@mines.edu,agebben@uwyo.edu>
|
||||
FROM debian:trixie
|
||||
LABEL org.opencontainers.image.authors=agebben@uwyo.edu
|
||||
ARG DEBIAN_FRONTEND=noninteractive
|
||||
#Update Container
|
||||
RUN apt update; apt dist-upgrade -y
|
||||
#Install latex packages. The specific version used when this file was created is assigned. Remove this to try and install a newer version. That may fix future problems if this code does not run.
|
||||
#RUN apt install -y texlive-full=2024.20240829-2 vim biber=2.20-2
|
||||
RUN apt install -y texlive-latex-extra=2024.20240829-1 vim biber=2.20-2
|
||||
|
||||
WORKDIR /LaTex
|
||||
17
LATEX/DOCKER_RUN.sh
Executable file
17
LATEX/DOCKER_RUN.sh
Executable file
@ -0,0 +1,17 @@
|
||||
#!/bin/bash
|
||||
#If the needed docker image does not exist run the script to build it. Pass in that a backup .tar.gz image should not be made.
|
||||
if [ ! "$(docker images -q acg/thesis_defense_latex:1.0 2> /dev/null)" ]; then
|
||||
cd ..
|
||||
export SAVE="No"
|
||||
bash DOCKER_THESIS_DEFENSE_LATEX.sh
|
||||
cd ./LATEX
|
||||
fi
|
||||
#If the docker container exists compile the Latex using the container, and output the pdf locally.
|
||||
if [ "$(docker images -q acg/thesis_defense_latex:1.0 2> /dev/null)" ]; then
|
||||
docker run -d -t --name beamer_container acg/thesis_defense_latex:1.0
|
||||
docker cp ./ beamer_container:/LaTex
|
||||
docker exec beamer_container bash /LaTex/build.sh
|
||||
docker cp beamer_container:/LaTex/Defense.pdf ./
|
||||
docker stop beamer_container
|
||||
docker remove beamer_container
|
||||
fi
|
||||
2
LATEX/biblatex.sh
Executable file
2
LATEX/biblatex.sh
Executable file
@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
biber 'Defense'
|
||||
7
LATEX/build.sh
Executable file
7
LATEX/build.sh
Executable file
@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
./clean.sh
|
||||
pdflatex -file-line-error -halt-on-error Defense.tex
|
||||
./biblatex.sh
|
||||
pdflatex -file-line-error -halt-on-error Defense.tex
|
||||
pdflatex -file-line-error -halt-on-error Defense.tex
|
||||
# pdflatex -file-line-error -halt-on-error Mines_Thesis.tex
|
||||
9
LATEX/clean.sh
Executable file
9
LATEX/clean.sh
Executable file
@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
rm -f Defense.aux
|
||||
rm -f Defense.nav
|
||||
rm -f Defense.run.xml
|
||||
rm -f Defense.toc
|
||||
rm -f Defense.bcf
|
||||
rm -f Defense.out
|
||||
rm -f Defense.snm
|
||||
rm -f Defense.log
|
||||
Loading…
x
Reference in New Issue
Block a user