How to create a Salix mirror

Post Reply
User avatar
JRD
Salix Warrior
Posts: 950
Joined: 7. Jun 2009, 22:52
Location: Lyon, France

How to create a Salix mirror

Post by JRD »

Here is my docker compose config for creating a Salix mirror.

You will need an additional docker to route the traffic to this compose and potentially something to do a Let’s encrypt certificate.

Personaly I used jwilder nginx-proxy with letsencrypt-nginx-proxy-companion image. But you can use whatever you want.

I will use `your.mirror` for your mirror hostname in the following files.

Here is the global `docker-compose.yml` file :

Code: Select all

version: "2"
networks:
  "proxy":
    external:
      name: "proxy_network"
  "cron":
  "rsync":
services:
  repo: 
    image: jrdasm/nginx-fancy
    environment:
      - "VIRTUAL_HOST=your.mirror"
      - "LETSENCRYPT_HOST=your.mirror"
      - "LETSENCRYPT_EMAIL=your@email"
    networks:
      - "proxy"
    volumes:
      - "./nginx-root.sh:/etc/nginx/shell.d/nginx-root.sh:ro"
      - "./nginx-default.conf:/etc/nginx/conf.d/default.conf:ro"
      - "/var/docker-volumes/salixrepo:/var/www:ro"
  cron:
    build:
      context: .
      dockerfile: cron.Dockerfile
    networks:
      - "cron"
    volumes:
      - "/var/docker-volumes/salixrepo:/var/www"
  rsync:
    image: vimagick/rsyncd
    networks:
      - "rsync"
    ports:
      - "0.0.0.0:873:873"
    volumes:
      - "./rsyncd.conf:/etc/rsyncd.conf:ro"
      - "/var/docker-volumes/salixrepo:/var/www:ro"
The `nginx-root.sh` file:

Code: Select all

#!/bin/bash
sed -ri 's/user[ \t]*nginx;/user root;/' /etc/nginx/nginx.conf
The `nginx-default.conf` file:

Code: Select all

server {
    listen          80;
    server_name     _;
    root            /var/www;
    charset         UTF-8;
    error_page      500 502 503 504  /50x.html;
    location = /50x.html {
        root        html;
    }
    location / {
        fancyindex on;
        fancyindex_exact_size off;
    }
    location ~ ^.*/MIRRORS$|^.*/MIRRORS-FTP$|^.*/MIRRORS-RSYNC$|^.*/TIMESTAMP$|^.*/SLKBUILD$|^.*/GPG-KEY$|^.*/README.*$|^.*/slack-.*$|^.*\.md5$|^.*\.asc$|^.*\.meta$|^.*\.dep$|^.*\.con$|^.*\.sug$|^.*\.patch$|^.*\.diff$|^.*\.desktop$|^.*\.sh$ {
        default_type text/plain;
    }
}
The `cron.Dockerfile` file:

Code: Select all

# vim: syn=dockerfile
# this is old, it should probably be 12 now
FROM debian:8
RUN apt-get update && apt-get -y install cron rsync
COPY sync-salixrepo /etc/cron.hourly/sync-salixrepo
RUN chmod +x /etc/cron.hourly/sync-salixrepo
CMD ["/usr/sbin/cron", "-f"]
The `sync-salixrepo` file:

Code: Select all

#!/bin/sh
if [ -e /var/run/rsync.salixos ]; then
  echo "[$(date '+%F %T')]: Cannot rsync because one is running" | tee -a /var/log/rsync.salixos.log
else
  echo "[$(date '+%F %T')]: rsync to SalixOS" | tee -a /var/log/rsync.salixos.log
  touch /var/run/rsync.salixos
  rsync -avz --delete --exclude=TIMESTAMP rsync://rsync.salixos.org/salix /var/www >> /var/log/rsync.salixos.log 2>&1 || true
  rsync -avz --delete --include=TIMESTAMP rsync://rsync.salixos.org/salix /var/www >> /var/log/rsync.salixos.log 2>&1 || true
  rm /var/run/rsync.salixos
fi
The `rsyncd.conf` file:

Code: Select all

# vim: syn=dosini
[global]
charset = utf-8
max connections = 10
reverse lookup = no
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock

[salix]
path = /var/www
comment = Salix OS your.mirror repo
read only = yes
ignore nonreadable = yes
dont compress = *.z *.gz *.bz2 *.xz *.zip *.tgz *.tbz *.tlz *.txz *.iso *.rpm *.deb
list = yes
This configuration works for multiple years but could be updated a bit (like using an internal docker volume) or simplified (use plain nginx without any fancy index).
Hope it helps.
Image
Post Reply