apt-mirror

Debianのミラーを建てる

DockerでCI/CDをしだすと、Docker Hub・Debianリポジトリとの通信がかなり増える。 (Debianベースじゃないイメージもあるが、概ねDebianベースが推奨されているので。)
Debianのガイドではftpmirrorが推奨されているが、場合によってはもっとお手軽なほうが良いこともある。(他人も面倒を見うる、など。)
以下は、apt-mirror を使う例。
############# config ##################
#
# set base_path    /var/spool/apt-mirror
#
# set mirror_path  $base_path/mirror
# set skel_path    $base_path/skel
# set var_path     $base_path/var
# set cleanscript $var_path/clean.sh
# set defaultarch  <running host architecture>
# set postmirror_script $var_path/postmirror.sh
# set run_postmirror 0
set nthreads     20
set _tilde 0
#
############# end config ##############

deb-amd64 http://ftp.jp.debian.org/debian stretch main contrib non-free
deb-i386 http://ftp.jp.debian.org/debian stretch main contrib non-free
deb-src http://ftp.jp.debian.org/debian stretch main contrib non-free
deb-amd64 http://ftp.jp.debian.org/debian stretch-updates main contrib non-free
deb-i386 http://ftp.jp.debian.org/debian stretch-updates main contrib non-free
deb-src http://ftp.jp.debian.org/debian stretch-updates main contrib non-free
deb-amd64 http://ftp.jp.debian.org/debian stretch-proposed-updates main contrib non-free
deb-i386 http://ftp.jp.debian.org/debian stretch-proposed-updates main contrib non-free
deb-src http://ftp.jp.debian.org/debian stretch-proposed-updates main contrib non-free
deb-amd64 http://ftp.jp.debian.org/debian stretch-backports main contrib non-free
deb-i386 http://ftp.jp.debian.org/debian stretch-backports main contrib non-free
deb-src http://ftp.jp.debian.org/debian stretch-backports main contrib non-free
deb-amd64 http://security.debian.org stretch/updates main contrib non-free
deb-i386 http://security.debian.org stretch/updates main contrib non-free
deb-src http://security.debian.org stretch/updates main contrib non-free

deb-amd64 http://ftp.jp.debian.org/debian jessie main contrib non-free
deb-i386 http://ftp.jp.debian.org/debian jessie main contrib non-free
deb-src http://ftp.jp.debian.org/debian jessie main contrib non-free
deb-amd64 http://ftp.jp.debian.org/debian jessie-updates main contrib non-free
deb-i386 http://ftp.jp.debian.org/debian jessie-updates main contrib non-free
deb-src http://ftp.jp.debian.org/debian jessie-updates main contrib non-free
deb-amd64 http://ftp.jp.debian.org/debian jessie-proposed-updates main contrib non-free
deb-i386 http://ftp.jp.debian.org/debian jessie-proposed-updates main contrib non-free
deb-src http://ftp.jp.debian.org/debian jessie-proposed-updates main contrib non-free
deb-amd64 http://ftp.jp.debian.org/debian jessie-backports main contrib non-free
deb-i386 http://ftp.jp.debian.org/debian jessie-backports main contrib non-free
deb-src http://ftp.jp.debian.org/debian jessie-backports main contrib non-free
deb-amd64 http://security.debian.org jessie/updates main contrib non-free
deb-i386 http://security.debian.org jessie/updates main contrib non-free
deb-src http://security.debian.org jessie/updates main contrib non-free

deb-amd64 http://ftp.jp.debian.org/debian wheezy main contrib non-free
deb-i386 http://ftp.jp.debian.org/debian wheezy main contrib non-free
deb-src http://ftp.jp.debian.org/debian wheezy main contrib non-free
deb-amd64 http://ftp.jp.debian.org/debian wheezy-updates main contrib non-free
deb-i386 http://ftp.jp.debian.org/debian wheezy-updates main contrib non-free
deb-src http://ftp.jp.debian.org/debian wheezy-updates main contrib non-free
deb-amd64 http://ftp.jp.debian.org/debian wheezy-proposed-updates main contrib non-free
deb-i386 http://ftp.jp.debian.org/debian wheezy-proposed-updates main contrib non-free
deb-src http://ftp.jp.debian.org/debian wheezy-proposed-updates main contrib non-free
deb-amd64 http://ftp.jp.debian.org/debian wheezy-backports main contrib non-free
deb-i386 http://ftp.jp.debian.org/debian wheezy-backports main contrib non-free
deb-src http://ftp.jp.debian.org/debian wheezy-backports main contrib non-free
deb-amd64 http://security.debian.org wheezy/updates main contrib non-free
deb-i386 http://security.debian.org wheezy/updates main contrib non-free
deb-src http://security.debian.org wheezy/updates main contrib non-free

clean http://ftp.jp.debian.org/debian
clean http://security.debian.org
ちなみに、もっと頭を使わない例だと、rsync daemon を建ててるミラーとrsyncをかける例もある。 更新を1段階でかけると「インデックスファイル がまだミラーされていないファイルを参照する期間ができてしまう」ので注意。
rsync -v --progress -aH \
  --exclude Packages* --exclude Sources* --exclude Release* --exclude InRelease --exclude i18n/* --exclude ls-lR* \
  rsync://ftp.jaist.ac.jp/pub/Linux/debian/ LOCAL_PATH
rsync -v --progress -aH --delete --delete-after \
  rsync://ftp.jaist.ac.jp/pub/Linux/debian/ LOCAL_PATH

Cygwinのミラーサーバー

Cygwinは簡単で、単に rsync をかけるだけで良いらしい。
rsync -vaz rsync://example.com/pub/cygwin/ /var/www/cygwin