2020-05-10 19:34:10 +00:00
|
|
|
"""
|
|
|
|
Automatically download, package, containerize and push Factorio server images.
|
|
|
|
|
|
|
|
For each version defined, the following will be declared:
|
|
|
|
- @factorio-headless-${version}: a repository containing the factorio server tarball
|
|
|
|
- //third_party/factorio:${version}-1: a container_image rule to build a docker container running a factorio server
|
|
|
|
- //third_party/factorio:push_${version}-1: a container_push rule to push that container image to registry.k0.hswaw.net/app/factorio:${version}-1
|
|
|
|
|
|
|
|
In addition, a //third_party/factorio:push_latest rule will also be created for the highest versioned server version. This is for convenience.
|
|
|
|
|
|
|
|
To add a new version of Factorio, just update the _versions map with the new version number and the sha256 sum of its tarball.
|
|
|
|
"""
|
|
|
|
|
|
|
|
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file")
|
|
|
|
load("@io_bazel_rules_docker//container:container.bzl", "container_image", "container_push")
|
|
|
|
|
|
|
|
# version -> sha256 of server tarball
|
|
|
|
_versions = {
|
2020-08-14 10:34:29 +00:00
|
|
|
"1.0.0": "81d9e1aa94435aeec4131c8869fa6e9331726bea1ea31db750b65ba42dbd1464",
|
2021-06-12 21:02:58 +00:00
|
|
|
"1.1.34": "21969321cf370e95066f86fddfcb83d1a23ed9b67d087c1cb47d43e87673ca69",
|
2021-06-18 19:30:21 +00:00
|
|
|
"1.1.35": "245577c809407251ae2920809ee5d0cc4afebdbeb23c730abb8e99a612e2f176",
|
2021-12-26 00:04:26 +00:00
|
|
|
"1.1.50": "15148b77a703c25412ed912e4230bdb66e1a9a4450ac52ccf495c2afede2e548",
|
2020-05-10 19:34:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
def factorio_repository(version, sha256):
|
|
|
|
http_file(
|
|
|
|
name = "factorio-headless-%s" % (version),
|
|
|
|
urls = [
|
|
|
|
"https://factorio.com/get-download/%s/headless/linux64" % (version),
|
|
|
|
],
|
|
|
|
sha256 = sha256,
|
|
|
|
downloaded_file_path = "factorio.tar.xz",
|
|
|
|
)
|
|
|
|
|
|
|
|
def factorio_repositories():
|
|
|
|
for v, sha256 in _versions.items():
|
|
|
|
factorio_repository(v, sha256)
|
|
|
|
|
|
|
|
def factorio_image(version, revision):
|
|
|
|
image_name = "%s-%d" % (version, revision)
|
|
|
|
container_image(
|
|
|
|
name = image_name,
|
|
|
|
base = "@prodimage-bionic//image",
|
|
|
|
tars = ["@factorio-headless-%s//file" % (version)],
|
|
|
|
files = [":entrypoint.sh"],
|
|
|
|
directory = "/",
|
|
|
|
entrypoint = ["/entrypoint.sh"],
|
|
|
|
)
|
|
|
|
container_push(
|
|
|
|
name = "push_%s-%d" % (version, revision),
|
|
|
|
image = ":%s" % (image_name),
|
|
|
|
format = "Docker",
|
|
|
|
registry = "registry.k0.hswaw.net",
|
|
|
|
repository = "app/factorio",
|
|
|
|
tag = "%s-%d" % (version, revision),
|
|
|
|
)
|
|
|
|
|
|
|
|
def _sort_by_version(v):
|
|
|
|
return [int(el) for el in v.split(".")]
|
|
|
|
|
|
|
|
def factorio_images():
|
|
|
|
revision_overrides = {
|
|
|
|
"0.18.12": 2,
|
|
|
|
}
|
|
|
|
for v in _versions.keys():
|
|
|
|
revision = revision_overrides.get(v, 1)
|
|
|
|
factorio_image(v, revision)
|
|
|
|
|
|
|
|
highest_version = sorted(_versions.keys(), key=_sort_by_version, reverse=True)[0]
|
|
|
|
revision = revision_overrides.get(highest_version, 1)
|
|
|
|
container_push(
|
|
|
|
name = "push_latest",
|
|
|
|
image = ":%s-%d" % (highest_version, revision),
|
|
|
|
format = "Docker",
|
|
|
|
registry = "registry.k0.hswaw.net",
|
2020-08-04 18:33:17 +00:00
|
|
|
repository = "q3k/factorio",
|
2020-05-10 19:34:10 +00:00
|
|
|
tag = "%s-%d" % (highest_version, revision),
|
|
|
|
)
|