init
This commit is contained in:
9
Dockerfile
Normal file
9
Dockerfile
Normal file
@@ -0,0 +1,9 @@
|
||||
FROM python:latest
|
||||
|
||||
RUN pip install requests
|
||||
COPY get_server.py get_server.py
|
||||
RUN chmod +x get_server.py
|
||||
WORKDIR /downloads
|
||||
|
||||
CMD [ "/get_server.py" ]
|
||||
ENTRYPOINT ["python"]
|
||||
18
Makefile
Normal file
18
Makefile
Normal file
@@ -0,0 +1,18 @@
|
||||
SHELL := /bin/bash
|
||||
|
||||
IMAGE ?= $(shell cat IMAGE):$(shell cat VERSION)
|
||||
IMAGE_LATEST ?= $(shell cat IMAGE):latest
|
||||
|
||||
.PHONY: buildx-context
|
||||
buildx-context:
|
||||
docker buildx create --name arm64 --use --platform linux/amd64,linux/arm64,linux/arm/v8
|
||||
|
||||
.PHONY: build
|
||||
build:
|
||||
@docker buildx build --platform linux/amd64,linux/arm64 . -t $(IMAGE)
|
||||
@docker buildx build --platform linux/amd64,linux/arm64 . -t $(IMAGE_LATEST)
|
||||
|
||||
.PHONY: push
|
||||
push:
|
||||
@docker push $(IMAGE)
|
||||
@docker push $(IMAGE_LATEST)
|
||||
27
README.md
Normal file
27
README.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# Minecraft Server Getter
|
||||
|
||||
Get the url for any minecraft server version
|
||||
|
||||
## Usage
|
||||
|
||||
### Python
|
||||
|
||||
Since this script is designed to be used in Docker it works with
|
||||
environment variables. Set SERVER_VERSION=<desired version> and
|
||||
get_server.py will write a file called "SERVER_VERSION" with the url
|
||||
to download the version requested.
|
||||
|
||||
```bash
|
||||
export SERVER_VERSION=1.16.4
|
||||
python get_server.py
|
||||
```
|
||||
|
||||
### Docker
|
||||
|
||||
This is the intended way to run get_server. The get_server image saves
|
||||
the SERVER_VERSION file to /downloads. Mounting /downloads to `pwd` will
|
||||
allow the image to write to your current directory.
|
||||
|
||||
```bash
|
||||
docker run -it -e SERVER_VERSION=1.16.4 -v $(pwd):/downloads ducoterra/get-minecraft:latest
|
||||
```
|
||||
1
SERVER_VERSION
Normal file
1
SERVER_VERSION
Normal file
@@ -0,0 +1 @@
|
||||
https://launchermeta.mojang.com/v1/packages/584f4f319f0acc2f8c9a7d992ae20b95f425c1c5/1.16.4.json
|
||||
42
get_server.py
Normal file
42
get_server.py
Normal file
@@ -0,0 +1,42 @@
|
||||
import requests
|
||||
import json
|
||||
import os
|
||||
|
||||
LATEST = "latest"
|
||||
RELEASE = "release"
|
||||
SNAPSHOT = "snapshot"
|
||||
REQUESTED_VERSION = os.getenv("SERVER_VERSION", LATEST)
|
||||
VERSION_FILE = "SERVER_VERSION"
|
||||
|
||||
def get_latest_version(latest):
|
||||
return latest.get(RELEASE)
|
||||
|
||||
def get_version(versions, latest, id):
|
||||
if id == LATEST:
|
||||
id = get_latest_version(latest)
|
||||
|
||||
result = list(filter(
|
||||
lambda item: item.get('id') == id,
|
||||
versions
|
||||
))
|
||||
if len(result) == 1:
|
||||
return result[0]
|
||||
elif len(result) > 1:
|
||||
raise ValueError(f"Version {id} didn't return 1 result, it returned {len(result)}!")
|
||||
else:
|
||||
raise ValueError(f"Version {id} had no matches.")
|
||||
|
||||
def write_version_file(version):
|
||||
with open(VERSION_FILE, "w") as f:
|
||||
return f.write(version.get('url'))
|
||||
|
||||
if __name__ == "__main__":
|
||||
version_manifest = requests.get("https://launchermeta.mojang.com/mc/game/version_manifest_v2.json")
|
||||
version_json = json.loads(version_manifest.text)
|
||||
versions = version_json.get('versions')
|
||||
latest = version_json.get(LATEST)
|
||||
|
||||
print(f"Attempting to get version {REQUESTED_VERSION}.")
|
||||
version = get_version(versions, latest, REQUESTED_VERSION)
|
||||
print(f"Found, writing url to VERSION file.")
|
||||
write_version_file(version)
|
||||
Reference in New Issue
Block a user