Update config

This commit is contained in:
Simon 2020-10-19 12:19:49 +02:00
parent 85a9a24085
commit ee2ed740f2
6 changed files with 59 additions and 19 deletions

5
.env Normal file
View File

@ -0,0 +1,5 @@
DOCKER_HOST=ssh://kosssi@vert:42422
NAME=slides
URL=slides.lamelio.fr
LOG_PATH=/var/log/nginx/access.log

2
.gitignore vendored
View File

@ -1,3 +1,3 @@
resources resources
public public
.env backups

View File

@ -1,4 +1,4 @@
FROM registry.lamelio.fr/nginx-lowtech:0.0.5 FROM registry.weko.io/nginx-lowtech:0.0.5
# Copie des sources du site # Copie des sources du site
COPY public /usr/share/nginx/html COPY public /usr/share/nginx/html

View File

@ -3,7 +3,7 @@
## Install ## Install
``` ```
git clone https://gitea.lamelio.fr/kosssi/slides.lamelio.fr.git --recurse-submodules git clone https://git.weko.io/kosssi/slides.lamelio.fr.git --recurse-submodules
``` ```
## Dev ## Dev

View File

@ -1,4 +1,4 @@
version: "3.7" version: "3.8"
volumes: volumes:
slides-log: slides-log:
@ -9,35 +9,30 @@ volumes:
services: services:
slides-logs: slides-logs:
container_name: slides-logs container_name: slides-logs
image: registry.lamelio.fr/goaccess image: registry.weko.io/goaccess
restart: always restart: always
volumes: volumes:
- slides-log:/var/log/nginx - slides-log:/var/log/nginx
- slides-stats:/usr/share/nginx/html/stats - slides-stats:/usr/share/nginx/html/stats
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
labels: labels:
com.centurylinklabs.watchtower.enable: true com.centurylinklabs.watchtower.enable: true
slides: slides:
container_name: ${NAME} container_name: ${NAME}
image: registry.lamelio.fr/slides image: registry.weko.io/slides
restart: always restart: always
environment:
- TZ=${TIMEZONE}
volumes: volumes:
- slides-log:/var/log/nginx - slides-log:/var/log/nginx
- slides-stats:/usr/share/nginx/html/stats - slides-stats:/usr/share/nginx/html/stats
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
labels: labels:
traefik.enable: "true" traefik.enable: "true"
traefik.http.routers.slides.rule: "Host(`${URL}`)" traefik.http.routers.slides.rule: "Host(`${URL}`)"
traefik.http.routers.slides.entrypoints: "websecure" traefik.http.routers.slides.entrypoints: "web"
traefik.http.routers.slides.tls.certResolver: "letsencrypt"
# Redirect https://www to https://
traefik.http.routers.slides-redirect-www.rule: "Host(`www.${URL}`)"
traefik.http.routers.slides-redirect-www.entrypoints: "websecure"
traefik.http.routers.slides-redirect-www.tls.certResolver: "letsencrypt"
traefik.http.routers.slides-redirect-www.middlewares: "redirect-www@docker"
com.centurylinklabs.watchtower.enable: true com.centurylinklabs.watchtower.enable: true

46
run
View File

@ -5,8 +5,28 @@
set -eu set -eu
START=`date +%s` START=`date +%s`
DOCKER_CONTEXT=vert
BACKUP_DATE=`date +%Y%m%d`
PROJECT=slides 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() { build_production() {
echo "👷 Construction du site en mode production" echo "👷 Construction du site en mode production"
rm -rf public rm -rf public
@ -23,6 +43,9 @@ help() {
echo "- ./run build 👷 Construction du site en mode production" echo "- ./run build 👷 Construction du site en mode production"
echo "- ./run docker 🐳 Création de l'image Docker" echo "- ./run docker 🐳 Création de l'image Docker"
echo "- ./run deploy 🚀 Déploiement avec docker-compose" 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 echo
} }
@ -32,7 +55,24 @@ install() {
} }
if [ $# -ge 1 ]; then if [ $# -ge 1 ]; then
if [ $1 == "dev" ]; 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" echo "🚧 Lancement du serveur pour le développement"
hugo server -D hugo server -D
elif [ $1 == "build" ]; then elif [ $1 == "build" ]; then
@ -41,8 +81,8 @@ if [ $# -ge 1 ]; then
echo "🐳 Création de l'image Docker" echo "🐳 Création de l'image Docker"
echo echo
docker build . -t kosssi/$PROJECT docker build . -t kosssi/$PROJECT
docker tag kosssi/$PROJECT registry.lamelio.fr/$PROJECT docker tag kosssi/$PROJECT registry.weko.io/$PROJECT
docker push registry.lamelio.fr/$PROJECT docker push registry.weko.io/$PROJECT
elif [ $1 == "deploy" ]; then elif [ $1 == "deploy" ]; then
echo "🚀 Déploiement avec docker-compose" echo "🚀 Déploiement avec docker-compose"
echo echo