mirror of
https://github.com/ansible/awx.git
synced 2026-05-10 10:57:35 -02:30
Cache downloaded roles & collections
Populate the cache the first time the job is run for a revision that needs them, and for future runs for that revision just copy it into the private directory. Delete the cache on project deletion.
This commit is contained in:
committed by
AlanCoding
parent
bedbafe0f9
commit
d272ee3521
@@ -194,6 +194,11 @@ class ProjectOptions(models.Model):
|
|||||||
if not check_if_exists or os.path.exists(smart_str(proj_path)):
|
if not check_if_exists or os.path.exists(smart_str(proj_path)):
|
||||||
return proj_path
|
return proj_path
|
||||||
|
|
||||||
|
def get_cache_path(self):
|
||||||
|
local_path = os.path.basename(self.local_path)
|
||||||
|
if local_path:
|
||||||
|
return os.path.join(settings.PROJECTS_ROOT, '.__awx_cache', local_path)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def playbooks(self):
|
def playbooks(self):
|
||||||
results = []
|
results = []
|
||||||
@@ -455,11 +460,12 @@ class Project(UnifiedJobTemplate, ProjectOptions, ResourceMixin, CustomVirtualEn
|
|||||||
)
|
)
|
||||||
|
|
||||||
def delete(self, *args, **kwargs):
|
def delete(self, *args, **kwargs):
|
||||||
path_to_delete = self.get_project_path(check_if_exists=False)
|
paths_to_delete = (self.get_project_path(check_if_exists=False), self.get_cache_path())
|
||||||
r = super(Project, self).delete(*args, **kwargs)
|
r = super(Project, self).delete(*args, **kwargs)
|
||||||
if self.scm_type and path_to_delete: # non-manual, concrete path
|
for path_to_delete in paths_to_delete:
|
||||||
from awx.main.tasks import delete_project_files
|
if self.scm_type and path_to_delete: # non-manual, concrete path
|
||||||
delete_project_files.delay(path_to_delete)
|
from awx.main.tasks import delete_project_files
|
||||||
|
delete_project_files.delay(path_to_delete)
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2181,6 +2181,7 @@ class RunProjectUpdate(BaseTask):
|
|||||||
'scm_url': scm_url,
|
'scm_url': scm_url,
|
||||||
'scm_branch': scm_branch,
|
'scm_branch': scm_branch,
|
||||||
'scm_clean': project_update.scm_clean,
|
'scm_clean': project_update.scm_clean,
|
||||||
|
'project_cache': project_update.get_cache_path(),
|
||||||
'roles_enabled': settings.AWX_ROLES_ENABLED,
|
'roles_enabled': settings.AWX_ROLES_ENABLED,
|
||||||
'collections_enabled': settings.AWX_COLLECTIONS_ENABLED,
|
'collections_enabled': settings.AWX_COLLECTIONS_ENABLED,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
---
|
---
|
||||||
# The following variables will be set by the runner of this playbook:
|
# The following variables will be set by the runner of this playbook:
|
||||||
# project_path: PROJECTS_DIR/_local_path_
|
# project_path: PROJECTS_DIR/_local_path_
|
||||||
|
# project_cache: CACHE_DIR/.__awx_cache/_local_path_
|
||||||
# scm_url: https://server/repo
|
# scm_url: https://server/repo
|
||||||
# insights_url: Insights service URL (from configuration)
|
# insights_url: Insights service URL (from configuration)
|
||||||
# scm_branch: branch/tag/revision (HEAD if unset)
|
# scm_branch: branch/tag/revision (HEAD if unset)
|
||||||
@@ -116,13 +117,17 @@
|
|||||||
tasks:
|
tasks:
|
||||||
|
|
||||||
- block:
|
- block:
|
||||||
|
- name: set content cache location
|
||||||
|
set_fact:
|
||||||
|
cache_dir: "{{ project_cache }}/{{ scm_branch }}"
|
||||||
|
|
||||||
- name: detect requirements.yml
|
- name: detect requirements.yml
|
||||||
stat:
|
stat:
|
||||||
path: '{{project_path|quote}}/roles/requirements.yml'
|
path: '{{project_path|quote}}/roles/requirements.yml'
|
||||||
register: doesRequirementsExist
|
register: doesRequirementsExist
|
||||||
|
|
||||||
- name: fetch galaxy roles from requirements.yml
|
- name: fetch galaxy roles from requirements.yml
|
||||||
command: ansible-galaxy role install -r roles/requirements.yml -p {{roles_destination|quote}}{{ ' -' + 'v' * ansible_verbosity if ansible_verbosity else '' }}
|
command: ansible-galaxy role install -r roles/requirements.yml -p {{ cache_dir }}/requirements_roles {{ ' -' + 'v' * ansible_verbosity if ansible_verbosity else '' }}
|
||||||
args:
|
args:
|
||||||
chdir: "{{project_path|quote}}"
|
chdir: "{{project_path|quote}}"
|
||||||
register: galaxy_result
|
register: galaxy_result
|
||||||
@@ -132,18 +137,27 @@
|
|||||||
ANSIBLE_FORCE_COLOR: false
|
ANSIBLE_FORCE_COLOR: false
|
||||||
GIT_SSH_COMMAND: "ssh -o StrictHostKeyChecking=no"
|
GIT_SSH_COMMAND: "ssh -o StrictHostKeyChecking=no"
|
||||||
|
|
||||||
|
- name: populate job directory with needed roles
|
||||||
|
synchronize:
|
||||||
|
src: "{{ cache_dir }}/requirements_roles"
|
||||||
|
dest: "{{ roles_destination }}"
|
||||||
|
|
||||||
when: roles_enabled|bool
|
when: roles_enabled|bool
|
||||||
tags:
|
tags:
|
||||||
- install_roles
|
- install_roles
|
||||||
|
|
||||||
- block:
|
- block:
|
||||||
|
- name: set content cache location
|
||||||
|
set_fact:
|
||||||
|
cache_dir: "{{ project_cache }}/{{ scm_branch }}"
|
||||||
|
|
||||||
- name: detect collections/requirements.yml
|
- name: detect collections/requirements.yml
|
||||||
stat:
|
stat:
|
||||||
path: '{{project_path|quote}}/collections/requirements.yml'
|
path: '{{project_path|quote}}/collections/requirements.yml'
|
||||||
register: doesCollectionRequirementsExist
|
register: doesCollectionRequirementsExist
|
||||||
|
|
||||||
- name: fetch galaxy collections from collections/requirements.yml
|
- name: fetch galaxy collections from collections/requirements.yml
|
||||||
command: ansible-galaxy collection install -r collections/requirements.yml -p {{collections_destination|quote}}{{ ' -' + 'v' * ansible_verbosity if ansible_verbosity else '' }}
|
command: ansible-galaxy collection install -r collections/requirements.yml -p {{ cache_dir }}/requirements_collections {{ ' -' + 'v' * ansible_verbosity if ansible_verbosity else '' }}
|
||||||
args:
|
args:
|
||||||
chdir: "{{project_path|quote}}"
|
chdir: "{{project_path|quote}}"
|
||||||
register: galaxy_collection_result
|
register: galaxy_collection_result
|
||||||
@@ -151,9 +165,14 @@
|
|||||||
changed_when: "'Installing ' in galaxy_collection_result.stdout"
|
changed_when: "'Installing ' in galaxy_collection_result.stdout"
|
||||||
environment:
|
environment:
|
||||||
ANSIBLE_FORCE_COLOR: false
|
ANSIBLE_FORCE_COLOR: false
|
||||||
ANSIBLE_COLLECTIONS_PATHS: "{{ collections_destination }}"
|
ANSIBLE_COLLECTIONS_PATHS: "{{ cache_dir }}/requirements_collections"
|
||||||
GIT_SSH_COMMAND: "ssh -o StrictHostKeyChecking=no"
|
GIT_SSH_COMMAND: "ssh -o StrictHostKeyChecking=no"
|
||||||
|
|
||||||
|
- name: populate job directory with needed collections
|
||||||
|
synchronize:
|
||||||
|
src: "{{ cache_dir }}/requirements_collections"
|
||||||
|
dest: "{{ collections_destination }}"
|
||||||
|
|
||||||
when:
|
when:
|
||||||
- "ansible_version.full is version_compare('2.8', '>=')"
|
- "ansible_version.full is version_compare('2.8', '>=')"
|
||||||
- collections_enabled|bool
|
- collections_enabled|bool
|
||||||
|
|||||||
Reference in New Issue
Block a user