Ajout des services Traefik, PostgreSQL et Gitea

This commit is contained in:
2020-05-15 23:34:50 +02:00
parent c28d762910
commit 9915693747
16 changed files with 409 additions and 0 deletions

6
postgres/.env Normal file
View File

@ -0,0 +1,6 @@
POSTGRES_IMAGE=postgres:12.2-alpine
POSTGRES_USER=user-example
POSTGRES_PASSWORD=password-example
POSTGRES_DB=postgres-database-name-example
POSTGRES_CONTAINER_NAME=postgres
POSTGRES_VOLUME_NAME=postgres

35
postgres/README.md Normal file
View File

@ -0,0 +1,35 @@
# PostgreSQL
> PostgreSQL est un système de gestion de base de données relationnelle et objet
>
> <cite>[Wikipédia][wikipedia]</cite>
## Configuration
Les variables contenu dans `.env` permettent de changer :
- `POSTGRES_IMAGE` : la version
- `POSTGRES_USER` : le nom d'utilisateur
- `POSTGRES_PASSWORD` : le mot de passe
- `POSTGRES_DB` : le nom de la base de données
- `POSTGRES_CONTAINER_NAME` : le nom du conteneur
- `POSTGRES_VOLUME_NAME` : le nom du volume
## Commandes
```sh
$ ./run
./run backup : Lancer la sauvegarde d'une base de données
./run restore : Restore une sauvegarde
```
## Liens
- [Site Officiel][site]
- [Code source][source]
- [Docker Hub][dockerhub]
[wikipedia]: https://fr.wikipedia.org/wiki/PostgreSQL
[site]: https://www.postgresql.org/
[source]: https://git.postgresql.org/gitweb/?p=postgresql.git
[dockerhub]: https://hub.docker.com/_/postgres

View File

@ -0,0 +1,19 @@
version: "3.8"
volumes:
postgres:
name: ${POSTGRES_VOLUME_NAME}
services:
postgres:
container_name: ${POSTGRES_CONTAINER_NAME}
image: ${POSTGRES_IMAGE}
restart: always
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
volumes:
- postgres:/var/lib/postgresql/data
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro

47
postgres/run Executable file
View File

@ -0,0 +1,47 @@
#!/bin/bash
set -eu
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
. $DIR/../help.sh
postgres_help() {
echo "./run backup : Lancer la sauvegarde d'une base de données"
echo "./run restore : Restore une sauvegarde"
}
postgres_backup() {
script_env
backup_folder_create
POSTGRES_BACKUP_FILE_DEFAULT=backups/`date +%Y%m%d_%H%M%S`_$POSTGRES_DB.sql
POSTGRES_BACKUP_FILE=${POSTGRES_BACKUP_FILE:-$POSTGRES_BACKUP_FILE_DEFAULT}
echo "🏁 Start backup PostgreSQL database '$POSTGRES_DB' in '$POSTGRES_BACKUP_FILE'"
docker exec -i $POSTGRES_CONTAINER_NAME pg_dump $POSTGRES_DB -U $POSTGRES_USER > $POSTGRES_BACKUP_FILE
}
postgres_restore() {
script_env
echo "🏁 Start restore PostgreSQL database '$POSTGRES_DB' from '$POSTGRES_BACKUP_FILE'"
docker restart $POSTGRES_CONTAINER_NAME
docker exec $POSTGRES_CONTAINER_NAME psql template1 -U $POSTGRES_USER -c "DROP DATABASE $POSTGRES_DB"
docker exec $POSTGRES_CONTAINER_NAME psql template1 -U $POSTGRES_USER -c "CREATE DATABASE $POSTGRES_DB with owner $POSTGRES_USER"
cat $POSTGRES_BACKUP_FILE | docker exec -i $POSTGRES_CONTAINER_NAME psql -U $POSTGRES_USER -d $POSTGRES_DB
}
if [ $# -ge 1 ]; then
if [ "${1}" == "backup" ]; then
script_start
postgres_backup
script_end
elif [ "${1}" == "restore" ]; then
script_start
postgres_restore
script_end
elif [ "${1}" != "--only-source" ]; then
postgres_help
fi
else
postgres_help
fi