51 lines
1.4 KiB
Python
51 lines
1.4 KiB
Python
def _dev_server_impl(ctx):
|
|
script = ctx.actions.declare_file(ctx.label.name + "_runner")
|
|
content = """
|
|
#!/bin/sh
|
|
set -eu
|
|
|
|
cp -f '%s' server.jar
|
|
printf eula=true > eula.txt
|
|
mkdir -p plugins
|
|
rm -f plugins/*.jar
|
|
for plugin in %s
|
|
do
|
|
cp -v \"$plugin\" plugins/
|
|
done
|
|
|
|
mkdir -p postgres-data
|
|
podman run \
|
|
--rm \
|
|
--name scrow-postgres-dev \
|
|
-p 5432:5432 \
|
|
-v ./postgres-data/:/data \
|
|
-e POSTGRES_USER=postgres \
|
|
-e POSTGRES_HOST_AUTH_METHOD=trust \
|
|
-d \
|
|
docker.io/postgres:alpine || true
|
|
echo "Starting paper server in $PWD"
|
|
exec env HOST_POSTGRES='jdbc:postgresql://127.0.0.1:5432/postgres' java -jar server.jar --nogui %s
|
|
""" % (
|
|
ctx.file.server_jar.short_path,
|
|
" ".join([p.short_path for p in ctx.files.plugins]),
|
|
" ".join(["--add-plugin %s" % p.short_path for p in ctx.files.local_plugins]),
|
|
)
|
|
ctx.actions.write(
|
|
output = script,
|
|
content = content,
|
|
is_executable = True,
|
|
)
|
|
return DefaultInfo(
|
|
executable = script,
|
|
runfiles = ctx.runfiles(files = [ctx.file.server_jar] + ctx.files.plugins + ctx.files.local_plugins)
|
|
)
|
|
|
|
dev_server = rule(
|
|
implementation = _dev_server_impl,
|
|
executable = True,
|
|
attrs = {
|
|
"server_jar": attr.label(allow_single_file = True, mandatory = True),
|
|
"plugins": attr.label_list(),
|
|
"local_plugins": attr.label_list(),
|
|
},
|
|
)
|