Skip to content

Instantly share code, notes, and snippets.

@AstraLuma
Last active January 26, 2020 03:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AstraLuma/fe52febc843167b1f5834f483cd716e6 to your computer and use it in GitHub Desktop.
Save AstraLuma/fe52febc843167b1f5834f483cd716e6 to your computer and use it in GitHub Desktop.
buildahscript proof of concept
#!/usr/bin/env buildahscript
#| pip: requests
#| arg: eula: bool
#| arg: version: str = "latest"
#| arg: type: str = "vanilla"
with TemporaryDirectory() as td:
bin = td / 'bin'
bin.mkdir()
with workspace('rust:buster') as build:
build.copy_in('cmd', '/tmp/cmd')
build.copy_in('localmc', '/tmp/localmc')
build.run(['cargo', 'build', '--release'], pwd='/tmp/cmd')
build.copy_out('/tmp/cmd/target/release/cmd', bin / 'cmd')
with workspace('rust:buster') as build:
build.copy_in('status', '/tmp/status')
build.copy_in('localmc', '/tmp/localmc')
build.copy_in('mcproto-min-async', '/tmp/mcproto-min-async')
build.run(['cargo', 'build', '--release'], pwd='/tmp/status')
build.copy_out('/tmp/status/target/release/status', bin / 'status')
# Download & extract mc-server-runner
with requests.get('https://github.com/itzg/mc-server-runner/releases/download/1.3.3/mc-server-runner_1.3.3_linux_amd64.tar.gz') as resp:
resp.raise_for_status()
with tarfile.open(resp, 'r|*') as tf:
for entry in tf:
if entry.name == 'mc-server-runner':
tf.extract(entry, bin / 'mc-server-runner')
with workspace('openjdk:8-jre-slim') as cont:
cont.copy_in(bin / 'cmd', '/usr/bin/cmd')
cont.copy_in(bin / 'status', '/usr/bin/status')
cont.copy_in(bin / 'mc-server-runner', '/mc-server-runner')
# TODO: Build /mc
cont.voumes |= {
"/mc/world", "/mc/server.properties", "/mc/logs",
"/mc/crash-reports", "/mc/banned-ips.json",
"/mc/banned-players.json", "/mc/ops.json", "/mc/whitelist.json",
}
cont.entrypoint = ["/mc-server-runner", "-shell", "/bin/sh"],
cont.cmd = ["/mc/launch"],
cont.healthcheck = ["status"],
cont.healthcheck_start_period = "5m",
return cont.commit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment