blob: c0b765a8bdbfbb3695f0054d7306d9c9d38e5b77 [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",
Serge Bazanskif7efc402021-06-18 19:30:21 +000021 "1.1.35": "245577c809407251ae2920809ee5d0cc4afebdbeb23c730abb8e99a612e2f176",
Sergiusz Bazanski48050572020-05-10 21:34:10 +020022}
23
24def factorio_repository(version, sha256):
25 http_file(
26 name = "factorio-headless-%s" % (version),
27 urls = [
28 "https://factorio.com/get-download/%s/headless/linux64" % (version),
29 ],
30 sha256 = sha256,
31 downloaded_file_path = "factorio.tar.xz",
32 )
33
34def factorio_repositories():
35 for v, sha256 in _versions.items():
36 factorio_repository(v, sha256)
37
38def factorio_image(version, revision):
39 image_name = "%s-%d" % (version, revision)
40 container_image(
41 name = image_name,
42 base = "@prodimage-bionic//image",
43 tars = ["@factorio-headless-%s//file" % (version)],
44 files = [":entrypoint.sh"],
45 directory = "/",
46 entrypoint = ["/entrypoint.sh"],
47 )
48 container_push(
49 name = "push_%s-%d" % (version, revision),
50 image = ":%s" % (image_name),
51 format = "Docker",
52 registry = "registry.k0.hswaw.net",
53 repository = "app/factorio",
54 tag = "%s-%d" % (version, revision),
55 )
56
57def _sort_by_version(v):
58 return [int(el) for el in v.split(".")]
59
60def factorio_images():
61 revision_overrides = {
62 "0.18.12": 2,
63 }
64 for v in _versions.keys():
65 revision = revision_overrides.get(v, 1)
66 factorio_image(v, revision)
67
68 highest_version = sorted(_versions.keys(), key=_sort_by_version, reverse=True)[0]
69 revision = revision_overrides.get(highest_version, 1)
70 container_push(
71 name = "push_latest",
72 image = ":%s-%d" % (highest_version, revision),
73 format = "Docker",
74 registry = "registry.k0.hswaw.net",
Serge Bazanski970b7682020-08-04 20:33:17 +020075 repository = "q3k/factorio",
Sergiusz Bazanski48050572020-05-10 21:34:10 +020076 tag = "%s-%d" % (highest_version, revision),
77 )