I was happy to build APT's package repository cache server (apt-cacher-ng) locally (in Docker).
I built an APT cache server in the article.
I'm a Python user, so I wanted to save time not only with apt-get install but also with pip install download time.
devpi-server
It seems that you can easily build a PyPI cache server by installing a wonderful package called devpi-server.
I decided to write this in a Dockerfile as well.
Note that pip install has a local cache mechanism (https://pip.pypa.io/en/latest/reference/pip_install.html?highlight=download#caching), so this method is single. It doesn't seem to make much sense if you just install a single on the server.
--When retrieving packages individually among multiple server instances --When the available line bandwidth is small or limited
Especially useful for.
Dockerfile
Below is the main subject of the Dockerfile.
Dockerfile
#
# Build:
# docker build -t devpi-server .
#
# Run:
# docker run -d -p 3141:3141 --name devpi-server-run devpi-server
#
FROM ubuntu
EXPOSE 3141
VOLUME ["/var/cache/devpi"]
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && \
apt-get install --no-install-recommends -y python3-pip && \
pip3 install -q -U pip devpi-server
CMD chmod 777 /var/cache/devpi && \
devpi-server \
--serverdir /var/cache/devpi \
--host 0.0.0.0 --port 3141
--trusted-host
In the cache server host name,--index-url
Specify the url of the target cache server with.
$ pip install --trusted-host XXX.XXX.XXX.XXX --index-url http://XXX.XXX.XXX.XXX:3141/root/pypi/ package-name
As you can see in https://pip.pypa.io/en/latest/user_guide.html#environment-variables, The pip install options can also be controlled by environment variables. In that case, PIP_ is prefixed with uppercase letters and snake cases. Specified by PIP_TRUSTED_HOST and PIP_INDEX_URL.
Measured with the time command. I only measured it once, so I didn't make a strict comparison, but I felt it was enough. --No-cache-dir is specified to invalidate the local cache.
$ time pip install --no-cache-dir numpy scipy matplotlib pandas ipython
real 3m29.583s
real 0m24.950s
There is a big difference. I felt like I was spending a lot of time downloading scipy and matplotlib, especially without the cache.
Recommended Posts