Waiting too few may result in the image not having finished being pulled, therefore the migrations not being applied since the old pod is still running.
57 lines
1.3 KiB
Python
57 lines
1.3 KiB
Python
import os
|
|
import sys
|
|
import time
|
|
|
|
try:
|
|
import toml
|
|
|
|
except ImportError:
|
|
print(
|
|
"You need to install `toml` to use this file. Run `pip install toml` and try again."
|
|
)
|
|
sys.exit()
|
|
|
|
try:
|
|
import yaml
|
|
|
|
except ImportError:
|
|
print(
|
|
"You need to install `yaml` to use this file. Run `pip install pyyaml` and try again."
|
|
)
|
|
sys.exit()
|
|
|
|
os.system("git pull")
|
|
|
|
data = toml.load(open("pyproject.toml", encoding="utf-8"))
|
|
version = data["project"]["version"].split(".")
|
|
latest_tag = "v" + version[1]
|
|
|
|
os.system(
|
|
f"microk8s kubectl set image sts/bot bot=registry.nyeki.dev/payphone/payphone/shard:{latest_tag}"
|
|
)
|
|
os.system(
|
|
f"""
|
|
microk8s kubectl set image pod/tasks \
|
|
connect=registry.nyeki.dev/payphone/payphone/tasks:{latest_tag}
|
|
"""
|
|
)
|
|
|
|
print("Waiting 30 seconds to run migrations...")
|
|
|
|
time.sleep(30)
|
|
|
|
with open("./k8s/bot.yml", encoding="utf-8") as stream:
|
|
try:
|
|
docs = list(yaml.load_all(stream, yaml.Loader))
|
|
data = docs[0]
|
|
|
|
os.system(f"microk8s kubectl exec bot-{data["spec"]["replicas"] - 1} -- uv run aerich upgrade")
|
|
except yaml.YAMLError as exc:
|
|
print("Could not read the amount of deployed shards.")
|
|
print(exc)
|
|
|
|
|
|
print("Done!")
|
|
|
|
# expire=registry.nyeki.dev/payphone/payphone/shard:v{latest_version}
|