diff --git a/.gitea/workflows/vintage-story-build-server.yml b/.gitea/workflows/vintage-story-build-server.yml new file mode 100644 index 0000000..c76d543 --- /dev/null +++ b/.gitea/workflows/vintage-story-build-server.yml @@ -0,0 +1,405 @@ +name: vintage-story-build-server + +on: + push: + branches: + - master + paths: + - '.gitea/workflows/vintage-story-build-server.yml' + - 'server/Dockerfile' + - 'server/*.sh' + - '!.cache/*' + - '!server/CHANGES.md' + - '!server/build-info.json' + schedule: + - cron: '35 21 * * 0' + +env: + IMAGE_REGISTRY: gitea.fithwum.tech + IMAGE_ORG: fithwum + IMAGE_REPO_DEBIAN: debian-base + IMAGE_REP)_VINTAGE_STORY: vintage-story + IMAGE_TAG_DEBIAN: bookworm + DIGEST_FILE: .cache/debian-base.digest + VERSIONS: server + +jobs: + docker-prune: + name: Docker prune (${{ matrix.runner }}) + runs-on: ${{ matrix.runner }} + strategy: + fail-fast: false + matrix: + runner: + - vm-docker-build2 + steps: + - name: Prune unused Docker images + run: | + echo "[INFO] Pruning Docker images on ${{ matrix.runner }}..." + docker image prune -a -f || true + + poll-debian-base-and-detect-changes: + runs-on: vm-docker-build2 + needs: docker-prune + outputs: + digest_changed: ${{ steps.compare_digest.outputs.changed }} + versions_changed: ${{ steps.check_changed_versions.outputs.versions_changed }} + new_versions: ${{ steps.check_new_versions.outputs.new_versions }} + steps: + - name: Checkout repo + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Ensure .cache exists + run: mkdir -p .cache && touch .cache/.gitkeep + + - name: Log in to Gitea Registry + run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login gitea.fithwum.tech -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin + + - name: Get current digest of debian-base image + id: get_digest + run: | + IMAGE="${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_ORG }}/${{ env.IMAGE_REPO_DEBIAN }}:${{ env.IMAGE_TAG_DEBIAN }}" + docker pull "$IMAGE" > /dev/null + DIGEST=$(docker inspect --format='{{index .RepoDigests 0}}' "$IMAGE") + echo "digest=$DIGEST" >> $GITHUB_OUTPUT + echo "$DIGEST" > .cache/debian-base.digest.new + + - name: Compare with stored digest + id: compare_digest + run: | + CURRENT_DIGEST="${{ steps.get_digest.outputs.digest }}" + LAST_DIGEST="$(cat ${{ env.DIGEST_FILE }} 2>/dev/null || echo '')" + + if [ "$CURRENT_DIGEST" = "$LAST_DIGEST" ]; then + echo "[INFO] Digest unchanged" + echo "changed=false" >> $GITHUB_OUTPUT + exit 0 + fi + + echo "[INFO] Digest changed → updating cache" + echo "$CURRENT_DIGEST" > ${{ env.DIGEST_FILE }} + + git config user.name "${{ secrets.GIT_USERNAME }}" + git config user.email "${{ secrets.GIT_EMAIL }}" + + git add ${{ env.DIGEST_FILE }} + git commit -m "Update base digest to $CURRENT_DIGEST" || true + + # --- Safe rebase with auto conflict resolution --- + git fetch origin master + if ! git rebase --strategy-option=theirs origin/master; then + echo "[WARN] Rebase conflict, auto-resolving by preferring local digest" + git rebase --abort + git fetch origin master + git reset --hard origin/master + echo "$CURRENT_DIGEST" > ${{ env.DIGEST_FILE }} + git add ${{ env.DIGEST_FILE }} + git commit -m "Force-update base digest to $CURRENT_DIGEST (auto-resolved)" + fi + + git push origin HEAD:master + echo "changed=true" >> $GITHUB_OUTPUT + + - name: Detect changed vintage-story versions + id: check_changed_versions + run: | + BEFORE_COMMIT="${{ github.event.before }}" + if [ -z "$BEFORE_COMMIT" ] || ! git cat-file -e "$BEFORE_COMMIT^{commit}" 2>/dev/null; then + BEFORE_COMMIT=$(git rev-parse HEAD~1) + fi + CHANGED=$(git diff --name-only "$BEFORE_COMMIT" HEAD || true) + CHANGED_VERSIONS="" + for version in $VERSIONS; do + echo "$CHANGED" | grep -q "^$version/.*\.\(sh\|Dockerfile\)$" && CHANGED_VERSIONS="$CHANGED_VERSIONS $version" + done + CHANGED_VERSIONS=$(echo "$CHANGED_VERSIONS" | xargs) # trim whitespace + echo "versions_changed=$CHANGED_VERSIONS" >> $GITHUB_OUTPUT + + - name: Detect vintage-story versions without build-info + id: check_new_versions + run: | + NEW_VERSIONS="" + GIT_CREDENTIAL="${{ secrets.GIT_TOKEN || secrets.GIT_PASSWORD }}" + git clone --depth=1 "https://${{ secrets.GIT_USERNAME }}:${GIT_CREDENTIAL}@gitea.fithwum.tech/fithwum/vintage-story.git" upload-repo + + for version in $VERSIONS; do + if [ ! -f "upload-repo/$version/build-info.json" ]; then + echo "[INFO] No build-info.json for $version → treating as new" + NEW_VERSIONS="$NEW_VERSIONS $version" + fi + done + + echo "new_versions=$NEW_VERSIONS" >> $GITHUB_OUTPUT + + build-vintage-story-images: + runs-on: vm-docker-build2 + needs: + - docker-prune + - poll-debian-base-and-detect-changes + if: | + needs.poll-debian-base-and-detect-changes.outputs.digest_changed == 'true' || + needs.poll-debian-base-and-detect-changes.outputs.versions_changed != '' || + needs.poll-debian-base-and-detect-changes.outputs.new_versions != '' + strategy: + matrix: + version: [vintage-story] + name: Build and Push ${{ matrix.version }} + steps: + - name: Checkout repo + uses: actions/checkout@v3 + + - name: Log in to Gitea Registry + run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login gitea.fithwum.tech -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin + + - name: Clone vintage-story repo (with retries) + run: | + GIT_CREDENTIAL="${{ secrets.GIT_TOKEN || secrets.GIT_PASSWORD }}" + for i in {1..5}; do + git clone "https://${{ secrets.GIT_USERNAME }}:${GIT_CREDENTIAL}@gitea.fithwum.tech/fithwum/vintage-story.git" upload-repo && break + echo "[WARN] Clone attempt $i failed. Retrying in 10s..." + sleep 10 + done + if [ ! -d upload-repo ]; then + echo "[ERROR] Failed to clone vintage-story repo after retries." + exit 1 + fi + + - name: Build and push image + run: | + IMAGE="$IMAGE_REGISTRY/$IMAGE_ORG/$IMAGE_REP)_VINTAGE_STORY:${{ matrix.version }}" + docker buildx build --platform linux/amd64 --push -t "$IMAGE" "./${{ matrix.version }}" + + generate-changelogs: + needs: build-vintage-story-images + runs-on: vm-docker-build2 + steps: + - name: Checkout repo + uses: actions/checkout@v3 + + - name: Create temporary changelog workspace + run: mkdir -p changelogs + + - name: Clone vintage-story repo + run: | + GIT_CREDENTIAL="${{ secrets.GIT_TOKEN || secrets.GIT_PASSWORD }}" + git clone --depth=3 "https://${{ secrets.GIT_USERNAME }}:${GIT_CREDENTIAL}@gitea.fithwum.tech/fithwum/vintage-story.git" upload-repo + + - name: Generate changelogs + run: | + for version in $VERSIONS; do + echo "[INFO] Generating changelog for $version" + changelog="changelogs/$version/CHANGES.md" + mkdir -p "$(dirname "$changelog")" + touch "$changelog" + + cd upload-repo + infofile="$version/build-info.json" + last_commit="" + if [ -f "$infofile" ]; then + last_commit=$(jq -r '.commit' "$infofile") + fi + + echo -e "## $(date -u +'%Y-%m-%dT%H:%M:%SZ')\n" > "../$changelog" + if [ -n "$last_commit" ]; then + COMMITS=$(git log "${last_commit}..HEAD" --pretty=format:"- %s (%an)" || true) + fi + if [ -z "$COMMITS" ]; then + echo "[INFO] No new commits since last build. Showing latest 5 instead." + COMMITS=$(git log -n 5 --pretty=format:"- %s (%an)" || true) + fi + echo "$COMMITS" >> "../$changelog" + cd .. + done + + - name: Copy changelogs into repo + run: | + for version in $VERSIONS; do + mkdir -p upload-repo/$version + cp changelogs/$version/CHANGES.md upload-repo/$version/ + done + + - name: Commit and push changelogs (temp branch) + run: | + cd upload-repo + + git config user.name "${{ secrets.GIT_USERNAME }}" + git config user.email "${{ secrets.GIT_EMAIL }}" + + TEMP_BRANCH="tmp-changelog-$(date +%s)" + + # Create temporary branch + git checkout -b "$TEMP_BRANCH" + + # Stage changes + git add */CHANGES.md + + # Nothing changed? + if git diff --cached --quiet; then + echo "[INFO] No changelog changes." + exit 0 + fi + + git commit -m "Update changelogs on $(date -u +'%Y-%m-%dT%H:%M:%SZ') [skip ci]" + + # Push temporary branch + git push origin HEAD:$TEMP_BRANCH + + # Rebase temp branch onto latest master + git fetch origin master + + git checkout "$TEMP_BRANCH" + + if ! git rebase origin/master; then + echo "[WARN] Rebase failed, using merge instead." + git rebase --abort || true + git merge origin/master --no-edit + fi + + git push origin HEAD:$TEMP_BRANCH --force + + # Fast-forward master + git checkout master + git reset --hard origin/master + + git merge --no-ff "$TEMP_BRANCH" \ + -m "Merge changelog updates" + + git push origin master + + git push origin --delete "$TEMP_BRANCH" || true + + generate-build-info: + needs: generate-changelogs + runs-on: vm-docker-build2 + steps: + - name: Checkout repo + uses: actions/checkout@v3 + + - name: Prepare temporary build-info workspace + run: mkdir -p buildinfo + + - name: Clone vintage-story repo + run: | + GIT_CREDENTIAL="${{ secrets.GIT_TOKEN || secrets.GIT_PASSWORD }}" + git clone --depth=1 "https://${{ secrets.GIT_USERNAME }}:${GIT_CREDENTIAL}@gitea.fithwum.tech/fithwum/vintage-story.git" upload-repo + + - name: Generate build-info files + run: | + human_size() { + local b=$1 d='' s=0 S=(B KB MB GB TB) + while ((b >= 1024 && s < ${#S[@]}-1)); do + d=$((b % 1024)); b=$((b / 1024)); s=$((s + 1)) + done + printf "%s%s\n" "$b" "${S[$s]}" + } + + for version in $VERSIONS; do + echo "[INFO] Generating build-info.json for $version" + image="${IMAGE_REGISTRY}/${IMAGE_ORG}/${IMAGE_REP)_VINTAGE_STORY}:$version" + infofile="buildinfo/$version/build-info.json" + mkdir -p "$(dirname "$infofile")" + + if ! docker pull "$image"; then + echo "[WARN] Failed to pull $image — setting fields to unknown/0" + digest="unknown" + size_bytes=0 + else + digest=$(docker inspect --format='{{if .RepoDigests}}{{index .RepoDigests 0}}{{else}}unknown{{end}}' "$image" 2>/dev/null || echo "unknown") + size_bytes=$(docker image inspect "$image" --format='{{.Size}}' 2>/dev/null || echo "0") + size_bytes=${size_bytes//[^0-9]/} + if [[ -z "$size_bytes" ]]; then size_bytes=0; fi + fi + + size_human=$(human_size "$size_bytes") + + cd upload-repo + commit=$(git rev-parse HEAD) + cd .. + + jq -n \ + --arg version "$version" \ + --arg commit "$commit" \ + --arg build_time "$(date -u +'%Y-%m-%dT%H:%M:%SZ')" \ + --arg image_tag "$image" \ + --arg digest "$digest" \ + --arg image_size "$size_human" \ + --argjson image_size_bytes "$size_bytes" \ + '{ + version: $version, + commit: $commit, + build_time: $build_time, + image_tag: $image_tag, + digest: $digest, + image_size: $image_size, + image_size_bytes: $image_size_bytes + }' > "$infofile" + done + + - name: Copy build-info.json into repo + run: | + for version in $VERSIONS; do + mkdir -p upload-repo/$version + cp "buildinfo/$version/build-info.json" "upload-repo/$version/" + done + + - name: Commit and push build-info (temp branch) + run: | + cd upload-repo + + git config user.name "${{ secrets.GIT_USERNAME }}" + git config user.email "${{ secrets.GIT_EMAIL }}" + + TEMP_BRANCH="tmp-buildinfo-$(date +%s)" + + # Create temporary branch + git checkout -b "$TEMP_BRANCH" + + # Stage changes + git add */build-info.json + + # Nothing changed? + if git diff --cached --quiet; then + echo "[INFO] No build-info changes." + exit 0 + fi + + git commit -m "Update build-info on $(date -u +'%Y-%m-%dT%H:%M:%SZ') [skip ci]" + + # Push temporary branch + git push origin HEAD:$TEMP_BRANCH + + # Rebase temp branch onto latest master + git fetch origin master + + git checkout "$TEMP_BRANCH" + + if ! git rebase origin/master; then + echo "[WARN] Rebase failed, using merge instead." + git rebase --abort || true + git merge origin/master --no-edit + fi + + git push origin HEAD:$TEMP_BRANCH --force + + # Merge into master + git checkout master + git reset --hard origin/master + + git merge --no-ff "$TEMP_BRANCH" \ + -m "Merge build-info updates" + + git push origin master + + git push origin --delete "$TEMP_BRANCH" || true + + for version in $VERSIONS; do + TAG="build-$version" + + git tag -d "$TAG" 2>/dev/null || true + git push origin ":refs/tags/$TAG" 2>/dev/null || true + + git tag "$TAG" + git push origin "$TAG" --force + done \ No newline at end of file diff --git a/my-Vintage-Story.xml b/my-Vintage-Story.xml new file mode 100755 index 0000000..a1454ff --- /dev/null +++ b/my-Vintage-Story.xml @@ -0,0 +1,33 @@ + + + Vintage-Story + gitea.fithwum.tech/fithwum/vintage-story:latest + https://hub.docker.com/r/fithwum/vintage-story/ + host + + sh + false + https://forums.unraid.net/topic/125134-support-fithwum-vintage-story-server/ + https://www.vintagestory.at + + This docker will run a vintage-story server. + GameServers: + + https://github.com/fithwum/files-for-dockers/templates/vintage-story_server_unraid.xml + https://gitea.fithwum.tech/fithwum/files-for-dockers/raw/branch/master/icons/vintage-story.png + + + + 1784389857 + Buy me a coffee if you like. + https://checkout.square.site/pay/340d93c602a042b8a223a2f7c184a6a2 + + + 1.21.5 + fithwum + /mnt/user/Games/Saves/vintagestory/ + /mnt/user/Games/Servers/vintage-story-server + 99 + 100 + + diff --git a/vanilla/Dockerfile b/server/Dockerfile similarity index 100% rename from vanilla/Dockerfile rename to server/Dockerfile diff --git a/vanilla/install_script.sh b/server/install_script.sh similarity index 86% rename from vanilla/install_script.sh rename to server/install_script.sh index 1fa4221..1b69ebe 100644 --- a/vanilla/install_script.sh +++ b/server/install_script.sh @@ -17,10 +17,7 @@ if [ -e /vs_server/server/server-$VS_VERSION.sh ] echo "INFO ! Cleaning old files." mkdir /vs_server/old-server-versions/ mv /vs_server/server/* /vs_server/old-server-versions/server/ - if wget --no-cache --show-progress --progress=bar:force:noscroll $VS_SERVER_FILE -O /vs_temp/vs_server_linux-x64_$VS_VERSION.tar.gz - then - echo "INFO ! server version $VS_VERSION download complete." - fi + wget --no-cache --show-progress --progress=bar:force:noscroll $VS_SERVER_FILE -O /vs_temp/vs_server_linux-x64_$VS_VERSION.tar.gz tar -xzf /vs_temp/vs_server_linux-x64_$VS_VERSION.tar.gz -C /vs_temp/files rm -fr /vs_temp/vs_server_linux-x64_*.*.*.tar.gz cp -uR /vs_temp/files/* /vs_server/server/ @@ -41,7 +38,7 @@ sleep 1 # Set permissions. chown 99:100 -R /vs_server -chmod 777 -R /vs_server +chmod 776 -R /vs_server chmod +x /vs_server/server/server-$VS_VERSION.sh sleep 1