container.scm 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. (library (container)
  2. (export /containers/json
  3. /containers/create)
  4. (import (rnrs base)
  5. (only (guile)
  6. lambda* λ)
  7. (web client)
  8. (web uri)
  9. (json)
  10. (ice-9 iconv)
  11. (list-helpers)
  12. (rnrs enums)
  13. (api-utils)
  14. (srfi srfi-1)))
  15. (define-api-route /containers/json GET application/x-www-form-urlencoded)
  16. (define-api-route /containers/create POST application/json)
  17. ;; REF: https://docs.docker.com/engine/api/v1.38/#operation/ContainerList
  18. ;; (define* (/containers/json dock-sock #:key (data #f))
  19. ;; (call-with-values
  20. ;; (lambda ()
  21. ;; (http-get "/containers/json"
  22. ;; #:port dock-sock
  23. ;; #:version '(1 . 1)
  24. ;; #:keep-alive? #f
  25. ;; #:headers '((host . ("localhost" . #f))
  26. ;; (content-type . (application/x-www-form-urlencoded (charset . "utf-8"))))
  27. ;; #:body (scm->json-string data)
  28. ;; #:decode-body? #t
  29. ;; #:streaming? #f))
  30. ;; (lambda (response response-text)
  31. ;; (let ([resp-text-as-string (bytevector->string response-text "utf-8")])
  32. ;; (cons response resp-text-as-string)))))
  33. ;; (define* (/containers/create dock-sock data)
  34. ;; (call-with-values
  35. ;; (lambda ()
  36. ;; (http-post "/containers/create"
  37. ;; #:port dock-sock
  38. ;; #:body (scm->json-string data)
  39. ;; ;; dockerd uses HTTP 1.1 it seems.
  40. ;; ;; other values will result in: "Bad Request: unsupported protocol version"
  41. ;; #:version '(1 . 1)
  42. ;; #:keep-alive? #f
  43. ;; ;; Apparently the `host` header must be specified.
  44. ;; ;; The `host` header in this case is ("localhost" . #f).
  45. ;; ;; The `host` header contains domain and port
  46. ;; #:headers '((host . ("localhost" . #f))
  47. ;; (content-type . (application/json (charset . "utf-8"))))
  48. ;; #:decode-body? #t
  49. ;; #:streaming? #f))
  50. ;; (lambda (response response-text)
  51. ;; (display
  52. ;; (simple-format #f
  53. ;; "RESPONSE TEXT: ~s"
  54. ;; (bytevector->string response-text "utf-8")))
  55. ;; (let ([resp-text-as-string (bytevector->string response-text "utf-8")])
  56. ;; (cons response resp-text-as-string)))))