aboutsummaryrefslogtreecommitdiffstats
path: root/roles/gitlab-ci-generator/templates/gitlab-ci.yml
blob: 51ceb054fa7ababc4b48f481b8b8bb8deaa54c93 (plain)
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
---
################################################################################
#
# !! DO NOT EDIT MANUALLY !!
#
# This file is generated by gitlab-ci-generator
#
################################################################################

stages:
{% for stage in stages %}
  - {{ stage }}
{% endfor %}

variables:
  GIT_SUBMODULE_STRATEGY: recursive
  VAULT_FILE: .vault

################################################################################
# Shared parameters
################################################################################
.runner_tags: &runner_tags
  tags:
{% for tag in runner.tags %}
    - {{ tag }}
{% endfor %}

.syntax_checking: &syntax_checking
  only:
    - pushes
  stage: lint

.artifacts_root: &artifacts_root
  name: "$CI_JOB_NAME-$CI_COMMIT_REF_NAME"
  paths:
    - vars/
    - inventory/

.artifacts: &artifacts
  artifacts:
    <<: *artifacts_root
    expire_in: 15 days

.artifacts_longexpire: &artifacts_longexpire
  artifacts:
    <<: *artifacts_root
    expire_in: 1 yrs

.runner_env: &runner_env
{% for var_name, var_value in runner.env_vars.items()|default({'foo': 'bar'}) %}
  {{ var_name }}: "{{ var_value }}"
{% endfor %}

################################################################################
# Linting
################################################################################

yaml_checking:
  <<: *syntax_checking
  <<: *runner_tags
  variables:
    <<: *runner_env
  image: {{ runner.docker_proxy }}sdesbure/yamllint:latest
  script:
    - >
      yamllint -d "line-length: {
      max: 80,
      allow-non-breakable-words: true,
      allow-non-breakable-inline-mappings: true}"
      .gitlab-ci.yml
    - yamllint *.yml

ansible_linting:
  <<: *syntax_checking
  <<: *runner_tags
  variables:
    <<: *runner_env
  image: {{ runner.docker_proxy }}sdesbure/ansible-lint:latest
  script:
    - ansible-lint -x ANSIBLE0010,ANSIBLE0013 run-ci.yml

{% if not (disable_pages | default(false)) %}
################################################################################
# Pages
################################################################################

pages:
  image: {{ runner.docker_proxy }}{{ runner.image }}:{{ runner.image_tag }}
  stage: lint
  <<: *runner_tags
  variables:
    <<: *runner_env
  script:
    - ./chained-ci-vue/init.sh ./pod_inventory
  artifacts:
    paths:
      - public
  only:
    - master
  except:
    - triggers
    - api
    - external
    - pipelines
    - schedules
    - web

{% endif %}

################################################################################
# Jobs
################################################################################

.vault_mgmt: &vault_mgmt
  before_script:
    - echo ${ANSIBLE_VAULT_PASSWORD} > ${PWD}/${VAULT_FILE}
  after_script:
    - rm -f $PWD/.vault

.set_config: &set_config
  <<: *runner_tags
  <<: *vault_mgmt
  image: {{ runner.docker_proxy }}{{ runner.image }}:{{ runner.image_tag }}
  script:
    - >
      ansible-playbook -i pod_inventory/inventory --limit ${pod}
      --vault-password-file ${PWD}/${VAULT_FILE}
      ${ansible_verbose} artifacts_init.yml

.run_ci: &run_ci
  <<: *runner_tags
  <<: *vault_mgmt
  image: {{ runner.docker_proxy }}{{ runner.image }}:{{ runner.image_tag }}
  script:
    - >
      ansible-playbook -i pod_inventory/inventory --limit ${pod}
      --extra-vars "step=${CI_JOB_NAME%:*}"
      --vault-password-file ${PWD}/${VAULT_FILE}
      ${ansible_verbose} run-ci.yml

.trigger: &trigger
  <<: *runner_tags
  <<: *vault_mgmt
  image: {{ runner.docker_proxy }}{{ runner.image }}:{{ runner.image_tag }}
  script:
    - >
      ansible-playbook -i pod_inventory/inventory --limit ${pod}
      --vault-password-file ${PWD}/${VAULT_FILE}
      ${ansible_verbose} --extra-vars "step=trigger" trigger_myself.yml

{% for pipeline in groups['all'] %}
################################################################################
# {{ pipeline }}
################################################################################

.{{ pipeline }}_global: &{{ pipeline }}_global
  variables:
    pod: {{ pipeline }}
    <<: *runner_env
{% if hostvars[pipeline].environment is defined %}
  environment:
    name: {{ hostvars[pipeline].environment }}
{% endif %}
  only:
    variables:
      - $POD == "{{ pipeline }}"
{% if hostvars[pipeline].inpod is defined %}
      - $INPOD == "{{ hostvars[pipeline].inpod }}"
{% endif %}
    refs:
      - web
      - schedules
      - triggers

{% for stage in stages %}
{% for task in hostvars[pipeline].scenario_steps %}
{% if hostvars[pipeline].scenario_steps[task].stage | default(
    gitlab.git_projects[hostvars[pipeline].scenario_steps[task].project].stage
  ) == stage %}
{{ task }}:{{ pipeline }}:
  stage: {{ stage }}
  <<: *{{ pipeline }}_global
{% if hostvars[pipeline].scenario_steps[task].project == 'config' %}
  <<: *set_config
{% elif hostvars[pipeline].scenario_steps[task].project == 'trigger' %}
  <<: *trigger
{% else %}
  <<: *run_ci
{% endif %}
{% if (hostvars[pipeline].scenario_steps[task].pull_artifacts
    | default(gitlab.git_projects[hostvars[pipeline].scenario_steps[task].project].pull_artifacts)
    | default(false))
    or task == 'config' %}
  <<: *artifacts{% if hostvars[pipeline].longlife_artifact | default(false) | bool %}_longexpire{% endif %}

{% endif %}
{% endif %}
{% endfor %}
{% endfor %}

{% endfor %}
##
# End of generated file
##