Run jlmkr as zipapp

This commit is contained in:
Jip-Hop 2024-07-16 16:12:12 +02:00
parent 9bdcfedd1a
commit 2256d31b94
5 changed files with 8 additions and 31 deletions

View File

@ -87,6 +87,7 @@ jobs:
env:
PYTHONUNBUFFERED: 1
run: |
sudo chown -R 0:0 src jlmkr.py ./test/test-jlmkr
python3 -m zipapp src/jlmkr -p "/usr/bin/env python3" -o jlmkr
sudo chown 0:0 jlmkr ./test/test-jlmkr
sudo bash ./test/test-jlmkr
sudo ./test/test.sh

1
.gitignore vendored
View File

@ -7,6 +7,7 @@ dist/
# jail-specific
/.lxc/
/jails/
jlmkr
# Mac-specific
.DS_Store

View File

@ -1,25 +0,0 @@
#!/usr/bin/env python3
# SPDX-FileCopyrightText: © 2024 Jip-Hop and the Jailmakers <https://github.com/Jip-Hop/jailmaker>
#
# SPDX-License-Identifier: LGPL-3.0-only
if __name__ == "__main__":
import subprocess
import sys
import os
# Get the path of the currently running script
current_path = os.path.realpath(__file__)
# Define the relative path you want to resolve
relative_path = "src/jlmkr"
# Resolve the relative path
script_path = os.path.join(os.path.dirname(current_path), relative_path)
# Get the arguments passed to the current script
args = sys.argv[1:]
# Pass all arguments to the other script using subprocess
subprocess.run(["python3", script_path] + args, check=True)

View File

@ -13,9 +13,9 @@ if [[ -z "$JLMKR_PATH" && -n "$SCALE_POOL_ROOT" ]]; then
elif [[ -z "$JLMKR_PATH" ]]; then
JLMKR_PATH=${PWD:-.}
fi
if [[ ! -r "$JLMKR_PATH/jlmkr.py" ]]; then
if [[ ! -r "$JLMKR_PATH/jlmkr" ]]; then
>&2 printf "%s\n" \
"couldn't find jlmkr.py. Are you running from the jailmaker directory?" \
"couldn't find jlmkr. Are you running from the jailmaker directory?" \
"If not, setup either JLMKR_PATH or SCALE_POOL_ROOT" \
""
@ -57,7 +57,7 @@ WAIT_FOR_JAIL=${WAIT_FOR_JAIL:-4s}
#### Functions
jlmkr () {
/usr/bin/env python3 "$JLMKR_PATH/jlmkr.py" "${@:---help}"
"$JLMKR_PATH/jlmkr" "${@:---help}"
}
iterate () {

View File

@ -8,5 +8,5 @@ set -euo pipefail
# TODO: test jlmkr.py from inside another working directory, with a relative path to a config file to test if it uses the config file (and doesn't look for it relative to the jlmkr.py file itself)
./jlmkr.py create --start --config=./templates/docker/config test
./jlmkr.py exec test docker run hello-world
./jlmkr create --start --config=./templates/docker/config test
./jlmkr exec test docker run hello-world