Make host copying more selective

The host copy process was taking too much, this makes that process more
selective.

Change-Id: Ic25559d9b68b6208ffdbed020cc79bd6b3d52fdd
Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
This commit is contained in:
Kevin Carter 2018-05-18 13:41:33 -05:00
parent f0ab1108c7
commit d520e80462
No known key found for this signature in database
GPG Key ID: 9443251A787B9FB3
11 changed files with 47 additions and 5 deletions

View File

@ -131,6 +131,12 @@ nspawn_copy_from_host: "{{ nspawn_default_copy_from_host | union(_nspawn_copy_fr
# - /etc/apt/preferences.d/
nspawn_container_cache_files_from_host: []
# Default list of packages to install within the build container cache. These
# packages are installed first, before running anything else within the image.
# nspawn_container_distro_required_packages:
# - gnupg
nspawn_container_distro_required_packages: "{{ _nspawn_container_distro_required_packages | default([]) }}"
# Default list of packages to install within the build container cache.
# nspawn_container_distro_packages:
# - curl

View File

@ -56,3 +56,8 @@
- name: Reload systemd-daemon
systemd:
daemon_reload: true
- name: Remove generated apt keys
file:
path: /root/repo.keys
state: absent

View File

@ -66,18 +66,33 @@
when:
- nspawn_image_cache_refresh | bool
- block:
- name: Generate apt keys from host for the container cache
command: "apt-key exportall"
changed_when: false
register: _apt_exportall
- name: Write exported keys to file
copy:
content: "{{ _apt_exportall.stdout }}"
dest: "/var/lib/machines/{{ nspawn_container_base_name }}/root/repo.keys"
notify:
- Remove generated apt keys
when:
- ansible_pkg_mgr == 'apt'
- name: Cached image preparation script
template:
src: "prep-scripts/nspawn_{{ nspawn_cache_map.distro }}_prep.sh.j2"
dest: "/var/lib/machines/{{ nspawn_container_base_name }}/usr/local/bin/cache-prep-commands.sh"
mode: "0755"
# This task runs several commands against the cached image to speed up the
# nspawn_container_create playbook.
- name: Prepare cached image setup commands
shell: "chroot /var/lib/machines/{{ nspawn_container_base_name }} /usr/local/bin/cache-prep-commands.sh > /var/log/nspawn-cache-prep-commands.log 2>&1"
changed_when: false
# This task runs several commands against the cached image to speed up the
# nspawn_container_create playbook.
- name: Sync files from the host into the container cache
shell: |
if [[ -e "{{ item }}" ]]; then

View File

@ -27,7 +27,7 @@ rpm --import /etc/pki/rpm-gpg/*
which dnf &>/dev/null && RHT_PKG_MGR='dnf' || RHT_PKG_MGR='yum'
# Create yum/dnf transaction file and run it all at once
echo "update" > /tmp/package-transaction.txt
echo "install {{ nspawn_container_distro_packages | join(' ') }}" >> /tmp/package-transaction.txt
echo "install {{ (nspawn_container_distro_packages | union(nspawn_container_distro_required_packages) | unique) | join(' ') }}" >> /tmp/package-transaction.txt
echo "run" >> /tmp/package-transaction.txt
$RHT_PKG_MGR -y shell /tmp/package-transaction.txt
yum-complete-transaction --cleanup-only

View File

@ -34,7 +34,7 @@ fi
# Key import
zypper --gpg-auto-import-keys -n dup --force-resolution -l
zypper --gpg-auto-import-keys -n in --force-resolution -l {{ nspawn_container_distro_packages | join(' ') }}
zypper --gpg-auto-import-keys -n in --force-resolution -l {{ (nspawn_container_distro_packages | union(nspawn_container_distro_required_packages) | unique) | join(' ') }}
rm -f /usr/bin/python || true
ln -s /usr/bin/python2.7 /usr/bin/python

View File

@ -24,8 +24,15 @@ set -e
# Update base distribution
export DEBIAN_FRONTEND=noninteractive
apt-get remove -y --purge snap* nspawn* lxd* resolvconf || true
apt-get update
apt-get install -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" --force-yes {{ nspawn_container_distro_required_packages | join(' ') }}
if [[ -f "/root/repo.keys" ]]; then
apt-key add /root/repo.keys
fi
apt-get install -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" --force-yes {{ nspawn_container_distro_packages | join(' ') }}
apt-get upgrade -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" --force-yes
apt-get clean

View File

@ -18,6 +18,7 @@
connection: local
become: true
vars:
bridges: []
nspawn_networks:
nspawn_address:
bridge: "nspawn0"

View File

@ -59,4 +59,5 @@ _nspawn_cache_map:
_nspawn_copy_from_host:
- /etc/pki/rpm-gpg/
- /etc/yum/pluginconf.d/fastestmirror.conf
- /etc/yum.repos.d/

View File

@ -54,7 +54,8 @@ _nspawn_cache_map:
release: "{{ hostvars[physical_host]['ansible_distribution_version'] }}"
_nspawn_copy_from_host:
- /etc/zypp
- /etc/zypp/repos.d/repo-oss.repo
- /etc/zypp/repos.d/repo-update.repo
## Set default mirror for openSUSE repositories
# NOTE(hwoarang): Ensure that the full path to the 'opensuse' directory is used.

View File

@ -28,6 +28,9 @@ _nspawn_hosts_distro_packages:
- pxz
- systemd-container
_nspawn_container_distro_required_packages:
- gnupg
_nspawn_container_distro_packages:
- apt-transport-https
- ca-certificates

View File

@ -28,6 +28,9 @@ _nspawn_hosts_distro_packages:
- pxz
- systemd-container
_nspawn_container_distro_required_packages:
- gnupg
_nspawn_container_distro_packages:
- apt-transport-https
- ca-certificates