Browse Source

new: [minecraft] add charm

odoo_fix_webhook_url
Valentin Lab 2 years ago
parent
commit
fbf9fa1529
  1. 6
      minecraft/build/Dockerfile
  2. 25
      minecraft/hooks/init
  3. 39
      minecraft/lib/common
  4. 23
      minecraft/metadata.yml

6
minecraft/build/Dockerfile

@ -0,0 +1,6 @@
FROM docker.0k.io/alpine:3.18
RUN apk add openjdk17 && \
mkdir /var/lib/minecraft
WORKDIR /var/lib/minecraft

25
minecraft/hooks/init

@ -0,0 +1,25 @@
#!/bin/bash
## Init is run on host
## For now it is run every time the script is launched, but
## it should be launched only once after build.
## Accessible variables are:
## - SERVICE_NAME Name of current service
## - DOCKER_BASE_IMAGE Base image from which this service might be built if any
## - SERVICE_DATASTORE Location on host of the DATASTORE of this service
## - SERVICE_CONFIGSTORE Location on host of the CONFIGSTORE of this service
. lib/common
set -e
version=$(options-get version) || exit 1
minecraft:init-binary "$version"
threads=$(options-get threads) || exit 1
mem=$(options-get mem) || exit 1
minecraft:init-command "$threads" "$mem"

39
minecraft/lib/common

@ -0,0 +1,39 @@
# -*- mode: shell-script -*-
MINECRAFT_PATH="$SERVICE_CONFIGSTORE/opt/apps/minecraft"
MINECRAFT_DATA="/var/lib/minecraft"
minecraft:init-binary() {
local version="$1"
MINECRAFT_BINARY="${MINECRAFT_PATH}/minecraft_server.${version}.jar"
if ! [ -f "$MINECRAFT_BINARY" ]; then
mkdir -p "${MINECRAFT_PATH}"
wget "https://docker.0k.io/downloads/minecraft_server.${version}.jar" \
-O "$MINECRAFT_BINARY"
fi
init-config-add "
$SERVICE_NAME:
volumes:
- \"${MINECRAFT_BINARY}:${MINECRAFT_DATA}/server.jar\"
"
}
minecraft:init-command() {
local threads="${1:-4}" mem="${2:-2048M}"
init-config-add "
$SERVICE_NAME:
command:
- java
- -Xmx${mem}
- -Xms${mem}
- -XX:ParallelGCThreads=${threads}
- -jar
- server.jar
- nogui
"
echo "eula=TRUE" > "$SERVICE_DATASTORE/${MINECRAFT_DATA}/eula.txt"
}

23
minecraft/metadata.yml

@ -0,0 +1,23 @@
description: "Minecraft"
maintainer: "Valentin Lab <valentin.lab@kalysto.org>"
data-resources:
- /var/lib/minecraft
default-options:
version: 1.19.4
forge: true
threads: 2
mem: 2048M
uses:
backup:
constraint: recommended
auto: pair
solves:
backup: "Automatic regular backup"
default-options:
## First pattern matching wins, no pattern matching includes.
## include-patterns are checked first, then exclude-patterns
## Patterns rules:
## - ending / for directory
## - '*' authorized
## - must start with a '/', will start from $SERVICE_DATASTORE
Loading…
Cancel
Save