2020-12-14 15:48:36 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# -e Exit immediately if a command exits with a non-zero status.
|
|
|
|
# -u Treat unset variables as an error when substituting.
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
START=`date +%s`
|
|
|
|
BACKUP_DATE=`date +%Y%m%d`
|
|
|
|
BACKUP_LOGS_FILENAME=${BACKUP_DATE}_${URL}_logs.tar
|
|
|
|
|
|
|
|
logs_backup() {
|
|
|
|
echo "📥 Sauvegarde les logs"
|
|
|
|
mkdir -p backups
|
|
|
|
ssh $DOCKER_CONTEXT mkdir -p backups/${URL}
|
|
|
|
docker --context $DOCKER_CONTEXT run -t --rm -v $HOME/backups/${URL}:/backup -v ${NAME}-log:/logs alpine:3.12.2 ash -c "cd /logs && tar cvf /backup/${BACKUP_LOGS_FILENAME} ."
|
|
|
|
ssh $DOCKER_CONTEXT "sudo chown kosssi:docker $HOME/backups/${URL}/${BACKUP_LOGS_FILENAME}"
|
|
|
|
scp $DOCKER_CONTEXT:$HOME/backups/${URL}/${BACKUP_LOGS_FILENAME} backups
|
|
|
|
}
|
|
|
|
|
|
|
|
logs_restore() {
|
|
|
|
echo "📤 Restaure les logs"
|
|
|
|
ssh $DOCKER_CONTEXT mkdir -p backups/${URL}
|
|
|
|
scp backups/${BACKUP_LOGS_FILENAME} $DOCKER_CONTEXT:$HOME/backups/${URL}/
|
|
|
|
docker --context $DOCKER_CONTEXT run -t --rm -v $HOME/backups/${URL}:/backup -v ${NAME}-log:/logs alpine:3.12.2 ash -c "cd /logs && tar xvf /backup/${BACKUP_LOGS_FILENAME} --strip 1"
|
|
|
|
}
|
|
|
|
|
|
|
|
stats() {
|
|
|
|
echo "🌠 Mise à jour de GoAccess"
|
|
|
|
docker --context $DOCKER_CONTEXT exec -it ${STATS_CONTAINER} ash /bin/stats.sh generate
|
|
|
|
}
|
|
|
|
|
|
|
|
install() {
|
|
|
|
echo "📦 Installation des dépendances 📦"
|
|
|
|
echo "----------------------------------"
|
|
|
|
echo
|
|
|
|
echo "- Récupération du theme"
|
|
|
|
git submodule update --init
|
|
|
|
echo "- Installation des dépendances node du theme"
|
|
|
|
cd themes/hugo-theme-lowtech && npm i
|
|
|
|
}
|
|
|
|
|
|
|
|
dev() {
|
|
|
|
echo "🚧 Lancement du serveur pour le développement"
|
|
|
|
hugo server -D
|
|
|
|
}
|
|
|
|
|
|
|
|
dev_prod() {
|
|
|
|
echo "🚧 Lancement du serveur pour le développement sans les brouillons"
|
|
|
|
hugo server
|
|
|
|
}
|
|
|
|
|
|
|
|
prod() {
|
|
|
|
echo
|
|
|
|
echo "🚀 Déploiement du site en mode production 🚀"
|
|
|
|
echo
|
|
|
|
rm -rf public
|
|
|
|
hugo --minify --environment production
|
|
|
|
node themes/hugo-theme-lowtech/scripts/typo
|
|
|
|
#DATE=`date +\"%Y0101\"` && find public -exec touch -d $DATE {} +
|
|
|
|
docker-compose --context $DOCKER_CONTEXT -f docker-compose.prod.yml up -d --build --force-recreate
|
|
|
|
}
|
|
|
|
|
|
|
|
staging() {
|
|
|
|
echo
|
|
|
|
echo "🚀 Déploiement du site en mode staging 🚀"
|
|
|
|
echo
|
|
|
|
rm -rf public
|
|
|
|
hugo --minify --environment staging
|
|
|
|
node themes/hugo-theme-lowtech/scripts/typo
|
|
|
|
#DATE=`date +\"%Y0101\"` && find public -exec touch -d $DATE {} +
|
|
|
|
docker-compose --context $DOCKER_CONTEXT -f docker-compose.staging.yml up -d --build --force-recreate
|
|
|
|
}
|
|
|
|
|
|
|
|
help_generic() {
|
2020-12-21 11:58:17 +01:00
|
|
|
echo
|
|
|
|
echo "💡 Aide 💡"
|
|
|
|
echo "----------"
|
|
|
|
echo
|
|
|
|
echo "Commandes :"
|
2020-12-14 15:48:36 +01:00
|
|
|
echo "- ./run install 📦 Installation des dépendances"
|
|
|
|
echo "- ./run dev 🚧 Lancement du serveur pour le développement"
|
|
|
|
echo "- ./run dev_prod 🚧 Lancement du serveur pour le développement sans les brouillons"
|
|
|
|
echo "- ./run prod 🚀 Déploiement du site en mode production"
|
|
|
|
echo "- ./run staging 🚀 Déploiement du site en mode staging"
|
|
|
|
echo "- ./run logs_backup 📥 Sauvegarde les logs"
|
|
|
|
echo "- ./run logs_restore 📤 Restaure les logs"
|
|
|
|
echo "- ./run stats 🌠 Mise à jour de GoAccess"
|
|
|
|
}
|
|
|
|
|
|
|
|
end() {
|
|
|
|
END=`date +%s`
|
|
|
|
echo
|
|
|
|
echo "✨ Done in $((END-START))s"
|
|
|
|
echo
|
|
|
|
}
|