├── .dockerignore ├── Dockerfile ├── .circleci └── config.yml ├── run.sh ├── LICENSE ├── README.md └── nginx-template.conf /.dockerignore: -------------------------------------------------------------------------------- 1 | README.md 2 | LICENSE 3 | .git/ 4 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM quay.io/vektorcloud/nginx:latest 2 | 3 | RUN apk add --no-cache wget bash 4 | 5 | COPY nginx-template.conf /nginx-template.conf 6 | COPY run.sh /run.sh 7 | 8 | EXPOSE 80 9 | ENTRYPOINT ["/run.sh"] 10 | -------------------------------------------------------------------------------- /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | jobs: 3 | build: 4 | working_directory: ~/build 5 | docker: 6 | - image: quay.io/vektorcloud/cibase:latest 7 | steps: 8 | - checkout 9 | - setup_remote_docker: 10 | version: 17.05.0-ce 11 | - run: docker build -t ${CIRCLE_PROJECT_REPONAME} . 12 | - deploy: 13 | command: | 14 | if [[ "$CIRCLE_BRANCH" == "master" ]]; then 15 | docker tag ${CIRCLE_PROJECT_REPONAME} quay.io/vektorcloud/${CIRCLE_PROJECT_REPONAME}:latest 16 | else 17 | docker tag ${CIRCLE_PROJECT_REPONAME} quay.io/vektorcloud/${CIRCLE_PROJECT_REPONAME}:${CIRCLE_BRANCH} 18 | fi 19 | docker login -u $DOCKER_USER -p $DOCKER_PASS quay.io 20 | docker push quay.io/vektorcloud/${CIRCLE_PROJECT_REPONAME} 21 | -------------------------------------------------------------------------------- /run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | CACHEDIR="/srv/www/apt" 4 | PKGREPO_URL="http://archive.ubuntu.com/ubuntu/pool/main/" 5 | 6 | function init_cachedirs() { 7 | # create dirs for package cache 8 | echo -n "initializing cache directories... " 9 | 10 | mkdir -p ${CACHEDIR}/debian 11 | mkdir -p ${CACHEDIR}/debian-security 12 | 13 | # create top-level directories for ubuntu as nginx will not create them recursively 14 | cd /tmp/ 15 | wget --force-directories -r --level=1 -R '*.html*,*.gif' --quiet $PKGREPO_URL 16 | mv archive.ubuntu.com/* /srv/www/apt/ 17 | 18 | chown nginx. -R /srv/www/apt 19 | echo "done" 20 | } 21 | 22 | [ -d $CACHEDIR ] || init_cachedirs 23 | 24 | RESOLVER=$(grep nameserver /etc/resolv.conf | awk '{print $2}' | head -1) 25 | sed "s|_RESOLVER_|$RESOLVER|g;s|_CACHEDIR_|$CACHEDIR|g" /nginx-template.conf > /etc/nginx/nginx.conf 26 | 27 | /usr/sbin/nginx -c /etc/nginx/nginx.conf 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 VektorLab Cloud 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # apt-cacher 2 | 3 | [![circleci][circleci]](https://circleci.com/gh/vektorcloud/apt-cacher) 4 | 5 | Apt-cacher is a simple apt package cache for use with Docker, but suitable in any case where an entire package mirror may be overkill. 6 | 7 | ## Quickstart 8 | 9 | ``` 10 | docker run -d --name=apt-cacher quay.io/vektorcloud/apt-cacher:latest 11 | ``` 12 | 13 | After apt-cacher is up, start any following containers linked to the cache: 14 | 15 | * Ubuntu: 16 | ``` 17 | docker run -ti --link apt-cacher:security.ubuntu.com --link apt-cacher:archive.ubuntu.com ubuntu:latest /bin/bash 18 | ``` 19 | 20 | * Debian: 21 | ``` 22 | docker run -ti --link apt-cacher:security.debian.org --link apt-cacher:ftp.debian.org debian:latest /bin/bash 23 | ``` 24 | 25 | To alternatively avoid having to link every running container, publish port 80 to the host: 26 | ``` 27 | docker run -d -p 80:80 --name=apt-cacher quay.io/vektorcloud/apt-cacher:latest 28 | ``` 29 | and add an /etc/hosts entry on the host pointing to localhost or the address of the interface you have docker bound to: 30 | ``` 31 | 127.0.0.1 ftp.debian.org 32 | 127.0.0.1 security.debian.org 33 | 127.0.0.1 archive.ubuntu.com 34 | 127.0.0.1 security.ubuntu.com 35 | ``` 36 | 37 | [circleci]: https://img.shields.io/circleci/build/gh/vektorcloud/apt-cacher?color=1dd6c9&logo=CircleCI&logoColor=1dd6c9&style=for-the-badge "apt-cacher" 38 | -------------------------------------------------------------------------------- /nginx-template.conf: -------------------------------------------------------------------------------- 1 | user nginx; 2 | daemon off; 3 | worker_processes 2; 4 | 5 | error_log /dev/stderr info; 6 | 7 | events { 8 | worker_connections 1024; 9 | } 10 | 11 | http { 12 | include mime.types; 13 | default_type application/octet-stream; 14 | 15 | sendfile on; 16 | keepalive_timeout 65; 17 | 18 | #gzip on; 19 | 20 | server { 21 | listen 0.0.0.0:80 default; 22 | server_name ftp.debian.org security.debian.org archive.ubuntu.com security.ubuntu.com; 23 | root _CACHEDIR_; 24 | 25 | access_log /dev/stdout; 26 | 27 | resolver _RESOLVER_; 28 | #allow 10.0.0.0/24; 29 | #allow 127.0.0.1; 30 | #deny all; 31 | 32 | location /debian/pool/ { 33 | try_files $uri @mirror; 34 | } 35 | 36 | location /debian-security/pool/ { 37 | try_files $uri @mirror; 38 | } 39 | 40 | location /ubuntu/pool/ { 41 | try_files $uri @mirror; 42 | } 43 | 44 | location / { 45 | proxy_next_upstream error timeout http_404; 46 | proxy_pass http://$host$request_uri; 47 | proxy_redirect off; 48 | proxy_set_header Host $host; 49 | proxy_set_header X-Real-IP $remote_addr; 50 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 51 | add_header X-Mirror-Upstream-Status $upstream_status; 52 | add_header X-Mirror-Upstream-Response-Time $upstream_response_time; 53 | add_header X-Mirror-Status $upstream_cache_status; 54 | } 55 | 56 | location @mirror { 57 | access_log /var/log/nginx/apt.remote.log; 58 | proxy_store on; 59 | proxy_store_access user:rw group:rw all:r; 60 | proxy_next_upstream error timeout http_404; 61 | proxy_pass http://$host$request_uri; 62 | proxy_redirect off; 63 | proxy_set_header Host $host; 64 | proxy_set_header X-Real-IP $remote_addr; 65 | proxy_set_header X-Forwarded_For $proxy_add_x_forwarded_for; 66 | add_header X-Mirror-Upstream-Status $upstream_status; 67 | add_header X-Mirror-Upstream-Response-Time $upstream_response_time; 68 | add_header X-Mirror-Status $upstream_cache_status; 69 | } 70 | } 71 | } 72 | --------------------------------------------------------------------------------