diff --git a/docs/curl to add container to pod.md b/docs/curl to add container to pod.md index 975f455..b20f6b9 100644 --- a/docs/curl to add container to pod.md +++ b/docs/curl to add container to pod.md @@ -1,31 +1,23 @@ -PODID="" +PODID=7e0604d0-c228-4a8c-8bb7-27eaa8c96c1e curl -X POST http://192.168.64.2:5000/api/workloads/containers \ -H "Content-Type: application/json" \ - -d '{ - "pod": "$PODID", - "containers": [ - { - "docker_image": "joke_container", - "container_name": "very-important-webserver", - "ports": [ - { - "internal": 8080, - "external": 8765, - "use_dns": false - } - ] - }, - { - "docker_image": "whoami81", - "container_name": "whoami-server", - "ports": [ - { - "internal": 81, - "external": 8081, - "use_dns": false - } - ] - } - ] - }' + -d @- <
{{joke}}
-
Loading joke from API...
-
Fetching public IP...
+
Loading joke from API…
+
Fetching public IP…
+
Fetching server port…
- + \ No newline at end of file diff --git a/sandbox/containers/joke_container/jokes.py b/sandbox/containers/joke_container/jokes.py index 34cf8cd..9af372e 100644 --- a/sandbox/containers/joke_container/jokes.py +++ b/sandbox/containers/joke_container/jokes.py @@ -1,8 +1,9 @@ import http.server import socketserver import random +import os -PORT = 8080 +PORT = int(os.getenv("PORT", 8080)) JOKES = [ "Why do programmers prefer dark mode? Because light attracts bugs!", @@ -60,17 +61,27 @@ JOKES = [ class JokeHandler(http.server.SimpleHTTPRequestHandler): def do_GET(self): if self.path == "/" or self.path == "/index.html": + try: + with open("index.html", "r") as f: + html = f.read() + except FileNotFoundError: + self.send_error(404, "index.html not found") + return + self.send_response(200) self.send_header("Content-type", "text/html") self.end_headers() - with open("index.html", "r") as file: - html = file.read() + joke = random.choice(JOKES) html = html.replace("{{joke}}", joke) + html = html.replace("{{PORTNUMBER}}", str(PORT)) self.wfile.write(html.encode("utf-8")) else: self.send_error(404, "File not found") -with socketserver.TCPServer(("", PORT), JokeHandler) as httpd: +if __name__ == "__main__": + if os.getenv("PORT"): + print(f"Port taken from environment: PORT={PORT}") print(f"Serving at http://0.0.0.0:{PORT}") - httpd.serve_forever() + with socketserver.TCPServer(("", PORT), JokeHandler) as httpd: + httpd.serve_forever() \ No newline at end of file diff --git a/websocket_server/main.py b/websocket_server/main.py index 3254c7a..ecdbe9a 100644 --- a/websocket_server/main.py +++ b/websocket_server/main.py @@ -18,7 +18,7 @@ base.socketio = SocketIO( app, cors_allowed_origins="*", ping_timeout=5, - ping_interval=2 + ping_interval=30 ) # Import all socket event handlers