| """ |
| 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.1.87": "60b3884b6dad1f4c7b30b7ef2b63619ff4a3204ac7fd894cf09d382b349857cc", |
| } |
| |
| 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), |
| ) |