Skip to content

Commit 6091913

Browse files
author
Slyke
committed
Added actual data from docker compose file into docs. Added more robust yaml merging
1 parent d378790 commit 6091913

File tree

2 files changed

+45
-33
lines changed

2 files changed

+45
-33
lines changed

docs/Custom.md

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,16 @@ Custom services can be added in a similar way to overriding default settings for
9898
Firstly, put the following into `compose-override.yml`:
9999
```
100100
services:
101+
mosquitto:
102+
ports:
103+
- 1996:1996
104+
- 9001:9001
101105
minecraft:
102106
image: itzg/minecraft-server
103107
ports:
104108
- "25565:25565"
105109
volumes:
106-
- "./services/minecraft:/data"
110+
- "./volumes/minecraft:/data"
107111
environment:
108112
EULA: "TRUE"
109113
TYPE: "PAPER"
@@ -123,8 +127,7 @@ services:
123127
- "4326:4326"
124128
- "4327:4327"
125129
volumes:
126-
- "./rcon_data:/opt/rcon-web-admin/db"
127-
130+
- "./volumes/rcon_data:/opt/rcon-web-admin/db"
128131
secrets:
129132
db_password:
130133
file: ./db_password
@@ -148,46 +151,47 @@ Using the Mosquitto example above, the final `docker-compose.yml` file will look
148151
version: '3.6'
149152
services:
150153
mosquitto:
154+
ports:
155+
- 1996:1996
156+
- 9001:9001
151157
container_name: mosquitto
152158
image: eclipse-mosquitto
153159
restart: unless-stopped
154-
user: "1883"
155-
ports:
156-
- 1883:1883
157-
- 9001:9001
160+
user: '1883'
158161
volumes:
159-
- ./volumes/mosquitto/data:/mosquitto/data
160-
- ./volumes/mosquitto/log:/mosquitto/log
161-
- ./volumes/mosquitto/pwfile:/mosquitto/pwfile
162-
- ./services/mosquitto/mosquitto.conf:/mosquitto/config/mosquitto.conf
163-
- ./services/mosquitto/filter.acl:/mosquitto/config/filter.acl
162+
- ./volumes/mosquitto/data:/mosquitto/data
163+
- ./volumes/mosquitto/log:/mosquitto/log
164+
- ./services/mosquitto/mosquitto.conf:/mosquitto/config/mosquitto.conf
165+
- ./services/mosquitto/filter.acl:/mosquitto/config/filter.acl
164166
minecraft:
165167
image: itzg/minecraft-server
166168
ports:
167-
- "25565:25565"
169+
- 25565:25565
168170
volumes:
169-
- "./volumes/minecraft:/data"
171+
- ./volumes/minecraft:/data
170172
environment:
171-
EULA: "TRUE"
172-
TYPE: "PAPER"
173-
ENABLE_RCON: "true"
174-
RCON_PASSWORD: "PASSWORD"
173+
EULA: 'TRUE'
174+
TYPE: PAPER
175+
ENABLE_RCON: 'true'
176+
RCON_PASSWORD: PASSWORD
175177
RCON_PORT: 28016
176-
VERSION: "1.15.2"
177-
REPLACE_ENV_VARIABLES: "TRUE"
178-
ENV_VARIABLE_PREFIX: "CFG_"
179-
CFG_DB_HOST: "http://localhost:3306"
180-
CFG_DB_NAME: "IOTstack Minecraft"
181-
CFG_DB_PASSWORD_FILE: "/run/secrets/db_password"
178+
VERSION: 1.15.2
179+
REPLACE_ENV_VARIABLES: 'TRUE'
180+
ENV_VARIABLE_PREFIX: CFG_
181+
CFG_DB_HOST: http://localhost:3306
182+
CFG_DB_NAME: IOTstack Minecraft
183+
CFG_DB_PASSWORD_FILE: /run/secrets/db_password
182184
restart: unless-stopped
183185
rcon:
184186
image: itzg/rcon
185187
ports:
186-
- "4326:4326"
187-
- "4327:4327"
188+
- 4326:4326
189+
- 4327:4327
188190
volumes:
189-
- "./volumes/rcon_data:/opt/rcon-web-admin/db"
191+
- ./volumes/rcon_data:/opt/rcon-web-admin/db
190192
secrets:
191193
db_password:
192194
file: ./db_password
193195
```
196+
197+
Do note that the order of the YAML keys is not guaranteed.

scripts/yaml_merge.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,21 @@
2727
pathOutput = sys.argv[3]
2828

2929
def mergeYaml(priorityYaml, defaultYaml):
30-
if isinstance(priorityYaml, dict) and isinstance(defaultYaml, dict):
31-
for k, v in defaultYaml.iteritems():
32-
if k not in priorityYaml:
33-
priorityYaml[k] = v
30+
finalYaml = {}
31+
if isinstance(defaultYaml, dict):
32+
for dk, dv in defaultYaml.items():
33+
if dk in priorityYaml:
34+
finalYaml[dk] = mergeYaml(priorityYaml[dk], dv)
3435
else:
35-
priorityYaml[k] = mergeYaml(priorityYaml[k], v)
36-
return defaultYaml
36+
finalYaml[dk] = dv
37+
for pk, pv in priorityYaml.items():
38+
if pk in finalYaml:
39+
finalYaml[pk] = mergeYaml(finalYaml[pk], pv)
40+
else:
41+
finalYaml[pk] = pv
42+
else:
43+
finalYaml = defaultYaml
44+
return finalYaml
3745

3846
with open(r'%s' % pathTempDockerCompose) as fileTempDockerCompose:
3947
yamlTempDockerCompose = yaml.load(fileTempDockerCompose, Loader=yaml.SafeLoader)

0 commit comments

Comments
 (0)