mirror of
https://github.com/itzg/docker-minecraft-server.git
synced 2026-09-16 10:57:59 +00:00
Add possibility to use secrets in environment variables (#512)
This commit is contained in:
@@ -277,6 +277,8 @@ Optionally you can also define a prefix to only match predefined enviroment vari
|
|||||||
|
|
||||||
`ENV_VARIABLE_PREFIX="CFG_"` <-- this is the default prefix
|
`ENV_VARIABLE_PREFIX="CFG_"` <-- this is the default prefix
|
||||||
|
|
||||||
|
If you want use file for value (like when use secrets) you can add suffix `_FILE` to your variable name (in run command).
|
||||||
|
|
||||||
There are some limitations to what characters you can use.
|
There are some limitations to what characters you can use.
|
||||||
|
|
||||||
| Type | Allowed Characters |
|
| Type | Allowed Characters |
|
||||||
@@ -323,7 +325,7 @@ services:
|
|||||||
# and here are the actual variables
|
# and here are the actual variables
|
||||||
CFG_DB_HOST: "http://localhost:3306"
|
CFG_DB_HOST: "http://localhost:3306"
|
||||||
CFG_DB_NAME: "minecraft"
|
CFG_DB_NAME: "minecraft"
|
||||||
CFG_DB_PASSWORD: "ug23u3bg39o-ogADSs"
|
CFG_DB_PASSWORD_FILE: "/run/secrets/db_password"
|
||||||
restart: always
|
restart: always
|
||||||
rcon:
|
rcon:
|
||||||
image: itzg/rcon
|
image: itzg/rcon
|
||||||
@@ -336,8 +338,16 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
mc:
|
mc:
|
||||||
rcon:
|
rcon:
|
||||||
|
|
||||||
|
secrets:
|
||||||
|
db_password:
|
||||||
|
file: ./db_password
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The content of `db_password`:
|
||||||
|
|
||||||
|
ug23u3bg39o-ogADSs
|
||||||
|
|
||||||
## Running a Bukkit/Spigot server
|
## Running a Bukkit/Spigot server
|
||||||
|
|
||||||
Enable Bukkit/Spigot server mode by adding a `-e TYPE=BUKKIT -e VERSION=1.8` or `-e TYPE=SPIGOT -e VERSION=1.8` to your command-line.
|
Enable Bukkit/Spigot server mode by adding a `-e TYPE=BUKKIT -e VERSION=1.8` or `-e TYPE=SPIGOT -e VERSION=1.8` to your command-line.
|
||||||
|
|||||||
@@ -10,6 +10,12 @@ if [ "${REPLACE_ENV_VARIABLES^^}" = "TRUE" ]; then
|
|||||||
if [[ "$name" = $ENV_VARIABLE_PREFIX* ]] \
|
if [[ "$name" = $ENV_VARIABLE_PREFIX* ]] \
|
||||||
&& [[ $value =~ ^[0-9a-zA-Z_:/=?.+\-]*$ ]] \
|
&& [[ $value =~ ^[0-9a-zA-Z_:/=?.+\-]*$ ]] \
|
||||||
&& [[ $name =~ ^[0-9a-zA-Z_\-]*$ ]]; then
|
&& [[ $name =~ ^[0-9a-zA-Z_\-]*$ ]]; then
|
||||||
|
# Read content from file environment
|
||||||
|
if [[ $name = *"_FILE" ]] && [[ -f $value ]]; then
|
||||||
|
name="${name/_FILE/}"
|
||||||
|
value=$(<$value)
|
||||||
|
fi
|
||||||
|
|
||||||
log "Replacing $name with $value ..."
|
log "Replacing $name with $value ..."
|
||||||
find /data/ -type f \
|
find /data/ -type f \
|
||||||
\( -name "*.yml" -or -name "*.yaml" -or -name "*.txt" -or -name "*.cfg" \
|
\( -name "*.yml" -or -name "*.yaml" -or -name "*.txt" -or -name "*.cfg" \
|
||||||
|
|||||||
Reference in New Issue
Block a user