diff --git a/.gitea/workflows/docker-publish.yml b/.gitea/workflows/docker-publish.yml new file mode 100644 index 0000000..665a441 --- /dev/null +++ b/.gitea/workflows/docker-publish.yml @@ -0,0 +1,37 @@ +name: Build and Publish Docker Image + +on: + push: + branches: + - main + workflow_dispatch: + +jobs: + test-and-publish: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '22' + + - name: Run tracker test suites + run: npm test + + - name: Log in to Gitea Container Registry + uses: docker/login-action@v3 + with: + registry: git.trevorstocks.ca + username: ${{ github.repository_owner }} + password: ${{ secrets.GITEA_TOKEN }} + + - name: Build and push image to git.trevorstocks.ca + run: | + IMAGE="git.trevorstocks.ca/faroegames/oaktracker" + SHA_TAG="sha-$(echo "${{ github.sha }}" | cut -c1-7)" + docker build -t "${IMAGE}:latest" -t "${IMAGE}:${SHA_TAG}" . + docker push "${IMAGE}:latest" + docker push "${IMAGE}:${SHA_TAG}" diff --git a/README.md b/README.md index 8adb437..9ddb4ce 100644 --- a/README.md +++ b/README.md @@ -64,4 +64,24 @@ docker compose up -d --build - Scheme: `http` (Nginx Proxy Manager handles HTTPS/SSL termination for your subdomain) - Forward Hostname / IP: your Unraid IP (or `professor-oak-tracker` if both containers share a custom Docker bridge network like `proxynet`) - Forward Port: `28473` - - Enable Websockets: not required, standard HTTPS/SSL termination works out of the box (for example, `https://oak.trevorstocks.ca/`) + +--- + +## Automatic Updates on Unraid (Instead of Manual `git pull`) + +Unraid's Docker dashboard **"apply update"** badge only checks **remote Docker registries**—containers built locally with `docker compose up -d --build` will show updates as `not available`. Choose either approach below: + +### Way 1 — Unraid Dashboard **"apply update"** Button (via Gitea Container Registry) + +1. In Gitea (`git.trevorstocks.ca`), make sure **Packages** and **Actions** (with a Docker runner) are enabled. +2. Push to `main`: [`.gitea/workflows/docker-publish.yml`](./.gitea/workflows/docker-publish.yml) runs `npm test` and pushes `git.trevorstocks.ca/faroegames/oaktracker:latest`. +3. In Gitea's **Packages** tab for `oaktracker`, set the container package visibility to **Public** (or run `docker login git.trevorstocks.ca` once in the Unraid terminal if keeping it private—note Unraid's automatic UI update checker works most reliably with public HTTPS packages; private custom registries may require clicking **Force Update** or using Watchtower). +4. On Unraid, add the container in **Docker → Add Container** (rather than Compose) with: + - **Name:** `professor-oak-tracker` + - **Repository:** `git.trevorstocks.ca/faroegames/oaktracker:latest` + - **Port:** Container `28473` → Host `28473` + - Now Unraid detects new pushes in its Docker tab (or Watchtower can auto-update it). + +### Way 2 — Hands-Free Auto-Rebuild via Unraid **User Scripts** (Zero Gitea Runner Needed) + +If you don't run a Gitea Actions Runner, keep building locally with `docker compose` and add [`scripts/unraid-git-update.sh`](./scripts/unraid-git-update.sh) to Unraid's **User Scripts** plugin on a schedule (e.g., `*/15 * * * *`). It checks `git fetch origin main` and only rebuilds/restarts when a new commit is pushed to `git.trevorstocks.ca`. diff --git a/docker-compose.yml b/docker-compose.yml index 89e3876..e5399ed 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,8 @@ services: professor-oak-tracker: + # For local builds on Unraid, use `build:` below. + # If publishing via Gitea Actions (.gitea/workflows/docker-publish.yml), you can replace `build:` with: + # image: git.trevorstocks.ca/faroegames/oaktracker:latest build: context: . dockerfile: Dockerfile diff --git a/scripts/unraid-git-update.sh b/scripts/unraid-git-update.sh new file mode 100644 index 0000000..078277f --- /dev/null +++ b/scripts/unraid-git-update.sh @@ -0,0 +1,22 @@ +#!/bin/bash +set -euo pipefail + +# Schedule this in Unraid's "User Scripts" plugin (e.g. every 15 minutes) +# to automatically pull & rebuild whenever you push updates to Gitea. + +APP_DIR="/mnt/user/appdata/professor-oak-tracker" +BRANCH="main" + +cd "${APP_DIR}" +git fetch origin "${BRANCH}" --quiet + +LOCAL_SHA="$(git rev-parse HEAD)" +REMOTE_SHA="$(git rev-parse "origin/${BRANCH}")" + +if [ "${LOCAL_SHA}" != "${REMOTE_SHA}" ]; then + echo "[oaktracker] Update detected (${LOCAL_SHA:0:7} -> ${REMOTE_SHA:0:7}), rebuilding container..." + git pull --ff-only origin "${BRANCH}" + docker compose up -d --build + docker image prune -f >/dev/null 2>&1 || true + echo "[oaktracker] Updated cleanly to ${REMOTE_SHA:0:7}." +fi diff --git a/tests/portal.test.mjs b/tests/portal.test.mjs index 2ad08b3..b23db7d 100644 --- a/tests/portal.test.mjs +++ b/tests/portal.test.mjs @@ -169,4 +169,11 @@ test('Both trackers expose a relative Hub navigation link and valid Docker/Nginx assert.ok(nginxConf.includes('application/javascript mjs;')); assert.ok(nginxConf.includes('location = /oras')); assert.ok(nginxConf.includes('location = /luminescent-platinum')); + + const giteaWorkflow = await fs.readFile(path.join(ROOT_DIR, '.gitea/workflows/docker-publish.yml'), 'utf8'); + assert.ok(giteaWorkflow.includes('git.trevorstocks.ca/faroegames/oaktracker')); + assert.ok(giteaWorkflow.includes('secrets.GITEA_TOKEN')); + + const updateScript = await fs.readFile(path.join(ROOT_DIR, 'scripts/unraid-git-update.sh'), 'utf8'); + assert.ok(updateScript.includes('docker compose up -d --build')); });