osbuild-composer: add a socket for Koji API

Add a systemd socket for Koji API. If enabled when osbuild-composer.service
is started, the service will also listen on the socket and serve Koji API
there.

Note that Koji API doesn't upload to Koji yet, this still needs to be hooked
up.

Based on a patch from Tom Gundersen, thanks!
This commit is contained in:
Ondřej Budai 2020-08-28 13:11:39 +02:00 committed by Tom Gundersen
parent 67e4182ba4
commit 91b86a1369
5 changed files with 132 additions and 25 deletions

View file

@ -0,0 +1,45 @@
// +build integration
package main
import (
"context"
"net/http"
"testing"
"github.com/osbuild/osbuild-composer/internal/kojiapi"
"github.com/stretchr/testify/require"
)
func TestKoji(t *testing.T) {
client, err := kojiapi.NewClientWithResponses("http://127.0.0.1:8701/")
if err != nil {
panic(err)
}
response, err := client.PostComposeWithResponse(context.Background(), kojiapi.PostComposeJSONRequestBody{
Distribution: "fedora-32",
ImageRequests: []kojiapi.ImageRequest{
{
Architecture: "x86_64",
ImageType: "qcow2",
Repositories: []kojiapi.Repository{
{
Baseurl: "http://download.fedoraproject.org/pub/fedora/linux/releases/32/Everything/x86_64/os/",
Gpgkey: "-----BEGIN PGP PUBLIC KEY BLOCK-----\n\nmQINBF1RVqsBEADWMBqYv/G1r4PwyiPQCfg5fXFGXV1FCZ32qMi9gLUTv1CX7rYy\nH4Inj93oic+lt1kQ0kQCkINOwQczOkm6XDkEekmMrHknJpFLwrTK4AS28bYF2RjL\nM+QJ/dGXDMPYsP0tkLvoxaHr9WTRq89A+AmONcUAQIMJg3JxXAAafBi2UszUUEPI\nU35MyufFt2ePd1k/6hVAO8S2VT72TxXSY7Ha4X2J0pGzbqQ6Dq3AVzogsnoIi09A\n7fYutYZPVVAEGRUqavl0th8LyuZShASZ38CdAHBMvWV4bVZghd/wDV5ev3LXUE0o\nitLAqNSeiDJ3grKWN6v0qdU0l3Ya60sugABd3xaE+ROe8kDCy3WmAaO51Q880ZA2\niXOTJFObqkBTP9j9+ZeQ+KNE8SBoiH1EybKtBU8HmygZvu8ZC1TKUyL5gwGUJt8v\nergy5Bw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5fu6xPqJdmGZRNjXtcyJlbSPVDIloxw==\n=QWRO\n-----END PGP PUBLIC KEY BLOCK-----\n",
},
},
},
},
})
require.NoError(t, err)
require.Equalf(t, http.StatusCreated, response.StatusCode(), "Error: got non-201 status. Full response: %v", string(response.Body))
require.NotNil(t, response.JSON201)
response2, err := client.GetComposeIdWithResponse(context.Background(), response.JSON201.Id)
require.NoError(t, err)
require.Equalf(t, response2.StatusCode(), 200, "Error: got non-200 status. Full response: %v", response2.Body)
}

View file

@ -13,6 +13,7 @@ import (
"github.com/osbuild/osbuild-composer/internal/distro/fedora32"
"github.com/osbuild/osbuild-composer/internal/distro/rhel8"
"github.com/osbuild/osbuild-composer/internal/jobqueue/fsjobqueue"
"github.com/osbuild/osbuild-composer/internal/kojiapi"
"github.com/osbuild/osbuild-composer/internal/common"
"github.com/osbuild/osbuild-composer/internal/distro"
@ -148,6 +149,24 @@ func main() {
common.PanicOnError(err)
}()
// Optionally run Koji API
if kojiListeners, exists := listeners["osbuild-composer-koji.socket"]; exists {
if len(kojiListeners) != 1 {
// Use Fatal to call os.Exit with non-zero return value
log.Fatal("The osbuild-composer-koji.socket unit is misconfigured. It should contain only one socket.")
}
kojiListener := kojiListeners[0]
kojiServer := kojiapi.NewServer(workers, rpm, distros)
go func() {
err = kojiServer.Serve(kojiListener)
// If the koji server fails, take down the whole process, not just a single goroutine
log.Fatal("osbuild-composer-koji.socket failed: ", err)
}()
}
if remoteWorkerListeners, exists := listeners["osbuild-remote-worker.socket"]; exists {
for _, listener := range remoteWorkerListeners {
log.Printf("Starting remote listener\n")