tangled
alpha
login
or
join now
pyrox.dev
/
nixpkgs
lol
0
fork
atom
overview
issues
pulls
pipelines
gitlab: move to pkgs/by-name
Yaya
8 months ago
4a1bbbba
816aa29c
+423
-424
12 changed files
expand all
collapse all
unified
split
pkgs
applications
version-management
gitlab
update.py
by-name
gi
gitlab
Remove-unsupported-database-names.patch
data.json
gitlab-workhorse
default.nix
package.nix
remove-hardcoded-locations.patch
reset_token.rake
rubyEnv
Gemfile
Gemfile.lock
gemset.nix
update.py
top-level
all-packages.nix
pkgs/applications/version-management/gitlab/Remove-unsupported-database-names.patch
pkgs/by-name/gi/gitlab/Remove-unsupported-database-names.patch
pkgs/applications/version-management/gitlab/data.json
pkgs/by-name/gi/gitlab/data.json
pkgs/applications/version-management/gitlab/default.nix
pkgs/by-name/gi/gitlab/package.nix
pkgs/applications/version-management/gitlab/gitlab-workhorse/default.nix
pkgs/by-name/gi/gitlab/gitlab-workhorse/default.nix
pkgs/applications/version-management/gitlab/remove-hardcoded-locations.patch
pkgs/by-name/gi/gitlab/remove-hardcoded-locations.patch
pkgs/applications/version-management/gitlab/reset_token.rake
pkgs/by-name/gi/gitlab/reset_token.rake
pkgs/applications/version-management/gitlab/rubyEnv/Gemfile
pkgs/by-name/gi/gitlab/rubyEnv/Gemfile
pkgs/applications/version-management/gitlab/rubyEnv/Gemfile.lock
pkgs/by-name/gi/gitlab/rubyEnv/Gemfile.lock
pkgs/applications/version-management/gitlab/rubyEnv/gemset.nix
pkgs/by-name/gi/gitlab/rubyEnv/gemset.nix
-421
pkgs/applications/version-management/gitlab/update.py
···
1
1
-
#!/usr/bin/env nix-shell
2
2
-
#! nix-shell -I nixpkgs=../../../.. -i python3 -p bundix bundler nix-update nix python3 python3Packages.requests python3Packages.click python3Packages.click-log python3Packages.packaging prefetch-yarn-deps git
3
3
-
4
4
-
import click
5
5
-
import click_log
6
6
-
import re
7
7
-
import logging
8
8
-
import subprocess
9
9
-
import json
10
10
-
import pathlib
11
11
-
import tempfile
12
12
-
from packaging.version import Version
13
13
-
from typing import Iterable
14
14
-
15
15
-
import requests
16
16
-
17
17
-
NIXPKGS_PATH = pathlib.Path(__file__).parent / "../../../../"
18
18
-
GITLAB_DIR = pathlib.Path(__file__).parent
19
19
-
20
20
-
logger = logging.getLogger(__name__)
21
21
-
click_log.basic_config(logger)
22
22
-
23
23
-
24
24
-
class GitLabRepo:
25
25
-
version_regex = re.compile(r"^v\d+\.\d+\.\d+(\-rc\d+)?(\-ee)?(\-gitlab)?")
26
26
-
27
27
-
def __init__(self, owner: str = "gitlab-org", repo: str = "gitlab"):
28
28
-
self.owner = owner
29
29
-
self.repo = repo
30
30
-
31
31
-
@property
32
32
-
def url(self):
33
33
-
return f"https://gitlab.com/{self.owner}/{self.repo}"
34
34
-
35
35
-
@property
36
36
-
def tags(self) -> Iterable[str]:
37
37
-
"""Returns a sorted list of repository tags"""
38
38
-
r = requests.get(self.url + "/refs?sort=updated_desc&ref=master").json()
39
39
-
tags = r.get("Tags", [])
40
40
-
41
41
-
# filter out versions not matching version_regex
42
42
-
versions = list(filter(self.version_regex.match, tags))
43
43
-
44
44
-
# sort, but ignore v, -ee and -gitlab for sorting comparisons
45
45
-
versions.sort(
46
46
-
key=lambda x: Version(
47
47
-
x.replace("v", "").replace("-ee", "").replace("-gitlab", "")
48
48
-
),
49
49
-
reverse=True,
50
50
-
)
51
51
-
return versions
52
52
-
def get_git_hash(self, rev: str):
53
53
-
return (
54
54
-
subprocess.check_output(
55
55
-
[
56
56
-
"nix-prefetch-url",
57
57
-
"--unpack",
58
58
-
f"https://gitlab.com/{self.owner}/{self.repo}/-/archive/{rev}/{self.repo}-{rev}.tar.gz",
59
59
-
]
60
60
-
)
61
61
-
.decode("utf-8")
62
62
-
.strip()
63
63
-
)
64
64
-
65
65
-
def get_yarn_hash(self, rev: str):
66
66
-
with tempfile.TemporaryDirectory() as tmp_dir:
67
67
-
with open(tmp_dir + "/yarn.lock", "w") as f:
68
68
-
f.write(self.get_file("yarn.lock", rev))
69
69
-
return (
70
70
-
subprocess.check_output(["prefetch-yarn-deps", tmp_dir + "/yarn.lock"])
71
71
-
.decode("utf-8")
72
72
-
.strip()
73
73
-
)
74
74
-
75
75
-
@staticmethod
76
76
-
def rev2version(tag: str) -> str:
77
77
-
"""
78
78
-
normalize a tag to a version number.
79
79
-
This obviously isn't very smart if we don't pass something that looks like a tag
80
80
-
:param tag: the tag to normalize
81
81
-
:return: a normalized version number
82
82
-
"""
83
83
-
# strip v prefix
84
84
-
version = re.sub(r"^v", "", tag)
85
85
-
# strip -ee and -gitlab suffixes
86
86
-
return re.sub(r"-(ee|gitlab)$", "", version)
87
87
-
88
88
-
def get_file(self, filepath, rev):
89
89
-
"""
90
90
-
returns file contents at a given rev
91
91
-
:param filepath: the path to the file, relative to the repo root
92
92
-
:param rev: the rev to fetch at
93
93
-
:return:
94
94
-
"""
95
95
-
return requests.get(self.url + f"/raw/{rev}/{filepath}").text
96
96
-
97
97
-
def get_data(self, rev):
98
98
-
version = self.rev2version(rev)
99
99
-
100
100
-
passthru = {
101
101
-
v: self.get_file(v, rev).strip()
102
102
-
for v in [
103
103
-
"GITALY_SERVER_VERSION",
104
104
-
"GITLAB_PAGES_VERSION",
105
105
-
"GITLAB_SHELL_VERSION",
106
106
-
"GITLAB_ELASTICSEARCH_INDEXER_VERSION",
107
107
-
]
108
108
-
}
109
109
-
passthru["GITLAB_WORKHORSE_VERSION"] = version
110
110
-
111
111
-
return dict(
112
112
-
version=self.rev2version(rev),
113
113
-
repo_hash=self.get_git_hash(rev),
114
114
-
yarn_hash=self.get_yarn_hash(rev),
115
115
-
owner=self.owner,
116
116
-
repo=self.repo,
117
117
-
rev=rev,
118
118
-
passthru=passthru,
119
119
-
)
120
120
-
121
121
-
122
122
-
def _get_data_json():
123
123
-
data_file_path = pathlib.Path(__file__).parent / "data.json"
124
124
-
with open(data_file_path, "r") as f:
125
125
-
return json.load(f)
126
126
-
127
127
-
128
128
-
def _call_nix_update(pkg, version):
129
129
-
"""calls nix-update from nixpkgs root dir"""
130
130
-
return subprocess.check_output(
131
131
-
["nix-update", pkg, "--version", version], cwd=NIXPKGS_PATH
132
132
-
)
133
133
-
134
134
-
135
135
-
@click_log.simple_verbosity_option(logger)
136
136
-
@click.group()
137
137
-
def cli():
138
138
-
pass
139
139
-
140
140
-
141
141
-
@cli.command("update-data")
142
142
-
@click.option("--rev", default="latest", help="The rev to use (vX.Y.Z-ee), or 'latest'")
143
143
-
def update_data(rev: str):
144
144
-
"""Update data.json"""
145
145
-
logger.info("Updating data.json")
146
146
-
147
147
-
repo = GitLabRepo()
148
148
-
if rev == "latest":
149
149
-
# filter out pre and rc releases
150
150
-
rev = next(filter(lambda x: not ("rc" in x or x.endswith("pre")), repo.tags))
151
151
-
152
152
-
data_file_path = pathlib.Path(__file__).parent / "data.json"
153
153
-
154
154
-
data = repo.get_data(rev)
155
155
-
156
156
-
with open(data_file_path.as_posix(), "w") as f:
157
157
-
json.dump(data, f, indent=2)
158
158
-
f.write("\n")
159
159
-
160
160
-
161
161
-
@cli.command("update-rubyenv")
162
162
-
def update_rubyenv():
163
163
-
"""Update rubyEnv"""
164
164
-
logger.info("Updating gitlab")
165
165
-
repo = GitLabRepo()
166
166
-
rubyenv_dir = pathlib.Path(__file__).parent / "rubyEnv"
167
167
-
168
168
-
# load rev from data.json
169
169
-
data = _get_data_json()
170
170
-
rev = data["rev"]
171
171
-
version = data["version"]
172
172
-
173
173
-
for fn in ["Gemfile.lock", "Gemfile"]:
174
174
-
with open(rubyenv_dir / fn, "w") as f:
175
175
-
f.write(repo.get_file(fn, rev))
176
176
-
177
177
-
# update to 1.2.9 to include https://gitlab.com/gitlab-org/ruby/gems/prometheus-client-mmap/-/commit/5d77f3f3e048834250589b416c6b3d4bba65a570
178
178
-
subprocess.check_output(
179
179
-
["sed", "-i", "s:'prometheus-client-mmap', '~> 1.2.8':'prometheus-client-mmap', '~> 1.2.9':g", "Gemfile"],
180
180
-
cwd=rubyenv_dir,
181
181
-
)
182
182
-
183
183
-
# Un-vendor sidekiq
184
184
-
#
185
185
-
# The sidekiq dependency was vendored to maintain compatibility with Redis 6.0 (as
186
186
-
# stated in this [comment]) but unfortunately, it seems to cause a crash in the
187
187
-
# application, as noted in this [upstream issue].
188
188
-
#
189
189
-
# We can safely swap out the dependency, as our Redis release in nixpkgs is >= 7.0.
190
190
-
#
191
191
-
# [comment]: https://gitlab.com/gitlab-org/gitlab/-/issues/468435#note_1979750600
192
192
-
# [upstream issue]: https://gitlab.com/gitlab-org/gitlab/-/issues/468435
193
193
-
subprocess.check_output(
194
194
-
["sed", "-i", "s|gem 'sidekiq', path: 'vendor/gems/sidekiq', require: 'sidekiq'|gem 'sidekiq', '~> 7.3.9'|g", "Gemfile"],
195
195
-
cwd=rubyenv_dir,
196
196
-
)
197
197
-
198
198
-
# Fetch vendored dependencies temporarily in order to build the gemset.nix
199
199
-
subprocess.check_output(["mkdir", "-p", "vendor/gems", "gems"], cwd=rubyenv_dir)
200
200
-
subprocess.check_output(
201
201
-
[
202
202
-
"sh",
203
203
-
"-c",
204
204
-
f"curl -L https://gitlab.com/gitlab-org/gitlab/-/archive/v{version}-ee/gitlab-v{version}-ee.tar.bz2?path=vendor/gems | tar -xj --strip-components=3",
205
205
-
],
206
206
-
cwd=f"{rubyenv_dir}/vendor/gems",
207
207
-
)
208
208
-
subprocess.check_output(
209
209
-
[
210
210
-
"sh",
211
211
-
"-c",
212
212
-
f"curl -L https://gitlab.com/gitlab-org/gitlab/-/archive/v{version}-ee/gitlab-v{version}-ee.tar.bz2?path=gems | tar -xj --strip-components=2",
213
213
-
],
214
214
-
cwd=f"{rubyenv_dir}/gems",
215
215
-
)
216
216
-
217
217
-
# Undo our gemset.nix patches so that bundix runs through
218
218
-
subprocess.check_output(
219
219
-
["sed", "-i", "-e", "s|\\${src}/||g", "gemset.nix"], cwd=rubyenv_dir
220
220
-
)
221
221
-
subprocess.check_output(
222
222
-
["sed", "-i", "-e", "s|^src:[[:space:]]||g", "gemset.nix"], cwd=rubyenv_dir
223
223
-
)
224
224
-
225
225
-
subprocess.check_output(["bundle", "lock"], cwd=rubyenv_dir)
226
226
-
subprocess.check_output(["bundix"], cwd=rubyenv_dir)
227
227
-
228
228
-
subprocess.check_output(
229
229
-
[
230
230
-
"sed",
231
231
-
"-i",
232
232
-
"-e",
233
233
-
"1c\\src: {",
234
234
-
"-e",
235
235
-
's:path = \\(vendor/[^;]*\\);:path = "${src}/\\1";:g',
236
236
-
"-e",
237
237
-
's:path = \\(gems/[^;]*\\);:path = "${src}/\\1";:g',
238
238
-
"gemset.nix",
239
239
-
],
240
240
-
cwd=rubyenv_dir,
241
241
-
)
242
242
-
subprocess.check_output(["rm", "-rf", "vendor", "gems"], cwd=rubyenv_dir)
243
243
-
244
244
-
# Reformat gemset.nix
245
245
-
subprocess.check_output(["nix-shell", "--run", "treefmt pkgs/applications/version-management/gitlab"], cwd=NIXPKGS_PATH)
246
246
-
247
247
-
248
248
-
@cli.command("update-gitaly")
249
249
-
def update_gitaly():
250
250
-
"""Update gitaly"""
251
251
-
logger.info("Updating gitaly")
252
252
-
data = _get_data_json()
253
253
-
gitaly_server_version = data['passthru']['GITALY_SERVER_VERSION']
254
254
-
repo = GitLabRepo(repo="gitaly")
255
255
-
gitaly_dir = pathlib.Path(__file__).parent / 'gitaly'
256
256
-
257
257
-
makefile = repo.get_file("Makefile", f"v{gitaly_server_version}")
258
258
-
makefile += "\nprint-%:;@echo $($*)\n"
259
259
-
260
260
-
git_version = subprocess.run(["make", "-f", "-", "print-GIT_VERSION"], check=True, input=makefile, text=True, capture_output=True).stdout.strip()
261
261
-
262
262
-
_call_nix_update("gitaly", gitaly_server_version)
263
263
-
_call_nix_update("gitaly.git", git_version)
264
264
-
265
265
-
266
266
-
@cli.command("update-gitlab-pages")
267
267
-
def update_gitlab_pages():
268
268
-
"""Update gitlab-pages"""
269
269
-
logger.info("Updating gitlab-pages")
270
270
-
data = _get_data_json()
271
271
-
gitlab_pages_version = data["passthru"]["GITLAB_PAGES_VERSION"]
272
272
-
_call_nix_update("gitlab-pages", gitlab_pages_version)
273
273
-
274
274
-
275
275
-
def get_container_registry_version() -> str:
276
276
-
"""Returns the version attribute of gitlab-container-registry"""
277
277
-
return subprocess.check_output(
278
278
-
[
279
279
-
"nix",
280
280
-
"--experimental-features",
281
281
-
"nix-command",
282
282
-
"eval",
283
283
-
"-f",
284
284
-
".",
285
285
-
"--raw",
286
286
-
"gitlab-container-registry.version",
287
287
-
],
288
288
-
cwd=NIXPKGS_PATH,
289
289
-
).decode("utf-8")
290
290
-
291
291
-
292
292
-
@cli.command("update-gitlab-shell")
293
293
-
def update_gitlab_shell():
294
294
-
"""Update gitlab-shell"""
295
295
-
logger.info("Updating gitlab-shell")
296
296
-
data = _get_data_json()
297
297
-
gitlab_shell_version = data["passthru"]["GITLAB_SHELL_VERSION"]
298
298
-
_call_nix_update("gitlab-shell", gitlab_shell_version)
299
299
-
300
300
-
301
301
-
@cli.command("update-gitlab-workhorse")
302
302
-
def update_gitlab_workhorse():
303
303
-
"""Update gitlab-workhorse"""
304
304
-
logger.info("Updating gitlab-workhorse")
305
305
-
data = _get_data_json()
306
306
-
gitlab_workhorse_version = data["passthru"]["GITLAB_WORKHORSE_VERSION"]
307
307
-
_call_nix_update("gitlab-workhorse", gitlab_workhorse_version)
308
308
-
309
309
-
310
310
-
@cli.command("update-gitlab-container-registry")
311
311
-
@click.option("--rev", default="latest", help="The rev to use (vX.Y.Z-ee), or 'latest'")
312
312
-
@click.option(
313
313
-
"--commit", is_flag=True, default=False, help="Commit the changes for you"
314
314
-
)
315
315
-
def update_gitlab_container_registry(rev: str, commit: bool):
316
316
-
"""Update gitlab-container-registry"""
317
317
-
logger.info("Updading gitlab-container-registry")
318
318
-
repo = GitLabRepo(repo="container-registry")
319
319
-
old_container_registry_version = get_container_registry_version()
320
320
-
321
321
-
if rev == "latest":
322
322
-
rev = next(filter(lambda x: not ("rc" in x or x.endswith("pre")), repo.tags))
323
323
-
324
324
-
version = repo.rev2version(rev)
325
325
-
_call_nix_update("gitlab-container-registry", version)
326
326
-
if commit:
327
327
-
new_container_registry_version = get_container_registry_version()
328
328
-
commit_container_registry(
329
329
-
old_container_registry_version, new_container_registry_version
330
330
-
)
331
331
-
332
332
-
333
333
-
@cli.command('update-gitlab-elasticsearch-indexer')
334
334
-
def update_gitlab_elasticsearch_indexer():
335
335
-
"""Update gitlab-elasticsearch-indexer"""
336
336
-
data = _get_data_json()
337
337
-
gitlab_elasticsearch_indexer_version = data['passthru']['GITLAB_ELASTICSEARCH_INDEXER_VERSION']
338
338
-
_call_nix_update('gitlab-elasticsearch-indexer', gitlab_elasticsearch_indexer_version)
339
339
-
340
340
-
341
341
-
@cli.command("update-all")
342
342
-
@click.option("--rev", default="latest", help="The rev to use (vX.Y.Z-ee), or 'latest'")
343
343
-
@click.option(
344
344
-
"--commit", is_flag=True, default=False, help="Commit the changes for you"
345
345
-
)
346
346
-
@click.pass_context
347
347
-
def update_all(ctx, rev: str, commit: bool):
348
348
-
"""Update all gitlab components to the latest stable release"""
349
349
-
old_data_json = _get_data_json()
350
350
-
old_container_registry_version = get_container_registry_version()
351
351
-
352
352
-
ctx.invoke(update_data, rev=rev)
353
353
-
354
354
-
new_data_json = _get_data_json()
355
355
-
356
356
-
ctx.invoke(update_rubyenv)
357
357
-
ctx.invoke(update_gitaly)
358
358
-
ctx.invoke(update_gitlab_pages)
359
359
-
ctx.invoke(update_gitlab_shell)
360
360
-
ctx.invoke(update_gitlab_workhorse)
361
361
-
ctx.invoke(update_gitlab_elasticsearch_indexer)
362
362
-
if commit:
363
363
-
commit_gitlab(
364
364
-
old_data_json["version"], new_data_json["version"], new_data_json["rev"]
365
365
-
)
366
366
-
367
367
-
ctx.invoke(update_gitlab_container_registry)
368
368
-
if commit:
369
369
-
new_container_registry_version = get_container_registry_version()
370
370
-
commit_container_registry(
371
371
-
old_container_registry_version, new_container_registry_version
372
372
-
)
373
373
-
374
374
-
375
375
-
def commit_gitlab(old_version: str, new_version: str, new_rev: str) -> None:
376
376
-
"""Commits the gitlab changes for you"""
377
377
-
subprocess.run(
378
378
-
[
379
379
-
"git",
380
380
-
"add",
381
381
-
"pkgs/applications/version-management/gitlab",
382
382
-
"pkgs/by-name/gi/gitaly",
383
383
-
"pkgs/by-name/gi/gitlab-elasticsearch-indexer",
384
384
-
"pkgs/by-name/gi/gitlab-pages",
385
385
-
],
386
386
-
cwd=NIXPKGS_PATH,
387
387
-
)
388
388
-
subprocess.run(
389
389
-
[
390
390
-
"git",
391
391
-
"commit",
392
392
-
"--message",
393
393
-
f"""gitlab: {old_version} -> {new_version}\n\nhttps://gitlab.com/gitlab-org/gitlab/-/blob/{new_rev}/CHANGELOG.md""",
394
394
-
],
395
395
-
cwd=NIXPKGS_PATH,
396
396
-
)
397
397
-
398
398
-
399
399
-
def commit_container_registry(old_version: str, new_version: str) -> None:
400
400
-
"""Commits the gitlab-container-registry changes for you"""
401
401
-
subprocess.run(
402
402
-
[
403
403
-
"git",
404
404
-
"add",
405
405
-
"pkgs/by-name/gi/gitlab-container-registry"
406
406
-
],
407
407
-
cwd=NIXPKGS_PATH,
408
408
-
)
409
409
-
subprocess.run(
410
410
-
[
411
411
-
"git",
412
412
-
"commit",
413
413
-
"--message",
414
414
-
f"gitlab-container-registry: {old_version} -> {new_version}\n\nhttps://gitlab.com/gitlab-org/container-registry/-/blob/v{new_version}-gitlab/CHANGELOG.md",
415
415
-
],
416
416
-
cwd=NIXPKGS_PATH,
417
417
-
)
418
418
-
419
419
-
420
420
-
if __name__ == "__main__":
421
421
-
cli()
+421
pkgs/by-name/gi/gitlab/update.py
···
1
1
+
#!/usr/bin/env nix-shell
2
2
+
#! nix-shell -I nixpkgs=../../../.. -i python3 -p bundix bundler nix-update nix python3 python3Packages.requests python3Packages.click python3Packages.click-log python3Packages.packaging prefetch-yarn-deps git
3
3
+
4
4
+
import click
5
5
+
import click_log
6
6
+
import re
7
7
+
import logging
8
8
+
import subprocess
9
9
+
import json
10
10
+
import pathlib
11
11
+
import tempfile
12
12
+
from packaging.version import Version
13
13
+
from typing import Iterable
14
14
+
15
15
+
import requests
16
16
+
17
17
+
NIXPKGS_PATH = pathlib.Path(__file__).parent / "../../../../"
18
18
+
GITLAB_DIR = pathlib.Path(__file__).parent
19
19
+
20
20
+
logger = logging.getLogger(__name__)
21
21
+
click_log.basic_config(logger)
22
22
+
23
23
+
24
24
+
class GitLabRepo:
25
25
+
version_regex = re.compile(r"^v\d+\.\d+\.\d+(\-rc\d+)?(\-ee)?(\-gitlab)?")
26
26
+
27
27
+
def __init__(self, owner: str = "gitlab-org", repo: str = "gitlab"):
28
28
+
self.owner = owner
29
29
+
self.repo = repo
30
30
+
31
31
+
@property
32
32
+
def url(self):
33
33
+
return f"https://gitlab.com/{self.owner}/{self.repo}"
34
34
+
35
35
+
@property
36
36
+
def tags(self) -> Iterable[str]:
37
37
+
"""Returns a sorted list of repository tags"""
38
38
+
r = requests.get(self.url + "/refs?sort=updated_desc&ref=master").json()
39
39
+
tags = r.get("Tags", [])
40
40
+
41
41
+
# filter out versions not matching version_regex
42
42
+
versions = list(filter(self.version_regex.match, tags))
43
43
+
44
44
+
# sort, but ignore v, -ee and -gitlab for sorting comparisons
45
45
+
versions.sort(
46
46
+
key=lambda x: Version(
47
47
+
x.replace("v", "").replace("-ee", "").replace("-gitlab", "")
48
48
+
),
49
49
+
reverse=True,
50
50
+
)
51
51
+
return versions
52
52
+
def get_git_hash(self, rev: str):
53
53
+
return (
54
54
+
subprocess.check_output(
55
55
+
[
56
56
+
"nix-prefetch-url",
57
57
+
"--unpack",
58
58
+
f"https://gitlab.com/{self.owner}/{self.repo}/-/archive/{rev}/{self.repo}-{rev}.tar.gz",
59
59
+
]
60
60
+
)
61
61
+
.decode("utf-8")
62
62
+
.strip()
63
63
+
)
64
64
+
65
65
+
def get_yarn_hash(self, rev: str):
66
66
+
with tempfile.TemporaryDirectory() as tmp_dir:
67
67
+
with open(tmp_dir + "/yarn.lock", "w") as f:
68
68
+
f.write(self.get_file("yarn.lock", rev))
69
69
+
return (
70
70
+
subprocess.check_output(["prefetch-yarn-deps", tmp_dir + "/yarn.lock"])
71
71
+
.decode("utf-8")
72
72
+
.strip()
73
73
+
)
74
74
+
75
75
+
@staticmethod
76
76
+
def rev2version(tag: str) -> str:
77
77
+
"""
78
78
+
normalize a tag to a version number.
79
79
+
This obviously isn't very smart if we don't pass something that looks like a tag
80
80
+
:param tag: the tag to normalize
81
81
+
:return: a normalized version number
82
82
+
"""
83
83
+
# strip v prefix
84
84
+
version = re.sub(r"^v", "", tag)
85
85
+
# strip -ee and -gitlab suffixes
86
86
+
return re.sub(r"-(ee|gitlab)$", "", version)
87
87
+
88
88
+
def get_file(self, filepath, rev):
89
89
+
"""
90
90
+
returns file contents at a given rev
91
91
+
:param filepath: the path to the file, relative to the repo root
92
92
+
:param rev: the rev to fetch at
93
93
+
:return:
94
94
+
"""
95
95
+
return requests.get(self.url + f"/raw/{rev}/{filepath}").text
96
96
+
97
97
+
def get_data(self, rev):
98
98
+
version = self.rev2version(rev)
99
99
+
100
100
+
passthru = {
101
101
+
v: self.get_file(v, rev).strip()
102
102
+
for v in [
103
103
+
"GITALY_SERVER_VERSION",
104
104
+
"GITLAB_PAGES_VERSION",
105
105
+
"GITLAB_SHELL_VERSION",
106
106
+
"GITLAB_ELASTICSEARCH_INDEXER_VERSION",
107
107
+
]
108
108
+
}
109
109
+
passthru["GITLAB_WORKHORSE_VERSION"] = version
110
110
+
111
111
+
return dict(
112
112
+
version=self.rev2version(rev),
113
113
+
repo_hash=self.get_git_hash(rev),
114
114
+
yarn_hash=self.get_yarn_hash(rev),
115
115
+
owner=self.owner,
116
116
+
repo=self.repo,
117
117
+
rev=rev,
118
118
+
passthru=passthru,
119
119
+
)
120
120
+
121
121
+
122
122
+
def _get_data_json():
123
123
+
data_file_path = pathlib.Path(__file__).parent / "data.json"
124
124
+
with open(data_file_path, "r") as f:
125
125
+
return json.load(f)
126
126
+
127
127
+
128
128
+
def _call_nix_update(pkg, version):
129
129
+
"""calls nix-update from nixpkgs root dir"""
130
130
+
return subprocess.check_output(
131
131
+
["nix-update", pkg, "--version", version], cwd=NIXPKGS_PATH
132
132
+
)
133
133
+
134
134
+
135
135
+
@click_log.simple_verbosity_option(logger)
136
136
+
@click.group()
137
137
+
def cli():
138
138
+
pass
139
139
+
140
140
+
141
141
+
@cli.command("update-data")
142
142
+
@click.option("--rev", default="latest", help="The rev to use (vX.Y.Z-ee), or 'latest'")
143
143
+
def update_data(rev: str):
144
144
+
"""Update data.json"""
145
145
+
logger.info("Updating data.json")
146
146
+
147
147
+
repo = GitLabRepo()
148
148
+
if rev == "latest":
149
149
+
# filter out pre and rc releases
150
150
+
rev = next(filter(lambda x: not ("rc" in x or x.endswith("pre")), repo.tags))
151
151
+
152
152
+
data_file_path = pathlib.Path(__file__).parent / "data.json"
153
153
+
154
154
+
data = repo.get_data(rev)
155
155
+
156
156
+
with open(data_file_path.as_posix(), "w") as f:
157
157
+
json.dump(data, f, indent=2)
158
158
+
f.write("\n")
159
159
+
160
160
+
161
161
+
@cli.command("update-rubyenv")
162
162
+
def update_rubyenv():
163
163
+
"""Update rubyEnv"""
164
164
+
logger.info("Updating gitlab")
165
165
+
repo = GitLabRepo()
166
166
+
rubyenv_dir = pathlib.Path(__file__).parent / "rubyEnv"
167
167
+
168
168
+
# load rev from data.json
169
169
+
data = _get_data_json()
170
170
+
rev = data["rev"]
171
171
+
version = data["version"]
172
172
+
173
173
+
for fn in ["Gemfile.lock", "Gemfile"]:
174
174
+
with open(rubyenv_dir / fn, "w") as f:
175
175
+
f.write(repo.get_file(fn, rev))
176
176
+
177
177
+
# update to 1.2.9 to include https://gitlab.com/gitlab-org/ruby/gems/prometheus-client-mmap/-/commit/5d77f3f3e048834250589b416c6b3d4bba65a570
178
178
+
subprocess.check_output(
179
179
+
["sed", "-i", "s:'prometheus-client-mmap', '~> 1.2.8':'prometheus-client-mmap', '~> 1.2.9':g", "Gemfile"],
180
180
+
cwd=rubyenv_dir,
181
181
+
)
182
182
+
183
183
+
# Un-vendor sidekiq
184
184
+
#
185
185
+
# The sidekiq dependency was vendored to maintain compatibility with Redis 6.0 (as
186
186
+
# stated in this [comment]) but unfortunately, it seems to cause a crash in the
187
187
+
# application, as noted in this [upstream issue].
188
188
+
#
189
189
+
# We can safely swap out the dependency, as our Redis release in nixpkgs is >= 7.0.
190
190
+
#
191
191
+
# [comment]: https://gitlab.com/gitlab-org/gitlab/-/issues/468435#note_1979750600
192
192
+
# [upstream issue]: https://gitlab.com/gitlab-org/gitlab/-/issues/468435
193
193
+
subprocess.check_output(
194
194
+
["sed", "-i", "s|gem 'sidekiq', path: 'vendor/gems/sidekiq', require: 'sidekiq'|gem 'sidekiq', '~> 7.3.9'|g", "Gemfile"],
195
195
+
cwd=rubyenv_dir,
196
196
+
)
197
197
+
198
198
+
# Fetch vendored dependencies temporarily in order to build the gemset.nix
199
199
+
subprocess.check_output(["mkdir", "-p", "vendor/gems", "gems"], cwd=rubyenv_dir)
200
200
+
subprocess.check_output(
201
201
+
[
202
202
+
"sh",
203
203
+
"-c",
204
204
+
f"curl -L https://gitlab.com/gitlab-org/gitlab/-/archive/v{version}-ee/gitlab-v{version}-ee.tar.bz2?path=vendor/gems | tar -xj --strip-components=3",
205
205
+
],
206
206
+
cwd=f"{rubyenv_dir}/vendor/gems",
207
207
+
)
208
208
+
subprocess.check_output(
209
209
+
[
210
210
+
"sh",
211
211
+
"-c",
212
212
+
f"curl -L https://gitlab.com/gitlab-org/gitlab/-/archive/v{version}-ee/gitlab-v{version}-ee.tar.bz2?path=gems | tar -xj --strip-components=2",
213
213
+
],
214
214
+
cwd=f"{rubyenv_dir}/gems",
215
215
+
)
216
216
+
217
217
+
# Undo our gemset.nix patches so that bundix runs through
218
218
+
subprocess.check_output(
219
219
+
["sed", "-i", "-e", "s|\\${src}/||g", "gemset.nix"], cwd=rubyenv_dir
220
220
+
)
221
221
+
subprocess.check_output(
222
222
+
["sed", "-i", "-e", "s|^src:[[:space:]]||g", "gemset.nix"], cwd=rubyenv_dir
223
223
+
)
224
224
+
225
225
+
subprocess.check_output(["bundle", "lock"], cwd=rubyenv_dir)
226
226
+
subprocess.check_output(["bundix"], cwd=rubyenv_dir)
227
227
+
228
228
+
subprocess.check_output(
229
229
+
[
230
230
+
"sed",
231
231
+
"-i",
232
232
+
"-e",
233
233
+
"1c\\src: {",
234
234
+
"-e",
235
235
+
's:path = \\(vendor/[^;]*\\);:path = "${src}/\\1";:g',
236
236
+
"-e",
237
237
+
's:path = \\(gems/[^;]*\\);:path = "${src}/\\1";:g',
238
238
+
"gemset.nix",
239
239
+
],
240
240
+
cwd=rubyenv_dir,
241
241
+
)
242
242
+
subprocess.check_output(["rm", "-rf", "vendor", "gems"], cwd=rubyenv_dir)
243
243
+
244
244
+
# Reformat gemset.nix
245
245
+
subprocess.check_output(["nix-shell", "--run", "treefmt pkgs/by-name/gi/gitlab"], cwd=NIXPKGS_PATH)
246
246
+
247
247
+
248
248
+
@cli.command("update-gitaly")
249
249
+
def update_gitaly():
250
250
+
"""Update gitaly"""
251
251
+
logger.info("Updating gitaly")
252
252
+
data = _get_data_json()
253
253
+
gitaly_server_version = data['passthru']['GITALY_SERVER_VERSION']
254
254
+
repo = GitLabRepo(repo="gitaly")
255
255
+
gitaly_dir = pathlib.Path(__file__).parent / 'gitaly'
256
256
+
257
257
+
makefile = repo.get_file("Makefile", f"v{gitaly_server_version}")
258
258
+
makefile += "\nprint-%:;@echo $($*)\n"
259
259
+
260
260
+
git_version = subprocess.run(["make", "-f", "-", "print-GIT_VERSION"], check=True, input=makefile, text=True, capture_output=True).stdout.strip()
261
261
+
262
262
+
_call_nix_update("gitaly", gitaly_server_version)
263
263
+
_call_nix_update("gitaly.git", git_version)
264
264
+
265
265
+
266
266
+
@cli.command("update-gitlab-pages")
267
267
+
def update_gitlab_pages():
268
268
+
"""Update gitlab-pages"""
269
269
+
logger.info("Updating gitlab-pages")
270
270
+
data = _get_data_json()
271
271
+
gitlab_pages_version = data["passthru"]["GITLAB_PAGES_VERSION"]
272
272
+
_call_nix_update("gitlab-pages", gitlab_pages_version)
273
273
+
274
274
+
275
275
+
def get_container_registry_version() -> str:
276
276
+
"""Returns the version attribute of gitlab-container-registry"""
277
277
+
return subprocess.check_output(
278
278
+
[
279
279
+
"nix",
280
280
+
"--experimental-features",
281
281
+
"nix-command",
282
282
+
"eval",
283
283
+
"-f",
284
284
+
".",
285
285
+
"--raw",
286
286
+
"gitlab-container-registry.version",
287
287
+
],
288
288
+
cwd=NIXPKGS_PATH,
289
289
+
).decode("utf-8")
290
290
+
291
291
+
292
292
+
@cli.command("update-gitlab-shell")
293
293
+
def update_gitlab_shell():
294
294
+
"""Update gitlab-shell"""
295
295
+
logger.info("Updating gitlab-shell")
296
296
+
data = _get_data_json()
297
297
+
gitlab_shell_version = data["passthru"]["GITLAB_SHELL_VERSION"]
298
298
+
_call_nix_update("gitlab-shell", gitlab_shell_version)
299
299
+
300
300
+
301
301
+
@cli.command("update-gitlab-workhorse")
302
302
+
def update_gitlab_workhorse():
303
303
+
"""Update gitlab-workhorse"""
304
304
+
logger.info("Updating gitlab-workhorse")
305
305
+
data = _get_data_json()
306
306
+
gitlab_workhorse_version = data["passthru"]["GITLAB_WORKHORSE_VERSION"]
307
307
+
_call_nix_update("gitlab-workhorse", gitlab_workhorse_version)
308
308
+
309
309
+
310
310
+
@cli.command("update-gitlab-container-registry")
311
311
+
@click.option("--rev", default="latest", help="The rev to use (vX.Y.Z-ee), or 'latest'")
312
312
+
@click.option(
313
313
+
"--commit", is_flag=True, default=False, help="Commit the changes for you"
314
314
+
)
315
315
+
def update_gitlab_container_registry(rev: str, commit: bool):
316
316
+
"""Update gitlab-container-registry"""
317
317
+
logger.info("Updading gitlab-container-registry")
318
318
+
repo = GitLabRepo(repo="container-registry")
319
319
+
old_container_registry_version = get_container_registry_version()
320
320
+
321
321
+
if rev == "latest":
322
322
+
rev = next(filter(lambda x: not ("rc" in x or x.endswith("pre")), repo.tags))
323
323
+
324
324
+
version = repo.rev2version(rev)
325
325
+
_call_nix_update("gitlab-container-registry", version)
326
326
+
if commit:
327
327
+
new_container_registry_version = get_container_registry_version()
328
328
+
commit_container_registry(
329
329
+
old_container_registry_version, new_container_registry_version
330
330
+
)
331
331
+
332
332
+
333
333
+
@cli.command('update-gitlab-elasticsearch-indexer')
334
334
+
def update_gitlab_elasticsearch_indexer():
335
335
+
"""Update gitlab-elasticsearch-indexer"""
336
336
+
data = _get_data_json()
337
337
+
gitlab_elasticsearch_indexer_version = data['passthru']['GITLAB_ELASTICSEARCH_INDEXER_VERSION']
338
338
+
_call_nix_update('gitlab-elasticsearch-indexer', gitlab_elasticsearch_indexer_version)
339
339
+
340
340
+
341
341
+
@cli.command("update-all")
342
342
+
@click.option("--rev", default="latest", help="The rev to use (vX.Y.Z-ee), or 'latest'")
343
343
+
@click.option(
344
344
+
"--commit", is_flag=True, default=False, help="Commit the changes for you"
345
345
+
)
346
346
+
@click.pass_context
347
347
+
def update_all(ctx, rev: str, commit: bool):
348
348
+
"""Update all gitlab components to the latest stable release"""
349
349
+
old_data_json = _get_data_json()
350
350
+
old_container_registry_version = get_container_registry_version()
351
351
+
352
352
+
ctx.invoke(update_data, rev=rev)
353
353
+
354
354
+
new_data_json = _get_data_json()
355
355
+
356
356
+
ctx.invoke(update_rubyenv)
357
357
+
ctx.invoke(update_gitaly)
358
358
+
ctx.invoke(update_gitlab_pages)
359
359
+
ctx.invoke(update_gitlab_shell)
360
360
+
ctx.invoke(update_gitlab_workhorse)
361
361
+
ctx.invoke(update_gitlab_elasticsearch_indexer)
362
362
+
if commit:
363
363
+
commit_gitlab(
364
364
+
old_data_json["version"], new_data_json["version"], new_data_json["rev"]
365
365
+
)
366
366
+
367
367
+
ctx.invoke(update_gitlab_container_registry)
368
368
+
if commit:
369
369
+
new_container_registry_version = get_container_registry_version()
370
370
+
commit_container_registry(
371
371
+
old_container_registry_version, new_container_registry_version
372
372
+
)
373
373
+
374
374
+
375
375
+
def commit_gitlab(old_version: str, new_version: str, new_rev: str) -> None:
376
376
+
"""Commits the gitlab changes for you"""
377
377
+
subprocess.run(
378
378
+
[
379
379
+
"git",
380
380
+
"add",
381
381
+
"pkgs/by-name/gi/gitlab",
382
382
+
"pkgs/by-name/gi/gitaly",
383
383
+
"pkgs/by-name/gi/gitlab-elasticsearch-indexer",
384
384
+
"pkgs/by-name/gi/gitlab-pages",
385
385
+
],
386
386
+
cwd=NIXPKGS_PATH,
387
387
+
)
388
388
+
subprocess.run(
389
389
+
[
390
390
+
"git",
391
391
+
"commit",
392
392
+
"--message",
393
393
+
f"""gitlab: {old_version} -> {new_version}\n\nhttps://gitlab.com/gitlab-org/gitlab/-/blob/{new_rev}/CHANGELOG.md""",
394
394
+
],
395
395
+
cwd=NIXPKGS_PATH,
396
396
+
)
397
397
+
398
398
+
399
399
+
def commit_container_registry(old_version: str, new_version: str) -> None:
400
400
+
"""Commits the gitlab-container-registry changes for you"""
401
401
+
subprocess.run(
402
402
+
[
403
403
+
"git",
404
404
+
"add",
405
405
+
"pkgs/by-name/gi/gitlab-container-registry"
406
406
+
],
407
407
+
cwd=NIXPKGS_PATH,
408
408
+
)
409
409
+
subprocess.run(
410
410
+
[
411
411
+
"git",
412
412
+
"commit",
413
413
+
"--message",
414
414
+
f"gitlab-container-registry: {old_version} -> {new_version}\n\nhttps://gitlab.com/gitlab-org/container-registry/-/blob/v{new_version}-gitlab/CHANGELOG.md",
415
415
+
],
416
416
+
cwd=NIXPKGS_PATH,
417
417
+
)
418
418
+
419
419
+
420
420
+
if __name__ == "__main__":
421
421
+
cli()
+2
-3
pkgs/top-level/all-packages.nix
···
3065
3065
3066
3066
gibberish-detector = with python3Packages; toPythonApplication gibberish-detector;
3067
3067
3068
3068
-
gitlab = callPackage ../applications/version-management/gitlab { };
3069
3069
-
gitlab-ee = callPackage ../applications/version-management/gitlab {
3068
3068
+
gitlab-ee = callPackage ../by-name/gi/gitlab/package.nix {
3070
3069
gitlabEnterprise = true;
3071
3070
};
3072
3071
3073
3072
gitlab-triage = callPackage ../applications/version-management/gitlab-triage { };
3074
3073
3075
3075
-
gitlab-workhorse = callPackage ../applications/version-management/gitlab/gitlab-workhorse { };
3074
3074
+
gitlab-workhorse = callPackage ../by-name/gi/gitlab/gitlab-workhorse { };
3076
3075
3077
3076
gitqlient = libsForQt5.callPackage ../applications/version-management/gitqlient { };
3078
3077