Sergiusz Bazanski | d1ccdcf | 2020-05-06 20:34:06 +0200 | [diff] [blame] | 1 | local kube = import "../../../kube/kube.libsonnet"; |
Rafał Hirsz | 12ab93a | 2020-05-16 21:02:52 +0200 | [diff] [blame] | 2 | local defaultWorldguardConfig = import "worldguard.libsonnet"; |
Sergiusz Bazanski | d1ccdcf | 2020-05-06 20:34:06 +0200 | [diff] [blame] | 3 | |
| 4 | { |
| 5 | local minecraft = self, |
| 6 | versions:: { |
Serge Bazanski | bbb1623 | 2020-08-01 12:04:04 +0200 | [diff] [blame] | 7 | "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 Bazanski | d1ccdcf | 2020-05-06 20:34:06 +0200 | [diff] [blame] | 9 | }, |
| 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ł Hirsz | 12ab93a | 2020-05-16 21:02:52 +0200 | [diff] [blame] | 70 | worldguardConfig:: defaultWorldguardConfig, |
| 71 | |
Sergiusz Bazanski | d1ccdcf | 2020-05-06 20:34:06 +0200 | [diff] [blame] | 72 | startsh:: ||| |
| 73 | #!/usr/bin/env bash |
| 74 | cd /home/minecraft/world |
| 75 | cp /home/minecraft/config/server.properties . |
Serge Bazanski | bbb1623 | 2020-08-01 12:04:04 +0200 | [diff] [blame] | 76 | cp /home/minecraft/server.jar . |
Rafał Hirsz | 12ab93a | 2020-05-16 21:02:52 +0200 | [diff] [blame] | 77 | 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 Bazanski | d1ccdcf | 2020-05-06 20:34:06 +0200 | [diff] [blame] | 81 | echo "eula=true" > eula.txt |
| 82 | |
| 83 | bash /home/minecraft/config/overviewer.sh & |
Serge Bazanski | bbb1623 | 2020-08-01 12:04:04 +0200 | [diff] [blame] | 84 | exec java -Xmx4G -Xms4G -jar server.jar |
Sergiusz Bazanski | d1ccdcf | 2020-05-06 20:34:06 +0200 | [diff] [blame] | 85 | |||, |
| 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ł Hirsz | 12ab93a | 2020-05-16 21:02:52 +0200 | [diff] [blame] | 104 | local worldguardConfig = std.manifestYamlDoc(server.worldguardConfig), |
| 105 | "worldguard_config.yaml": std.base64(worldguardConfig), |
Sergiusz Bazanski | d1ccdcf | 2020-05-06 20:34:06 +0200 | [diff] [blame] | 106 | "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 Bazanski | 7fa92b4 | 2020-05-18 01:06:07 +0200 | [diff] [blame] | 145 | grpc: { containerPort: 2137 }, |
Sergiusz Bazanski | d1ccdcf | 2020-05-06 20:34:06 +0200 | [diff] [blame] | 146 | }, |
| 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 Bazanski | f316932 | 2020-05-18 23:47:37 +0200 | [diff] [blame] | 170 | 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 Bazanski | d1ccdcf | 2020-05-06 20:34:06 +0200 | [diff] [blame] | 180 | }, |
| 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 Bazanski | f316932 | 2020-05-18 23:47:37 +0200 | [diff] [blame] | 193 | { name: "bridge", port: 8080, targetPort: 8081, protocol: "TCP" }, |
Sergiusz Bazanski | 7fa92b4 | 2020-05-18 01:06:07 +0200 | [diff] [blame] | 194 | { name: "grpc", port: 2137, targetPort: 2137, protocol: "TCP" }, |
Sergiusz Bazanski | d1ccdcf | 2020-05-06 20:34:06 +0200 | [diff] [blame] | 195 | ], |
| 196 | type: "LoadBalancer", |
| 197 | externalTrafficPolicy: "Local", |
| 198 | }, |
| 199 | }, |
| 200 | }, |
| 201 | |
| 202 | ns: kube.Namespace("minecraft"), |
| 203 | |
| 204 | q3k: { |
Serge Bazanski | bbb1623 | 2020-08-01 12:04:04 +0200 | [diff] [blame] | 205 | survival: minecraft.server("q3k-survival", "paper-1.16.1") { |
Sergiusz Bazanski | d1ccdcf | 2020-05-06 20:34:06 +0200 | [diff] [blame] | 206 | properties+: { |
| 207 | motd: "wypierdol z polski kropka pe el", |
Sergiusz Bazanski | 6a0b75b | 2020-05-16 21:05:09 +0200 | [diff] [blame] | 208 | "enforce-whitelist": true, |
Sergiusz Bazanski | d1ccdcf | 2020-05-06 20:34:06 +0200 | [diff] [blame] | 209 | }, |
Rafał Hirsz | 12ab93a | 2020-05-16 21:02:52 +0200 | [diff] [blame] | 210 | worldguardConfig+: { |
| 211 | mobs+: { |
| 212 | "block-creeper-block-damage": true, |
| 213 | }, |
| 214 | }, |
Sergiusz Bazanski | d1ccdcf | 2020-05-06 20:34:06 +0200 | [diff] [blame] | 215 | }, |
| 216 | }, |
| 217 | } |