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