mirror of
https://github.com/dragonlock2/matthewtran.com.git
synced 2025-10-11 20:17:54 +00:00
56 lines
1.5 KiB
Python
Executable File
56 lines
1.5 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import json
|
|
import shutil
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
SOURCE_DIR = "/var/source"
|
|
|
|
IMAGES = {
|
|
"game": [
|
|
"minecraft",
|
|
],
|
|
}
|
|
|
|
def generate(cfg):
|
|
# minecraft
|
|
shutil.copy("minecraft/server.default", "minecraft/server.properties")
|
|
with open("minecraft/server.properties", "a") as f:
|
|
f.write(f"level-name=data/{cfg["minecraft"]["world"]}")
|
|
|
|
def run(cmds):
|
|
try:
|
|
subprocess.check_output(["ssh", f"core@{cfg["core"]["hostname"]}.local", ";".join(cmds)], stderr=subprocess.STDOUT)
|
|
except subprocess.CalledProcessError as e:
|
|
print("\033[31m", end="")
|
|
print(e.output.decode())
|
|
print("\033[0m", end="")
|
|
exit(1)
|
|
|
|
if __name__ == "__main__":
|
|
cfg = json.load(open("config/server.json"))
|
|
|
|
# generate helper files
|
|
generate(cfg)
|
|
|
|
# copy files
|
|
for f in (f for l in IMAGES.values() for f in l):
|
|
subprocess.run(["scp", "-r", f, f"core@{cfg["core"]["hostname"]}.local:{SOURCE_DIR}"], check=True)
|
|
|
|
# run builds
|
|
for user in IMAGES:
|
|
print(f"building images for {user}...")
|
|
run([f"cd {SOURCE_DIR}"] + [
|
|
f"sudo -u {user} podman build --tag {i} {SOURCE_DIR}/{i}"
|
|
for i in IMAGES[user]
|
|
])
|
|
|
|
# restart pods
|
|
for user in IMAGES:
|
|
print(f"restarting pod for {user}...")
|
|
run([
|
|
f"cd {SOURCE_DIR}",
|
|
f"sudo systemctl --machine={user}@.host --user restart {user}-pod " + " ".join(IMAGES[user]),
|
|
])
|