]>
Commit | Line | Data |
---|---|---|
8fa7ff2c IB |
1 | from buildbot.plugins import * |
2 | from buildbot_common.build_helpers import * | |
3 | import os | |
4 | from buildbot.util import bytes2unicode | |
5 | import json | |
f6e48e3a | 6 | from functools import partial |
8fa7ff2c IB |
7 | |
8 | __all__ = [ "configure", "E" ] | |
9 | ||
10 | class E(): | |
11 | PROJECT = "immaeEu" | |
12 | BUILDBOT_URL = "https://git.immae.eu/buildbot/{}/".format(PROJECT) | |
13 | SOCKET = "unix:/run/buildbot/{}.sock".format(PROJECT) | |
14 | PB_SOCKET = "unix:address=/run/buildbot/{}_pb.sock".format(PROJECT) | |
8fa7ff2c | 15 | SSH_KEY_PATH = "/var/lib/buildbot/buildbot_key" |
bd0cb07b | 16 | SSH_HOST_PATH = "/var/lib/buildbot/buildbot_hosts" |
8fa7ff2c IB |
17 | SSH_HOST_KEY = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIFbhFTl2A2RJn5L51yxJM4XfCS2ZaiSX/jo9jFSdghF" |
18 | XMPP_RECIPIENTS = os.environ["BUILDBOT_XMPP_RECIPIENTS"].split(" ") | |
19 | ||
251c0a13 | 20 | BIP39_GIT_URL = "https://git.immae.eu/perso/Immae/Projets/Cryptomonnaies/BIP39.git" |
0012da0f | 21 | IMMAE_EU_GIT_URL = "gitolite@git.immae.eu:perso/Immae/Sites/Blog" |
577d00ee | 22 | HISTORY_GIT_URL = "gitolite@git.immae.eu:perso/Immae/Sites/History" |
f2a18fd6 | 23 | RECETTES_GIT_URL = "gitolite@git.immae.eu:perso/Immae/Sites/Recettes" |
0012da0f | 24 | COURS_GIT_URL = "gitolite@git.immae.eu:perso/Immae/Sites/Cours" |
97f5a24b | 25 | DOCS_GIT_URL = "gitolite@git.immae.eu:perso/Immae/Sites/Docs" |
573e1710 IB |
26 | NORMALESUP_GIT_URL = "gitolite@git.immae.eu:perso/Immae/Projets/Sites/Normalesup" |
27 | ||
cb589b2e | 28 | COURS_RELEASE_PATH = "/var/lib/buildbot/outputs/immae/cours" |
0012da0f IB |
29 | COURS_TARBALL_PATH = "/var/lib/ftp/release.immae.eu/cours" |
30 | COURS_TARBALL_URL = "https://release.immae.eu/cours" | |
cb589b2e | 31 | BIP39_RELEASE_PATH = "/var/lib/buildbot/outputs/immae/bip39" |
577d00ee | 32 | HISTORY_RELEASE_PATH = "/var/lib/buildbot/outputs/immae/history" |
cb589b2e | 33 | IMMAE_EU_RELEASE_PATH = "/var/lib/buildbot/outputs/immae/blog" |
97f5a24b | 34 | DOCS_RELEASE_PATH = "/var/lib/buildbot/outputs/immae/docs" |
cb589b2e IB |
35 | RECETTES_RELEASE_PATH = "/var/lib/buildbot/outputs/immae/recettes" |
36 | NORMALESUP_RELEASE_PATH = "/var/lib/buildbot/outputs/immae/recherche" | |
60d328e2 IB |
37 | GSMCELLS_RELEASE_PATH = "/var/lib/ftp/release.immae.eu/gsm_cells" |
38 | GSMCELLS_RELEASE_URL = "https://release.immae.eu/gsm_cells" | |
0012da0f | 39 | |
8fa7ff2c IB |
40 | # master.cfg |
41 | SECRETS_FILE = os.getcwd() + "/secrets" | |
42 | LDAP_URL = "ldaps://ldap.immae.eu:636" | |
43 | LDAP_ADMIN_USER = "cn=buildbot,ou=services,dc=immae,dc=eu" | |
44 | LDAP_BASE = "dc=immae,dc=eu" | |
45 | LDAP_PATTERN = "(uid=%(username)s)" | |
46 | LDAP_GROUP_PATTERN = "(&(memberOf=cn=groups,ou=immaeEu,cn=buildbot,ou=services,dc=immae,dc=eu)(member=%(dn)s))" | |
47 | TITLE_URL = "https://www.immae.eu" | |
48 | TITLE = "Immae website" | |
49 | ||
8fa7ff2c IB |
50 | def configure(c): |
51 | c["buildbotURL"] = E.BUILDBOT_URL | |
52 | c["www"]["port"] = E.SOCKET | |
53 | ||
f6e48e3a IB |
54 | worker_name = "generic-worker-immae-eu" |
55 | c['workers'].append(worker.LocalWorker(worker_name)) | |
56 | ||
57 | withbranch = [] | |
58 | withoutbranch = [] | |
59 | ||
60 | withoutbranch.append(configure_gsm_cells(c, worker_name)) | |
61 | ||
62 | withbranch.append(_configure("immae_eu", immae_eu_build_factory, c, worker_name)) | |
63 | withbranch.append(_configure("normalesup", normalesup_build_factory, c, worker_name)) | |
64 | withbranch.append(_configure("cours", cours_build_factory, c, worker_name)) | |
65 | withbranch.append(_configure("recettes", recettes_build_factory, c, worker_name)) | |
66 | withbranch.append(_configure("docs", docs_build_factory, c, worker_name)) | |
67 | withbranch.append(_configure("history", history_build_factory, c, worker_name)) | |
68 | withbranch.append(_configure("bip39", bip39_build_factory, c, worker_name)) | |
69 | ||
70 | withbranch.append(_configure_symfony("Chloe", c, worker_name, | |
71 | "gitolite@git.immae.eu:perso/Immae/Sites/Chloe/New")) | |
72 | withbranch.append(_configure_symfony("Florian", c, worker_name, | |
73 | "gitolite@git.immae.eu:perso/florian_telles/stabilo")) | |
74 | withbranch.append(configure_symfony_isabelle_aten(c, worker_name)) | |
75 | withbranch.append(_configure_symfony("Ludivine", c, worker_name, | |
76 | "gitolite@git.immae.eu:perso/Immae/Sites/Ludivine")) | |
77 | withbranch.append(_configure_symfony("Connexionswing", c, worker_name, | |
78 | "gitolite@git.immae.eu:perso/Immae/Projets/Connexionswing")) | |
79 | withbranch.append(_configure_symfony("Piedsjaloux", c, worker_name, | |
80 | "gitolite@git.immae.eu:Pieds_jaloux/NewSite")) | |
81 | ||
82 | c['schedulers'].append(force_scheduler("force_immae_eu", withbranch)) | |
83 | c['schedulers'].append(force_scheduler("force_no_branch_immae_eu", withoutbranch, nobranch=True)) | |
84 | ||
85 | configure_slack_push(c, E.SECRETS_FILE, all_builder_names(c)) | |
86 | configure_xmpp_push(c, E.SECRETS_FILE, all_builder_names(c), E.XMPP_RECIPIENTS) | |
87 | ||
88 | BRANCH_TO_SYMFONY_ENV = { | |
89 | "Ludivine": { | |
90 | "master": "prod", | |
91 | "test": "dev", | |
92 | }, | |
93 | "Connexionswing": { | |
94 | "master": "prod", | |
95 | "test": "dev", | |
96 | }, | |
97 | "Piedsjaloux": { | |
98 | "master": "prod", | |
99 | "test": "dev", | |
8fa7ff2c | 100 | } |
f6e48e3a IB |
101 | } |
102 | ||
103 | BRANCH_TO_SERVICE_NAME = { | |
104 | "Chloe": { | |
105 | "test": "phpfpm-chloe_new_integration", | |
106 | #"master": "phpfpm-chloe_production", | |
107 | }, | |
108 | "Florian": { | |
109 | "stabilo_dev": "phpfpm-florian_app", | |
110 | }, | |
111 | "IsabelleAten": { | |
112 | "test": "phpfpm-isabelle_aten_integration", | |
113 | "master": "phpfpm-isabelle_aten_production", | |
114 | }, | |
115 | "Ludivine": { | |
116 | "test": "phpfpm-ludivine_integration", | |
117 | "master": "phpfpm-ludivine_production", | |
118 | }, | |
119 | "Connexionswing": { | |
120 | "test": "phpfpm-connexionswing_integration", | |
121 | "master": "phpfpm-connexionswing_production", | |
122 | }, | |
123 | "Piedsjaloux": { | |
124 | "test": "phpfpm-piedsjaloux_integration", | |
125 | "master": "phpfpm-piedsjaloux_production", | |
126 | }, | |
127 | } | |
128 | ||
129 | BRANCH_TO_POST_STEP = { | |
130 | "Connexionswing": { | |
131 | "master": "SYMFONY_ENV=prod php ./bin/console assetic:dump --env=prod --no-debug" | |
132 | }, | |
133 | } | |
134 | ||
135 | def need_follow_systemd(name, step): | |
136 | return step.getProperty("branch") in BRANCH_TO_SERVICE_NAME.get(name, {}) | |
137 | ||
138 | def need_post_step(name, step): | |
139 | return step.getProperty("branch") in BRANCH_TO_POST_STEP.get(name, {}) | |
140 | ||
141 | @util.renderer | |
142 | def get_post_step_command(props, name): | |
143 | if props.hasProperty("branch") and len(props["branch"]) > 0: | |
144 | post_step = BRANCH_TO_POST_STEP.get(name, {}).get(props["branch"]) | |
145 | if post_step is not None: | |
146 | return post_step | |
147 | ||
148 | @util.renderer | |
149 | def get_parameters_file(props, name): | |
150 | if props.hasProperty("branch") and len(props["branch"]) > 0: | |
151 | env = BRANCH_TO_SYMFONY_ENV.get(name, {}).get(props["branch"], "dev") | |
152 | else: | |
153 | env = "dev" | |
154 | return E.SECRETS_FILE + "/symfony_{}_{}_parameters.yml".format(name, env) | |
155 | ||
156 | @util.renderer | |
157 | def get_composer_install_command(props, name): | |
158 | if props.hasProperty("branch") and len(props["branch"]) > 0: | |
159 | env = BRANCH_TO_SYMFONY_ENV.get(name, {}).get(props["branch"], "dev") | |
160 | else: | |
161 | env = "dev" | |
162 | ||
163 | return "SYMFONY_ENV={} composer install".format(env) + (" --no-dev" if env == "prod" else "") | |
164 | ||
165 | @util.renderer | |
166 | def get_systemd_service_invocation_command(props, name): | |
167 | if props.hasProperty("branch") and len(props["branch"]) > 0: | |
168 | service = BRANCH_TO_SERVICE_NAME.get(name, {}).get(props["branch"]) | |
169 | if service is not None: | |
bd0cb07b | 170 | return "ssh -o UserKnownHostsFile={0} -i {1} buildbot@eldiron systemctl show -p InvocationID --value {2}.service".format(E.SSH_HOST_PATH, E.SSH_KEY_PATH, service) |
f6e48e3a IB |
171 | |
172 | @util.renderer | |
173 | def follow_systemd_command(props, name, invocation_id): | |
174 | if props.hasProperty("branch") and len(props["branch"]) > 0: | |
175 | service = BRANCH_TO_SERVICE_NAME.get(name, {}).get(props["branch"]) | |
176 | if service is not None: | |
177 | return ["follow-systemd-unit", service, util.Property("service_invocation_id")] | |
178 | ||
179 | def configure_gsm_cells(c, worker_name): | |
180 | builder_name = "GSMCells_build" | |
60d328e2 | 181 | c['schedulers'].append(schedulers.Nightly(name="GSMCells-weekly", |
f6e48e3a IB |
182 | builderNames=[builder_name], dayOfWeek=6, hour=3)) |
183 | c['builders'].append(util.BuilderConfig(name=builder_name, workernames=[worker_name], factory=gsm_cells_build_factory())) | |
184 | ||
185 | return builder_name | |
186 | ||
187 | def _configure(name, factory, c, worker_name): | |
188 | if name == "bip39": | |
189 | capitalized = "BIP39" | |
190 | else: | |
191 | capitalized = "".join([n.capitalize() for n in name.split('_')]) | |
192 | builder_name = "{}_build".format(capitalized) | |
193 | ||
194 | c['schedulers'].append(git_hook_scheduler(capitalized, [builder_name])) | |
195 | c['builders'].append(util.BuilderConfig(name=builder_name, workernames=[worker_name], factory=factory())) | |
196 | ||
197 | return builder_name | |
198 | ||
199 | def configure_symfony_isabelle_aten(c, worker_name): | |
200 | return _configure_symfony("IsabelleAten", c, worker_name, | |
201 | "gitolite@git.immae.eu:perso/Immae/Sites/Aten", parameters_path=None, | |
2ff9258e IB |
202 | other_steps=lambda path_env : [ |
203 | NixShellCommand(name="Install yarn", | |
f6e48e3a | 204 | logEnviron=False, haltOnFailure=True, |
2ff9258e IB |
205 | env=path_env, command="yarn install"), |
206 | NixShellCommand(name="Build frontend", | |
f6e48e3a | 207 | logEnviron=False, haltOnFailure=True, |
2ff9258e IB |
208 | env=path_env, command="yarn run encore production") |
209 | ] | |
f6e48e3a IB |
210 | ) |
211 | ||
212 | def _configure_symfony(name, c, worker_name, *args, **kwargs): | |
213 | builder_name = "Symfony_{}_build".format(name) | |
214 | ||
215 | c['schedulers'].append(git_hook_scheduler("Symfony_{}".format(name), [builder_name])) | |
216 | c['builders'].append(util.BuilderConfig(name=builder_name, workernames=[worker_name], factory=symfony_project_factory(name, *args, **kwargs))) | |
217 | ||
218 | return builder_name | |
219 | ||
220 | def history_build_factory(): | |
577d00ee | 221 | path_env = { |
bd0cb07b | 222 | "PATH": "/run/current-system/sw/bin" |
577d00ee IB |
223 | } |
224 | factory = util.BuildFactory() | |
225 | factory.addStep(steps.Git(logEnviron=False, repourl=E.HISTORY_GIT_URL, | |
226 | submodules=True, sshPrivateKey=open(E.SSH_KEY_PATH).read().rstrip(), | |
f6e48e3a | 227 | sshHostKey=E.SSH_HOST_KEY, mode="full", method="fresh")) |
bd0cb07b | 228 | factory.addStep(NixShellCommand(name="build website", |
f6e48e3a | 229 | logEnviron=False, haltOnFailure=True, |
bd0cb07b | 230 | env=path_env, command="jekyll build")) |
577d00ee | 231 | factory.addStep(steps.MasterShellCommand(command="rm -rf {}".format(E.HISTORY_RELEASE_PATH))) |
f6e48e3a | 232 | factory.addStep(steps.DirectoryUpload(workersrc="_site", |
577d00ee IB |
233 | masterdest=E.HISTORY_RELEASE_PATH, |
234 | url="https://www.immae.eu/history")) | |
235 | factory.addStep(steps.MasterShellCommand(command="chmod -R a+rX {}".format(E.HISTORY_RELEASE_PATH))) | |
236 | ||
f6e48e3a | 237 | return factory |
577d00ee | 238 | |
f6e48e3a | 239 | def docs_build_factory(): |
97f5a24b | 240 | path_env = { |
bd0cb07b | 241 | "PATH": "/run/current-system/sw/bin" |
97f5a24b IB |
242 | } |
243 | factory = util.BuildFactory() | |
244 | factory.addStep(steps.Git(logEnviron=False, repourl=E.DOCS_GIT_URL, | |
245 | submodules=True, sshPrivateKey=open(E.SSH_KEY_PATH).read().rstrip(), | |
f6e48e3a | 246 | sshHostKey=E.SSH_HOST_KEY, mode="full", method="fresh")) |
bd0cb07b | 247 | factory.addStep(NixShellCommand(name="build website", |
f6e48e3a | 248 | logEnviron=False, haltOnFailure=True, |
bd0cb07b | 249 | env=path_env, command="make html")) |
97f5a24b | 250 | factory.addStep(steps.MasterShellCommand(command="rm -rf {}".format(E.DOCS_RELEASE_PATH))) |
f6e48e3a | 251 | factory.addStep(steps.DirectoryUpload(workersrc="_build/html", |
97f5a24b IB |
252 | masterdest=E.DOCS_RELEASE_PATH, |
253 | url="https://www.immae.eu/docs")) | |
254 | factory.addStep(steps.MasterShellCommand(command="chmod -R a+rX {}".format(E.DOCS_RELEASE_PATH))) | |
255 | ||
f6e48e3a | 256 | return factory |
97f5a24b | 257 | |
f6e48e3a | 258 | def recettes_build_factory(): |
f2a18fd6 | 259 | path_env = { |
bd0cb07b | 260 | "PATH": "/run/current-system/sw/bin" |
f2a18fd6 IB |
261 | } |
262 | factory = util.BuildFactory() | |
263 | factory.addStep(steps.Git(logEnviron=False, repourl=E.RECETTES_GIT_URL, | |
264 | submodules=True, sshPrivateKey=open(E.SSH_KEY_PATH).read().rstrip(), | |
f6e48e3a | 265 | sshHostKey=E.SSH_HOST_KEY, mode="full", method="fresh")) |
6b017278 | 266 | factory.addStep(NixShellCommand(name="build website", |
f6e48e3a | 267 | logEnviron=False, haltOnFailure=True, |
6b017278 | 268 | env=path_env, command="jekyll build --trace --baseurl /recettes")) |
f2a18fd6 | 269 | factory.addStep(steps.MasterShellCommand(command="rm -rf {}".format(E.RECETTES_RELEASE_PATH))) |
f6e48e3a | 270 | factory.addStep(steps.DirectoryUpload(workersrc="_site", |
f2a18fd6 IB |
271 | masterdest=E.RECETTES_RELEASE_PATH, |
272 | url="https://www.immae.eu/recettes")) | |
273 | factory.addStep(steps.MasterShellCommand(command="chmod -R a+rX {}".format(E.RECETTES_RELEASE_PATH))) | |
274 | ||
f6e48e3a | 275 | return factory |
f2a18fd6 | 276 | |
f6e48e3a | 277 | def bip39_build_factory(): |
251c0a13 | 278 | path_env = { |
bd0cb07b IB |
279 | "PATH": "/run/current-system/sw/bin", |
280 | "NIX_PATH": "nixpkgs=channel:nixos-unstable", | |
251c0a13 IB |
281 | } |
282 | factory = util.BuildFactory() | |
283 | factory.addStep(steps.Git(logEnviron=False, repourl=E.BIP39_GIT_URL, | |
f6e48e3a | 284 | submodules=True, mode="full", method="fresh")) |
bd0cb07b IB |
285 | factory.addStep(NixShellCommand(name="build file", nixPackages=["python3"], |
286 | logEnviron=False, haltOnFailure=True, env=path_env, command="python compile.py")) | |
251c0a13 | 287 | factory.addStep(steps.FileUpload(name="upload file", workersrc="bip39-standalone.html", |
f6e48e3a | 288 | masterdest=E.BIP39_RELEASE_PATH + "/index.html", |
251c0a13 IB |
289 | url="https://tools.immae.eu/BIP39", mode=0o644)) |
290 | factory.addStep(steps.MasterShellCommand(command="chmod -R a+rX {}".format(E.BIP39_RELEASE_PATH))) | |
291 | ||
f6e48e3a | 292 | return factory |
251c0a13 | 293 | |
f6e48e3a | 294 | def immae_eu_build_factory(): |
0012da0f | 295 | path_env = { |
bd0cb07b | 296 | "PATH": "/run/current-system/sw/bin", |
0012da0f | 297 | } |
8fa7ff2c | 298 | factory = util.BuildFactory() |
573e1710 | 299 | factory.addStep(steps.Git(logEnviron=False, repourl=E.IMMAE_EU_GIT_URL, |
f78fbfbf | 300 | submodules=True, sshPrivateKey=open(E.SSH_KEY_PATH).read().rstrip(), |
f6e48e3a | 301 | sshHostKey=E.SSH_HOST_KEY, mode="full", method="fresh")) |
bd0cb07b IB |
302 | factory.addStep(NixShellCommand(name="build website", |
303 | logEnviron=False, haltOnFailure=True, pure=False, | |
304 | env=path_env, command="make html")) | |
0012da0f | 305 | factory.addStep(steps.MasterShellCommand(command="rm -rf {}".format(E.IMMAE_EU_RELEASE_PATH))) |
f6e48e3a | 306 | factory.addStep(steps.DirectoryUpload(workersrc="output", |
0012da0f | 307 | masterdest=E.IMMAE_EU_RELEASE_PATH, |
8fa7ff2c | 308 | url="https://www.immae.eu")) |
0012da0f | 309 | factory.addStep(steps.MasterShellCommand(command="chmod -R a+rX {}".format(E.IMMAE_EU_RELEASE_PATH))) |
8fa7ff2c | 310 | |
f6e48e3a | 311 | return factory |
573e1710 | 312 | |
f6e48e3a | 313 | def cours_build_factory(): |
0012da0f | 314 | path_env = { |
bd0cb07b | 315 | "PATH": "/run/current-system/sw/bin", |
830b619f | 316 | "CI": "yes" |
0012da0f IB |
317 | } |
318 | factory = util.BuildFactory() | |
319 | factory.addStep(steps.Git(logEnviron=False, repourl=E.COURS_GIT_URL, | |
320 | submodules=True, sshPrivateKey=open(E.SSH_KEY_PATH).read().rstrip(), | |
f6e48e3a | 321 | sshHostKey=E.SSH_HOST_KEY, mode="incremental")) |
bd0cb07b IB |
322 | factory.addStep(NixShellCommand(name="build website", |
323 | logEnviron=False, haltOnFailure=True, pure=True, | |
324 | command="make build", env=path_env)) | |
0012da0f | 325 | factory.addStep(steps.MasterShellCommand(command="rm -rf {}".format(E.COURS_RELEASE_PATH))) |
f6e48e3a | 326 | factory.addStep(steps.DirectoryUpload(workersrc="build", |
0012da0f IB |
327 | masterdest=E.COURS_RELEASE_PATH, |
328 | url="https://www.immae.eu/cours")) | |
329 | factory.addStep(steps.MasterShellCommand(command="chmod -R a+rX {}".format(E.COURS_RELEASE_PATH))) | |
330 | ||
bd0cb07b IB |
331 | factory.addStep(NixShellCommand(name="build pdfs", |
332 | logEnviron=False, haltOnFailure=True, pure=True, | |
333 | command="make pdfs", env=path_env)) | |
0012da0f IB |
334 | |
335 | package = util.Interpolate("cours_%(kw:clean_branch)s.tar.gz", clean_branch=clean_branch) | |
336 | release_file = "{0}/cours_%(kw:clean_branch)s.tar.gz" | |
337 | package_dest = util.Interpolate(release_file.format(E.COURS_TARBALL_PATH), clean_branch=clean_branch) | |
338 | package_url = util.Interpolate(release_file.format(E.COURS_TARBALL_URL), clean_branch=clean_branch) | |
339 | factory.addStep(steps.ShellCommand(name="build pdf tarball", | |
f6e48e3a | 340 | logEnviron=False, haltOnFailure=True, |
0012da0f IB |
341 | command=["tar", "-cvf", package, "-C", "pdfs", "mp", "mpsi"], env=path_env)) |
342 | factory.addStep(steps.FileUpload(name="upload package", workersrc=package, | |
f6e48e3a | 343 | masterdest=package_dest, url=package_url, mode=0o644)) |
0012da0f | 344 | |
f6e48e3a | 345 | return factory |
0012da0f | 346 | |
f6e48e3a | 347 | def normalesup_build_factory(): |
0012da0f | 348 | path_env = { |
bd0cb07b IB |
349 | "PATH": "/run/current-system/sw/bin", |
350 | "GIT_SSH_COMMAND": "ssh -i {0} -o UserKnownHostsFile={1}".format(E.SSH_KEY_PATH, E.SSH_HOST_PATH), | |
0012da0f | 351 | } |
573e1710 IB |
352 | factory = util.BuildFactory() |
353 | factory.addStep(steps.Git(logEnviron=False, repourl=E.NORMALESUP_GIT_URL, | |
354 | submodules=True, sshPrivateKey=open(E.SSH_KEY_PATH).read().rstrip(), | |
f6e48e3a | 355 | sshHostKey=E.SSH_HOST_KEY, mode="incremental")) |
bd0cb07b IB |
356 | factory.addStep(NixShellCommand(name="build website", |
357 | logEnviron=False, haltOnFailure=True, pure=False, | |
358 | command="make build", env=path_env)) | |
573e1710 | 359 | factory.addStep(steps.ShellCommand(name="give read access to all files", |
f6e48e3a | 360 | logEnviron=False, haltOnFailure=True, |
0012da0f | 361 | command="chmod -R a+rX build", env=path_env)) |
573e1710 | 362 | factory.addStep(steps.ShellCommand(name="synchronize with phare", |
f6e48e3a | 363 | logEnviron=False, haltOnFailure=True, |
0012da0f | 364 | env=path_env, command=[ |
573e1710 | 365 | "rsync", "-av", "--delete", |
bd0cb07b | 366 | "-e", "ssh -i {0} -o UserKnownHostsFile={1}".format(E.SSH_KEY_PATH, E.SSH_HOST_PATH), |
573e1710 | 367 | "build/", |
0012da0f | 368 | os.environ["BUILDBOT_NORMALESUP_HOST"] |
573e1710 | 369 | ])) |
0012da0f | 370 | factory.addStep(steps.MasterShellCommand(command="rm -rf {}".format(E.NORMALESUP_RELEASE_PATH))) |
f6e48e3a | 371 | factory.addStep(steps.DirectoryUpload(workersrc="build", masterdest=E.NORMALESUP_RELEASE_PATH, |
0012da0f IB |
372 | url="https://www.immae.eu/recherche")) |
373 | factory.addStep(steps.MasterShellCommand(command="chmod -R a+rX {}".format(E.NORMALESUP_RELEASE_PATH))) | |
573e1710 | 374 | |
f6e48e3a | 375 | return factory |
60d328e2 | 376 | |
f6e48e3a | 377 | def gsm_cells_build_factory(): |
60d328e2 | 378 | path_env = { |
bd0cb07b IB |
379 | "PATH": "/run/current-system/sw/bin", |
380 | "NIX_PATH": "nixpkgs=channel:nixos-unstable", | |
60d328e2 IB |
381 | "IN_BUILDBOT": "yes", |
382 | } | |
383 | master_env = { | |
384 | "HTACCESS": ''' | |
385 | Options +FollowSymLinks | |
386 | IndexIgnore * | |
387 | ''' | |
388 | } | |
389 | for k, v in os.environ.items(): | |
390 | if k.startswith("BUILDBOT_GSM_CELLS_"): | |
391 | path_env[k[len("BUILDBOT_GSM_CELLS_"):]] = v | |
392 | ||
393 | script = os.environ["BUILDBOT_PROJECT_DIR"] + "/scripts/lacells_download" | |
394 | factory = util.BuildFactory() | |
bd0cb07b IB |
395 | factory.addStep(steps.FileDownload(mastersrc=script, workerdest="lacells_download", mode=0o755)) |
396 | factory.addStep(NixShellCommand(name="download files", | |
397 | logEnviron=False, haltOnFailure=True, command="./lacells_download", | |
398 | nixPackages=["sqlite", "wget", "gzip"], pure=False, env=path_env)) | |
60d328e2 IB |
399 | factory.addStep(steps.ShellCommand(name="give read access to all files", |
400 | logEnviron=False, haltOnFailure=True, | |
401 | command="chmod a+r lacells.db", env=path_env)) | |
402 | factory.addStep(steps.FileUpload(workersrc="lacells.db", | |
403 | masterdest=(E.GSMCELLS_RELEASE_PATH+"/lacells.db"), url=(E.GSMCELLS_RELEASE_URL+"/lacells.db"))) | |
404 | factory.addStep(steps.MasterShellCommand(command="touch {}/.duplicity-ignore".format(E.GSMCELLS_RELEASE_PATH))) | |
405 | factory.addStep(steps.MasterShellCommand(command='echo "$HTACCESS" > {}/.htaccess'.format(E.GSMCELLS_RELEASE_PATH), | |
406 | env=master_env)) | |
407 | factory.addStep(steps.MasterShellCommand(command="ln -sf lacells.db {}/lacells.db.new".format(E.GSMCELLS_RELEASE_PATH))) | |
408 | factory.addStep(steps.MasterShellCommand(command="chmod -R a+rX {}".format(E.GSMCELLS_RELEASE_PATH))) | |
409 | ||
f6e48e3a | 410 | return factory |
2ff9258e | 411 | |
f6e48e3a | 412 | def symfony_project_factory(name, repourl, parameters_path="app/config/parameters.yml", other_steps=lambda a : []): |
bd0cb07b IB |
413 | master_path_env = { |
414 | "PATH": os.environ["BUILDBOT_SYMFONY_MASTER_PATH"] + ":${PATH}" | |
415 | } | |
416 | path_env = { | |
417 | "PATH": "/run/current-system/sw/bin" | |
418 | } | |
2ff9258e IB |
419 | |
420 | for k, v in os.environ.items(): | |
421 | if k.startswith("BUILDBOT_SYMFONY_{}_".format(name)): | |
422 | path_env[k[len("BUILDBOT_SYMFONY_{}_".format(name)):]] = v | |
423 | ||
424 | factory = util.BuildFactory() | |
425 | factory.addStep(steps.Git(logEnviron=False, repourl=repourl, | |
426 | submodules=True, sshPrivateKey=open(E.SSH_KEY_PATH).read().rstrip(), | |
f6e48e3a | 427 | sshHostKey=E.SSH_HOST_KEY, mode="full", method="fresh")) |
2ff9258e | 428 | if parameters_path is not None: |
f6e48e3a | 429 | factory.addStep(steps.FileDownload(mastersrc=get_parameters_file.withArgs(name), |
2ff9258e IB |
430 | workerdest=parameters_path)) |
431 | factory.addStep(NixShellCommand(name="build website", | |
f6e48e3a IB |
432 | logEnviron=False, haltOnFailure=True, |
433 | env=path_env, command=get_composer_install_command.withArgs(name))) | |
434 | if name in BRANCH_TO_POST_STEP: | |
435 | factory.addStep(NixShellCommand(name="build website post", | |
436 | logEnviron=False, haltOnFailure=True, doStepIf=partial(need_post_step, name), | |
437 | env=path_env, command=get_post_step_command.withArgs(name))) | |
2ff9258e IB |
438 | if parameters_path is not None: |
439 | factory.addStep(steps.ShellCommand(name="Remove parameters.yml", | |
440 | logEnviron=False, haltOnFailure=True, | |
441 | command="rm -f {}".format(parameters_path))) | |
442 | for step in other_steps(path_env): | |
443 | factory.addStep(step) | |
444 | package = util.Interpolate("{}_%(kw:clean_branch)s.tar.gz".format(name), clean_branch=clean_branch) | |
445 | release_file = "{0}/{1}/%(kw:clean_branch)s.tar.gz" | |
446 | package_dest = util.Interpolate(release_file.format("/var/lib/ftp/release.immae.eu/buildbot", name), clean_branch=clean_branch) | |
447 | # Tar doesn’t like creating the tarball in the same directory | |
448 | factory.addStep(steps.ShellCommand(name="Make a tarball 1/2", | |
f6e48e3a | 449 | logEnviron=False, haltOnFailure=True, env=path_env, |
2ff9258e IB |
450 | command=["touch", package])) |
451 | factory.addStep(steps.ShellCommand(name="Make a tarball 2/2", | |
f6e48e3a | 452 | logEnviron=False, haltOnFailure=True, env=path_env, |
2ff9258e | 453 | command=["tar", "--exclude", package, "-czf", package, "."])) |
f6e48e3a IB |
454 | factory.addStep(steps.SetPropertyFromCommand(command=get_systemd_service_invocation_command.withArgs(name), |
455 | property="service_invocation_id", doStepIf=partial(need_follow_systemd, name))) | |
2ff9258e | 456 | factory.addStep(steps.FileUpload(name="upload package", |
f6e48e3a | 457 | workersrc=package, masterdest=package_dest, mode=0o644)) |
bd0cb07b | 458 | factory.addStep(steps.MasterShellCommand(command=follow_systemd_command.withArgs(name, util.Property("service_invocation_id")), env=master_path_env, logEnviron=False, doStepIf=partial(need_follow_systemd, name))) |
f6e48e3a | 459 | return factory |