diff options
| -rw-r--r-- | .dockerignore | 5 | ||||
| -rw-r--r-- | Dockerfile | 6 | ||||
| -rw-r--r-- | html/index.html (renamed from index.html) | 0 | ||||
| -rwxr-xr-x | src/app.py (renamed from app.py) | 0 | ||||
| l--------- | src/html | 1 | ||||
| -rwxr-xr-x | src/server.py (renamed from server.py) | 16 | ||||
| -rwxr-xr-x | test/test.sh | 4 |
7 files changed, 22 insertions, 10 deletions
diff --git a/.dockerignore b/.dockerignore index 069ef0d..d5aa556 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,6 +1,5 @@ * -!app.py -!index.html +!html/ !requirements.txt -!server.py +!src/ @@ -2,12 +2,12 @@ FROM python:3.14-alpine RUN mkdir -p /var/lib/void -COPY [".", "/usr/src/"] -WORKDIR /usr/src +COPY [".", "/opt/void/"] +WORKDIR /opt/void RUN pip install -q -r requirements.txt # I don't know why, but in Docker, simple print() statements show nothing: # https://stackoverflow.com/q/29663459 # Fixed by adding the -u flag: -CMD ["python3", "-u", "./server.py", "--void", "/var/lib/void/void.state"] +CMD ["python3", "-u", "src/server.py", "--void", "/var/lib/void/void.state"] diff --git a/index.html b/html/index.html index 124c7ea..124c7ea 100644 --- a/index.html +++ b/html/index.html diff --git a/src/html b/src/html new file mode 120000 index 0000000..5eb7cf0 --- /dev/null +++ b/src/html @@ -0,0 +1 @@ +../html/
\ No newline at end of file diff --git a/server.py b/src/server.py index 8c1470e..0328d55 100755 --- a/server.py +++ b/src/server.py @@ -24,6 +24,10 @@ def script_dir(): return os.path.dirname(os.path.realpath(__file__)) +def default_html_dir(): + return os.path.join(script_dir(), 'html') + + def set_exiting(): global EXITING with SignalHandler.LOCK: @@ -118,17 +122,25 @@ def parse_args(args=None): help='set port number', ) parser.add_argument( + '-d', + '--dir', + metavar='DIR', + default=default_html_dir(), + help='HTML directory path', + ) + parser.add_argument( '-v', '--void', metavar='PATH', dest='backup', help='set path to the void' ) return parser.parse_args(args) def main(args=None): + args = parse_args(args) + # It's a failsafe; this script is only allowed to serve the directory it # resides in. - os.chdir(script_dir()) + os.chdir(args.dir) - args = parse_args(args) with Void(args.backup) as void: RequestHandler.VOID = void httpd = make_server(args.port) diff --git a/test/test.sh b/test/test.sh index 9b1bc14..4b04350 100755 --- a/test/test.sh +++ b/test/test.sh @@ -28,7 +28,7 @@ dump() { run_server() { dump "Starting up server..." - "$script_dir/../server.py" --port "$server_port" & + "$script_dir/../src/server.py" --port "$server_port" & server_pid="$!" dump "Its PID is $server_pid" sleep 5 @@ -173,7 +173,7 @@ run_cgi_test() { local query_string="what=$what" dump "Running CGI test for query string: $query_string" - QUERY_STRING="$query_string" "$script_dir/../app.py" > "$curl_output_file" + QUERY_STRING="$query_string" "$script_dir/../src/app.py" > "$curl_output_file" cgi_check_header |
