factoriotools / factorio-docker

Factorio headless server in a Docker container
https://hub.docker.com/r/factoriotools/factorio/
MIT License
918 stars 218 forks source link

Generic way to watch for new versions, honoring stable vs. experimental #386

Closed bplein closed 3 years ago

bplein commented 3 years ago

All,

This is more of a "how do I" vs. a bug report.

For the past couple of years I've been following Experimental, and I have code that periodically pulls the tags from the docker hub repo, and if the highest number is different from my last running version, I pull the image and restart with that specific image ("factoriotools/factorio:1.1.30" for example).

I'd like to make a more generic approach, where my configuration could declare "stable" or "experimental" and then do much of the same.

My preference has been to determine the specific version, and declare that in my docker-compose.yml (via an environment variable), vs. just running :latest or :stable and taking whatever that is.

Thoughts? Am I overthinking this? What are you all doing to manage switching versions?

The reason I bring this up is that I think I might run some of my 5 game servers on "stable" vs. "experimental" and now that stable and experimental are the same, it's non-disruptive. I have no idea when the Factorio devs are going to start developing on another experimental branch.

StopMotionCuber commented 3 years ago

This is pretty much a duplicate of #383 If you don't like to wait for an update of the docker image, you might want to parse the JSON on https://www.factorio.com/updater/get-available-versions?apiVersion=2 yourself and put the appropriate tag for the stable release

bplein commented 3 years ago

Well, that's the wrong way to do it. I don't run code directly from Factorio, I use this container image. And there's a lag (sometimes long) between code changes at Factorio.com and this GitHub repo change and then again when a build is successful. The programmatic way is to look for a new image, not at Factorio.com.

The how to question is really about parsing the tags at Docker Hub to find the latest stable vs latest experimental. Right now my regex is just looking for the highest code version.

bplein commented 3 years ago

And to make sure my point was clear: this is not a case of a pull getting the wrong image. The question is generic in nature and not related to the coding or building of the container image. It's "what is the proper way to programmatically determine the latest stable code version (or experimental for that matter". I only have a solution for the latter.

It may be a moot point. Right now stable and experimental point to the same version and that may not change.

bplein commented 1 year ago

Commenting here in case anyone else needs this: I was using wget to scrape the Docker API for the tags and using a bunch of ugly sed and sort to get the latest version.

That broke in the past few weeks, and I am now using their new API version as well as jq for a much cleaner implementation. Well, a little cleaner!

LATEST=$(curl -sL https://hub.docker.com/v2/namespaces/factoriotools/repositories/factorio/tags?page_size=100 | jq -r '.results | .[] | .name' | sort -t. -k 1.1,1n -k 2,2n -k 3,3n -k 4,4n | tail -1 || { echo "wget failed with value for LATEST = -$LATEST-" ; exit 1; })

This assumes that the newest tag is in the first 100 returned, so it could break down the line.

It curls the API, runs it through jq -r to find all the name items which are the tags (-r returns raw values without quotes), and sorts it, and keeps the last value.