games/factorio: add modproxy

This adds a mod proxy system, called, well, modproxy.

It sits between Factorio server instances and the Factorio mod portal,
allowing for arbitrary mod download without needing the servers to know
Factorio credentials.

Change-Id: I7bc405a25b6f9559cae1f23295249f186761f212
diff --git a/personal/q3k/factorio/kube/factorio.libsonnet b/personal/q3k/factorio/kube/factorio.libsonnet
index fc64aaa..4f2ff39 100644
--- a/personal/q3k/factorio/kube/factorio.libsonnet
+++ b/personal/q3k/factorio/kube/factorio.libsonnet
@@ -11,6 +11,7 @@
         appName: "factorio",
         storageClassName: "waw-hdd-redundant-2",
         prefix: "", # if set, should be 'foo-'
+        proxyImage: error "proxyImage must be set",
 
         rconPort: 2137,
         rconPassword: "farts",
@@ -27,6 +28,8 @@
                 memory: "1Gi",
             },
         },
+
+        mods: [],
     },
 
 
@@ -67,6 +70,16 @@
         },
     },
 
+    configMap: kube.ConfigMap(factorio.makeName("config")) {
+        metadata+: factorio.metadata,
+        data: {
+            "mods.pb.text": std.join("\n", [
+                "mod { name: \"%s\" version: \"%s\" }" % [m.name, m.version],
+                for m in cfg.mods
+            ]),
+        },
+    },
+
     deployment: kube.Deployment(factorio.makeName("factorio")) {
         metadata+: factorio.metadata,
         spec+: {
@@ -76,6 +89,23 @@
                     volumes_: {
                         data: kube.PersistentVolumeClaimVolume(factorio.volumeClaimData),
                         mods: kube.PersistentVolumeClaimVolume(factorio.volumeClaimMods),
+                        config: kube.ConfigMapVolume(factorio.configMap),
+                    },
+                    initContainers_: {
+                        modproxy: kube.Container("modproxy") {
+                            image: cfg.proxyImage,
+                            command: [
+                                "/games/factorio/modproxy/client",
+                                "-hspki_disable",
+                                "-factorio_path", "/factorio",
+                                "-proxy", "proxy.factorio.svc.cluster.local:4200",
+                                "-config_path", "/factorio/mods.pb.text",
+                            ],
+                            volumeMounts_: {
+                                mods: { mountPath: "/factorio/mods" },
+                                config: { mountPath: "/factorio/mods.pb.text", subPath: "mods.pb.text" },
+                            },
+                        },
                     },
                     containers_: {
                         factorio: kube.Container(factorio.makeName("factorio")) {