Skip to content
Snippets Groups Projects
Commit d5e65f81 authored by Olivier Maury's avatar Olivier Maury
Browse files

Créer un script de déploiement. refs www#1

parent e8c4ae23
No related branches found
No related tags found
1 merge request!5Script deploiement
#!/bin/bash
function echo_bold_green {
echo -e "\033[32;1m"$1"\033[0m";
}
function echo_bold_red {
echo -e "\033[31;1m"$1"\033[0m";
}
function usage {
echo "$0 -h shows usage"
echo "$0 -p deploy on pre-production"
echo "$0 -P deploy on production"
}
while getopts ":pPh" option
do
case "${option}" in
h)
usage
exit 0
;;
p)
COLOR="\033[33;1;7m"
DESTPATH=agrometinfo-preprod/
export HUGO_ENV=preproduction
SERVER=proxy
;;
P)
COLOR="\033[31;1;7m"
DESTPATH=""
export HUGO_ENV=production
SERVER=agrometinfo-prod
;;
*)
usage
exit 0
;;
esac
done
if [ $OPTIND -eq 1 ]; then
echo_bold_red "No argument were passed"
usage
exit 0
fi
DESTDIR=/var/www/html/$DESTPATH
echo -e "Are you sure to deploy AgroMetInfo doc on $COLOR$SERVER\033[0m:$COLOR$DESTDIR\033[0m ($COLOR$HUGO_ENV\033[0m)? (y/N)"
read -p "" -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Deployment is cancelled!";
exit 0;
fi
echo_bold_green "Check if $SERVER is available"
if ping -c1 -w3 $SERVER >/dev/null 2>&1
then
echo OK;
else
echo_bold_red "ping on $SERVER did not respond, check VPN or host name or IP";
exit 1;
fi
echo_bold_green "Check if lychee is installed"
if [ ! -f bin/lychee ]; then
LYCHEETGZ=lychee-v0.12.0-x86_64-unknown-linux-gnu.tar.gz
echo_bold_green "Getting Lychee to check help center"
mkdir -p ~/tmp bin
if [ ! -f ~/tmp/$LYCHEETGZ ]; then
wget "https://github.com/lycheeverse/lychee/releases/download/v0.12.0/$LYCHEETGZ" -O ~/tmp/$LYCHEETGZ
fi
tar zxf ~/tmp/$LYCHEETGZ -C bin
fi
echo_bold_green "Cleaning public/..."
rm -fr public/
echo_bold_green "Building site..."
hugo
echo_bold_green "- Launching Hugo server..."
hugo server &
sleep 1
echo_bold_green "- Checking links..."
bin/lychee http://localhost:1313/
if [ $? -ne 0 ]; then
echo_bold_red "Errors were found"
pkill hugo
exit 1
fi
rsync -rvz --delete --copy-links public/ $SERVER:$DESTDIR
echo_bold_green "- Killing hugo..."
pkill hugo
echo_bold_green "Deployment done."
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment