fetch-javascript-tarball: introduce zuul_use_fetch_output

This change enables using fetch-javascript role along with
the fetch-output role. By default the role still synchronizes
artifacts back to the executor.

Change-Id: I8450ecf91b3387445ebe2436754d1b88f2a77844
This commit is contained in:
Tristan Cacqueray 2019-09-11 20:39:49 +00:00
parent be8308c7ac
commit 9204e7d1d8
5 changed files with 74 additions and 14 deletions

View File

@ -6,3 +6,11 @@ Fetch a Javascript tarball back to be published.
:default: {{ zuul.project.src_dir }} :default: {{ zuul.project.src_dir }}
Directory to run npm in. Directory to run npm in.
.. zuul:rolevar:: zuul_use_fetch_output
:default: false
Whether to synchronize files to the executor work dir, or to copy them
on the test instance.
When set to false, the role synchronizes the file to the executor.
When set to true, the job needs to use the fetch-output role later.

View File

@ -1 +1,3 @@
zuul_work_dir: "{{ zuul.project.src_dir }}" zuul_work_dir: "{{ zuul.project.src_dir }}"
zuul_output_dir: "{{ ansible_user_dir }}/zuul-output"
zuul_use_fetch_output: "{{ zuul_site_use_fetch_output|default(false) }}"

View File

@ -1,23 +1,25 @@
- name: Rename tarball for uploading - name: Rename tarball for uploading
shell: | shell: |
mkdir -p dist mkdir -p {{ zuul_output_dir }}/artifacts
cp *.tgz dist/{{ zuul.project.short_name }}-{{ project_ver }}.tar.gz cp *.tgz {{ zuul_output_dir }}/artifacts/{{ zuul.project.short_name }}-{{ project_ver }}.tar.gz
cp *.tgz dist/{{ zuul.project.short_name }}-latest.tar.gz cp *.tgz {{ zuul_output_dir }}/artifacts/{{ zuul.project.short_name }}-latest.tar.gz
args: args:
chdir: "{{ zuul_work_dir }}" chdir: "{{ zuul_work_dir }}"
tags: tags:
# Ignore ANSIBLE0007: No need to use file module instead of mkdir # Ignore ANSIBLE0007: No need to use file module instead of mkdir
- skip_ansible_lint - skip_ansible_lint
- name: Ensure artifacts directory exists - block:
file: - name: Ensure artifacts directory exists
path: "{{ zuul.executor.work_root }}/artifacts" file:
state: directory path: "{{ zuul.executor.work_root }}/artifacts"
delegate_to: localhost state: directory
delegate_to: localhost
- name: Collect artifacts - name: Collect artifacts
synchronize: synchronize:
dest: "{{ zuul.executor.work_root }}/artifacts/" dest: "{{ zuul.executor.work_root }}/artifacts/"
mode: pull mode: pull
src: "{{ zuul_work_dir }}/dist/" src: "{{ zuul_output_dir }}/artifacts/"
verify_host: true verify_host: true
when: not zuul_use_fetch_output

View File

@ -0,0 +1,26 @@
- hosts: all
pre_tasks:
- name: Create fake tarball
shell: |
mkdir -p {{ zuul.project.src_dir }}
tar czf {{ zuul.project.src_dir }}/dist.tgz /etc/os-release
tasks:
- import_role:
name: fetch-javascript-tarball
vars:
project_ver: master
- import_role:
name: fetch-output
when: zuul_use_fetch_output
post_tasks:
- name: Check for artifact on the test instance
stat:
path: "{{ ansible_user_dir }}/zuul-output/artifacts/zuul-jobs-latest.tar.gz"
register: _test_artifact
failed_when: not _test_artifact.stat.exists
- name: Check for artifact on the executor
stat:
path: "{{ zuul.executor.work_root }}/artifacts/zuul-jobs-latest.tar.gz"
delegate_to: localhost
register: _executor_artifact
failed_when: not _executor_artifact.stat.exists

View File

@ -7,6 +7,26 @@
vars: vars:
role_name: install-nodejs role_name: install-nodejs
- job:
name: zuul-jobs-test-fetch-javascript-tarball
description: Test the fetch-javascript-tarball
files:
- roles/fetch-javascript-tarball/.*
- roles/fetch-output/.*
run: test-playbooks/javascripts/fetch-javascript-tarball.yaml
vars:
zuul_use_fetch_output: true
- job:
name: zuul-jobs-test-fetch-javascript-tarball-synchronize
description: Test the fetch-javascript-tarball without fetch-output
files:
- roles/fetch-javascript-tarball/.*
run: test-playbooks/javascripts/fetch-javascript-tarball.yaml
vars:
zuul_use_fetch_output: false
# -* AUTOGENERATED *- # -* AUTOGENERATED *-
# The following project section is autogenerated by # The following project section is autogenerated by
# tools/update-test-platforms.py # tools/update-test-platforms.py
@ -16,5 +36,7 @@
check: check:
jobs: &id001 jobs: &id001
- zuul-jobs-test-install-nodejs - zuul-jobs-test-install-nodejs
- zuul-jobs-test-fetch-javascript-tarball
- zuul-jobs-test-fetch-javascript-tarball-synchronize
gate: gate:
jobs: *id001 jobs: *id001