Compare commits
No commits in common. "registry-v2" and "registry" have entirely different histories.
registry-v
...
registry
2
Dockerfile
Normal file
2
Dockerfile
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
FROM nginx:1.19
|
||||||
|
COPY index.html /usr/share/nginx/html/index.html
|
38
README.md
38
README.md
@ -8,7 +8,7 @@ accessible via une UI. Votre Docker Hub!
|
|||||||
Ici, remplacer testuser et testpassword par le nom d'utilisateur et le mot de passe désiré.
|
Ici, remplacer testuser et testpassword par le nom d'utilisateur et le mot de passe désiré.
|
||||||
```sh
|
```sh
|
||||||
sudo apt-get install apache2-utils
|
sudo apt-get install apache2-utils
|
||||||
htpasswd -Bbn testuser testpassword > registry-config/htpasswd
|
htpasswd -Bbn testuser testpassword > auth/htpasswd
|
||||||
```
|
```
|
||||||
|
|
||||||
### LANCER LA STACK
|
### LANCER LA STACK
|
||||||
@ -31,3 +31,39 @@ Entrer l'utilisateur et le mot de passe créés plus tôt, puis:
|
|||||||
docker tag localhost/mon_image:tag
|
docker tag localhost/mon_image:tag
|
||||||
docker push localhost/mon_image:tag
|
docker push localhost/mon_image:tag
|
||||||
```
|
```
|
||||||
|
### MAINTENACE REGISTRE:
|
||||||
|
|
||||||
|
Dans le dossier utils du projet, vous trouverez des scripts de maintenance de votre registre. Ils nécessitent des champs à renseigner tel que l'adresse du registre ou le chemin de stockage de votre volume contenant les images du registre.
|
||||||
|
|
||||||
|
#### STACK-BACKUP-REGISTRY
|
||||||
|
|
||||||
|
1) Renseigner lURL du registre
|
||||||
|
|
||||||
|
2) Créer un crontab pour sauvegarde quotidienne:
|
||||||
|
```bash
|
||||||
|
crontab -e
|
||||||
|
```
|
||||||
|
|
||||||
|
3) Configurer l'heure de sauvegarde (ici, à 00h00 chaque jours):
|
||||||
|
```bash
|
||||||
|
0 0 * * * /path/docker/utils/stack-backup-registry.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
#### REGISTRY-IMAGE-CLEANING
|
||||||
|
|
||||||
|
1) Copier regctl:
|
||||||
|
```bash
|
||||||
|
sudo mv utils/regctl /usr/bin/
|
||||||
|
```
|
||||||
|
|
||||||
|
2) Renseigner /path/docker/utils/registry-image-cleaning.sh
|
||||||
|
|
||||||
|
3) Créer une crontab:
|
||||||
|
```bash
|
||||||
|
crontab -e
|
||||||
|
```
|
||||||
|
|
||||||
|
4) A la fin du fichier, y placer la fréquence de la crontab ainsi que le chemin du script:
|
||||||
|
```bash
|
||||||
|
0 0 * * * /path/docker/utils/registry-image-cleaning.sh
|
||||||
|
```
|
||||||
|
0
auth/htpasswd
Normal file
0
auth/htpasswd
Normal file
@ -1,41 +1,34 @@
|
|||||||
version: '3.8'
|
version: '2.0'
|
||||||
|
|
||||||
services:
|
services:
|
||||||
registry-ui:
|
|
||||||
image: joxit/docker-registry-ui:main
|
# REGISTRY
|
||||||
container_name: registry-ui
|
registry:
|
||||||
restart: always
|
image: registry:2.6.2
|
||||||
|
container_name: registry
|
||||||
ports:
|
ports:
|
||||||
- 8087:80
|
- "5000:5000"
|
||||||
environment:
|
environment:
|
||||||
- SINGLE_REGISTRY=true
|
REGISTRY_AUTH: htpasswd
|
||||||
- REGISTRY_TITLE=Docker Registry UI
|
REGISTRY_AUTH_HTPASSWD_REALM: Registry Realm
|
||||||
- DELETE_IMAGES=true
|
REGISTRY_AUTH_HTPASSWD_PATH: /auth/htpasswd
|
||||||
- SHOW_CONTENT_DIGEST=true
|
volumes:
|
||||||
- NGINX_PROXY_PASS_URL=http://registry:5000
|
- ./auth:/auth
|
||||||
- SHOW_CATALOG_NB_TAGS=true
|
- ./registry-data:/var/lib/registry
|
||||||
- CATALOG_MIN_BRANCHES=1
|
- ./registry-config:/etc/docker/registry
|
||||||
- CATALOG_MAX_BRANCHES=1
|
|
||||||
- TAGLIST_PAGE_SIZE=100
|
|
||||||
- REGISTRY_SECURED=false
|
|
||||||
- CATALOG_ELEMENTS_LIMIT=1000
|
|
||||||
networks:
|
networks:
|
||||||
- registry-ui-net
|
- registry-ui-net
|
||||||
|
|
||||||
registry:
|
# UI
|
||||||
image: registry:2.8.2
|
ui:
|
||||||
container_name: registry
|
image: joxit/docker-registry-ui:1.5-static
|
||||||
restart: always
|
container_name: ui_registry
|
||||||
|
ports:
|
||||||
|
- 8087:80
|
||||||
environment:
|
environment:
|
||||||
REGISTRY_HTTP_HEADERS_Access-Control-Origin: '[http://registry.example.com]'
|
- REGISTRY_TITLE=DockerRegistry
|
||||||
REGISTRY_HTTP_HEADERS_Access-Control-Allow-Methods: '[HEAD,GET,OPTIONS,DELETE]'
|
- REGISTRY_URL=http://registry:5000
|
||||||
REGISTRY_HTTP_HEADERS_Access-Control-Credentials: '[true]'
|
depends_on:
|
||||||
REGISTRY_HTTP_HEADERS_Access-Control-Allow-Headers: '[Authorization,Accept,Cache-Control]'
|
- registry
|
||||||
REGISTRY_HTTP_HEADERS_Access-Control-Expose-Headers: '[Docker-Content-Digest]'
|
|
||||||
REGISTRY_STORAGE_DELETE_ENABLED: 'true'
|
|
||||||
volumes:
|
|
||||||
- ./registry/data:/var/lib/registry
|
|
||||||
- ./registry/config:/etc/docker/registry
|
|
||||||
networks:
|
networks:
|
||||||
- registry-ui-net
|
- registry-ui-net
|
||||||
|
|
||||||
|
5
index.html
Normal file
5
index.html
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<html>
|
||||||
|
<title>Hello Docker</title>
|
||||||
|
<p>Hello le Garage numerique!</p>
|
||||||
|
</html>
|
||||||
|
|
@ -1,39 +0,0 @@
|
|||||||
version: 0.1
|
|
||||||
log:
|
|
||||||
fields:
|
|
||||||
service: registry
|
|
||||||
storage:
|
|
||||||
delete:
|
|
||||||
enabled: true
|
|
||||||
cache:
|
|
||||||
blobdescriptor: inmemory
|
|
||||||
filesystem:
|
|
||||||
rootdirectory: /var/lib/registry
|
|
||||||
maintenance:
|
|
||||||
uploadpurging:
|
|
||||||
enabled: true
|
|
||||||
age: 168h
|
|
||||||
interval: 24h
|
|
||||||
dryrun: false
|
|
||||||
readonly:
|
|
||||||
enabled: false
|
|
||||||
http:
|
|
||||||
addr: :5000
|
|
||||||
headers:
|
|
||||||
X-Content-Type-Options: [nosniff]
|
|
||||||
Access-Control-Allow-Origin: ['http://127.0.0.1:8000']
|
|
||||||
Access-Control-Allow-Credentials: [true]
|
|
||||||
Access-Control-Allow-Methods: ['HEAD', 'GET', 'OPTIONS', 'DELETE']
|
|
||||||
Access-Control-Allow-Headers: ['Authorization', 'Accept', 'Cache-Control']
|
|
||||||
Access-Control-Max-Age: [1728000]
|
|
||||||
Access-Control-Allow-Credentials: [true]
|
|
||||||
Access-Control-Expose-Headers: ['Docker-Content-Digest']
|
|
||||||
auth:
|
|
||||||
htpasswd:
|
|
||||||
realm: basic-realm
|
|
||||||
path: /etc/docker/registry/htpasswd
|
|
||||||
health:
|
|
||||||
storagedriver:
|
|
||||||
enabled: true
|
|
||||||
interval: 10s
|
|
||||||
threshold: 3
|
|
BIN
utils/regctl
Executable file
BIN
utils/regctl
Executable file
Binary file not shown.
63
utils/registry-image-cleaning.sh
Executable file
63
utils/registry-image-cleaning.sh
Executable file
@ -0,0 +1,63 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
#//// GREG POUR LE GARAGE NUMERIQUE \\\\#
|
||||||
|
|
||||||
|
# Ce script fonctionne avec le docker-compose.yml du projet https://gitlab.com/greglebreton/docker.git -> branche docker-registry
|
||||||
|
# Ce script maintient un registre privée accueillant des sauvegardes de conteneurs quotidiennement de manière automatisée.
|
||||||
|
# Le delta est exprimé en jour et est effectué par comparaison entre la date du jour et la date d'enregistrement de l'image.
|
||||||
|
|
||||||
|
date=$(date +"%Y-%m-%d")
|
||||||
|
|
||||||
|
# A RENSEIGNER
|
||||||
|
## chemin vers le dossier docker cloné sans le dernier /
|
||||||
|
registryPath=""
|
||||||
|
## exemple monRegistreDocker.monDomaine.com
|
||||||
|
dockerRegistryAdress=""
|
||||||
|
## nombre de jours de sauvegarde à conserver par rapport à la date du jour (à ajuster si les sauvegardes ne sont pas quotidiennes)
|
||||||
|
max=""
|
||||||
|
## registres à ignorer
|
||||||
|
exceptions=( "container1" "container2" )
|
||||||
|
|
||||||
|
###################################################################################################
|
||||||
|
|
||||||
|
echo "docker clean start..."
|
||||||
|
|
||||||
|
## DOCKER LIST IMG REGISTRY
|
||||||
|
registry=$(ls $registryPath/registry-data/docker/registry/v2/repositories/)
|
||||||
|
|
||||||
|
## DOCKER LIST TAGS FOR EACH REPO
|
||||||
|
for repo in $registry
|
||||||
|
do
|
||||||
|
for ex in ${exceptions[@]}
|
||||||
|
do
|
||||||
|
if [ $repo == $ex ]
|
||||||
|
then
|
||||||
|
break
|
||||||
|
else
|
||||||
|
tags=$(ls $registryPath/registry-data/docker/registry/v2/repositories/$repo/_manifests/tags/)
|
||||||
|
|
||||||
|
for tag in $tags
|
||||||
|
do
|
||||||
|
datebackup=$(stat -c '%w' $registryPath/registry-data/docker/registry/v2/repositories/$repo/_manifests/tags/$tag)
|
||||||
|
gooddatebackup="${datebackup:0:10}"
|
||||||
|
|
||||||
|
echo $gooddatebackup
|
||||||
|
|
||||||
|
if [ ${tag:0:2} == "01" ]
|
||||||
|
then
|
||||||
|
break
|
||||||
|
else
|
||||||
|
let delta=($(date +%s -d $date)-$(date +%s -d $gooddatebackup))/86400
|
||||||
|
|
||||||
|
if [ $delta -gt $max ]
|
||||||
|
then
|
||||||
|
echo "$dockerRegistryAdress/$repo:$tag deleted!"
|
||||||
|
regctl tag rm $dockerRegistryAdress/$repo:$tag
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "registre nettoyé"
|
89
utils/stack-backup-registry.sh
Executable file
89
utils/stack-backup-registry.sh
Executable file
@ -0,0 +1,89 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
#//// GREG POUR LE GARAGE NUMERIQUE \\\\#
|
||||||
|
|
||||||
|
# Script automatisant le push de conteneur vers un registre privé de backups ainsi que les volumes correspondants.
|
||||||
|
# Le docker login au registre doit être effectué au moins une fois manuellement.
|
||||||
|
# Configurer l'adresse du registre ainsi que les informations sur le serveur de backups
|
||||||
|
# Les volumes et labels sont archivés et transférés par ssh vers le serveur de backup une fois par mois (le 1er).
|
||||||
|
|
||||||
|
############################## CONFIG ##############################
|
||||||
|
|
||||||
|
date=`date +%d-%m`
|
||||||
|
# dockerregistry="monregistre.mondomaine.com"
|
||||||
|
dockerregistry=""
|
||||||
|
# sshHost="user@server-IP"
|
||||||
|
sshHost=""
|
||||||
|
# sshPort=9999
|
||||||
|
sshPort=
|
||||||
|
backupFolder="~/docker-volumes-backup/"
|
||||||
|
# exceptions=( "container1" "container2")
|
||||||
|
#exceptions=( "" )
|
||||||
|
|
||||||
|
############################## CONTAINERS BACKUP ##############################
|
||||||
|
|
||||||
|
# LISTING DES CONTAINERS
|
||||||
|
stack=$(docker ps -aq)
|
||||||
|
|
||||||
|
for container in $stack
|
||||||
|
do
|
||||||
|
echo "backup du conteneur $container"
|
||||||
|
# GET CONTAINER NAME
|
||||||
|
docker inspect --format='{{.Name}}' $container > containers.txt
|
||||||
|
containerName=$(sed 's/[/]*//' containers.txt)
|
||||||
|
|
||||||
|
for exception in ${exceptions[@]}
|
||||||
|
do
|
||||||
|
if [ $container == $exception ]
|
||||||
|
then
|
||||||
|
break
|
||||||
|
else
|
||||||
|
# COMMIT AND PUSH TO REGSTRY
|
||||||
|
docker container commit $container $dockerregistry$containerName-backup:$date
|
||||||
|
docker push $dockerregistry$containerName-backup:$date
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
done
|
||||||
|
|
||||||
|
# CLEANING
|
||||||
|
rm -rf containers.txt
|
||||||
|
|
||||||
|
############################## VOLUMES & LABELS BACKUP ##############################
|
||||||
|
|
||||||
|
if [ ${date:0:02} == "01" ]
|
||||||
|
then
|
||||||
|
# LISTING DES VOLUMES
|
||||||
|
volumes=$(docker volume ls -q)
|
||||||
|
|
||||||
|
for volume in $volumes
|
||||||
|
do
|
||||||
|
echo "backup du volume $volume"
|
||||||
|
|
||||||
|
# GET CONTAINER ID
|
||||||
|
containerId=$(docker ps -a -q --filter volume=$volume)
|
||||||
|
# GET CONTAINER NAME
|
||||||
|
docker inspect --format='{{.Name}}' $containerId > volumes.txt
|
||||||
|
container=$(sed 's/[/]*//' volumes.txt)
|
||||||
|
|
||||||
|
# STOP THE CONTAINER (FOR VOLUMES INTEGRITY)
|
||||||
|
docker stop $container
|
||||||
|
# BACKUP VOLUME IN ARCHIVE
|
||||||
|
docker run -v $volume:/volume -v $(pwd)/backup:/backup --rm loomchild/volume-backup backup volumes/$container-volume:$date
|
||||||
|
# BACKUP DOCKER VOLUMES LABELS
|
||||||
|
docker inspect $volume -f "{{json .Labels}}" > backup/labels/$container-labels.json
|
||||||
|
# RESTART THE CONTAINER
|
||||||
|
docker start $container
|
||||||
|
|
||||||
|
# CLEANING
|
||||||
|
rm -rf volumes.txt
|
||||||
|
done
|
||||||
|
|
||||||
|
# MV VOLUMES & LABELS BACKUP TO BACKUP HOST
|
||||||
|
scp -r -P $sshPort $(pwd)/backup/* $sshHost:$backupFolder
|
||||||
|
# CLEANING
|
||||||
|
rm -rf containers.txt; rm -rf $(pwd)/backup/volumes/*; rm -rf $(pwd)/backup/labels/*
|
||||||
|
|
||||||
|
echo "copie des archives de volumes vers le serveur de backup ok"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "backup des containers terminée"
|
Loading…
x
Reference in New Issue
Block a user