blob: b6ed8e1314dbf523924c685f2079acaefa3e33c6 [file] [log] [blame]
Sergiusz Bazanski48050572020-05-10 21:34:10 +02001"""
2Automatically download, package, containerize and push Factorio server images.
3
4For each version defined, the following will be declared:
5 - @factorio-headless-${version}: a repository containing the factorio server tarball
6 - //third_party/factorio:${version}-1: a container_image rule to build a docker container running a factorio server
7 - //third_party/factorio:push_${version}-1: a container_push rule to push that container image to registry.k0.hswaw.net/app/factorio:${version}-1
8
9In addition, a //third_party/factorio:push_latest rule will also be created for the highest versioned server version. This is for convenience.
10
11To add a new version of Factorio, just update the _versions map with the new version number and the sha256 sum of its tarball.
12"""
13
14load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file")
15load("@io_bazel_rules_docker//container:container.bzl", "container_image", "container_push")
16
17# version -> sha256 of server tarball
18_versions = {
Serge Bazanski791ab6d2020-08-14 10:34:29 +000019 "1.0.0": "81d9e1aa94435aeec4131c8869fa6e9331726bea1ea31db750b65ba42dbd1464",
Dariusz Niemczykb3799c82021-06-12 23:02:58 +020020 "1.1.34": "21969321cf370e95066f86fddfcb83d1a23ed9b67d087c1cb47d43e87673ca69",
Sergiusz Bazanski48050572020-05-10 21:34:10 +020021}
22
23def factorio_repository(version, sha256):
24 http_file(
25 name = "factorio-headless-%s" % (version),
26 urls = [
27 "https://factorio.com/get-download/%s/headless/linux64" % (version),
28 ],
29 sha256 = sha256,
30 downloaded_file_path = "factorio.tar.xz",
31 )
32
33def factorio_repositories():
34 for v, sha256 in _versions.items():
35 factorio_repository(v, sha256)
36
37def factorio_image(version, revision):
38 image_name = "%s-%d" % (version, revision)
39 container_image(
40 name = image_name,
41 base = "@prodimage-bionic//image",
42 tars = ["@factorio-headless-%s//file" % (version)],
43 files = [":entrypoint.sh"],
44 directory = "/",
45 entrypoint = ["/entrypoint.sh"],
46 )
47 container_push(
48 name = "push_%s-%d" % (version, revision),
49 image = ":%s" % (image_name),
50 format = "Docker",
51 registry = "registry.k0.hswaw.net",
52 repository = "app/factorio",
53 tag = "%s-%d" % (version, revision),
54 )
55
56def _sort_by_version(v):
57 return [int(el) for el in v.split(".")]
58
59def factorio_images():
60 revision_overrides = {
61 "0.18.12": 2,
62 }
63 for v in _versions.keys():
64 revision = revision_overrides.get(v, 1)
65 factorio_image(v, revision)
66
67 highest_version = sorted(_versions.keys(), key=_sort_by_version, reverse=True)[0]
68 revision = revision_overrides.get(highest_version, 1)
69 container_push(
70 name = "push_latest",
71 image = ":%s-%d" % (highest_version, revision),
72 format = "Docker",
73 registry = "registry.k0.hswaw.net",
Serge Bazanski970b7682020-08-04 20:33:17 +020074 repository = "q3k/factorio",
Sergiusz Bazanski48050572020-05-10 21:34:10 +020075 tag = "%s-%d" % (highest_version, revision),
76 )