add ENV MIRROR_URL to replace apt sources of default mirror.list
This commit is contained in:
parent
05ebe88f72
commit
85eb8318fa
|
|
@ -3,14 +3,17 @@ MAINTAINER Terry Chen <seterrychen@gmail.com>
|
||||||
|
|
||||||
ENV DEBIAN_FRONTEND noninteractive
|
ENV DEBIAN_FRONTEND noninteractive
|
||||||
ENV TIMEOUT 12h
|
ENV TIMEOUT 12h
|
||||||
|
ENV MIRROR_URL http://tw.archive.ubuntu.com/ubuntu
|
||||||
|
|
||||||
RUN \
|
RUN \
|
||||||
apt-get update && \
|
apt-get update && \
|
||||||
apt-get install -y apt-mirror apache2 && \
|
apt-get install -y apt-mirror apache2 && \
|
||||||
apt-get clean && \
|
apt-get clean && \
|
||||||
|
mv /etc/apt/mirror.list / && \
|
||||||
rm -rf /var/lib/apt/lists/*
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
VOLUME /etc/apt
|
|
||||||
EXPOSE 80
|
EXPOSE 80
|
||||||
COPY setup.sh /setup.sh
|
COPY setup.sh /setup.sh
|
||||||
|
|
||||||
|
VOLUME ["/etc/apt", "/var/spool/apt-mirror"]
|
||||||
CMD ["/bin/bash", "setup.sh"]
|
CMD ["/bin/bash", "setup.sh"]
|
||||||
|
|
|
||||||
13
README.md
13
README.md
|
|
@ -12,8 +12,17 @@ docker run -v /path/data:/var/spool/apt-mirror \
|
||||||
```
|
```
|
||||||
/path/data is where to store data, and the TIMEOUT var to repeatedly execute apt-mirror.
|
/path/data is where to store data, and the TIMEOUT var to repeatedly execute apt-mirror.
|
||||||
|
|
||||||
If you don't setting variable of mirror.list and TIMEOUT, it will using the default [mirror.list](mirror.list), and
|
If you don't setting variable of mirror.list and TIMEOUT, it will using the [default mirror.list](mirror.list), and
|
||||||
the default TIMEOUT is 6 hours. To see the [TIMEOUT format description](http://www.cyberciti.biz/faq/linux-unix-sleep-bash-scripting/)
|
the default TIMEOUT is 12 hours. To see the [TIMEOUT format description](http://www.cyberciti.biz/faq/linux-unix-sleep-bash-scripting/).
|
||||||
|
|
||||||
|
Or running command
|
||||||
|
```
|
||||||
|
docker run -v /path/data:/var/spool/apt-mirror \
|
||||||
|
-e MIRROR_URL=http://tw.archive.ubuntu.com/ubuntu \
|
||||||
|
-e TIMEOUT=timeout-value \
|
||||||
|
-d -p port_number:80 seterrychen/apt-mirror-http-server
|
||||||
|
```
|
||||||
|
MIRROR_URL can used to replace apt sources of [default mirror.list](mirror.list)
|
||||||
|
|
||||||
## Note
|
## Note
|
||||||
It will take time to download, then start http server. Using ``docker logs -f container-id`` to check the process.
|
It will take time to download, then start http server. Using ``docker logs -f container-id`` to check the process.
|
||||||
|
|
|
||||||
22
mirror.list
22
mirror.list
|
|
@ -14,16 +14,16 @@ set _tilde 0
|
||||||
#
|
#
|
||||||
############# end config ##############
|
############# end config ##############
|
||||||
|
|
||||||
deb http://tw.archive.ubuntu.com/ubuntu trusty main restricted universe multiverse
|
deb http://archive.ubuntu.com/ubuntu trusty main restricted universe multiverse
|
||||||
deb http://tw.archive.ubuntu.com/ubuntu trusty-security main restricted universe multiverse
|
deb http://archive.ubuntu.com/ubuntu trusty-security main restricted universe multiverse
|
||||||
deb http://tw.archive.ubuntu.com/ubuntu trusty-updates main restricted universe multiverse
|
deb http://archive.ubuntu.com/ubuntu trusty-updates main restricted universe multiverse
|
||||||
#deb http://tw.archive.ubuntu.com/ubuntu trusty-proposed main restricted universe multiverse
|
#deb http://archive.ubuntu.com/ubuntu trusty-proposed main restricted universe multiverse
|
||||||
#deb http://tw.archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse
|
#deb http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse
|
||||||
|
|
||||||
deb-src http://tw.archive.ubuntu.com/ubuntu trusty main restricted universe multiverse
|
deb-src http://archive.ubuntu.com/ubuntu trusty main restricted universe multiverse
|
||||||
deb-src http://tw.archive.ubuntu.com/ubuntu trusty-security main restricted universe multiverse
|
deb-src http://archive.ubuntu.com/ubuntu trusty-security main restricted universe multiverse
|
||||||
deb-src http://tw.archive.ubuntu.com/ubuntu trusty-updates main restricted universe multiverse
|
deb-src http://archive.ubuntu.com/ubuntu trusty-updates main restricted universe multiverse
|
||||||
#deb-src http://tw.archive.ubuntu.com/ubuntu trusty-proposed main restricted universe multiverse
|
#deb-src http://archive.ubuntu.com/ubuntu trusty-proposed main restricted universe multiverse
|
||||||
#deb-src http://tw.archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse
|
#deb-src http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse
|
||||||
|
|
||||||
clean http://tw.archive.ubuntu.com/ubuntu
|
clean http://archive.ubuntu.com/ubuntu
|
||||||
|
|
|
||||||
32
setup.sh
32
setup.sh
|
|
@ -1,12 +1,5 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
function create_link {
|
||||||
# read mirror.list to link /var/www/package folder
|
|
||||||
mkdir /var/www/package
|
|
||||||
sed -i '12s/DocumentRoot \/var\/www\/html/DocumentRoot \/var\/www\/package/' /etc/apache2/sites-enabled/000-default.conf
|
|
||||||
service apache2 restart
|
|
||||||
|
|
||||||
while true; do
|
|
||||||
|
|
||||||
# parse mirror.list to share under /var/www/package path
|
# parse mirror.list to share under /var/www/package path
|
||||||
for i in `egrep -o '(rsync|ftp|https?)://[^ ]+' /etc/apt/mirror.list`; do
|
for i in `egrep -o '(rsync|ftp|https?)://[^ ]+' /etc/apt/mirror.list`; do
|
||||||
url=${i/http:\/\//''}
|
url=${i/http:\/\//''}
|
||||||
|
|
@ -15,13 +8,32 @@ while true; do
|
||||||
IFS='/' read -a distName <<< "$url"
|
IFS='/' read -a distName <<< "$url"
|
||||||
dest=$target${distName[-1]}
|
dest=$target${distName[-1]}
|
||||||
if [ ! -h $dest ]; then
|
if [ ! -h $dest ]; then
|
||||||
echo "create $dest"
|
echo "Create $dest"
|
||||||
ln -s /var/spool/apt-mirror/mirror/$url $dest
|
ln -s /var/spool/apt-mirror/mirror/$url $dest
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# read mirror.list to link /var/www/package folder
|
||||||
|
mkdir /var/www/package
|
||||||
|
sed -i '12s|DocumentRoot /var/www/html|DocumentRoot /var/www/package|' /etc/apache2/sites-enabled/000-default.conf
|
||||||
|
service apache2 restart
|
||||||
|
|
||||||
|
# If user doesn't provide mirror.list, using default setting
|
||||||
|
need_create_line=true
|
||||||
|
if [ ! -e /etc/apt/mirror.list ]; then
|
||||||
|
echo "Using default mirror.list"
|
||||||
|
ln -s /mirror.list /etc/apt/mirror.list
|
||||||
|
sed -i "s|http://archive.ubuntu.com/ubuntu|$MIRROR_URL|g" /etc/apt/mirror.list
|
||||||
|
create_link
|
||||||
|
need_create_line=false
|
||||||
|
fi
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
if $need_create_line; then
|
||||||
|
create_link
|
||||||
|
fi
|
||||||
apt-mirror
|
apt-mirror
|
||||||
printf "\n\n====== wait $TIMEOUT to execute apt-mirror again ======\n\n"
|
printf "\n\n====== wait $TIMEOUT to execute apt-mirror again ======\n\n"
|
||||||
sleep $TIMEOUT
|
sleep $TIMEOUT
|
||||||
|
|
||||||
done
|
done
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue