Commit 8f38cc27 authored by Michael Droettboom's avatar Michael Droettboom Committed by GitHub

Merge pull request #263 from madhur-tandon/master

Expose Port 8000 for easy manual testing
parents a134831a ffa2f7df
......@@ -64,6 +64,26 @@ on your `PATH`.
`pytest test/`
# Manual Testing
The port 8000 of the docker environment and the host system are automatically
binded when ``./run_docker`` is run.
This can be used to test the ``pyodide`` builds running within the docker
environment using external browser programs on the host system.
To do this, simply run ``./bin/pyodide serve``
This serves the ``build`` directory of the ``pyodide`` project on port 8000.
* To serve a different directory, use the ``--build_dir`` argument followed by
the path of the directory
* To serve on a different port, use the ``--port`` argument followed by the
desired port number
Make sure that the port passed in ``--port`` argument is same as the one
defined as ``DOCKER_PORT`` in the ``run_docker`` script.
# Benchmarking
Install the same dependencies as for testing.
......
......@@ -4,6 +4,7 @@ import argparse
from . import buildall
from . import buildpkg
from . import pywasmcross
from . import serve
def main():
......@@ -12,7 +13,8 @@ def main():
for command_name, module in (("buildpkg", buildpkg),
("buildall", buildall),
("pywasmcross", pywasmcross)):
("pywasmcross", pywasmcross),
("serve", serve)):
parser = module.make_parser(subparsers.add_parser(command_name))
parser.set_defaults(func=module.main)
......
import os
import sys
import argparse
import http.server
import socketserver
import pathlib
TEST_PATH = pathlib.Path(__file__).parents[0].resolve()
BUILD_PATH = TEST_PATH / '..' / 'build'
class Handler(http.server.SimpleHTTPRequestHandler):
def end_headers(self):
self.send_header('Access-Control-Allow-Origin', '*')
super().end_headers()
Handler.extensions_map['.wasm'] = 'application/wasm'
def make_parser(parser):
parser.description = ('Start a server with the supplied '
'build_dir and port.')
parser.add_argument('--build_dir', action='store', type=str,
default=BUILD_PATH, help='set the build directory')
parser.add_argument('--port', action='store', type=int,
default=8000, help='set the PORT number')
return parser
def server(port):
httpd = socketserver.TCPServer(('', port), Handler)
return httpd
def main(args):
build_dir = args.build_dir
port = args.port
httpd = server(port)
os.chdir(build_dir)
print("serving from {0} at localhost:".format(build_dir) + str(port))
try:
httpd.serve_forever()
except KeyboardInterrupt:
print("\n...shutting down http server")
httpd.shutdown()
sys.exit()
if __name__ == "__main__":
parser = make_parser(argparse.ArgumentParser())
args = parser.parse_args()
main(args)
#!/bin/sh
docker run --rm -v $PWD:/src --user root -e NB_UID=$UID -e NB_GID=$GID -it iodide/pyodide-env:0.3.1 /bin/bash
DOCKER_PORT=8000
SYSTEM_PORT=8000
docker run -p $SYSTEM_PORT:$DOCKER_PORT --rm -v $PWD:/src --user root -e NB_UID=$UID -e NB_GID=$GID -it iodide/pyodide-env:0.3.1 /bin/bash
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment