Pour faire suite à l’article précédent sur Gitlab, voici comment installer Redmine avec Docker
Dans ce tuto, le port 3000 du conteneur est mappé sur le ports 4432.
Cela veux dire que le reverse proxy de Nginx installé sur l’host devra « écouter » sur le port 4432.
1 – Configuration du conteneur Docker
1.1 – Création du conteneur
Premièrement, il faut récupérer la dernière image Docker de Redmine.
#https://hub.docker.com/_/redmine/ docker pull redmine
1.2 – docker-compose
On créé un fichier docker-compose.yml avec le contenu suivant:
version: '2' services: redmine: image: redmine container_name: 'redmine.example.com' volumes: - "/srv/redmine/files:/usr/src/redmine/files" - "/srv/redmine/config/configuration.yml:/usr/src/redmine/config/configuration.yml" ports: - 4432:3000 environment: REDMINE_DB_MYSQL: mariadb REDMINE_DB_PASSWORD: password depends_on: - mariadb restart: always mariadb: image: mariadb container_name: mariadb environment: MYSQL_ROOT_PASSWORD: password MYSQL_DATABASE: redmine restart: always volumes: - "/srv/mariadb:/var/lib/mysql"
Pour ajouter un conteneur phpmyadmin lié à mariadb ajoutez ceci au fichier docker-compose.yml
phpmyadmin: image: nazarpc/phpmyadmin environment: MYSQL_ROOT_PASSWORD: password MYSQL_DATABASE: redmine restart: always ports: - 1234:80 links: - mariadb:mysql
On peut ensuite accéder à phpmyadmin sur cette URL: http://127.0.0.1:1234
Lancement du conteneur
docker-compose up -d
2 – Configuration SMTP
Dans le fichier docker-compose.yml le fichier de configuration est monté sur /srv/redmine/config/configuration.yml .
Ce fichier contient la configuration SMTP.
Exemple de configuration avec Gmail:
email_delivery: delivery_method: :smtp smtp_settings: enable_starttls_auto: "true" address: "smtp.gmail.com" port: 587 domain: "smtp.gmail.com" authentication: :plain user_name: "USER@gmail.com" password: "PASSWORD"
Une fois la configuration effectuée, il faut redémarrer le conteneur:
docker-compose stop docker-compose up -d
3 – Configuration du reverse proxy sur la machine host
Dans ce tutoriel nous allons utiliser Nginx pour mettre en place un reverse proxy mais vous pouvez également utiliser Apache.
Installation de Nginx
apt-get install nginx
Configuration du proxy
cd /etc/nginx/ vim sites-available/redmine.example.com
Contenu de /etc/nginx/sites-available/redmine.example.com
server { listen *:443 ssl http2; ## Strong SSL Security ## https://raymii.org/s/tutorials/Strong_SSL_Security_On_nginx.html & https://cipherli.st/ ssl on; ssl_certificate /srv/redmine/ssl/redmine.example.com.crt; ssl_certificate_key /srv/redmine/ssl/redmine.example.com.key; ssl_ciphers 'ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4'; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; ssl_session_cache builtin:1000 shared:SSL:10m; ssl_session_timeout 5m; server_tokens off; ## Don't show the nginx version number, a security best practice proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto https; server_name redmine.example.com; access_log /var/log/redmine.example.com.access.log; error_log /var/log/redmine.example.com.nginx_error.log debug; location / { proxy_pass http://127.0.0.1:4432/; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /var/www/nginx-default; } }
Pour terminer:
ln -s /etc/nginx/sites-available/redmine.example.com sites-enabled/redmine.example.com /etc/init.d/nginx restart
4 – Première connexion
Rendez vous sur https://redmine.example.com/ pour la première authentification.
Les accès par défaut sont admin/admin.
Rendez-vous sur https://redmine.example.com/settings pour configurer le hostname et le protocol https et sur https://redmine.example.com/settings?tab=authentication pour empêcher la création de compte.
BONUS: Backup/Restore
Pour faire une backup de Redmine, il suffit d’exporter la base « redmine » de mariadb et de faire une archive du dossier /srv/redmine/files qui contient les fichiers uploadés.
Pour exporter la base redmine de l’instance mariadb:
docker exec mariadb sh -c 'exec mysqldump -uroot -p"password" redmine' > /chemin/sur/host/redmine.sql
Script bash pour la création automatique d’une archive du dossier /srv/redmine/file:
#!/bin/bash # Number of backups to keep NBACKUPS_TO_KEEP=6 # Also keep backups of the first day of each month KEEP_FIRST_DAY_MONTH=true REDMINE_VOLUMES_PATH="/srv/redmine" BACKUP_PATH="/path/to/backups" EMAIL_DEST="admin@redmine.example.com" EMAIL_SUBJECT="redmine.example.com - backup" TODAY=$(date) HOST=$(hostname) NEWLINE_CHAR="\n" if [ ! -d $BACKUP_PATH/files ]; then mkdir -p $BACKUP_PATH/files; fi echo "----------------" MESSAGE_TO_SEND="----------------" echo "$TODAY - $HOST" MESSAGE_TO_SEND=$MESSAGE_TO_SEND"${NEWLINE_CHAR}$TODAY - $HOST" echo "Backing up redmine into $BACKUP_PATH" MESSAGE_TO_SEND=$MESSAGE_TO_SEND${NEWLINE_CHAR}"backing up redmine into $BACKUP_PATH" echo "----------------" MESSAGE_TO_SEND=$MESSAGE_TO_SEND${NEWLINE_CHAR}"----------------" echo "" LINE="creating /usr/src/redmine/files archive.." MESSAGE_TO_SEND=$MESSAGE_TO_SEND${NEWLINE_CHAR}$LINE echo $LINE umask 0077;tar cfz $BACKUP_PATH/files/$(date "+files-redmine-%s.tgz") -C / $REDMINE_VOLUMES_PATH/files -P echo "done" MESSAGE_TO_SEND=$MESSAGE_TO_SEND${NEWLINE_CHAR}"done"${NEWLINE_CHAR} echo "" MESSAGE_TO_SEND=$MESSAGE_TO_SEND${NEWLINE_CHAR}"Removing old backups" echo "Removing old backups" backups=( $( ls $BACKUP_PATH/files/ | sort -n -r -t _ -k 2 ) ); i=1; for filename in "${backups[@]}";do if [ $i -gt $NBACKUPS_TO_KEEP ] then if [ $KEEP_FIRST_DAY_MONTH == true ] then day=$( date -d @$( echo $filename | sed -e "s/files-redmine-//g" | sed -e "s/.tgz//g") '+%d' ) if [ ! $day == 01 ] then rm "$BACKUP_PATH/files/$filename" LINE="removed $filename" MESSAGE_TO_SEND=$MESSAGE_TO_SEND${NEWLINE_CHAR}$LINE echo $LINE else LINE="keeping $filename" MESSAGE_TO_SEND=$MESSAGE_TO_SEND${NEWLINE_CHAR}$LINE echo $LINE fi else rm "$BACKUP_PATH/files/$filename" LINE="removed $filename" MESSAGE_TO_SEND=$MESSAGE_TO_SEND${NEWLINE_CHAR}$LINE echo $LINE fi fi i=$[i+1] done MESSAGE_TO_SEND=$MESSAGE_TO_SEND${NEWLINE_CHAR}"done" echo "done" echo "----------------"; MESSAGE_TO_SEND=$MESSAGE_TO_SEND${NEWLINE_CHAR}"----------------" echo -e $MESSAGE_TO_SEND | mail -s "$EMAIL_SUBJECT" $EMAIL_DEST
Pour restaurer, extraire l’archive des fichiers dans /srv/redmine/files et importer /chemin/sur/host/redmine.sql dans l’instance mariadb.
sources:
http://www.redmine.org/boards/2/topics/14177
https://github.com/docker-library/docs/tree/master/mariadb
https://hub.docker.com/r/nazarpc/phpmyadmin/
redmine.org/projects/redmine/wiki/redmineinstall
Pour l’installation de docker-compose ou pour générer les certificats SSL jetez un oeil à mon précédent article: Installer Gitlab en https avec Docker et Nginx
Tutoriel réalisé sous Ubuntu Xenial (16.04 LTS)