Skip to content

Commit

Permalink
Add an APT cache proxy option and dev container
Browse files Browse the repository at this point in the history
Add a Debian stable based container using apt-cacher-ng to the
`dev/docker-compose.yml` environment.

Add an option to configure an APT cache proxy to the installation.
  • Loading branch information
fredericmoulins committed Apr 9, 2020
1 parent e4efe46 commit 06d0ca0
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ system_default:
reboot_timeout: 180 # max time to wait when restarting the server
keep_certs: false # keep the letsencrypt certificates locally,
# even when using a live environment
apt_cacher: ~ # IP address or DNS name for an apt-cacher

###############################################################################
# Once the system is in place, it is possible to use 'limit' for the rule,
Expand Down
17 changes: 17 additions & 0 deletions devel/apt-cacher/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Adapted from https://docs.docker.com/engine/examples/apt-cacher-ng/
#
# Build: docker build -t apt-cacher .
# Run: docker run -d -p 3142:3142 --name apt-cacher-run apt-cacher
#
# and then you can run containers with:
# docker run -t -i --rm -e http_proxy http://dockerhost:3142/ debian bash
#
# Here, `dockerhost` is the IP address or FQDN of a host running the Docker daemon
# which acts as an APT proxy server.
FROM debian:stable

VOLUME ["/var/cache/apt-cacher-ng"]
RUN apt-get update && apt-get install -y apt-cacher-ng

EXPOSE 3142
CMD chown apt-cacher-ng:root /var/cache/apt-cacher-ng && /etc/init.d/apt-cacher-ng start && tail -f /var/log/apt-cacher-ng/*
12 changes: 12 additions & 0 deletions devel/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ services:
networks:
acmenet:
ipv4_address: 10.30.50.3
apt-cacher:
build: apt-cacher
ports:
- 3142:3142
volumes:
- apt-cache:/var/cache/apt-cacher-ng
networks:
acmenet:
ipv4_address: 10.30.50.4

networks:
acmenet:
Expand All @@ -35,3 +44,6 @@ networks:
driver: default
config:
- subnet: 10.30.50.0/24

volumes:
apt-cache:
14 changes: 14 additions & 0 deletions install/playbooks/roles/packages/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@
src: sources.list
dest: /etc/apt/sources.list

- name: Use a proxy if needed
when: system.apt_cacher != None
tags: apt
template:
src: proxy
dest: /etc/apt/apt.conf.d/proxy

- name: Make sure no proxy is configured if not needed
when: system.apt_cacher == None
tags: apt
file:
path: /etc/apt/apt.conf.d/proxy
state: absent

# Some cloud providers, the cache_valid_time condition
# is not working just after the installation (vultr)
- name: Force the packages cache update on the first installation
Expand Down
1 change: 1 addition & 0 deletions install/playbooks/roles/packages/templates/proxy
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Acquire::http { Proxy "http://{{ system.apt_cacher }}:3142"; }

0 comments on commit 06d0ca0

Please sign in to comment.