Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated "latest" Build without Version Decleration #47

Open
fanuch opened this issue Oct 18, 2022 · 8 comments
Open

Automated "latest" Build without Version Decleration #47

fanuch opened this issue Oct 18, 2022 · 8 comments

Comments

@fanuch
Copy link

fanuch commented Oct 18, 2022

Problem

New Terraria player here.

There have been a couple of days over the past month where my friends and I have been faced with a pop-up saying our version wasn't in sync with our server after a Steam Terraria update.

I noticed a couple of things in this repo:

  1. There is a cron for building once a day
  2. There is a directory structure for version numbers

Both of these don't lend themselves to keeping up with the latest version as there is a manual process to change the URL in the server download ZIP and those delays can take a while to notice and remedy.

Solution

My proposed solution is to use the following endpoint to grab server version number and build a docker image as soon as a new version is detected.

Link:
https://www.terraria.org/api/get/dedicated-servers-names

Returns:

[
  "terraria-server-1445.zip",
  "terraria-server-1441-fixed.zip"
]

In bash, I wrote this to parse out the first element in that JSON list:

curl -s https://www.terraria.org/api/get/dedicated-servers-names | grep -o 'terraria-server-[^"]*' | head -1

Which returns:

terraria-server-1445.zip

I would suggest that there is a workflow with GitHub Actions where you can check that server endpoint more frequently and compare against your known version.

If the version is new, then automatically build and tag image with :latest

I added/changed this to your Dockerfile and it works in always sourcing the right version:

#...
# Download and install Vanilla Server
RUN curl -s https://www.terraria.org/api/get/dedicated-servers-names | grep -o 'terraria-server-[^"]*' | head -1 | tee latest_version.txt

RUN mkdir /tmp/terraria && \
    cd /tmp/terraria && \
    curl -sL https://www.terraria.org/api/download/pc-dedicated-server/$(cat latest.txt) --output terraria-server.zip && \
#...

Summary

Just an idea but I think this workflow will stop issues being raised with "new version available" and means you as maintainer don't need to drop everything to push out for a new version :)

@hskrtich
Copy link
Contributor

Fantastic! I looked for some sort of api with the latest version number so I could automate the process. I would love to not need to manually update that. I will work on getting that built into my scripts.

Thank you for providing the endpoint.

@hskrtich
Copy link
Contributor

@fanuch Where did you find this api link??

@fanuch
Copy link
Author

fanuch commented Oct 22, 2022

No worries @hskrtich!

Their website is a web of obfuscated and minimised JS.

I happened on that link but don't wish for even my enemy to pull apart their JS haha

If you want specifics I can go find it again :)

@hskrtich
Copy link
Contributor

What would be really nice is a full list of versions so I can properly build the last 4 minor versions but Im not sure its worth it.

@fanuch
Copy link
Author

fanuch commented Oct 22, 2022

Oh I would have loved that but if it is somewhere, it's hidden.

I think it might need to be a local task and not one where we can trust the upstream to track.

I'll post my research soon 👍

@fanuch
Copy link
Author

fanuch commented Oct 22, 2022

Okay, so.

Go to https://www.terraria.org/

image

image

  1. Open dev tools in your browser ('m using Firefox)
  2. Click on "Debugger"
  3. In the left panel, navigate to "Main Thread" > "www.terraria.org" >
  4. static/js
  5. main.61ebd860.chunk.js
  6. Click the "Prettify/unminify" button
  7. Search for "api/get/dedicated-servers-names"

(Actually, search for "api" ... a lot more stuff comes up 👀 )

@hskrtich
Copy link
Contributor

Thanks for the info! I took a look as well and I didnt find anything that had a list of versions. Ive decided to put together a separate repo that will hold a json of all the terraform versions with links to the server zip's

@fanuch
Copy link
Author

fanuch commented Oct 22, 2022

Located these two that keep versions.
Might not be "up to the second" but they could be leveraged!

https://terraria.wiki.gg/wiki/Desktop_version_history
https://terraria.fandom.com/wiki/PC_version_history

Seeing as there are Docker images, my recommendation is to keep previous tags in the Docker repo, and list out a table here of valid tags.

If someone wants to build they will need to pass a variable to the Dockerfile such as:

# ...
ARG VERSION=latest # Current latest version

RUN \
if [ $VERSION = "latest" ]; then 
    curl -s https://www.terraria.org/api/get/dedicated-servers-names | \
        grep -o 'terraria-server-[^"]*' | \
        head -1 | \
        tee version.txt;
else;
     echo $VERSION > version.txt
fi

RUN mkdir /tmp/terraria && \
    cd /tmp/terraria && \
    curl -sL https://www.terraria.org/api/download/pc-dedicated-server/$(cat version.txt) --output terraria-server.zip && \
#...

Bit clunky but the idea is that they could pass in their own version if they wanted to manually build an old version like 1.4.4.1:

docker build -t terraria --build-arg VERSION=1.4.4.1 .

Otherwise they could pull the old tag, or on a regular build, it will always pull the latest version off that version endpoint

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants