blob: c2bbdf8f9bb4b19c7d71bae759b2e31ddfa9c991 [file] [log] [blame]
local kube = import "../../kube/kube.libsonnet";
{
local top = self,
Server(name):: {
local server = self,
local cfg = server.cfg,
cfg:: {
namespace: error "namespace must be set",
storageClassName: "waw-hdd-redundant-3",
image: "openrct2/openrct2-cli:0.2.4",
save: error "save must be set",
password: "", # disabled if empty.
admins: {
q3k: "a6a3727038eb53b35ad28ba88dc80810f94c6c3d",
},
},
metadata:: {
namespace: cfg.namespace,
},
volumeClaim: kube.PersistentVolumeClaim(name) {
metadata+: server.metadata,
spec+: {
storageClassName: cfg.storageClassName,
accessModes: [ "ReadWriteOnce" ],
resources: {
requests: {
storage: "5Gi",
},
},
},
},
config: kube.ConfigMap(name + "-config") {
metadata+: server.metadata,
// admins with local server as co-admin
local admins = cfg.admins + {
openrct2: "",
},
data: {
"users.json": std.manifestJson([
{ hash: admins[name], name: name, groupId: 0 }
for name in std.objectFields(admins)
]),
"run.sh": |||
set -ex
set -o pipefail
SAVES=/home/openrct2/.config/OpenRCT2/save/autosave
if [ -d "$SAVES" ]; then
echo "Save directory exists, checking for autosaves..."
latest="$SAVES/$(ls -Art "$SAVES" | tail -n 1)"
if [ -f "$latest" ]; then
echo "Found new autosave: $latest"
export OPENRCT2_SAVE="$latest"
fi
fi
echo "Running save $OPENRCT2_SAVE..."
if [ ! -z "$OPENRCT2_PASSWORD" ]; then
echo "Running with password..."
openrct2-cli host "$OPENRCT2_SAVE" --password "$OPENRCT2_PASSWORD"
else
echo "Running without password..."
openrct2-cli host "$OPENRCT2_SAVE"
fi
|||
},
},
deployment: kube.Deployment(name) {
metadata+: server.metadata,
spec+: {
template+: {
spec+: {
volumes_: {
data: kube.PersistentVolumeClaimVolume(server.volumeClaim),
config: kube.ConfigMapVolume(server.config),
},
initContainers: [
kube.Container("configure-users") {
image: cfg.image,
command: [
"/bin/bash", "-c",
"cp /config/users.json /home/openrct2/.config/OpenRCT2/users.json",
],
volumeMounts_: {
data: { mountPath: "/home/openrct2/.config/OpenRCT2" },
config: { mountPath: "/config" },
},
},
],
containers_: {
server: kube.Container("server") {
image: cfg.image,
env_: {
OPENRCT2_SAVE: cfg.save,
OPENRCT2_PASSWORD: cfg.password,
},
command: [
"/bin/bash", "/config/run.sh",
],
ports_: {
client: { containerPort: 11753 },
},
volumeMounts_: {
data: { mountPath: "/home/openrct2/.config/OpenRCT2" },
config: { mountPath: "/config" },
},
resources: {
requests: {
cpu: "500m",
memory: "100Mi",
},
limits: {
cpu: "1",
memory: "1Gi",
},
},
},
},
},
},
},
},
svc: kube.Service(name) {
metadata+: server.metadata,
target_pod:: server.deployment.spec.template,
spec+: {
ports: [
{ name: "client", port: 11753, targetPort: 11753, protocol: "TCP" },
],
type: "LoadBalancer",
externalTrafficPolicy: "Local",
},
},
},
servers: {
alcatraz: top.Server("openrct2-q3k-alcatraz") {
cfg+: {
namespace: "personal-q3k",
save: "https://q3k.org/u/480883b2d44658523dcf6561d71d7e3eb91be13253e2bc96378f86a62b380a97.sv6",
},
},
},
}