Skip to content

Commit ea20e0b

Browse files
committed
Add local version of upload-logs-s3
1 parent e92fe33 commit ea20e0b

File tree

4 files changed

+117
-0
lines changed

4 files changed

+117
-0
lines changed

roles/upload-logs-s3/README.rst

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
Upload logs to S3
2+
3+
Before using this role, create at least one bucket and set up
4+
appropriate access controls or lifecycle events. This role will not
5+
automatically create buckets.
6+
7+
This role requires the ``boto3`` Python package to be
8+
installed in the Ansible environment on the Zuul executor.
9+
10+
**Role Variables**
11+
12+
.. zuul:rolevar:: zuul_site_upload_logs
13+
:default: true
14+
15+
Controls when logs are uploaded. true, the default, means always
16+
upload logs. false means never upload logs. 'failure' means to only
17+
upload logs when the job has failed.
18+
19+
.. note:: Intended to be set by admins via site-variables.
20+
21+
.. zuul:rolevar:: zuul_log_partition
22+
:default: false
23+
24+
If set to true, then the first component of the log path will be
25+
removed from the object name and added to the bucket name, so that
26+
logs for different changes are distributed across a large number of
27+
buckets.
28+
29+
.. zuul:rolevar:: zuul_log_bucket
30+
31+
This role *will not* create buckets which do not already exist. If
32+
partitioning is not enabled, this is the name of the bucket which
33+
will be used. If partitioning is enabled, then this will be used
34+
as the prefix for the bucket name which will be separated from the
35+
partition name by an underscore. For example, "logs_42" would be
36+
the bucket name for partition 42.
37+
38+
Note that you will want to set this to a value that uniquely
39+
identifies your Zuul installation.
40+
41+
.. zuul:rolevar:: zuul_log_bucket_public
42+
:default: true
43+
44+
Set to false to make logs private.
45+
46+
.. zuul:rolevar:: zuul_log_path
47+
:default: Generated by the role `set-zuul-log-path-fact`
48+
49+
Prepend this path to the object names when uploading.
50+
51+
.. zuul:rolevar:: zuul_log_create_indexes
52+
:default: true
53+
54+
Whether to create `index.html` files with directory indexes.
55+
56+
.. zuul:rolevar:: zuul_log_aws_access_key
57+
58+
AWS access key to use.
59+
60+
.. zuul:rolevar:: zuul_log_aws_secret_key
61+
62+
AWS secret key for the AWS access key.
63+
64+
.. zuul:rolevar:: upload_logs_s3_endpoint
65+
66+
The endpoint to use when uploading logs to an s3 compatible service.
67+
By default this will be automatically constructed by boto but should be set when working with non-aws hosted s3 service.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
zuul_log_partition: false
2+
zuul_log_create_indexes: true
3+
zuul_log_bucket_public: true
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dependencies:
2+
- role: upload-logs-base
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
- name: Set zuul-log-path fact
2+
include_role:
3+
name: set-zuul-log-path-fact
4+
when: zuul_log_path is not defined
5+
6+
# Always upload (true), never upload (false) or only on failure ('failure')
7+
- name: Upload logs
8+
when: zuul_site_upload_logs | default(true) | bool or
9+
(zuul_site_upload_logs == 'failure' and not zuul_success | bool)
10+
block:
11+
# Use chmod instead of file because ansible 2.5 file with recurse and
12+
# follow can't really handle symlinks to .
13+
- name: Debug log_root
14+
debug:
15+
msg: "log_root {{ zuul.executor.log_root }}"
16+
17+
- name: Ensure logs are readable before uploading
18+
delegate_to: "{{ _undocumented_test_worker_node_ | default('localhost') }}"
19+
command: "chmod -R u=rwX,g=rX,o=rX {{ zuul.executor.log_root }}/"
20+
# ANSIBLE0007 chmod used in place of argument mode to file
21+
tags:
22+
- skip_ansible_lint
23+
24+
- name: Upload logs to S3
25+
delegate_to: "{{ _undocumented_test_worker_node_ | default('localhost') }}"
26+
zuul_s3_upload:
27+
endpoint: "{{ upload_logs_s3_endpoint | default(omit) }}"
28+
partition: "{{ zuul_log_partition }}"
29+
bucket: "{{ zuul_log_bucket }}"
30+
public: "{{ zuul_log_bucket_public }}"
31+
prefix: "{{ zuul_log_path }}"
32+
indexes: "{{ zuul_log_create_indexes }}"
33+
aws_access_key: "{{ zuul_log_aws_access_key }}"
34+
aws_secret_key: "{{ zuul_log_aws_secret_key }}"
35+
files:
36+
- "{{ zuul.executor.log_root }}/"
37+
register: upload_results
38+
39+
- name: Return log URL to Zuul
40+
delegate_to: localhost
41+
zuul_return:
42+
data:
43+
zuul:
44+
log_url: "{{ upload_results.url }}/"
45+
when: upload_results is defined

0 commit comments

Comments
 (0)