feat: add initial port mapping example - #435
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new port-mapping/ example demonstrating how to expose an internal HTTP service (port 8080) via Unikraft Cloud port mapping to external 443 over TLS/HTTP, including both kraft CLI and direct API workflows.
Changes:
- Introduces a minimal Python HTTP server plus container/Kraft packaging files for deployment.
- Adds a step-by-step README covering deploy/operate flows via
kraftCLI and via API helper scripts. - Adds configuration templates (
ukc.config.template,app.config) and API shell scripts for instance/image operations.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| port-mapping/ukc.config.template | Adds UKC user/token/metro config template and derived UKC_API base URL. |
| port-mapping/server.py | Adds a minimal HTTP server that listens on port 8080. |
| port-mapping/README.md | Documents CLI + API workflows for port mapping example. |
| port-mapping/Kraftfile | Defines Unikraft Cloud runtime, rootfs build, and command. |
| port-mapping/Dockerfile | Builds a Python slim OCI image containing the server. |
| port-mapping/app.config | Adds shared env vars for image/instance naming and port mapping. |
| port-mapping/api/stop-instance.sh | Adds API helper script to stop an instance. |
| port-mapping/api/start-instance.sh | Adds API helper script to start an instance. |
| port-mapping/api/query.sh | Adds API helper script to discover FQDN and query the service. |
| port-mapping/api/push-image.sh | Adds API workflow helper to push a packaged image. |
| port-mapping/api/pkg-image.sh | Adds API workflow helper to package an image. |
| port-mapping/api/get-instance-info.sh | Adds API helper script to list instance info. |
| port-mapping/api/delete-instance.sh | Adds API helper script to delete an instance. |
| port-mapping/api/create-instance.sh | Adds API helper script to create an instance with explicit port mapping. |
| port-mapping/.gitignore | Prevents committing the real ukc.config file. |
馃挕 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
72ee4d2 to
42f510b
Compare
Roxanacmaria
left a comment
There was a problem hiding this comment.
I reviewed the implementation and tested it on my side. Everything worked as expected, and I was able to follow the implementation without any issues. The code is clear, the documentation is easy to understand, and I did not encounter any problems while running the project.
Looks good to me. Nice work!
Dan-Andrei-Simionescu
left a comment
There was a problem hiding this comment.
I went through the code and tested the functionality locally. Everything behaves as intended. The code structure is clean, the instructions provided in the documentation are straightforward to follow.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 15 out of 15 changed files in this pull request and generated 4 comments.
Suppressed comments (10)
port-mapping/README.md:72
kraft cloud instance get -o jsonreturns the instance list directly, and its CLI representation exposes the address as.fqdn(as inbasic-ops/README.md:326); it does not have the API wrapper.data.instances[]or.service_group.domains. This filter therefore produces no hostname and the followingcurlcannot query the app. Use the CLI-shaped filter here.
fqdn=https://$(kraft cloud instance get port-mapping-demo -o json 2>/dev/null | jq -r '.data.instances[] | select(.name == "port-mapping-demo") | .service_group.domains[0].fqdn')
port-mapping/README.md:16
- The overview promises instance-log retrieval as part of both the CLI and API workflows, but this change adds no
api/get-instance-logs.shand the API command lists contain no log request. As written, the API example cannot perform one of the advertised operations; add the API log operation or narrow the claim.
- getting logs from an instance
port-mapping/README.md:74
-kdisables TLS certificate verification for the HTTPS service, so this copy-paste command accepts a man-in-the-middle endpoint and undermines the security that thetls+httpmapping is meant to demonstrate. Use normal certificate validation here, or clearly scope an exception to a known test certificate.
curl -k "$fqdn"
port-mapping/api/create-instance.sh:31
- This pipes
curldirectly intojq, so the pipeline returnsjq's status rather thancurl's. A connection failure therefore produces an apparently successful script with no error output, allowing the documented deployment flow to continue as if instance creation succeeded; capture and check thecurlstatus before parsing.
}" | jq
port-mapping/api/delete-instance.sh:24
- Although this tests the
curlresult, the finalrm -f out errbecomes the script's exit status, so a failed delete request is reported as success. Preserve the status before cleanup and exit with it so callers can detect the failure.
if test $? -ne 0; then
cat err 1>&2
else
cat out | jq
fi
port-mapping/api/get-instance-info.sh:17
- Although this tests the
curlresult, the finalrm -f out errbecomes the script's exit status, so network or JSON-processing failures are reported as success. Preserve the status before cleanup and exit with it; otherwisequery.shand callers cannot detect a failed request.
if test $? -ne 0; then
cat err 1>&2
else
cat out | jq
fi
port-mapping/api/query.sh:8
- The API query helper disables TLS certificate verification with
-k, so its copy-paste output accepts a man-in-the-middle endpoint even though it is querying the HTTPS service. Remove the bypass or make it an explicitly documented test-only option.
curl -k "$fqdn"
port-mapping/api/start-instance.sh:20
- Although this tests the
curlresult, the finalrm -f out errbecomes the script's exit status, so a failed start request is reported as success. Preserve the status before cleanup and exit with it so the documented workflow can detect the failure.
if test $? -ne 0; then
cat err 1>&2
else
cat out | jq
fi
port-mapping/api/stop-instance.sh:20
- Although this tests the
curlresult, the finalrm -f out errbecomes the script's exit status, so a failed stop request is reported as success. Preserve the status before cleanup and exit with it so the documented workflow can detect the failure.
if test $? -ne 0; then
cat err 1>&2
else
cat out | jq
fi
port-mapping/server.py:20
- This new example has no end-to-end test, although
TESTING.mdstates that each example owns atest_<example>.pyand the analogous Python HTTP example is covered. Add a test that builds this image, deploys443:8080/tls+http, and asserts the response so regressions in the port mapping and entrypoint are exercised.
server = HTTPServer(("0.0.0.0", 8080), Handler)
| \"image\": \"${UKC_USER}/${IMAGE_NAME}:latest\", | ||
| \"memory_mb\": ${MEMORY_MB}, | ||
| \"vcpus\": ${VCPUS}, | ||
| \"autostart\": true, |
| . ./ukc.config | ||
| . ./app.config | ||
|
|
||
| kraft pkg push index.unikraft.io/"${UKC_USER}"/"${IMAGE_NAME}" . |
| -H "Content-Type: application/json" \ | ||
| "${UKC_API}/instances/start" \ | ||
| -d "{ | ||
| \"name\": \"${INSTANCE_NAME}\", |
| -H "Content-Type: application/json" \ | ||
| "${UKC_API}/instances/stop" \ | ||
| -d "{ | ||
| \"name\": \"${INSTANCE_NAME}\", |
No description provided.