Slides/run

99 lines
2.9 KiB
Bash
Executable File

#!/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`
DOCKER_CONTEXT=vert
BACKUP_DATE=`date +%Y%m%d`
PROJECT=slides
logs_backup() {
mkdir -p backups
ssh $DOCKER_CONTEXT mkdir -p backups/slides
docker --context $DOCKER_CONTEXT run -t --rm -v $HOME/backups/slides:/backup -v slides-log:/logs alpine:3.11.6 ash -c "cd /logs && tar cvf /backup/${BACKUP_DATE}_logs.tar ."
ssh $DOCKER_CONTEXT "sudo chown kosssi:docker $HOME/backups/slides/${BACKUP_DATE}_logs.tar"
scp $DOCKER_CONTEXT:$HOME/backups/slides/${BACKUP_DATE}_logs.tar backups
}
logs_restore() {
ssh $DOCKER_CONTEXT mkdir -p backups/slides
scp backups/${BACKUP_DATE}_logs.tar $DOCKER_CONTEXT:$HOME/backups/slides/
docker --context $DOCKER_CONTEXT run -t --rm -v $HOME/backups/slides:/backup -v slides-log:/logs alpine:3.11.6 ash -c "cd /logs && tar xvf /backup/${BACKUP_DATE}_logs.tar --strip 1"
}
logs_update() {
docker --context $DOCKER_CONTEXT exec -it slides-logs ash /bin/stats.sh generate
}
build_production() {
echo "👷 Construction du site en mode production"
rm -rf public
hugo --environment production --minify
}
help() {
echo "💡 Aide"
echo "-------"
echo
echo "Commandes :"
echo "- ./run install 📦 Installation des dépendances"
echo "- ./run dev 🚧 Lancement du serveur pour le développement"
echo "- ./run build 👷 Construction du site en mode production"
echo "- ./run docker 🐳 Création de l'image Docker"
echo "- ./run deploy 🚀 Déploiement avec docker-compose"
echo "- ./run logs backup 📥 Sauvegarde les logs"
echo "- ./run logs restore 📤 Restore les logs"
echo "- ./run logs update 🌠 Mise à jour de GoAccess"
echo
}
install() {
echo "📦 Installation des dépendances"
git submodule update --init
}
if [ $# -ge 1 ]; then
if [ $1 == "logs" ]; then
if [ $# -ge 2 ]; then
if [ $2 == "backup" ]; then
echo "📥 Sauvegarde les logs"
logs_backup
elif [ $2 == "restore" ]; then
echo "📤 Restore les logs"
logs_restore
elif [ $2 == "update" ]; then
echo "🌠 Mise à jour de GoAccess"
logs_update
else
help
fi
else
help
fi
elif [ $1 == "dev" ]; then
echo "🚧 Lancement du serveur pour le développement"
hugo server -D
elif [ $1 == "build" ]; then
build_production
elif [ $1 == "docker" ]; then
echo "🐳 Création de l'image Docker"
echo
docker build . -t kosssi/$PROJECT
docker tag kosssi/$PROJECT registry.weko.io/$PROJECT
docker push registry.weko.io/$PROJECT
elif [ $1 == "deploy" ]; then
echo "🚀 Déploiement avec docker-compose"
echo
docker-compose up -d
elif [ $1 == "install" ]; then
install
fi
else
help
fi
END=`date +%s`
echo "✨ Done in $((END-START))s"