Add apt-cacher-ng to reduce network load
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
# install roles and collections
|
||||
ansible-galaxy install -r requirements.yml
|
||||
|
||||
# Install the playbook
|
||||
# Install the frontend
|
||||
ansible-playbook -i inventory.yaml -e @secrets.enc --ask-vault-pass frontend.yaml
|
||||
|
||||
# Github runner
|
||||
@@ -13,4 +13,24 @@ ansible-playbook -i inventory.yaml -e @secrets.enc --ask-vault-pass gitea.yaml
|
||||
|
||||
# graphana + prometheus
|
||||
ansible-playbook -i inventory.yaml -e @secrets.enc --ask-vault-pass monitor.yaml
|
||||
|
||||
# apt-cacheer-ng
|
||||
ansible-playbook -i inventory.yaml --ask-become-pass apt-cacher-ng.yaml
|
||||
```
|
||||
|
||||
To make use of the apt cache, ensure you have a file like this with CACHE_HOST changes to your actual host
|
||||
|
||||
```bash
|
||||
echo << EOF >> /etc/apt/apt.conf.d/01proxy
|
||||
Acquire::HTTP::Proxy "http://<CACHE_HOST>:3142";
|
||||
Acquire::HTTPS::Proxy "false";
|
||||
EOF
|
||||
```
|
||||
|
||||
or add these to a Dockerfile
|
||||
|
||||
```
|
||||
RUN echo 'Acquire::HTTP::Proxy "http://<CACHE_HOST>:3142";' >> /etc/apt/apt.conf.d/01proxy \
|
||||
&& echo 'Acquire::HTTPS::Proxy "false";' >> /etc/apt/apt.conf.d/01proxy
|
||||
```
|
||||
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
---
|
||||
- name: APT Cache Server
|
||||
hosts: apt-cacher-ng
|
||||
|
||||
vars:
|
||||
username: matt
|
||||
nas_host: 192.168.1.160
|
||||
|
||||
mounts:
|
||||
apt_cache:
|
||||
local: "/var/cache/packages"
|
||||
remote: "/var/nfs/shared/apt_cache"
|
||||
|
||||
docker_add_repo: true
|
||||
docker_users:
|
||||
- "{{ username }}"
|
||||
|
||||
roles:
|
||||
- role: geerlingguy.git
|
||||
become: true
|
||||
- role: geerlingguy.docker
|
||||
become: true
|
||||
|
||||
|
||||
tasks:
|
||||
- name: Create app directory in home
|
||||
ansible.builtin.file:
|
||||
path: "{{ ansible_env.HOME }}/apt-cacher-ng"
|
||||
state: directory
|
||||
mode: "0755"
|
||||
|
||||
- name: Copy the apt-cacher-ng compose file to the host
|
||||
ansible.builtin.copy:
|
||||
src: apt-cacher-ng/compose.yaml
|
||||
dest: "{{ ansible_env.HOME }}/apt-cacher-ng/compose.yaml"
|
||||
|
||||
- name: Stop apt-cacher-ng services if running
|
||||
community.docker.docker_compose_v2:
|
||||
project_src: "{{ ansible_env.HOME }}/apt-cacher-ng/"
|
||||
state: absent
|
||||
ignore_errors: true
|
||||
|
||||
- name: Unmount NFS volumes before creating mountpoint directories
|
||||
ansible.posix.mount:
|
||||
path: "{{ item.value.local }}"
|
||||
state: unmounted
|
||||
loop: "{{ mounts | dict2items }}"
|
||||
become: true
|
||||
|
||||
- name: Create mountpoint directories for apt-cacher-ng
|
||||
ansible.builtin.file:
|
||||
path: "{{ item.value.local }}"
|
||||
state: directory
|
||||
mode: "0755"
|
||||
loop: "{{mounts | dict2items }}"
|
||||
become: true
|
||||
|
||||
- name: Mount an NFS volume for cache
|
||||
ansible.posix.mount:
|
||||
src: "{{ nas_host }}:{{ item.value.remote }}"
|
||||
path: "{{ item.value.local }}"
|
||||
opts: nfsvers=3,proto=tcp,rw
|
||||
state: mounted
|
||||
fstype: nfs
|
||||
loop: "{{ mounts | dict2items }}"
|
||||
become: true
|
||||
|
||||
|
||||
- name: Create and start services
|
||||
community.docker.docker_compose_v2:
|
||||
project_src: "{{ ansible_env.HOME }}/apt-cacher-ng/"
|
||||
state: present
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
---
|
||||
services:
|
||||
apt-cacher-ng:
|
||||
image: mbentley/apt-cacher-ng
|
||||
container_name: apt-cacher-ng
|
||||
init: true
|
||||
environment:
|
||||
- PUID=977
|
||||
- PGID=988
|
||||
ports:
|
||||
- "3142:3142"
|
||||
volumes:
|
||||
- /var/cache/packages/apt-cacher-ng:/var/cache/apt-cacher-ng
|
||||
restart: always
|
||||
+4
-1
@@ -25,4 +25,7 @@ all:
|
||||
rpi5-1: {}
|
||||
gitea:
|
||||
hosts:
|
||||
rpi5-2: {}
|
||||
rpi5-2: {}
|
||||
apt-cacher-ng:
|
||||
hosts:
|
||||
rpi4-2: {}
|
||||
Reference in New Issue
Block a user