Allow a venv to be downloaded from a URL
In order to enable the ability to build venvs on a target, then serve them via http(s) from a central storage host, we enable the ability to set the path to be a URL. If this is done then the venvs will be sourced from that URL when installing. Change-Id: I166de361f568bfdf28c0f5d916ff8175827c45f4
This commit is contained in:
parent
58f0eaa468
commit
879ae97343
@ -70,10 +70,13 @@ venv_reuse_build_only: no
|
||||
# venvs.
|
||||
venv_reuse_build_wheels: yes
|
||||
|
||||
# The path where a built venv should be stored on the
|
||||
# deployment host. By default, ensure that the location
|
||||
# separates venvs per distribution and architecture to
|
||||
# prevent re-use of venvs between them.
|
||||
# The path where a built venv is stored on the By default,
|
||||
# a path on the deployment host is used which ensures that
|
||||
# the location separates venvs per distribution and architecture
|
||||
# to prevent re-use of venvs between them. If the path set
|
||||
# begins with http(s):// then the install process will
|
||||
# recognise this and deploy from a URL instead of the
|
||||
# deployment host.
|
||||
venv_reuse_download_venv_path: "{{ lookup('env', 'HOME') | default('/opt', true) }}/cache/venvs/{{ venv_reuse_download_subfolder }}"
|
||||
|
||||
# NOTE(hwoarang): ansible_distribution may return a string with spaces
|
||||
@ -81,7 +84,8 @@ venv_reuse_download_venv_path: "{{ lookup('env', 'HOME') | default('/opt', true)
|
||||
# in order to create a more sensible repo name for the distro.
|
||||
venv_reuse_download_subfolder: "{{ (ansible_distribution | lower) | replace(' ', '_') }}-{{ ansible_distribution_version.split('.')[:2] | join('.') }}-{{ ansible_architecture | lower }}"
|
||||
|
||||
# The owner of the venv_reuse_download_venv_path
|
||||
# The owner of the venv_reuse_download_venv_path if it is
|
||||
# housed on the deployment host.
|
||||
venv_reuse_download_path_owner: "{{ lookup('env', 'USER') | default('root', true) }}"
|
||||
|
||||
# The path where the wheels are cached on the target host
|
||||
|
@ -79,7 +79,8 @@
|
||||
- venv changed
|
||||
|
||||
- name: Package the venv when venv_reuse_enable is enabled
|
||||
when: venv_reuse_enable | bool
|
||||
when:
|
||||
- venv_reuse_enable | bool
|
||||
block:
|
||||
|
||||
- name: Clean up the virtualenv before packaging
|
||||
@ -124,5 +125,6 @@
|
||||
- src: "{{ venv_destination_path }}.checksum"
|
||||
dest: "{{ venv_reuse_download_venv_path }}/{{ venv_destination_path | basename }}.checksum"
|
||||
when:
|
||||
- _venv_source == 'file'
|
||||
- _venv_package_build is mapping
|
||||
- _venv_package_build | changed
|
||||
|
@ -18,14 +18,33 @@
|
||||
src: "{{ venv_reuse_download_venv_path }}/{{ venv_destination_path | basename }}.checksum"
|
||||
dest: "{{ venv_destination_path | dirname }}/"
|
||||
register: _venv_checksum_copy
|
||||
when:
|
||||
- _venv_source == 'file'
|
||||
|
||||
- name: Retrieve checksum for venv download
|
||||
uri:
|
||||
url: "{{ venv_reuse_download_venv_path }}/{{ venv_destination_path | basename }}.checksum"
|
||||
dest: "{{ venv_destination_path | dirname }}/"
|
||||
return_content: yes
|
||||
register: _venv_checksum_download
|
||||
when:
|
||||
- _venv_source == 'url'
|
||||
|
||||
- name: Attempt venv download
|
||||
get_url:
|
||||
url: "{{ venv_reuse_download_venv_path }}/{{ venv_destination_path | basename }}.tgz"
|
||||
dest: "{{ venv_destination_path | dirname }}/"
|
||||
checksum: "sha1:{{ _venv_checksum_download.content | trim }}"
|
||||
when:
|
||||
- _venv_source == 'url'
|
||||
|
||||
- name: Remove existing venv on target host if it is changing
|
||||
file:
|
||||
path: "{{ venv_destination_path }}"
|
||||
state: absent
|
||||
when:
|
||||
- _venv_checksum_copy is mapping
|
||||
- _venv_checksum_copy | changed
|
||||
- (_venv_checksum_copy is mapping and _venv_checksum_copy | changed) or
|
||||
(_venv_checksum_download is mapping and _venv_checksum_download | changed)
|
||||
|
||||
- name: Create venv directory on the target host
|
||||
file:
|
||||
@ -40,6 +59,7 @@
|
||||
remote_src: no
|
||||
when:
|
||||
- (_venv_checksum_copy is mapping and _venv_checksum_copy | changed) or
|
||||
(_venv_checksum_download is mapping and _venv_checksum_download | changed) or
|
||||
_venv_dir_create | changed
|
||||
notify:
|
||||
- venv changed
|
||||
@ -53,6 +73,7 @@
|
||||
warn: no
|
||||
when:
|
||||
- (_venv_checksum_copy is mapping and _venv_checksum_copy | changed) or
|
||||
(_venv_checksum_download is mapping and _venv_checksum_download | changed) or
|
||||
_venv_dir_create | changed
|
||||
tags:
|
||||
- skip_ansible_lint
|
||||
|
@ -32,6 +32,10 @@
|
||||
- venv_reuse_build_only | bool
|
||||
- not venv_reuse_enable | bool
|
||||
|
||||
- name: Check whether the venv_reuse_download_venv_path is a URL or a file path
|
||||
set_fact:
|
||||
_venv_source: "{{ (venv_reuse_download_venv_path is match('^https?://.*')) | ternary('url', 'file') }}"
|
||||
|
||||
- name: Ensure that venv_reuse_download_path exists on the deployment host
|
||||
file:
|
||||
path: "{{ venv_reuse_download_venv_path }}"
|
||||
@ -40,6 +44,7 @@
|
||||
delegate_to: localhost
|
||||
run_once: yes
|
||||
when:
|
||||
- _venv_source == 'file'
|
||||
- venv_reuse_enable | bool
|
||||
|
||||
- name: Check if venv tgz is present on the deployment host
|
||||
@ -53,6 +58,7 @@
|
||||
delegate_to: localhost
|
||||
run_once: yes
|
||||
when:
|
||||
- _venv_source == 'file'
|
||||
- venv_reuse_enable | bool
|
||||
|
||||
- name: Ensure that virtualenv is installed on the destination host
|
||||
|
@ -29,6 +29,9 @@
|
||||
- (_venv_checksum_copy is defined and
|
||||
_venv_checksum_copy is mapping and
|
||||
_venv_checksum_copy | changed) or
|
||||
(_venv_checksum_download is defined and
|
||||
_venv_checksum_download is mapping and
|
||||
_venv_checksum_download | changed) or
|
||||
(_install_venv_pip_packages is defined and
|
||||
_install_venv_pip_packages is mapping and
|
||||
_install_venv_pip_packages | changed)
|
||||
|
Loading…
x
Reference in New Issue
Block a user