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