From 8bac02bbcfdd3980c0b0e3d8a425a0ebe8a1bc0c Mon Sep 17 00:00:00 2001 From: Geoff Bourne Date: Sun, 19 Sep 2021 21:32:59 -0500 Subject: [PATCH] Added JSON-patching support #1051 --- Dockerfile | 2 +- README.md | 50 ++++++++++++++++++++++++++++++++--------- start-setupEnvVariables | 10 +++++++++ 3 files changed, 51 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index e43fa4fe..46f7d49d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -60,7 +60,7 @@ RUN easy-add --var os=${TARGETOS} --var arch=${TARGETARCH}${TARGETVARIANT} \ --var version=0.1.1 --var app=maven-metadata-release --file {{.app}} \ --from https://github.com/itzg/{{.app}}/releases/download/{{.version}}/{{.app}}_{{.version}}_{{.os}}_{{.arch}}.tar.gz -ARG MC_HELPER_VERSION=1.2.1 +ARG MC_HELPER_VERSION=1.3.0 RUN curl -fsSL https://github.com/itzg/mc-image-helper/releases/download/v${MC_HELPER_VERSION}/mc-image-helper-${MC_HELPER_VERSION}.tgz \ | tar -C /usr/share -zxf - \ && ln -s /usr/share/mc-image-helper-${MC_HELPER_VERSION}/bin/mc-image-helper /usr/bin diff --git a/README.md b/README.md index 3935e9ff..bd7d1029 100644 --- a/README.md +++ b/README.md @@ -1124,14 +1124,6 @@ services: CFG_DB_HOST: "http://localhost:3306" CFG_DB_NAME: "minecraft" CFG_DB_PASSWORD_FILE: "/run/secrets/db_password" - restart: always - rcon: - image: itzg/rcon - ports: - - "4326:4326" - - "4327:4327" - volumes: - - "rcon:/opt/rcon-web-admin/db" volumes: mc: @@ -1142,9 +1134,47 @@ secrets: file: ./db_password ``` -The content of `db_password`: +### Patching existing files - ug23u3bg39o-ogADSs +JSON path based patches can be applied to one or more existing files by setting the variable `PATCH_DEFINITIONS` to the path of a directory that contains one or more [patch definition json files](https://github.com/itzg/mc-image-helper#patchdefinition) or a [patch set json file](https://github.com/itzg/mc-image-helper#patchset). + +Variable placeholders in the patch values can be restricted by setting `REPLACE_ENV_VARIABLE_PREFIX`, which defaults to "CFG_". + +The following example shows a patch-set file were various fields in the `paper.yaml` configuration file can be modified and added: + +```json +{ + "patches": [ + { + "file": "/data/paper.yml", + "ops": [ + { + "$set": { + "path": "$.verbose", + "value": true + } + }, + { + "$set": { + "path": "$.settings['velocity-support'].enabled", + "value": "${CFG_VELOCITY_ENABLED}", + "value-type": "bool" + } + }, + { + "$put": { + "path": "$.settings", + "key": "my-test-setting", + "value": "testing" + } + } + ] + } + ] +} +``` + +> **NOTES:** Only JSON and Yaml files can be patched at this time. TOML support is planned to be added next. Removal of comments and other cosmetic changes will occur when patched files are processed. ### Running with a custom server JAR diff --git a/start-setupEnvVariables b/start-setupEnvVariables index 51232c0f..67677af8 100755 --- a/start-setupEnvVariables +++ b/start-setupEnvVariables @@ -2,12 +2,15 @@ . ${SCRIPTS:-/}start-utils +set -e + : ${REPLACE_ENV_IN_PLACE:=${REPLACE_ENV_VARIABLES:-false}} : ${REPLACE_ENV_PATHS:=/data} : ${REPLACE_ENV_SUFFIXES:=yml,yaml,txt,cfg,conf,properties,hjson,json,tml,toml} : ${REPLACE_ENV_VARIABLE_PREFIX:=${ENV_VARIABLE_PREFIX:-CFG_}} : ${REPLACE_ENV_VARIABLES_EXCLUDES:=} : ${REPLACE_ENV_VARIABLES_EXCLUDE_PATHS:=} +: ${PATCH_DEFINITIONS:=} : ${DEBUG:=false} if isTrue "${REPLACE_ENV_IN_PLACE}"; then @@ -21,4 +24,11 @@ if isTrue "${REPLACE_ENV_IN_PLACE}"; then "${REPLACE_ENV_PATHS[@]}" fi +if [[ ${PATCH_DEFINITIONS} ]]; then + log "Applying patch definitions from ${PATCH_DEFINITIONS}" + mc-image-helper --debug=${DEBUG} patch \ + --patch-env-prefix=${REPLACE_ENV_VARIABLE_PREFIX} \ + "${PATCH_DEFINITIONS}" +fi + exec ${SCRIPTS:-/}start-finalExec $@