blob: 309a76d56606714e967add0c34f4fb5625eae7a7 [file] [log] [blame]
"""
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 = {
"1.0.0": "81d9e1aa94435aeec4131c8869fa6e9331726bea1ea31db750b65ba42dbd1464",
"1.1.34": "21969321cf370e95066f86fddfcb83d1a23ed9b67d087c1cb47d43e87673ca69",
"1.1.35": "245577c809407251ae2920809ee5d0cc4afebdbeb23c730abb8e99a612e2f176",
"1.1.50": "15148b77a703c25412ed912e4230bdb66e1a9a4450ac52ccf495c2afede2e548",
}
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",
repository = "q3k/factorio",
tag = "%s-%d" % (highest_version, revision),
)