
Python venvs are not particularly portable. To overcome this problem we have a bunch of stuff implemented to fix them after we unpack them. This ranges from relatively simple things like re-implementing python in the venv and changing the shebangs for everything in it, to more complex things like having to package a venv per distro/architecture. All of this can be eliminated by simplifying the mechanism into just creating the venv on the target host, and installing the python packages into it. To help speed up the build, we can simply build wheels before hand and store them on a web server somewhere. This patch implements the changes to: 1. Do away with packaging the venv. 2. Keep it simple. We install into the venv, and that's that. 3. Add a toggle to rebuild the venv if you'd like to. 4. Use import_tasks with tags for each stage so that it's easy to skip a portion of what executes. Change-Id: I708b5cf32e5cce6a18624d0b3be0cd4c828ad389
85 lines
2.8 KiB
YAML
85 lines
2.8 KiB
YAML
---
|
|
# Copyright 2018, 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.
|
|
|
|
# TODO(odyssey4me):
|
|
# Set a fact for the selective inclusion of the build package list.
|
|
# Perhaps do this if the distro/architecture of the target host differs
|
|
# from the build host.
|
|
|
|
- name: Install distro packages for venv build
|
|
package:
|
|
name: "{{ venv_build_distro_package_list + venv_install_distro_package_list }}"
|
|
state: "{{ venv_distro_package_state }}"
|
|
update_cache: "{{ (ansible_pkg_mgr in ['apt', 'zypper']) | ternary('yes', omit) }}"
|
|
cache_valid_time: "{{ (ansible_pkg_mgr == 'apt') | ternary(venv_distro_cache_valid_time, omit) }}"
|
|
when:
|
|
- (venv_build_distro_package_list | length > 0) or
|
|
(venv_install_distro_package_list | length > 0)
|
|
register: _install_distro_packages
|
|
until: _install_distro_packages is success
|
|
retries: 5
|
|
delay: 2
|
|
|
|
- name: Ensure a fresh venv_install_destination_path if venv_rebuild is enabled
|
|
file:
|
|
path: "{{ venv_install_destination_path }}"
|
|
state: absent
|
|
when:
|
|
- venv_rebuild | bool
|
|
|
|
# NOTE(odyssey4me):
|
|
# Not using --always-copy for CentOS/SuSE due to
|
|
# https://github.com/pypa/virtualenv/issues/565
|
|
- name: Create the virtualenv (if it does not exist)
|
|
command: >-
|
|
virtualenv
|
|
{{ _venv_create_extra_options }}
|
|
--python={{ venv_python_executable }}
|
|
{{ (ansible_pkg_mgr == 'apt') | ternary('--always-copy', '') }}
|
|
{{ venv_install_destination_path }}
|
|
args:
|
|
creates: "{{ venv_install_destination_path }}/bin/activate"
|
|
|
|
- name: Upgrade pip/setuptools/wheel to the versions we want
|
|
pip:
|
|
name:
|
|
- pip
|
|
- setuptools
|
|
- wheel
|
|
state: "{{ venv_pip_package_state }}"
|
|
virtualenv: "{{ venv_install_destination_path }}"
|
|
extra_args: >-
|
|
--log /var/log/python_venv_build.log
|
|
{{ venv_pip_install_args }}
|
|
register: _update_virtualenv_packages
|
|
until: _update_virtualenv_packages is success
|
|
retries: 5
|
|
delay: 2
|
|
|
|
- name: Install python packages into the venv
|
|
pip:
|
|
name: "{{ venv_pip_packages }}"
|
|
state: "{{ venv_pip_package_state }}"
|
|
virtualenv: "{{ venv_install_destination_path }}"
|
|
extra_args: >-
|
|
--log /var/log/python_venv_build.log
|
|
{{ venv_pip_install_args }}
|
|
register: _install_venv_pip_packages
|
|
until: _install_venv_pip_packages is success
|
|
retries: 5
|
|
delay: 2
|
|
notify:
|
|
- venv changed
|