forked from chaoss/grimoirelab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ansible_release.yml
179 lines (162 loc) · 5.14 KB
/
ansible_release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
---
## Build and push GrimoireLab Docker images to DockerHub
##
## For this playbook to work, ensure docker-py is Installed
## pip install docker-py
##
## Run as:
## ansible-playbook ansible_release.yml --extra-vars "RELEASE=18.03-04"
## ansible-playbook ansible_release.yml --check --extra-vars "RELEASE=18.04-01" --tags "build"
## ansible-playbook ansible_release.yml --check --extra-vars "RELEASE=latest" --tags "build"
## ansible-playbook ansible_release.yml --check --extra-vars "RELEASE=18.04-01" --tags "push"
##
## Build Python packages and containers, not failing if something goes wrong
## ANSIBLE_STDOUT_CALLBACK=debug ansible-playbook ansible_release.yml --check --extra-vars "RELEASE=18.04-01 fail=" --tags "build"
##
## Variables:
## - RELEASE: release id (default "latest", other examples: "18.07-11"...)
## - LOCAL: use repos_local.json to override repos with local ones
## (default "NO", set as "YES" if using local repos)
## - FAIL: fail if errors (default "YES", set as "NO" if not to fail)
##
## Tags:
## - build_pkgs: Build Python packages (and factory container image)
## - build: Build Python packages and all container images, and run tests
## - push: Push packages and containers to Pypi and DockerHub
## - test: Run package tests (assumes container images are available)
- name: Build grimoirelab/factory
hosts: localhost
tags:
- build
tasks:
- include_tasks: ansible_build_tag.yml
loop:
- factory
- name: Build GrimoireLab packages
hosts: localhost
tags:
- build
- build_pkgs
vars:
RELEASE: "latest"
LOCAL: "NO"
FAIL: "YES"
fail: "{{ ' ' if (FAIL=='NO') else '--fail' }}"
repos_file: ""
repo_vol: "{{ playbook_dir }}/..:/grimoirelab"
tasks:
- name: "Define local vars if LOCAL"
set_fact:
repos_file: "--reposfile /grimoirelab/docker/repos_local.json"
when: LOCAL == "YES"
- name: "Create directories for packages and old packages"
file:
path: "{{playbook_dir}}/{{item}}"
state: directory
mode: 0777
with_items:
- dist
- dist.old
- name: "Move old packages from dist to dist.old"
command: "mv -f {{item}} {{ playbook_dir }}/dist.old"
with_fileglob:
"{{playbook_dir}}/dist/*"
- name: "Create directories for logs"
file:
path: "{{playbook_dir}}/logs"
state: directory
mode: 0777
- name: "Build packages using grimoirelab/factory ({{ RELEASE }})"
when: RELEASE != 'latest'
docker_container:
name: factory
image: "grimoirelab/factory:{{ RELEASE }}"
volumes:
- "{{ playbook_dir }}/dist:/dist"
- "{{ playbook_dir }}/logs:/logs"
- "{{ playbook_dir }}/../releases/{{ RELEASE }}:/release"
- "{{repo_vol}}"
command: "--build --install --check {{ fail }} --relfile /release {{repos_file}}"
detach: False
register: result
- debug:
# msg: "Building output:\n{{result.ansible_facts.docker_container.Output}}"
msg: "Building output:\n{{result.ansible_facts}}"
when: RELEASE != 'latest' and result.ansible_facts is defined
- name: "Build packages using grimoirelab/factory (latest in master)"
when: RELEASE == 'latest'
docker_container:
name: factory
image: "grimoirelab/factory:{{ RELEASE }}"
volumes:
- "{{ playbook_dir }}/dist:/dist"
- "{{ playbook_dir }}/logs:/logs"
command: "--build --install --check {{ fail }}"
detach: False
register: result
- debug:
msg: "Building output:\n{{result.ansible_facts.docker_container.Output}}"
when: RELEASE == 'latest' and result.ansible_facts is defined
- name: "Build grimoirelab/{installed,full}"
hosts: localhost
tags:
- build
tasks:
- include_tasks: ansible_build_tag.yml
loop:
- installed
- full
- name: "Test using grimoirelab/full"
hosts: localhost
tags:
- build
- test
vars:
FAIL: "YES"
tasks:
- name: "Test using grimoirelab/full:{{RELEASE}}"
docker_container:
name: factory
image: "grimoirelab/full:{{ RELEASE }}"
volumes:
- "{{ playbook_dir }}/dist:/dist"
- "{{ playbook_dir }}/logs:/logs"
- "{{ playbook_dir }}/testconf:/testconf"
- "{{ playbook_dir }}/../releases/{{ RELEASE }}:/release"
env:
TEST: "YES"
FAIL: "{{FAIL}}"
detach: False
register: result
- debug:
msg: "Testing output:\n{{result.ansible_facts.docker_container.Output}}"
when: result.ansible_facts is defined
- name: "Build grimoirelab/secured"
hosts: localhost
tags:
- build
tasks:
- include_tasks: ansible_build_tag.yml
loop:
- secured
- name: "Push packages to pypi"
hosts: localhost
tags:
- push
- push_pypi
tasks:
- command: "twine upload --skip-existing {{item}}"
with_fileglob:
"{{playbook_dir}}/dist/*"
- name: "Push to DockerHub"
hosts: localhost
tags:
- push
- push_docker
tasks:
- include_tasks: ansible_push.yml
loop:
- factory
- installed
- full
- secured