blob: 7c7b0ae58dce01be064d8e3f1644550134c83c3e [file] [log] [blame]
Sergiusz Bazanskid1ccdcf2020-05-06 20:34:06 +02001local kube = import "../../../kube/kube.libsonnet";
Rafał Hirsz12ab93a2020-05-16 21:02:52 +02002local defaultWorldguardConfig = import "worldguard.libsonnet";
Sergiusz Bazanskid1ccdcf2020-05-06 20:34:06 +02003
4{
5 local minecraft = self,
6 versions:: {
Serge Bazanskibbb16232020-08-01 12:04:04 +02007 "spigot-1.16.1": "registry.k0.hswaw.net/q3k/minecraft:spigot-1.16.1-r2",
8 "paper-1.16.1": "registry.k0.hswaw.net/q3k/minecraft:paper-1.16.1-r2",
Sergiusz Bazanskid1ccdcf2020-05-06 20:34:06 +02009 },
10 server(name, version):: {
11 local server = self,
12 name:: name,
13 version:: version,
14 image:: minecraft.versions[server.version],
15
16 metadata:: {
17 namespace: "minecraft",
18 },
19
20 componentName(component):: "%s-%s" % [server.name, component],
21
22 properties:: {
23 "spawn-protection": 16,
24 "max-tick-time": 60000,
25 "query.port": 25565,
26 "generator-settings": "",
27 "force-gamemode": false,
28 "allow-nether": true,
29 "enforce-whitelist": false,
30 "gamemode": "survival",
31 "broadcast-console-to-ops": true,
32 "enable-query": false,
33 "player-idle-timeout": 0,
34 "difficulty": "easy",
35 "broadcast-rcon-to-ops": true,
36 "spawn-monsters": true,
37 "op-permission-level": 4,
38 "pvp": true,
39 "snooper-enabled": true,
40 "level-type": "default",
41 "hardcore": false,
42 "enable-command-block": false,
43 "network-compression-threshold": 256,
44 "max-players": 20,
45 "max-world-size": 29999984,
46 "resource-pack-sha1": "",
47 "function-permission-level": 2,
48 "rcon.port": 25575,
49 "server-port": 25565,
50 "debug": false,
51 "server-ip": "",
52 "spawn-npcs": true,
53 "allow-flight": false,
54 "level-name": "world",
55 "view-distance": 10,
56 "resource-pack": "",
57 "spawn-animals": true,
58 "white-list": false,
59 "rcon.password": "",
60 "generate-structures": true,
61 "online-mode": true,
62 "max-build-height": 256,
63 "level-seed": "",
64 "prevent-proxy-connections": false,
65 "use-native-transport": true,
66 "motd": "A Minecraft Server",
67 "enable-rcon": false,
68 },
69
Rafał Hirsz12ab93a2020-05-16 21:02:52 +020070 worldguardConfig:: defaultWorldguardConfig,
71
Sergiusz Bazanskid1ccdcf2020-05-06 20:34:06 +020072 startsh:: |||
73 #!/usr/bin/env bash
74 cd /home/minecraft/world
75 cp /home/minecraft/config/server.properties .
Serge Bazanskibbb16232020-08-01 12:04:04 +020076 cp /home/minecraft/server.jar .
Rafał Hirsz12ab93a2020-05-16 21:02:52 +020077 mkdir -p plugins/WorldGuard
78 cp /home/minecraft/worldedit-*.jar plugins
79 cp /home/minecraft/worldguard-*.jar plugins
80 cp /home/minecraft/config/worldguard_config.yaml plugins/WorldGuard/config.yml
Sergiusz Bazanskid1ccdcf2020-05-06 20:34:06 +020081 echo "eula=true" > eula.txt
82
83 bash /home/minecraft/config/overviewer.sh &
Serge Bazanskibbb16232020-08-01 12:04:04 +020084 exec java -Xmx4G -Xms4G -jar server.jar
Sergiusz Bazanskid1ccdcf2020-05-06 20:34:06 +020085 |||,
86
87 overviewersh:: |||
88 #!/usr/bin/env bash
89 mkdir -p overviewer/world
90 sleep 60
91 while true; do
92 echo "Rendering Overviewer map..."
93 overviewer.py -p 1 --rendermodes=normal,lighting,smooth-lighting,cave world overviewer/world
94 echo "Done."
95 sleep 900
96 done
97 |||,
98
99 secretProperties: kube.Secret(server.componentName("properties")) {
100 metadata+: server.metadata,
101 data: {
102 local properties = std.join("\n", ["%s=%s" % [k, std.toString(server.properties[k])] for k in std.objectFields(server.properties)]),
103 "server.properties": std.base64(properties),
Rafał Hirsz12ab93a2020-05-16 21:02:52 +0200104 local worldguardConfig = std.manifestYamlDoc(server.worldguardConfig),
105 "worldguard_config.yaml": std.base64(worldguardConfig),
Sergiusz Bazanskid1ccdcf2020-05-06 20:34:06 +0200106 "start.sh": std.base64(server.startsh),
107 "overviewer.sh": std.base64(server.overviewersh),
108 },
109 },
110
111 worldVolume: kube.PersistentVolumeClaim(server.componentName("world")) {
112 metadata+: server.metadata,
113 spec+: {
114 storageClassName: "waw-hdd-redundant-3",
115 accessModes: ["ReadWriteOnce"],
116 resources: {
117 requests: {
118 storage: "10Gi",
119 },
120 },
121 },
122 },
123
124 deploy: kube.Deployment(server.componentName("deploy")) {
125 metadata+: server.metadata,
126 spec+: {
127 template+: {
128 spec+: {
129 volumes_: {
130 config: kube.SecretVolume(server.secretProperties),
131 world: kube.PersistentVolumeClaimVolume(server.worldVolume),
132 },
133 containers_: {
134 default: kube.Container("default") {
135 image: server.image,
136 command: [
137 "bash", "/home/minecraft/config/start.sh",
138 ],
139 volumeMounts_: {
140 config: { mountPath: "/home/minecraft/config" },
141 world: { mountPath: "/home/minecraft/world" },
142 },
143 ports_: {
144 minecraft: { containerPort: 25565 },
Sergiusz Bazanski7fa92b42020-05-18 01:06:07 +0200145 grpc: { containerPort: 2137 },
Sergiusz Bazanskid1ccdcf2020-05-06 20:34:06 +0200146 },
147 resources: {
148 requests: {
149 memory: "6G",
150 cpu: "2",
151 },
152 limits: {
153 memory: "6G",
154 cpu: "4",
155 },
156 },
157 },
158 overviewer: kube.Container("overviewer") {
159 image: "halverneus/static-file-server:v1.8.0",
160 env_: {
161 FOLDER: "/home/minecraft/world/overviewer/world",
162 },
163 volumeMounts_: {
164 world: { mountPath: "/home/minecraft/world" },
165 },
166 ports_: {
167 web: { containerPort: 8080 },
168 },
169 },
Sergiusz Bazanskif3169322020-05-18 23:47:37 +0200170 bridge: kube.Container("bridge") {
171 image: "registry.k0.hswaw.net/q3k/minecraft-hscloud-bridge:20200518c",
172 command: [
173 "/personal/q3k/minecraft/plugin/hscloud/bridge/bridge",
174 "-plugin", "127.0.0.1:2137",
175 ],
176 ports_: {
177 bridge: { containerPort: 8081 },
178 },
179 },
Sergiusz Bazanskid1ccdcf2020-05-06 20:34:06 +0200180 },
181 },
182 },
183 },
184 },
185
186 svc: kube.Service(server.componentName("svc")) {
187 metadata+: server.metadata,
188 target_pod:: server.deploy.spec.template,
189 spec+: {
190 ports: [
191 { name: "minecraft", port: 25565, targetPort: 25565, protocol: "TCP" },
192 { name: "web", port: 80, targetPort: 8080, protocol: "TCP" },
Sergiusz Bazanskif3169322020-05-18 23:47:37 +0200193 { name: "bridge", port: 8080, targetPort: 8081, protocol: "TCP" },
Sergiusz Bazanski7fa92b42020-05-18 01:06:07 +0200194 { name: "grpc", port: 2137, targetPort: 2137, protocol: "TCP" },
Sergiusz Bazanskid1ccdcf2020-05-06 20:34:06 +0200195 ],
196 type: "LoadBalancer",
197 externalTrafficPolicy: "Local",
198 },
199 },
200 },
201
202 ns: kube.Namespace("minecraft"),
203
204 q3k: {
Serge Bazanskibbb16232020-08-01 12:04:04 +0200205 survival: minecraft.server("q3k-survival", "paper-1.16.1") {
Sergiusz Bazanskid1ccdcf2020-05-06 20:34:06 +0200206 properties+: {
207 motd: "wypierdol z polski kropka pe el",
Sergiusz Bazanski6a0b75b2020-05-16 21:05:09 +0200208 "enforce-whitelist": true,
Sergiusz Bazanskid1ccdcf2020-05-06 20:34:06 +0200209 },
Rafał Hirsz12ab93a2020-05-16 21:02:52 +0200210 worldguardConfig+: {
211 mobs+: {
212 "block-creeper-block-damage": true,
213 },
214 },
Sergiusz Bazanskid1ccdcf2020-05-06 20:34:06 +0200215 },
216 },
217}