From 7df53679cb54b76932e8cbcc3f0df2aa02754032 Mon Sep 17 00:00:00 2001 From: sthkm3 Date: Mon, 2 Nov 2026 21:59:13 +0800 Subject: [PATCH] Add TrueNAS compose, separate DB volume, and release script Co-Authored-By: Claude Opus 5.5 --- Dockerfile | 5 +++++ docker-compose.yml | 11 +++++++++++ release.ps1 | 25 +++++++++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 docker-compose.yml create mode 100644 release.ps1 diff --git a/Dockerfile b/Dockerfile index dc3c137..63eee9f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,4 +3,9 @@ WORKDIR /app COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt COPY . . + +# 資料庫放在獨立的 volume +ENV DB_PATH=/data/game.db +VOLUME ["/data"] + CMD ["python", "main.py"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..fca0171 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,11 @@ +# TrueNAS 部署用:Apps → Discover Apps → Install via YAML +services: + game-bot: + image: gitea.sthkm3.org/sthkm3/discordgamebot:latest + container_name: discord-game-bot + restart: unless-stopped + environment: + DISCORD_BOT_TOKEN: ${DISCORD_BOT_TOKEN} + volumes: + # 換成 TrueNAS 上的 dataset 路徑 + - /mnt/pool/apps/discord-game-bot/db:/data diff --git a/release.ps1 b/release.ps1 new file mode 100644 index 0000000..ca0ba69 --- /dev/null +++ b/release.ps1 @@ -0,0 +1,25 @@ +# 用法:.\release.ps1 +# 從 config.py 讀版本號 → build image → 推到 gitea registry → 打 git tag +$ErrorActionPreference = "Stop" + +$Image = "gitea.sthkm3.org/sthkm3/discordgamebot" +$Version = (Select-String -Path config.py -Pattern 'VERSION = "V?([^"]+)"').Matches[0].Groups[1].Value + +if (git status --porcelain) { + throw "有未 commit 的修改,請先 commit 再發布" +} +if (git tag --list "v$Version") { + throw "v$Version 已經發布過了,請先更新 config.py 的 VERSION" +} + +docker build -t "${Image}:$Version" -t "${Image}:latest" . +if ($LASTEXITCODE) { throw "docker build 失敗" } +docker push "${Image}:$Version" +if ($LASTEXITCODE) { throw "docker push 失敗" } +docker push "${Image}:latest" +if ($LASTEXITCODE) { throw "docker push 失敗" } + +git tag "v$Version" +git push origin "v$Version" + +Write-Host "已發布 ${Image}:$Version"