Skip to content

Commit

Permalink
minecraft: use v2 (#1053)
Browse files Browse the repository at this point in the history
  • Loading branch information
stavros-k authored Nov 29, 2024
1 parent fe51d70 commit 557a21a
Show file tree
Hide file tree
Showing 83 changed files with 6,014 additions and 1,463 deletions.
6 changes: 3 additions & 3 deletions ix-dev/community/minecraft/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ icon: https://media.sys.truenas.net/apps/minecraft/icons/icon.svg
keywords:
- world
- building
lib_version: 1.1.7
lib_version_hash: d05e43e25b7dc1736be6cc1efa4b9255368aa346e3e7a4350a38440f29b73186
lib_version: 2.0.26
lib_version_hash: e82ef6b594774d6160be29cae52fd4f8367518498ea1cd386d7d9edc4ea8b654
maintainers:
- email: [email protected]
name: truenas
Expand All @@ -38,4 +38,4 @@ sources:
- https://github.com/itzg/docker-minecraft-server
title: Minecraft
train: community
version: 1.11.22
version: 1.12.0
38 changes: 38 additions & 0 deletions ix-dev/community/minecraft/questions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ groups:
description: Configure Network for Minecraft
- name: Storage Configuration
description: Configure Storage for Minecraft
- name: Labels Configuration
description: Configure Labels for Minecraft
- name: Resources Configuration
description: Configure Resources for Minecraft

Expand Down Expand Up @@ -779,6 +781,42 @@ questions:
description: The domain to use for the SMB share.
schema:
type: string
- variable: labels
label: ""
group: Labels Configuration
schema:
type: list
default: []
items:
- variable: label
label: Label
schema:
type: dict
attrs:
- variable: key
label: Key
schema:
type: string
required: true
- variable: value
label: Value
schema:
type: string
required: true
- variable: containers
label: Containers
description: Containers where the label should be applied
schema:
type: list
items:
- variable: container
label: Container
schema:
type: string
required: true
enum:
- value: minecraft
description: minecraft
- variable: resources
label: ""
group: Resources Configuration
Expand Down
155 changes: 61 additions & 94 deletions ix-dev/community/minecraft/templates/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,100 +1,67 @@
{# Stores storage items that contains info for volumes, vol mounts, perms dirs and perms mounts #}
{% set storage_items = namespace(items=[]) %}
{# Stores the top level volumes #}
{% set volumes = namespace(items={}) %}
{# Stores the container volume mounts #}
{% set volume_mounts = namespace(items=[]) %}
{% set tpl = ix_lib.base.render.Render(values) %}

{% do storage_items.items.append(ix_lib.base.storage.storage_item(data=dict(values.storage.data, **{"mount_path": "/data"}), values=values)) %}
{% do storage_items.items.append(ix_lib.base.storage.storage_item(data={"type":"anonymous", "mount_path": "/tmp"})) %}
{% set c1 = tpl.add_container(values.consts.minecraft_container_name, values.minecraft.image_selector) %}
{% do c1.set_tty(true) %}
{% do c1.set_stdin(true) %}
{% do c1.add_caps(["CHOWN", "DAC_OVERRIDE", "FOWNER", "SETGID", "SETUID"]) %}
{% do c1.healthcheck.set_custom_test("mc-health") %}
{% do c1.healthcheck.set_start_period(120) %}

{% for store in values.storage.additional_storage %}
{% do storage_items.items.append(ix_lib.base.storage.storage_item(data=store, values=values)) %}
{% endfor %}

{# Add each item to the above lists #}
{% for item in storage_items.items %}
{% if item.vol and volumes.items.update(item.vol) %}{% endif %}
{% if item.vol_mount and volume_mounts.items.append(item.vol_mount) %}{% endif %}
{% endfor %}
{% do c1.environment.add_env("GUI", "FALSE") %}
{% do c1.environment.add_env("EULA", values.minecraft.eula|string|upper) %}
{% do c1.environment.add_env("SERVER_PORT", values.network.server_port) %}
{% do c1.environment.add_env("VERSION", values.minecraft.version) %}
{% do c1.environment.add_env("TYPE", values.minecraft.type) %}
{% do c1.environment.add_env("MOTD", values.minecraft.motd) %}
{% do c1.environment.add_env("DIFFICULTY", values.minecraft.difficulty) %}
{% do c1.environment.add_env("MODE", values.minecraft.mode) %}
{% do c1.environment.add_env("SERVER_NAME", values.minecraft.server_name) %}
{% do c1.environment.add_env("MAX_PLAYERS", values.minecraft.max_players) %}
{% do c1.environment.add_env("MAX_WORLD_SIZE", values.minecraft.max_world_size) %}
{% do c1.environment.add_env("ALLOW_NETHER", values.minecraft.allow_nether|string|upper) %}
{% do c1.environment.add_env("ANNOUNCE_PLAYER_ACHIEVEMENTS", values.minecraft.announce_player_achievements|string|upper) %}
{% do c1.environment.add_env("ENABLE_COMMAND_BLOCK", values.minecraft.enable_command_block|string|upper) %}
{% do c1.environment.add_env("FORCE_GAMEMODE", values.minecraft.force_game_mode|string|upper) %}
{% do c1.environment.add_env("GENERATE_STRUCTURES", values.minecraft.generate_structures|string|upper) %}
{% do c1.environment.add_env("HARDCORE", values.minecraft.hardcore|string|upper) %}
{% do c1.environment.add_env("MAX_BUILD_HEIGHT", values.minecraft.max_build_height) %}
{% do c1.environment.add_env("SPAWN_ANIMALS", values.minecraft.spawn_animals|string|upper) %}
{% do c1.environment.add_env("SPAWN_MONSTERS", values.minecraft.spawn_monsters|string|upper) %}
{% do c1.environment.add_env("SPAWN_NPCS", values.minecraft.spawn_npcs|string|upper) %}
{% do c1.environment.add_env("SPAWN_PROTECTION", values.minecraft.spawn_protection|string|upper) %}
{% do c1.environment.add_env("VIEW_DISTANCE", values.minecraft.view_distance) %}
{% do c1.environment.add_env("PVP", values.minecraft.pvp|string|upper) %}
{% do c1.environment.add_env("LEVEL_TYPE", values.minecraft.level_type) %}
{% do c1.environment.add_env("ALLOW_FLIGHT", values.minecraft.allow_flight|string|upper) %}
{% do c1.environment.add_env("ONLINE_MODE", values.minecraft.online_mode|string|upper) %}
{% do c1.environment.add_env("MAX_TICK_TIME", values.minecraft.max_tick_time) %}
{% if values.minecraft.seed %}
{% do c1.environment.add_env("SEED", values.minecraft.seed) %}
{% endif %}
{% if values.minecraft.ops %}
{% do c1.environment.add_env("OPS", values.minecraft.ops | join(",")) %}
{% endif %}
{% if values.minecraft.whitelist %}
{% do c1.environment.add_env("WHITELIST", values.minecraft.whitelist | join(",")) %}
{% endif %}

{# Containers #}
services:
{{ values.consts.minecraft_container_name }}:
image: {{ ix_lib.base.utils.get_image(images=values.images, name=values.minecraft.image_selector) }}
restart: unless-stopped
tty: true
stdin_open: true
deploy:
resources: {{ ix_lib.base.resources.resources(values.resources) | tojson }}
devices: {{ ix_lib.base.resources.get_devices(values.resources) | tojson }}
{% if values.network.host_network %}
network_mode: host
{% endif %}
{% set caps = ix_lib.base.security.get_caps(add=["CHOWN", "DAC_OVERRIDE", "FOWNER", "SETGID", "SETUID"]) %}
cap_add: {{ caps.add | tojson }}
cap_drop: {{ caps.drop | tojson }}
security_opt: {{ ix_lib.base.security.get_sec_opts() | tojson }}
{% if values.network.dns_opts %}
dns_opt: {{ ix_lib.base.network.dns_opts(values.network.dns_opts) | tojson }}
{% endif %}
healthcheck: {{ ix_lib.base.healthchecks.check_health(test="mc-health", start_period=120) | tojson }}
{% set app_env = {
"GUI": "FALSE",
"EULA": values.minecraft.eula|string|upper,
"SERVER_PORT": values.network.server_port,
"VERSION": values.minecraft.version,
"TYPE": values.minecraft.type,
"MOTD": values.minecraft.motd,
"DIFFICULTY": values.minecraft.difficulty,
"MODE": values.minecraft.mode,
"SERVER_NAME": values.minecraft.server_name,
"MAX_PLAYERS": values.minecraft.max_players,
"MAX_WORLD_SIZE": values.minecraft.max_world_size,
"ALLOW_NETHER": values.minecraft.allow_nether|string|upper,
"ANNOUNCE_PLAYER_ACHIEVMENTS": values.minecraft.announce_player_achievements|string|upper,
"ENABLE_COMMAND_BLOCK": values.minecraft.enable_command_block|string|upper,
"FORCE_GAMEMODE": values.minecraft.force_game_mode|string|upper,
"GENERATE_STRUCTURES": values.minecraft.generate_structures|string|upper,
"HARDCORE": values.minecraft.hardcore|string|upper,
"MAX_BUILD_HEIGHT": values.minecraft.max_build_height,
"SPAWN_ANIMALS": values.minecraft.spawn_animals|string|upper,
"SPAWN_MONSTERS": values.minecraft.spawn_monsters|string|upper,
"SPAWN_NPCS": values.minecraft.spawn_npcs|string|upper,
"SPAWN_PROTECTION": values.minecraft.spawn_protection|string|upper,
"VIEW_DISTANCE": values.minecraft.view_distance,
"PVP": values.minecraft.pvp|string|upper,
"LEVEL_TYPE": values.minecraft.level_type,
"ALLOW_FLIGHT": values.minecraft.allow_flight|string|upper,
"ONLINE_MODE": values.minecraft.online_mode|string|upper,
"MAX_TICK_TIME": values.minecraft.max_tick_time,
} %}
{% if values.minecraft.seed and app_env.update({"SEED": values.minecraft.seed}) %}{% endif %}
{% if values.minecraft.ops and app_env.update({"OPS": values.minecraft.ops | join(",")}) %}{% endif %}
{% if values.minecraft.whitelist and app_env.update({"WHITELIST": values.minecraft.whitelist | join(",")}) %}{% endif %}
{% if values.minecraft.enable_rcon %}
{% do app_env.update({
"ENABLE_RCON": values.minecraft.enable_rcon|string|upper,
"RCON_PORT": values.network.rcon_port,
"RCON_PASSWORD": values.minecraft.rcon_password,
}) %}
{% endif %}
environment: {{ ix_lib.base.environment.envs(app=app_env, user=values.minecraft.additional_envs, values=values) | tojson }}
{% if not values.network.host_network %}
ports:
- {{ ix_lib.base.ports.get_port(port={"target": values.network.server_port, "published": values.network.server_port}) | tojson }}
{% if values.minecraft.enable_rcon %}
- {{ ix_lib.base.ports.get_port(port={"target": values.network.rcon_port, "published": values.network.rcon_port}) | tojson }}
{% endif %}
{% for port in values.network.additional_ports %}
- {{ ix_lib.base.ports.get_port(port={"target": port.target, "published": port.published, "protocol": port.protocol}) | tojson }}
{% endfor %}
{% endif %}
volumes: {{ volume_mounts.items | tojson }}
{% do c1.environment.add_user_envs(values.minecraft.additional_envs) %}

{% if volumes.items %}
volumes: {{ volumes.items | tojson }}
{% do c1.ports.add_port(values.network.server_port, values.network.server_port) %}
{% if values.minecraft.enable_rcon %}
{% do c1.ports.add_port(values.network.rcon_port, values.network.rcon_port) %}
{% do c1.environment.add_env("ENABLE_RCON", values.minecraft.enable_rcon|string|upper) %}
{% do c1.environment.add_env("RCON_PORT", values.network.rcon_port) %}
{% do c1.environment.add_env("RCON_PASSWORD", values.minecraft.rcon_password) %}
{% endif %}

x-portals: {{ ix_lib.base.metadata.get_portals([]) | tojson }}
x-notes: {{ ix_lib.base.metadata.get_notes("Minecraft") | tojson }}
{% for port in values.network.additional_ports %}
{% do c1.ports.add_port(port.published, port.target, {"protocol": port.protocol}) %}
{% endfor %}

{% do c1.add_storage("/data", values.storage.data) %}
{% for store in values.storage.additional_storage %}
{% do c1.add_storage(store.mount_path, store) %}
{% endfor %}

{{ tpl.render() | tojson }}

This file was deleted.

Loading

0 comments on commit 557a21a

Please sign in to comment.