From 02e58dfda8d30e89ed8f228247878e4aaf324a6a Mon Sep 17 00:00:00 2001 From: Kevin Carter Date: Thu, 21 Jul 2016 09:54:40 -0500 Subject: [PATCH] Implemented package caching on the repo server This change implements package caching on the repo server. To take advantage of this a deploy will need to do nothing more than setup an apt-proxy configuration file. This will speed up package delivery while also providing ha capabilities within the environment. Change-Id: I78b2fba6a1f294751bd7098513060015cb41300c Signed-off-by: Kevin Carter --- defaults/main.yml | 9 +++ handlers/main.yml | 7 ++ .../notes/pkg-cacher-cfeae8fb990904a4.yaml | 6 ++ tasks/main.yml | 2 + tasks/repo_cacher.yml | 75 +++++++++++++++++++ templates/acng.conf.j2 | 20 +++++ vars/debian.yml | 3 + vars/redhat.yml | 4 + 8 files changed, 126 insertions(+) create mode 100644 releasenotes/notes/pkg-cacher-cfeae8fb990904a4.yaml create mode 100644 tasks/repo_cacher.yml create mode 100644 templates/acng.conf.j2 diff --git a/defaults/main.yml b/defaults/main.yml index 1602961..defaf23 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -38,3 +38,12 @@ repo_recreate_keys: False # Main web server port repo_server_port: 8181 + +# Toggle the implementation of the Package Cache service +repo_pkg_cache_enabled: true + +# Set the listening port for the Package Cache service +repo_pkg_cache_port: 3142 + +# Set the listening address for the PAckage Cache service +repo_pkg_cache_bind: "0.0.0.0" diff --git a/handlers/main.yml b/handlers/main.yml index 5e41638..291a79f 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -30,6 +30,13 @@ enabled: yes pattern: "rsync" +- name: reload acng + service: + name: "apt-cacher-ng" + state: restarted + enabled: yes + pattern: "apt-cacher-ng" + - name: reload fcgiwrap service: name: "fcgiwrap" diff --git a/releasenotes/notes/pkg-cacher-cfeae8fb990904a4.yaml b/releasenotes/notes/pkg-cacher-cfeae8fb990904a4.yaml new file mode 100644 index 0000000..d4ec4b7 --- /dev/null +++ b/releasenotes/notes/pkg-cacher-cfeae8fb990904a4.yaml @@ -0,0 +1,6 @@ +--- +features: + - The repo server now has a Package Cache service for distribution packages. To leverage + the cache, deployers will need to configure the package manager on all hosts to use the + cache as a proxy. If a deployer would prefer to disable this service, the variable + ``repo_pkg_cache_enabled`` should be set to ``false``. diff --git a/tasks/main.yml b/tasks/main.yml index c02f843..a42167e 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -39,6 +39,8 @@ - include: repo_pre_install.yml - include: repo_install.yml - include: repo_post_install.yml +- include: repo_cacher.yml + when: repo_pkg_cache_enabled | bool - include: repo_key_populate.yml diff --git a/tasks/repo_cacher.yml b/tasks/repo_cacher.yml new file mode 100644 index 0000000..005b301 --- /dev/null +++ b/tasks/repo_cacher.yml @@ -0,0 +1,75 @@ +--- +# Copyright 2016, Rackspace US, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- name: Install repo caching server packages (yum) + yum: + pkg: "{{ item }}" + state: latest + enablerepo: "epel-testing" + register: install_packages + until: install_packages|success + retries: 5 + delay: 5 + with_items: "{{ repo_pkg_cache_server_packages }}" + when: + - ansible_pkg_mgr == 'yum' + - repo_pkg_cache_enabled | bool + +- name: Install repo caching server packages (apt) + apt: + pkg: "{{ item }}" + state: latest + register: install_packages + until: install_packages|success + retries: 5 + delay: 5 + with_items: "{{ repo_pkg_cache_server_packages }}" + when: + - ansible_pkg_mgr == 'apt' + - repo_pkg_cache_enabled | bool + +- name: Create cache directory + file: + path: "{{ repo_service_home_folder }}/repo/pkg-cache" + state: "directory" + owner: "apt-cacher-ng" + group: "{{ repo_service_group_name }}" + mode: "02775" + +- name: Stat the cache path + stat: + path: /var/cache/apt-cacher-ng + register: acs + +- name: Remove cacher directory if its a directory + file: + path: "/var/cache/apt-cacher-ng" + state: "absent" + when: + - acs.stat.isdir is defined and acs.stat.isdir + +- name: Link cacher to the repo path + file: + src: "{{ repo_service_home_folder }}/repo/pkg-cache" + dest: "/var/cache/apt-cacher-ng" + state: "link" + +- name: Drop acng.conf + template: + src: "acng.conf.j2" + dest: "/etc/apt-cacher-ng/acng.conf" + notify: + - reload acng + diff --git a/templates/acng.conf.j2 b/templates/acng.conf.j2 new file mode 100644 index 0000000..5f66bdb --- /dev/null +++ b/templates/acng.conf.j2 @@ -0,0 +1,20 @@ +# {{ ansible_managed }} + +CacheDir: {{ repo_service_home_folder }}/repo/pkg-cache +LogDir: /var/log/apt-cacher-ng +Port: {{ repo_pkg_cache_port }} +BindAddress: {{ repo_pkg_cache_bind }} +Remap-debrep: file:deb_mirror*.gz /debian ; file:backends_debian # Debian Archives +Remap-uburep: file:ubuntu_mirrors /ubuntu ; file:backends_ubuntu # Ubuntu Archives +Remap-debvol: file:debvol_mirror*.gz /debian-volatile ; file:backends_debvol # Debian Volatile Archives +Remap-cygwin: file:cygwin_mirrors /cygwin # ; file:backends_cygwin # incomplete, please create this file or specify preferred mirrors here +Remap-sfnet: file:sfnet_mirrors # ; file:backends_sfnet # incomplete, please create this file or specify preferred mirrors here +Remap-alxrep: file:archlx_mirrors /archlinux # ; file:backend_archlx # Arch Linux +Remap-fedora: file:fedora_mirrors # Fedora Linux +Remap-epel: file:epel_mirrors # Fedora EPEL +Remap-slrep: file:sl_mirrors # Scientific Linux +ReportPage: acng-report.html +PidFile: /var/run/apt-cacher-ng +ExTreshold: 4 +LocalDirs: acng-doc /usr/share/doc/apt-cacher-ng +PassThroughPattern: .* diff --git a/vars/debian.yml b/vars/debian.yml index f40a5bd..c108113 100644 --- a/vars/debian.yml +++ b/vars/debian.yml @@ -24,3 +24,6 @@ repo_server_packages: - lsyncd - nginx-extras - rsync + +repo_pkg_cache_server_packages: + - apt-cacher-ng diff --git a/vars/redhat.yml b/vars/redhat.yml index bd76f94..fe5c6ec 100644 --- a/vars/redhat.yml +++ b/vars/redhat.yml @@ -23,3 +23,7 @@ repo_server_packages: - lsyncd - nginx - rsync + +repo_pkg_cache_server_packages: + - apt-cacher-ng +