Skip to content

Commit

Permalink
Updated deploy-gdc-docs.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
bilalbaqar committed Jul 30, 2024
1 parent 06f9cec commit d483bdc
Showing 1 changed file with 49 additions and 50 deletions.
99 changes: 49 additions & 50 deletions deploy-gdc-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,18 @@ fi

echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: Building script for ${ENVIRONMENT}"

rm /tmp/${ENVIRONMENT}-buildlog.txt
exec 3>&1 4>&2
trap 'exec 2>&4 1>&3' 0 1 2 3
exec 1>/tmp/${ENVIRONMENT}-buildlog.txt 2>&1

if [ -d "~/gdc-docs-${ENVIRONMENT}/" ]; then
if [ -d "/home/ubuntu/gdc-docs-${ENVIRONMENT}/" ]; then
echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: Directory exists, removing"
sudo rm /home/ubuntu/gdc-docs-${ENVIRONMENT}/ -R
# Added by ray 2018-07-11 since it was erroring trying to find a directory ?
sleep 10s
echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: Directory exists, removing"
sudo rm ~/gdc-docs-${ENVIRONMENT}/ -R
else
echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: Directory ~/gdc-docs-${ENVIRONMENT}/ does not exist"
fi
echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: Creating directory and cloning git repo"
mkdir ~/gdc-docs-${ENVIRONMENT}/

git clone [email protected]:NCI-GDC/gdc-docs.git ~/gdc-docs-${ENVIRONMENT}/
cd ~/gdc-docs-${ENVIRONMENT}/

Expand All @@ -51,6 +52,16 @@ else
exit;
fi

echo "Checking out branch feat/mkdocs-material - PLEASE REMOVE AFTER DEV"
/usr/bin/git checkout feat/mkdocs-material

# Building virtualenv and installing dependencies
echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: Building virtualenv for ${ENVIRONMENT}"
python3 -m virtualenv -p python3.8 venv
source venv/bin/activate
pip install pip-tools
pip-sync requirements.txt

#iconv --verbose -f ascii -t utf-8 -o /tmp/test docs/Data_Portal/PDF/Data_Portal_UG.pd
hasEncodingError=false
echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: Veryfing if all MARKDOWN have no encoding issue"
Expand All @@ -73,59 +84,47 @@ if $hasEncodingError ; then
exit
fi

#echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: Veryfing if all MARKDOWN files are UTF-8 encoded"
#countWrongFiles=$(for f in `find docs/ | egrep -v Eliminate`; do echo "$f" ' -- ' `file -bi "$f"` ; done | grep ".md" | grep -v "utf-8" | wc -l)
#echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: Number of incorrectly encoded files: ${countWrongFiles}"

#if [ "$countWrongFiles" -gt 0 ] ; then
# echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: ERROR the following files are not encoded in UTF-8"
# for f in `find docs/ | egrep -v Eliminate`; do echo "$f" ' -- ' `file -bi "$f"` ; done | grep ".md" | grep -v "utf-8"
# if [ -f /tmp/${ENVIRONMENT}-buildlog.txt ]; then
# echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: Copying log file"
# cp /tmp/${ENVIRONMENT}-buildlog.txt /var/www/gdc-docs-${ENVIRONMENT}.nci.nih.gov/buildlog.txt
# fi
# exit
#fi

echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: Looking for User Guides"
userGuides=()
for i in $( ls *_UG.yml ); do
userGuides+=(${i::${#i}-7})
done
echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: Number of User Guides found: ${#userGuides[@]}"

for userGuide in "${userGuides[@]}"; do
echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: ${userGuide}: Starting creation"
if [ ! -d "docs/Data_Portal/PDF/" ]; then
echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: ${userGuide}: PDF Directory does not exists, creating ..."
mkdir docs/${userGuide}/PDF/
fi
echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: ${userGuide}: Building pandoc document"
/usr/local/bin/mkdocs2pandoc -f ${userGuide}_UG.yml -o docs/${userGuide}/PDF/${userGuide}_UG.pd
echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: ${userGuide}: Replacing strings in pandoc document "
/bin/sed -i -e 's/# / /g' docs/${userGuide}/PDF/${userGuide}_UG.pd
/bin/sed -i -e 's/### /## /g' docs/${userGuide}/PDF/${userGuide}_UG.pd
/bin/sed -i -e 's/\/site\//\/docs\//g' docs/${userGuide}/PDF/${userGuide}_UG.pd
/bin/sed -i -e "s/(images/(https:\/\/gdc-docs.nci.nih.gov\/"$userGuide"\/Users_Guide\/images/g" docs/${userGuide}/PDF/${userGuide}_UG.pd #To make images clickable in the PDF
echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: ${userGuide}: Building PDF from pandoc document "
/usr/bin/pandoc --listings -H theme/latex/listings-setup.tex --toc -V documentclass=report -V geometry:"top=2cm, bottom=1.5cm, left=1cm, right=1cm" -f markdown+grid_tables+table_captions docs/${userGuide}/PDF/${userGuide}_Title.txt -o docs/${userGuide}/PDF/${userGuide}_UG.pdf docs/${userGuide}/PDF/${userGuide}_UG.pd
done
# Uncomment below - Bilal
# echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: Looking for User Guides"
# userGuides=()
# for i in $( ls *_UG.yml ); do
# userGuides+=(${i::${#i}-7})
# done
# echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: Number of User Guides found: ${#userGuides[@]}"

# for userGuide in "${userGuides[@]}"; do
# echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: ${userGuide}: Starting creation"
# if [ ! -d "docs/Data_Portal/PDF/" ]; then
# echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: ${userGuide}: PDF Directory does not exists, creating ..."
# mkdir docs/${userGuide}/PDF/
# fi
# echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: ${userGuide}: Building pandoc document"
# /usr/local/bin/mkdocs2pandoc -f ${userGuide}_UG.yml -o docs/${userGuide}/PDF/${userGuide}_UG.pd
# echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: ${userGuide}: Replacing strings in pandoc document "
# /bin/sed -i -e 's/# / /g' docs/${userGuide}/PDF/${userGuide}_UG.pd
# /bin/sed -i -e 's/### /## /g' docs/${userGuide}/PDF/${userGuide}_UG.pd
# /bin/sed -i -e 's/\/site\//\/docs\//g' docs/${userGuide}/PDF/${userGuide}_UG.pd
# /bin/sed -i -e "s/(images/(https:\/\/gdc-docs.nci.nih.gov\/"$userGuide"\/Users_Guide\/images/g" docs/${userGuide}/PDF/${userGuide}_UG.pd #To make images clickable in the PDF
# echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: ${userGuide}: Building PDF from pandoc document "
# /usr/bin/pandoc --listings -H theme/latex/listings-setup.tex --toc -V documentclass=report -V geometry:"top=2cm, bottom=1.5cm, left=1cm, right=1cm" -f markdown+grid_tables+table_captions docs/${userGuide}/PDF/${userGuide}_Title.txt -o docs/${userGuide}/PDF/${userGuide}_UG.pdf docs/${userGuide}/PDF/${userGuide}_UG.pd
# done

echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: Cleaning previous website directory (rm)"
sudo rm /var/www/gdc-docs-${ENVIRONMENT}.nci.nih.gov/* -R
# Added by ray 2018-07-11 since it was erroring trying to find a directory ?
sleep 10s

echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: Build Encyclopedia"
python buildencyclopedia.py
#python buildencyclopedia.py

echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: Deploying new version to /var/www/gdc-docs-${ENVIRONMENT}.nci.nih.gov/"
/usr/local/bin/mkdocs build -v --site-dir /var/www/gdc-docs-${ENVIRONMENT}.nci.nih.gov/
venv/bin/mkdocs build -v --site-dir /var/www/gdc-docs-${ENVIRONMENT}.nci.nih.gov/

if [ -f /tmp/${ENVIRONMENT}-buildlog.txt ]; then
echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: Copying log file"
cp /tmp/${ENVIRONMENT}-buildlog.txt /var/www/gdc-docs-${ENVIRONMENT}.nci.nih.gov/buildlog.txt
fi

#echo "$(date +'%d %B %Y - %k:%M'): ${ENVIRONMENT}: Temporarily creating symlink"
#Temporary fix to address a link that would be broken otherwise in the submission portal due to a change of the dictionary name
#rm /var/www/gdc-docs-${ENVIRONMENT}.nci.nih.gov/Dictionary/ -R
#ln -sfn /var/www/gdc-docs-${ENVIRONMENT}.nci.nih.gov/Data_Dictionary /var/www/gdc-docs-${ENVIRONMENT}.nci.nih.gov/Dictionary
# After build files will have ubuntu:ubuntu permissions giving error on requests. Fixing permissions here.
sudo chown -R ubuntu:www-data /var/www/gdc-docs-${ENVIRONMENT}.nci.nih.gov

0 comments on commit d483bdc

Please sign in to comment.