From 0e5dab8b78c3341068cbb05d23e83dfec3914559 Mon Sep 17 00:00:00 2001 From: Olivier Maury <Olivier.Maury@inrae.fr> Date: Mon, 25 Sep 2023 11:34:52 +0200 Subject: [PATCH] =?UTF-8?q?Cr=C3=A9er=20un=20script=20de=20d=C3=A9ploiemen?= =?UTF-8?q?t.=20refs=20agroclim/agrometinfo/www#1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/deploy.sh | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100755 bin/deploy.sh diff --git a/bin/deploy.sh b/bin/deploy.sh new file mode 100755 index 0000000..e53c114 --- /dev/null +++ b/bin/deploy.sh @@ -0,0 +1,88 @@ +#!/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." -- GitLab