cloudapi: Listen on /run/cloudapi/api.socket

Add a local socket for communicating with the cloudapi. It is started by
osbuild-composer.socket and is located at /run/cloudapi/api.socket

cloudapi requests can be passed to it using curl like this:

curl -k --unix-socket /run/cloudapi/api.socket --header 'Content-Type: application/json' \
--data request.json http://localhost/api/image-builder-composer/v2/compose

A simple request.json looks like this:

{
  "distribution": "fedora-38",
  "image_request":
    {
      "architecture": "x86_64",
      "image_type": "guest-image",
      "upload_options": {},
      "repositories": [
          {
            "name": "fedora",
            "metalink": "https://mirrors.fedoraproject.org/metalink?repo=fedora-38&arch=x86_64",
            "check_gpg": false
          },
          {
            "name": "updates",
            "metalink": "https://mirrors.fedoraproject.org/metalink?repo=updates-released-f38&arch=x86_64",
            "check_gpg": false
          }
      ]
    }
}
This commit is contained in:
Brian C. Lane 2023-07-13 08:19:27 -07:00 committed by Sanne Raymaekers
parent 6735e74897
commit ea05f400e6
2 changed files with 9 additions and 2 deletions

View file

@ -91,14 +91,20 @@ func main() {
}
if l, exists := listeners["osbuild-composer.socket"]; exists {
if len(l) != 1 {
logrus.Fatal("The osbuild-composer.socket unit is misconfigured. It should contain only one socket.")
if len(l) != 2 {
logrus.Fatal("The osbuild-composer.socket unit is misconfigured. It should contain two sockets.")
}
err = composer.InitWeldr(repositoryConfigs, l[0], config.weldrDistrosImageTypeDenyList())
if err != nil {
logrus.Fatalf("Error initializing weldr API: %v", err)
}
// Start cloudapi using the 2nd socket and no certs
err = composer.InitAPI(ServerCertFile, ServerKeyFile, false, false, false, l[1])
if err != nil {
logrus.Fatalf("Error initializing Cloud API using local socket: %v", err)
}
}
if l, exists := listeners["osbuild-local-worker.socket"]; exists {

View file

@ -3,6 +3,7 @@ Description=OSBuild Composer Weldr API socket
[Socket]
ListenStream=/run/weldr/api.socket
ListenStream=/run/cloudapi/api.socket
SocketGroup=weldr
SocketMode=660