commit c6b9eee5980821762cb0ece3bc9c3fbcc801afea Author: Kenneth Date: Sun Feb 1 16:09:50 2026 +0000 first commit diff --git a/.gitea/workflows/build-image.yml b/.gitea/workflows/build-image.yml new file mode 100644 index 0000000..39bae5d --- /dev/null +++ b/.gitea/workflows/build-image.yml @@ -0,0 +1,64 @@ +name: Build and Push Image + +on: + push: + branches: + - main + - master + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set image variables + id: vars + env: + REGISTRY_URL: ${{ secrets.REGISTRY_URL }} + run: | + set -euo pipefail + REGISTRY_HOST="${REGISTRY_URL#https://}" + REGISTRY_HOST="${REGISTRY_HOST#http://}" + REPO_NAME="${GITHUB_REPOSITORY##*/}" + if [ -z "$REPO_NAME" ]; then + REPO_NAME="$(basename "$PWD")" + fi + TERRARIA_VERSION="$(awk -F= '/^ARG T_VERSION=/{print $2; exit}' Dockerfile)" + if [ -z "$TERRARIA_VERSION" ]; then + echo "T_VERSION not found in Dockerfile" >&2 + exit 1 + fi + echo "registry_host=$REGISTRY_HOST" >> "$GITHUB_OUTPUT" + echo "image=$REGISTRY_HOST/$REPO_NAME" >> "$GITHUB_OUTPUT" + echo "terraria_version=$TERRARIA_VERSION" >> "$GITHUB_OUTPUT" + + - name: Log in to Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ steps.vars.outputs.registry_host }} + username: ${{ secrets.REGISTRY_USERNAME }} + password: ${{ secrets.REGISTRY_PASSWORD }} + + - name: Extract metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ steps.vars.outputs.image }} + tags: | + type=sha + type=raw,value=latest + type=raw,value=${{ steps.vars.outputs.terraria_version }} + + - name: Build and push + uses: docker/build-push-action@v6 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8d38478 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,36 @@ +FROM debian:bookworm-slim + +ARG T_VERSION=1451 +ARG T_ZIP=terraria-server-${T_VERSION}.zip +ARG T_URL=https://terraria.org/api/download/pc-dedicated-server/${T_ZIP} + +# Tools needed to fetch + unpack the official server zip +RUN apt-get update && apt-get install -y --no-install-recommends \ + ca-certificates wget unzip \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /opt/terraria + +# Download + extract +RUN wget -O /tmp/terraria.zip "${T_URL}" \ + && unzip /tmp/terraria.zip -d /opt/terraria \ + && rm /tmp/terraria.zip \ + && chmod +x "/opt/terraria/${T_VERSION}/Linux/TerrariaServer.bin.x86_64" + +# Runtime dirs (mounted via volumes) +RUN mkdir -p /config /worlds + +# Optional: run as non-root (recommended) +RUN useradd -m -u 1000 terraria \ + && chown -R terraria:terraria /config /worlds /opt/terraria +USER terraria + +WORKDIR /opt/terraria/${T_VERSION}/Linux + +EXPOSE 7777/tcp 7777/udp + +COPY --chown=terraria:terraria entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh + +ENTRYPOINT ["/entrypoint.sh"] + diff --git a/README.md b/README.md new file mode 100644 index 0000000..80e2cb8 --- /dev/null +++ b/README.md @@ -0,0 +1,42 @@ +# Terraria Dedicated Server (Docker) + +Lightweight Terraria dedicated server image built from the official server zip. + +## Build + +```bash +docker build -t terraria-server . +``` + +To build a specific Terraria version: + +```bash +docker build --build-arg T_VERSION=1451 -t terraria-server:1451 . +``` + +## Run + +```bash +docker run --rm -it \ + -p 7777:7777/tcp -p 7777:7777/udp \ + -v "$PWD/config:/config" \ + -v "$PWD/worlds:/worlds" \ + terraria-server +``` + +## Configuration + +- Config file default: `/config/serverconfig.txt` +- World path default: `/worlds` + +You can override these with environment variables: + +```bash +docker run --rm -it \ + -e CONFIG_FILE=/config/serverconfig.txt \ + -e WORLD_PATH=/worlds \ + -p 7777:7777/tcp -p 7777:7777/udp \ + -v "$PWD/config:/config" \ + -v "$PWD/worlds:/worlds" \ + terraria-server +``` diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..2c68d47 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +set -euo pipefail + +CONFIG_FILE="${CONFIG_FILE:-/config/serverconfig.txt}" +WORLD_PATH="${WORLD_PATH:-/worlds}" + +# Terraria server is interactive if no -config is provided. +# We always pass a config by default so it boots unattended. +exec ./TerrariaServer.bin.x86_64 \ + -config "${CONFIG_FILE}" \ + -worldpath "${WORLD_PATH}" +