docs and sandbox update

This commit is contained in:
2025-07-26 00:54:28 +09:30
parent 98b009ab1c
commit 7613ce4be7
6 changed files with 58 additions and 46 deletions
+20 -28
View File
@@ -1,31 +1,23 @@
PODID="" PODID=7e0604d0-c228-4a8c-8bb7-27eaa8c96c1e
curl -X POST http://192.168.64.2:5000/api/workloads/containers \ curl -X POST http://192.168.64.2:5000/api/workloads/containers \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d '{ -d @- <<EOF
"pod": "$PODID", {
"containers": [ "pod": "${PODID}",
{ "containers": [
"docker_image": "joke_container", {
"container_name": "very-important-webserver", "docker_image": "joke_container",
"ports": [ "container_name": "amazing-joke-server99",
{ "ports": [
"internal": 8080, {
"external": 8765, "internal": 9092,
"use_dns": false "external": 8766,
} "use_dns": false
] }
}, ],
{ "env": { "PORT": "9092" }
"docker_image": "whoami81", }
"container_name": "whoami-server", ]
"ports": [ }
{ EOF
"internal": 81,
"external": 8081,
"use_dns": false
}
]
}
]
}'
+5 -6
View File
@@ -1,6 +1,4 @@
curl -X POST http://192.168.64.2:5000/api/workloads/containers \ curl -X POST http://192.168.64.2:5000/api/workloads/containers -H "Content-Type: application/json" -d '{
-H "Content-Type: application/json" \
-d '{
"virtual_data_center": "b1d09477-742b-485e-87c3-5dad36dd4f9e", "virtual_data_center": "b1d09477-742b-485e-87c3-5dad36dd4f9e",
"containers": [ "containers": [
{ {
@@ -8,11 +6,12 @@ curl -X POST http://192.168.64.2:5000/api/workloads/containers \
"container_name": "very-important-webserver", "container_name": "very-important-webserver",
"ports": [ "ports": [
{ {
"internal": 8080, "internal": 9090,
"external": 8765, "external": 9090,
"use_dns": false "use_dns": false
} }
] ],
"env": { "PORT": "9090" }
}, },
{ {
"docker_image": "whoami81", "docker_image": "whoami81",
@@ -5,6 +5,4 @@ WORKDIR /app
COPY jokes.py . COPY jokes.py .
COPY index.html . COPY index.html .
EXPOSE 8080
CMD ["python", "jokes.py"] CMD ["python", "jokes.py"]
+16 -4
View File
@@ -39,8 +39,9 @@
<div class="container"> <div class="container">
<div class="box" id="static-joke">{{joke}}</div> <div class="box" id="static-joke">{{joke}}</div>
<div class="box" id="api-joke">Loading joke from API...</div> <div class="box" id="api-joke">Loading joke from API…</div>
<div class="box" id="public-ip">Fetching public IP...</div> <div class="box" id="public-ip">Fetching public IP…</div>
<div class="box" id="server-port">Fetching server port…</div>
</div> </div>
<script> <script>
@@ -53,6 +54,7 @@
const fontSize = 16; const fontSize = 16;
const columns = canvas.width / fontSize; const columns = canvas.width / fontSize;
const drops = Array(Math.floor(columns)).fill(1); const drops = Array(Math.floor(columns)).fill(1);
function drawMatrix() { function drawMatrix() {
ctx.fillStyle = 'rgba(0, 0, 0, 0.05)'; ctx.fillStyle = 'rgba(0, 0, 0, 0.05)';
ctx.fillRect(0, 0, canvas.width, canvas.height); ctx.fillRect(0, 0, canvas.width, canvas.height);
@@ -69,7 +71,17 @@
} }
setInterval(drawMatrix, 33); setInterval(drawMatrix, 33);
// Fetch API joke // Show server port
fetch(window.location.href, {method: 'HEAD'})
.then(r => {
document.getElementById('server-port').textContent =
'Server port: {{PORTNUMBER}}';
})
.catch(() => {
document.getElementById('server-port').textContent = 'Server port: unknown';
});
// Fetch random dad joke
fetch("https://icanhazdadjoke.com/", { fetch("https://icanhazdadjoke.com/", {
headers: { "Accept": "application/json" } headers: { "Accept": "application/json" }
}) })
@@ -94,4 +106,4 @@
}); });
</script> </script>
</body> </body>
</html> </html>
+16 -5
View File
@@ -1,8 +1,9 @@
import http.server import http.server
import socketserver import socketserver
import random import random
import os
PORT = 8080 PORT = int(os.getenv("PORT", 8080))
JOKES = [ JOKES = [
"Why do programmers prefer dark mode? Because light attracts bugs!", "Why do programmers prefer dark mode? Because light attracts bugs!",
@@ -60,17 +61,27 @@ JOKES = [
class JokeHandler(http.server.SimpleHTTPRequestHandler): class JokeHandler(http.server.SimpleHTTPRequestHandler):
def do_GET(self): def do_GET(self):
if self.path == "/" or self.path == "/index.html": 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_response(200)
self.send_header("Content-type", "text/html") self.send_header("Content-type", "text/html")
self.end_headers() self.end_headers()
with open("index.html", "r") as file:
html = file.read()
joke = random.choice(JOKES) joke = random.choice(JOKES)
html = html.replace("{{joke}}", joke) html = html.replace("{{joke}}", joke)
html = html.replace("{{PORTNUMBER}}", str(PORT))
self.wfile.write(html.encode("utf-8")) self.wfile.write(html.encode("utf-8"))
else: else:
self.send_error(404, "File not found") 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}") print(f"Serving at http://0.0.0.0:{PORT}")
httpd.serve_forever() with socketserver.TCPServer(("", PORT), JokeHandler) as httpd:
httpd.serve_forever()
+1 -1
View File
@@ -18,7 +18,7 @@ base.socketio = SocketIO(
app, app,
cors_allowed_origins="*", cors_allowed_origins="*",
ping_timeout=5, ping_timeout=5,
ping_interval=2 ping_interval=30
) )
# Import all socket event handlers # Import all socket event handlers