blob: c2bbdf8f9bb4b19c7d71bae759b2e31ddfa9c991 [file] [log] [blame]
Sergiusz Bazanski262c6e02019-11-24 02:19:48 +01001local kube = import "../../kube/kube.libsonnet";
2
3{
4 local top = self,
5
6 Server(name):: {
7 local server = self,
8 local cfg = server.cfg,
9
10 cfg:: {
11 namespace: error "namespace must be set",
12 storageClassName: "waw-hdd-redundant-3",
13
14 image: "openrct2/openrct2-cli:0.2.4",
15 save: error "save must be set",
16
17 password: "", # disabled if empty.
18
19 admins: {
20 q3k: "a6a3727038eb53b35ad28ba88dc80810f94c6c3d",
21 },
22 },
23
24 metadata:: {
25 namespace: cfg.namespace,
26 },
27
28 volumeClaim: kube.PersistentVolumeClaim(name) {
29 metadata+: server.metadata,
30 spec+: {
31 storageClassName: cfg.storageClassName,
32 accessModes: [ "ReadWriteOnce" ],
33 resources: {
34 requests: {
35 storage: "5Gi",
36 },
37 },
38 },
39 },
40
41 config: kube.ConfigMap(name + "-config") {
42 metadata+: server.metadata,
43
44 // admins with local server as co-admin
45 local admins = cfg.admins + {
46 openrct2: "",
47 },
48 data: {
49 "users.json": std.manifestJson([
50 { hash: admins[name], name: name, groupId: 0 }
51 for name in std.objectFields(admins)
52 ]),
53 "run.sh": |||
54 set -ex
55 set -o pipefail
56
57 SAVES=/home/openrct2/.config/OpenRCT2/save/autosave
58 if [ -d "$SAVES" ]; then
59 echo "Save directory exists, checking for autosaves..."
60 latest="$SAVES/$(ls -Art "$SAVES" | tail -n 1)"
61 if [ -f "$latest" ]; then
62 echo "Found new autosave: $latest"
63 export OPENRCT2_SAVE="$latest"
64 fi
65 fi
66
67 echo "Running save $OPENRCT2_SAVE..."
68 if [ ! -z "$OPENRCT2_PASSWORD" ]; then
69 echo "Running with password..."
70 openrct2-cli host "$OPENRCT2_SAVE" --password "$OPENRCT2_PASSWORD"
71 else
72 echo "Running without password..."
73 openrct2-cli host "$OPENRCT2_SAVE"
74 fi
75 |||
76 },
77 },
78
79 deployment: kube.Deployment(name) {
80 metadata+: server.metadata,
81 spec+: {
82 template+: {
83 spec+: {
84 volumes_: {
85 data: kube.PersistentVolumeClaimVolume(server.volumeClaim),
86 config: kube.ConfigMapVolume(server.config),
87 },
88
89 initContainers: [
90 kube.Container("configure-users") {
91 image: cfg.image,
92 command: [
93 "/bin/bash", "-c",
94 "cp /config/users.json /home/openrct2/.config/OpenRCT2/users.json",
95 ],
96 volumeMounts_: {
97 data: { mountPath: "/home/openrct2/.config/OpenRCT2" },
98 config: { mountPath: "/config" },
99 },
100 },
101 ],
102 containers_: {
103 server: kube.Container("server") {
104 image: cfg.image,
105 env_: {
106 OPENRCT2_SAVE: cfg.save,
107 OPENRCT2_PASSWORD: cfg.password,
108 },
109 command: [
110 "/bin/bash", "/config/run.sh",
111 ],
112 ports_: {
113 client: { containerPort: 11753 },
114 },
115 volumeMounts_: {
116 data: { mountPath: "/home/openrct2/.config/OpenRCT2" },
117 config: { mountPath: "/config" },
118 },
119 resources: {
120 requests: {
121 cpu: "500m",
122 memory: "100Mi",
123 },
124 limits: {
125 cpu: "1",
126 memory: "1Gi",
127 },
128 },
129 },
130 },
131 },
132 },
133 },
134 },
135
136 svc: kube.Service(name) {
137 metadata+: server.metadata,
138 target_pod:: server.deployment.spec.template,
139 spec+: {
140 ports: [
141 { name: "client", port: 11753, targetPort: 11753, protocol: "TCP" },
142 ],
143 type: "LoadBalancer",
Sergiusz Bazanski31058182019-11-24 02:38:17 +0100144 externalTrafficPolicy: "Local",
Sergiusz Bazanski262c6e02019-11-24 02:19:48 +0100145 },
146 },
147 },
148
149 servers: {
Sergiusz Bazanski31058182019-11-24 02:38:17 +0100150 alcatraz: top.Server("openrct2-q3k-alcatraz") {
Sergiusz Bazanski262c6e02019-11-24 02:19:48 +0100151 cfg+: {
152 namespace: "personal-q3k",
Sergiusz Bazanski31058182019-11-24 02:38:17 +0100153 save: "https://q3k.org/u/480883b2d44658523dcf6561d71d7e3eb91be13253e2bc96378f86a62b380a97.sv6",
Sergiusz Bazanski262c6e02019-11-24 02:19:48 +0100154 },
155 },
156 },
157}