feat: Update deploy

This commit is contained in:
Simon 2022-12-08 16:09:06 +01:00
parent 14502b52eb
commit 3dda08d6ab
9 changed files with 52 additions and 153 deletions

View File

@ -1,3 +0,0 @@
**
!public
!.env

47
.drone.yml Normal file
View File

@ -0,0 +1,47 @@
---
# drone encrypt kosssi/slides.lamelio.fr $AWS_ACCESS_KEY_ID
kind: secret
name: PRODUCTION_AWS_ACCESS_KEY_ID
data: SzwoRUH77HIgApNSr4pIWzShKEqfrjDY6wm/KICad7+LoJAC/CB/l2KV9QB++RmbtT1Liy2C
---
# drone encrypt kosssi/slides.lamelio.fr $AWS_SECRET_ACCESS_KEY
kind: secret
name: PRODUCTION_AWS_SECRET_ACCESS_KEY
data: E7w1BA/oedq53fzYAemHlUP6UX84ejtnapAXt1M0d/O7z4iV4KjTzv2tr8dDZaomBSR3DiZtA4lx/irnzkhPyYHnWF1eF9MQSA70ijMP+Aq2cP/ED8mULYFkzBs=
---
kind: pipeline
type: docker
name: prod
platform:
os: linux
arch: arm64
steps:
- name: install submodule
image: drone/git
commands:
- git submodule update --init
- name: build website
image: klakegg/hugo:0.107.0-ext-debian-ci
commands:
- hugo --minify
- name: deploy
image: klakegg/hugo:0.107.0-ext-debian-ci
environment:
AWS_ACCESS_KEY_ID:
from_secret: PRODUCTION_AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY:
from_secret: PRODUCTION_AWS_SECRET_ACCESS_KEY
commands:
- hugo deploy
trigger:
event:
- push
branch:
- master

5
.env
View File

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

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
resources
public
backups
.hugo_build.lock

2
.gitmodules vendored
View File

@ -1,3 +1,3 @@
[submodule "themes/reveal-hugo"]
path = themes/reveal-hugo
url = git@github.com:dzello/reveal-hugo.git
url = https://github.com/dzello/reveal-hugo.git

View File

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

View File

@ -11,3 +11,6 @@ unsafe = true
baseName = "index"
mediaType = "text/html"
isHTML = true
[[deployment.targets]]
URL = "s3://slides.lamelio.fr?endpoint=http://10.20.20.10:3900&disableSSL=true&s3ForcePathStyle=true&region=garage"

View File

@ -1,42 +0,0 @@
version: "3.8"
volumes:
slides-log:
name: slides-log
slides-stats:
name: slides-stats
services:
slides-logs:
container_name: slides-logs
image: registry.weko.io/goaccess:1.4.6
restart: always
volumes:
- slides-log:/var/log/nginx
- slides-stats:/usr/share/nginx/html/stats
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
labels:
com.centurylinklabs.watchtower.enable: true
slides:
container_name: ${NAME}
image: registry.weko.io/slides
restart: always
volumes:
- slides-log:/var/log/nginx
- slides-stats:/usr/share/nginx/html/stats
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
labels:
traefik.enable: "true"
traefik.http.routers.slides.rule: "Host(`${URL}`)"
traefik.http.routers.slides.entrypoints: "web"
com.centurylinklabs.watchtower.enable: true
networks:
default:
external:
name: traefik

98
run
View File

@ -1,98 +0,0 @@
#!/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"