diff --git a/minecraft/.common/Makefile b/minecraft/.common/Makefile new file mode 100644 index 0000000..0792771 --- /dev/null +++ b/minecraft/.common/Makefile @@ -0,0 +1,27 @@ +SHELL := /bin/bash + +IMAGE ?= $(shell cat IMAGE):$(shell cat VERSION) +IMAGE_LATEST ?= $(shell cat IMAGE):latest +PWD ?= $(shell pwd) + +.PHONY: buildx-context +buildx-context: + docker buildx create --name arm64 --use --platform linux/amd64,linux/arm64 + +.PHONY: buildx-clear +buildx-clear: + docker buildx rm arm64 + +.PHONY: build +build: + docker buildx build --load . -t $(IMAGE) + @docker buildx build --load . -t $(IMAGE_LATEST) + +.PHONY: push +push: + docker buildx build --platform linux/amd64 --push . -t $(IMAGE) + @docker buildx build --platform linux/amd64 --push . -t $(IMAGE_LATEST) + +.PHONY: run +run: + docker run -it -v $(PWD):/mc_data $(IMAGE) bash diff --git a/minecraft/.gitignore b/minecraft/.gitignore new file mode 100644 index 0000000..adbb97d --- /dev/null +++ b/minecraft/.gitignore @@ -0,0 +1 @@ +data/ \ No newline at end of file diff --git a/minecraft/.gitlab-ci.yml b/minecraft/.gitlab-ci.yml new file mode 100644 index 0000000..1abb03c --- /dev/null +++ b/minecraft/.gitlab-ci.yml @@ -0,0 +1,21 @@ +variables: + CI_PROJECT_NAME: "minecraft" + CI_PROJECT_DIR: "." + CI_REGISTRY_IMAGE: hub.ducoterra.net/ducoterra/minecraft + +stages: + - build + - test + - deploy + +build: + only: + variables: + - $CI_COMMIT_TAG + stage: build + image: + name: gcr.io/kaniko-project/executor:debug + entrypoint: [""] + script: + - echo $DEPLOY + - /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG \ No newline at end of file diff --git a/minecraft/Dockerfile b/minecraft/Dockerfile new file mode 100644 index 0000000..e401881 --- /dev/null +++ b/minecraft/Dockerfile @@ -0,0 +1,10 @@ +FROM openjdk:latest + +RUN groupadd -r minecraft -g 2000 +RUN useradd --no-log-init minecraft -u 2000 -g 2000 -m +WORKDIR /mc_data +RUN chown -R minecraft:minecraft . + +USER minecraft +# Copy files only if they don't yet exist (server.jar, server.properties, etc) and start the server +CMD java -Xmx"$MAX_RAM"G -Xms"$MIN_RAM"G -jar ./server.jar nogui diff --git a/minecraft/IMAGE b/minecraft/IMAGE new file mode 100644 index 0000000..a26228d --- /dev/null +++ b/minecraft/IMAGE @@ -0,0 +1 @@ +ducoterra/minecraft diff --git a/minecraft/Makefile b/minecraft/Makefile new file mode 100644 index 0000000..c114817 --- /dev/null +++ b/minecraft/Makefile @@ -0,0 +1 @@ +include .common/Makefile diff --git a/minecraft/README.md b/minecraft/README.md new file mode 100644 index 0000000..7249982 --- /dev/null +++ b/minecraft/README.md @@ -0,0 +1,80 @@ +# Minecraft + +## Getting server.jar + +![Click Installations](img/main.png) +![Select the Options Menu](img/menu.png) +![Click Edit](img/edit.png) +![Click Download Server](img/server.png) + +## Running Locally + +```bash +docker-compose build minecraft +docker-compose up minecraft +``` + +## Uploading to Docker Hub + +In docker-compose.yaml, update the image tag to: + +```yaml +... +services: + minecraft: + build: . + image: /minecraft:-1 + ports: +... +``` + +then run + +```bash +docker-compose push +``` + +## Running in kubernetes + +In k8s/deploy.yaml, edit the deploy + +```yaml +... + spec: + containers: + - name: minecraft + image: + ports: +... +``` + +Then run the following + +```bash +kubectl apply -f k8s/pvc +kubectl apply -f k8s +``` + +Your minecraft server will be available on port 25565 + +## Create a Backup + +```bash +kubectl cp :/mc_data +``` + +## Restore from Backup + +```bash +kubectl cp :/mc_data +``` + +## Cool seeds + +### 7485786574821478084 + +Spawns you next to a nether portal with golden axe and pickaxe. River and Village close by. + +### -8018833100564192815 + +Use with an amplified world, massive island diff --git a/minecraft/VERSION b/minecraft/VERSION new file mode 100644 index 0000000..3eefcb9 --- /dev/null +++ b/minecraft/VERSION @@ -0,0 +1 @@ +1.0.0 diff --git a/minecraft/helm/.helmignore b/minecraft/helm/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/minecraft/helm/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/minecraft/helm/Chart.yaml b/minecraft/helm/Chart.yaml new file mode 100644 index 0000000..6e2f7cd --- /dev/null +++ b/minecraft/helm/Chart.yaml @@ -0,0 +1,23 @@ +apiVersion: v2 +name: minecraft +description: A Minecraft server for kubernetes + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 1.1.0 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +appVersion: 1.0.0 diff --git a/minecraft/helm/README.md b/minecraft/helm/README.md new file mode 100644 index 0000000..0b3d699 --- /dev/null +++ b/minecraft/helm/README.md @@ -0,0 +1,3 @@ +# Minecraft Server + +Creates a vanilla Minecraft server. diff --git a/minecraft/helm/app-readme.md b/minecraft/helm/app-readme.md new file mode 100644 index 0000000..0b3d699 --- /dev/null +++ b/minecraft/helm/app-readme.md @@ -0,0 +1,3 @@ +# Minecraft Server + +Creates a vanilla Minecraft server. diff --git a/minecraft/helm/ix_values.yaml b/minecraft/helm/ix_values.yaml new file mode 100644 index 0000000..4648913 --- /dev/null +++ b/minecraft/helm/ix_values.yaml @@ -0,0 +1,2 @@ +image: ducoterra/minecraft:latest +server_version: "1.17.1" diff --git a/minecraft/helm/minecraft-logo.png b/minecraft/helm/minecraft-logo.png new file mode 100644 index 0000000..d9ada6f Binary files /dev/null and b/minecraft/helm/minecraft-logo.png differ diff --git a/minecraft/helm/questions.yaml b/minecraft/helm/questions.yaml new file mode 100644 index 0000000..0182ab7 --- /dev/null +++ b/minecraft/helm/questions.yaml @@ -0,0 +1,38 @@ +groups: + - name: "Server Config" + description: "Minecraft Server Configuration" + - name: "Storage" + description: "Minecraft Server Storage" +questions: + - variable: server_version + description: "Server Version" + label: "Version" + group: "Server Config" + schema: + type: string + default: "1.17.1" + required: false + - variable: port + description: "Listen Port" + group: "Server Config" + label: "Port" + schema: + type: int + default: 25565 + required: true + - variable: max_ram + description: "Total RAM allocated to the server" + group: "Server Config" + label: "RAM Limit (GiB)" + schema: + type: int + default: 4 + required: true + - variable: max_cpu + description: "# CPU Cores Allocated to the server" + group: "Server Config" + label: "CPU Limit (# Cores)" + schema: + type: int + default: 4 + required: true diff --git a/minecraft/helm/templates/configmap.yaml b/minecraft/helm/templates/configmap.yaml new file mode 100644 index 0000000..43a784a --- /dev/null +++ b/minecraft/helm/templates/configmap.yaml @@ -0,0 +1,8 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ .Release.Name }} +data: + eula.txt: | + eula=true + server.properties: {{ toYaml .Values.server_props | indent 2 }} \ No newline at end of file diff --git a/minecraft/helm/templates/deploy.yaml b/minecraft/helm/templates/deploy.yaml new file mode 100644 index 0000000..e6a0c7e --- /dev/null +++ b/minecraft/helm/templates/deploy.yaml @@ -0,0 +1,70 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ .Release.Name }} +spec: + selector: + matchLabels: + app: {{ .Release.Name }} + strategy: + type: Recreate + template: + metadata: + labels: + app: {{ .Release.Name }} + spec: + initContainers: + - name: get-version + image: {{ .Values.get_server.image }} + imagePullPolicy: Always + env: + - name: SERVER_VERSION + value: {{ .Values.server_version }} + volumeMounts: + - mountPath: /downloads + name: data + - name: download-server + image: {{ .Values.get_server.image }} + imagePullPolicy: Always + command: ["bash", "-c", "curl -o server.jar $(cat SERVER_VERSION)"] + volumeMounts: + - mountPath: /downloads + name: data + containers: + - name: {{ .Release.Name }} + image: {{ .Values.image }} + imagePullPolicy: Always + ports: + - containerPort: 25565 + volumeMounts: + - mountPath: /mc_data + name: data + - name: properties + mountPath: /mc_data/server.properties + subPath: server.properties + - name: properties + mountPath: /mc_data/eula.txt + subPath: eula.txt + tty: true + stdin: true + env: + - name: MAX_RAM + value: {{ .Values.max_ram | quote }} + - name: MIN_RAM + value: "1" + resources: + requests: + memory: {{ div .Values.max_ram 2 }}Gi + cpu: 1m + limits: + memory: {{ add 1 .Values.max_ram }}Gi + cpu: {{ .Values.max_cpu | quote }} + volumes: + - name: data + persistentVolumeClaim: + claimName: {{ .Release.Name }} + - name: properties + configMap: + name: {{ .Release.Name }} + securityContext: + fsGroup: 2000 diff --git a/minecraft/helm/templates/pvc.yaml b/minecraft/helm/templates/pvc.yaml new file mode 100644 index 0000000..e825a00 --- /dev/null +++ b/minecraft/helm/templates/pvc.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: {{ .Release.Name }} + annotations: + "helm.sh/resource-policy": keep +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 32Gi \ No newline at end of file diff --git a/minecraft/helm/templates/service.yaml b/minecraft/helm/templates/service.yaml new file mode 100644 index 0000000..eade03e --- /dev/null +++ b/minecraft/helm/templates/service.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ .Release.Name }} +spec: + selector: + app: {{ .Release.Name }} + ports: + - port: {{ .Values.port }} + targetPort: 25565 + name: {{ .Release.Name }} + type: LoadBalancer \ No newline at end of file diff --git a/minecraft/helm/values.yaml b/minecraft/helm/values.yaml new file mode 100644 index 0000000..01943f6 --- /dev/null +++ b/minecraft/helm/values.yaml @@ -0,0 +1,45 @@ +image: ducoterra/minecraft:latest +get_server: + image: ducoterra/get-minecraft:latest +server_version: "1.17.1" +port: 20101 +max_cpu: 4 +max_ram: 4 +server_props: | + max-tick-time=60000 + generator-settings= + force-gamemode=false + allow-nether=true + gamemode=0 + broadcast-console-to-ops=true + enable-query=false + player-idle-timeout=0 + difficulty=3 + spawn-monsters=true + op-permission-level=4 + pvp=true + snooper-enabled=true + level-type=default + hardcore=false + enable-command-block=false + max-players=20 + network-compression-threshold=256 + resource-pack-sha1= + max-world-size=29999984 + server-port=25565 + server-ip= + spawn-npcs=true + allow-flight=true + level-name=world + view-distance=32 + resource-pack= + spawn-animals=true + white-list=true + generate-structures=true + online-mode=true + max-build-height=256 + level-seed= + prevent-proxy-connections=false + use-native-transport=true + motd=This is gonna be interesting + enable-rcon=false diff --git a/minecraft/servers.md b/minecraft/servers.md new file mode 100644 index 0000000..67a699d --- /dev/null +++ b/minecraft/servers.md @@ -0,0 +1,19 @@ +# Servers + +## Minecraft + +```bash +helm upgrade --install minecraft ./helm --set tag=1.15.2_7 --set port=25565 +``` + +## Pubcraft + +```bash +helm upgrade --install pubcraft ./helm --set tag=1.15.2_7 --set port=20100 +``` + +## TestCraft + +```bash +helm upgrade --install testcraft ./helm --set tag=1.16.1_2 --set port=25566 +``` diff --git a/minecraft/setenv.sh b/minecraft/setenv.sh new file mode 100755 index 0000000..a6290aa --- /dev/null +++ b/minecraft/setenv.sh @@ -0,0 +1 @@ +kubectl config set current-context k3os-alpha.dnet-ducoterra-minecraft \ No newline at end of file diff --git a/minecraft/values/values-camcraft.yaml b/minecraft/values/values-camcraft.yaml new file mode 100644 index 0000000..da74c4b --- /dev/null +++ b/minecraft/values/values-camcraft.yaml @@ -0,0 +1,42 @@ +image: hub.ducoterra.net/ducoterra/minecraft:1.16.4 +port: 20101 +max_cpu: 8 +max_ram: 8 +server_props: | + max-tick-time=60000 + generator-settings= + force-gamemode=false + allow-nether=true + gamemode=0 + broadcast-console-to-ops=true + enable-query=false + player-idle-timeout=0 + difficulty=3 + spawn-monsters=true + op-permission-level=4 + pvp=true + snooper-enabled=true + level-type=default + hardcore=false + enable-command-block=false + max-players=20 + network-compression-threshold=256 + resource-pack-sha1= + max-world-size=29999984 + server-port=25565 + server-ip= + spawn-npcs=true + allow-flight=true + level-name=world + view-distance=32 + resource-pack= + spawn-animals=true + white-list=true + generate-structures=true + online-mode=true + max-build-height=256 + level-seed= + prevent-proxy-connections=false + use-native-transport=true + motd=This is gonna be interesting + enable-rcon=false diff --git a/minecraft/values/values-minecraft.yaml b/minecraft/values/values-minecraft.yaml new file mode 100644 index 0000000..f06240a --- /dev/null +++ b/minecraft/values/values-minecraft.yaml @@ -0,0 +1,42 @@ +image: hub.ducoterra.net/ducoterra/minecraft:1.16.4 +port: 25565 +max_cpu: 8 +max_ram: 6 +server_props: | + max-tick-time=60000 + generator-settings= + force-gamemode=false + allow-nether=true + gamemode=0 + broadcast-console-to-ops=true + enable-query=false + player-idle-timeout=0 + difficulty=3 + spawn-monsters=true + op-permission-level=4 + pvp=true + snooper-enabled=true + level-type=default + hardcore=false + enable-command-block=false + max-players=20 + network-compression-threshold=256 + resource-pack-sha1= + max-world-size=29999984 + server-port=25565 + server-ip= + spawn-npcs=true + allow-flight=true + level-name=world + view-distance=32 + resource-pack= + spawn-animals=true + white-list=true + generate-structures=true + online-mode=true + max-build-height=256 + level-seed= + prevent-proxy-connections=false + use-native-transport=true + motd=This is gonna be interesting + enable-rcon=false \ No newline at end of file diff --git a/minecraft/values/values-pubcraft.yaml b/minecraft/values/values-pubcraft.yaml new file mode 100644 index 0000000..5b5583d --- /dev/null +++ b/minecraft/values/values-pubcraft.yaml @@ -0,0 +1,42 @@ +image: hub.ducoterra.net/ducoterra/minecraft:1.16.4 +port: 20100 +max_cpu: 8 +max_ram: 6 +server_props: | + max-tick-time=60000 + generator-settings= + force-gamemode=false + allow-nether=true + gamemode=0 + broadcast-console-to-ops=true + enable-query=false + player-idle-timeout=0 + difficulty=3 + spawn-monsters=true + op-permission-level=4 + pvp=true + snooper-enabled=true + level-type=default + hardcore=false + enable-command-block=false + max-players=20 + network-compression-threshold=256 + resource-pack-sha1= + max-world-size=29999984 + server-port=25565 + server-ip= + spawn-npcs=true + allow-flight=true + level-name=world + view-distance=32 + resource-pack= + spawn-animals=true + white-list=true + generate-structures=true + online-mode=true + max-build-height=256 + level-seed= + prevent-proxy-connections=false + use-native-transport=true + motd=This is gonna be interesting + enable-rcon=false \ No newline at end of file diff --git a/minecraft/values/values-testcraft.yaml b/minecraft/values/values-testcraft.yaml new file mode 100644 index 0000000..38f3966 --- /dev/null +++ b/minecraft/values/values-testcraft.yaml @@ -0,0 +1,42 @@ +image: hub.ducoterra.net/ducoterra/minecraft:1.16.4 +port: 25566 +max_cpu: 8 +max_ram: 6 +server_props: | + max-tick-time=60000 + generator-settings= + force-gamemode=false + allow-nether=true + gamemode=0 + broadcast-console-to-ops=true + enable-query=false + player-idle-timeout=0 + difficulty=3 + spawn-monsters=true + op-permission-level=4 + pvp=true + snooper-enabled=true + level-type=amplified + hardcore=false + enable-command-block=false + max-players=20 + network-compression-threshold=256 + resource-pack-sha1= + max-world-size=29999984 + server-port=25565 + server-ip= + spawn-npcs=true + allow-flight=true + level-name=world + view-distance=64 + resource-pack= + spawn-animals=true + white-list=true + generate-structures=true + online-mode=true + max-build-height=512 + level-seed= + prevent-proxy-connections=false + use-native-transport=true + motd=This is gonna be interesting + enable-rcon=false \ No newline at end of file