From 2ea8661801b613be1f1f1122d92f690634aa4ea6 Mon Sep 17 00:00:00 2001 From: "Andrea Frittoli (andreaf)" Date: Tue, 3 Oct 2017 17:24:32 +0100 Subject: [PATCH] Add compress capabilities to stage artifacts Compress files and files in folders. Use gz by default. Change-Id: I72796e64a65fe88d85168734ac881ee3ec2ce100 --- roles/stage-output/README.rst | 5 +++++ roles/stage-output/defaults/main.yaml | 1 + roles/stage-output/tasks/main.yaml | 15 +++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/roles/stage-output/README.rst b/roles/stage-output/README.rst index c503758e2..9e5e848dd 100644 --- a/roles/stage-output/README.rst +++ b/roles/stage-output/README.rst @@ -47,3 +47,8 @@ intended to be used before output fetching in a base job's post-playbook. - log zuul.conf --(staged as)--> zuul_conf.txt + +.. zuul:rolevar:: stage_compress_logs + :default: True + + When True, files staged as logs will be compressed individually. diff --git a/roles/stage-output/defaults/main.yaml b/roles/stage-output/defaults/main.yaml index daece5503..61c8c89df 100644 --- a/roles/stage-output/defaults/main.yaml +++ b/roles/stage-output/defaults/main.yaml @@ -1,2 +1,3 @@ stage_dir: "{{ ansible_user_dir }}" extensions_to_txt: +stage_compress_logs: true diff --git a/roles/stage-output/tasks/main.yaml b/roles/stage-output/tasks/main.yaml index 58b0a1248..e6ce01f61 100644 --- a/roles/stage-output/tasks/main.yaml +++ b/roles/stage-output/tasks/main.yaml @@ -19,6 +19,7 @@ set_fact: source: "{{ item.stat.path }}" dest: "{{ item.item.value }}/{{ item.stat.path|basename|regex_replace('\\.(' + extensions_regex + ')$', '_\\1.txt') }}" + type: "{{ item.item.value }}" with_items: "{{ sources.results }}" when: - item.stat.exists @@ -45,3 +46,17 @@ # zuul, using command command: cp -pR {{ item.source}} {{ stage_dir }}/{{ item.dest }} with_items: "{{ all_sources }}" + +# NOTE(andreaf) The ansible module does not support recursive archive, so +# using gzip is the only option here. The good bit is that gzip itself is +# almost idempotent, as it will not compress again files with .gz extension. +# gzip will however return 1 if any compressed file is encountered, so we +# must ignore that (there's no specific error code). +- name: Archive everything from docs sources + shell: gzip --recursive --best {{ item.dest }} || true + args: + chdir: "{{ stage_dir }}" + with_items: "{{ all_sources }}" + when: + - stage_compress_logs + - item.type == 'logs'