services/registry/run

65 lines
1.7 KiB
Plaintext
Raw Permalink Normal View History

2020-06-01 09:42:30 +02:00
#!/bin/bash
set -eu
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
. $DIR/../help.sh
. $DIR/../postgres/run --only-source
registry_help() {
echo "./run htpasswd : 🔑 Génération du fichier htpasswd"
echo "./run build : 🏗 Construction de l'image custom"
echo "./run backup : 💾 Sauvegarde des images du registry"
}
registry_htpasswd() {
script_env
mkdir -p auth
echo "🔑 Génération du fichier htpasswd"
docker run --entrypoint htpasswd $REGISTRY_IMAGE -Bbn $REGISTRY_USER $REGISTRY_PASSWORD > auth/htpasswd
}
registry_build() {
script_env
echo "🏗 Construction de l'image custom"
DOCKER_FILE_DEFAULT=.
DOCKER_FILE=${DOCKER_FILE:-$DOCKER_FILE_DEFAULT}
docker build $DOCKER_FILE -t $REGISTRY_CUSTOM_IMAGE
}
registry_backup() {
script_env
echo "💾 Sauvegarde des images du registry"
REGISTRY_BACKUP_FILE_DEFAULT=`date +%Y%m%d_%H%M%S`_${REGISTRY_DOMAIN}.tar
REGISTRY_BACKUP_FILE=${REGISTRY_BACKUP_FILE:-$REGISTRY_BACKUP_FILE_DEFAULT}
2021-01-04 11:30:02 +01:00
docker run --rm --volumes-from registry -v /home/pi/backups/registry:/backup alpine:3.12.3 ash -c "cd /var/lib/registry && tar cvf /backup/$REGISTRY_BACKUP_FILE ."
2020-06-01 09:42:30 +02:00
}
registry_restore() {
script_env
2021-01-04 11:30:02 +01:00
docker run -it --rm -v $HOME/backups/${REGISTRY_DOMAIN}:/backup --volumes-from registry alpine:3.12.3 ash -c "cd /var/lib/registry && tar xvf /backup/${BACKUP_DATE}_${REGISTRY_DOMAIN}.tar --strip 1"
2020-06-01 09:42:30 +02:00
}
if [ $# -ge 1 ]; then
if [ "${1}" == "htpasswd" ]; then
script_start
registry_htpasswd
script_end
elif [ "${1}" == "build" ]; then
script_start
registry_build
script_end
elif [ "${1}" == "backup" ]; then
script_start
registry_backup
script_end
elif [ "${1}" != "--only-source" ]; then
registry_help
fi
else
registry_help
fi