Compare commits

...

3 Commits

Author SHA1 Message Date
restitux 4a4b6fd185 Add basic graphql api 2023-01-14 06:02:17 -07:00
restitux 30fed27126 Refactor pipeline api lister to inside listen 2023-01-14 01:35:29 -07:00
restitux b58b1ab5d9 Update go modules 2023-01-14 01:35:19 -07:00
9 changed files with 467 additions and 34 deletions
+214
View File
@@ -0,0 +1,214 @@
package admin_api
import (
"fmt"
"net/http"
"git.ohea.xyz/cursorius/server/database"
"github.com/google/uuid"
"github.com/graphql-go/graphql"
"github.com/graphql-go/handler"
)
func createSchema(db database.Database) (graphql.Schema, error) {
webhookType := graphql.NewObject(graphql.ObjectConfig{
Name: "Webhook",
Description: "A webhook for triggering pipelines",
Fields: graphql.Fields{
"id": &graphql.Field{
Type: graphql.NewNonNull(graphql.String),
Description: "The id of the webhook.",
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
if webhook, ok := p.Source.(database.Webhook); ok {
return webhook.Id, nil
}
return nil, nil
},
},
"serverType": &graphql.Field{
Type: graphql.NewNonNull(graphql.String),
Description: "The format of the webhook.",
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
if webhook, ok := p.Source.(database.Webhook); ok {
return webhook.ServerType, nil
}
return nil, nil
},
},
"secret": &graphql.Field{
Type: graphql.NewNonNull(graphql.String),
Description: "The secret used to validate the webhook.",
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
if webhook, ok := p.Source.(database.Webhook); ok {
return webhook.Secret, nil
}
return nil, nil
},
},
},
})
pipelineType := graphql.NewObject(graphql.ObjectConfig{
Name: "Pipeline",
Description: "A pipeline for running ci jobs",
Fields: graphql.Fields{
"id": &graphql.Field{
Type: graphql.NewNonNull(graphql.String),
Description: "The id of the pipeline.",
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
if pipeline, ok := p.Source.(database.Pipeline); ok {
return pipeline.Id, nil
}
return nil, nil
},
},
"name": &graphql.Field{
Type: graphql.NewNonNull(graphql.String),
Description: "The name of the pipeline.",
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
if pipeline, ok := p.Source.(database.Pipeline); ok {
return pipeline.Name, nil
}
return nil, nil
},
},
"url": &graphql.Field{
Type: graphql.NewNonNull(graphql.String),
Description: "The url of the pipeline.",
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
if pipeline, ok := p.Source.(database.Pipeline); ok {
return pipeline.Url, nil
}
return nil, nil
},
},
"pollInterval": &graphql.Field{
Type: graphql.NewNonNull(graphql.Int),
Description: "The polling interval for the pipeline.",
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
if pipeline, ok := p.Source.(database.Pipeline); ok {
return pipeline.PollInterval, nil
}
return nil, nil
},
},
"createWebhook": &graphql.Field{
Type: webhookType,
Description: "Create a new webhook",
Args: graphql.FieldConfigArgument{
"type": &graphql.ArgumentConfig{
Type: graphql.NewNonNull(graphql.String),
},
},
Resolve: func(params graphql.ResolveParams) (interface{}, error) {
webhook, err := db.CreateWebhook(
database.WebhookSender(params.Args["type"].(string)),
params.Source.(database.Pipeline).Id,
)
if err != nil {
return nil, err
}
return webhook, nil
},
},
"webhooks": &graphql.Field{
Type: graphql.NewNonNull(graphql.NewList(graphql.NewNonNull(webhookType))),
Description: "The list of webhooks for the pipeline.",
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
if pipeline, ok := p.Source.(database.Pipeline); ok {
return db.GetWebhooksForPipeline(pipeline.Id)
}
return []database.Webhook{}, nil
},
},
},
})
queryType := graphql.NewObject(graphql.ObjectConfig{
Name: "Query",
Fields: graphql.Fields{
"Pipeline": &graphql.Field{
Type: pipelineType,
Args: graphql.FieldConfigArgument{
"id": &graphql.ArgumentConfig{
Type: graphql.NewNonNull(graphql.String),
Description: "The id of the requested pipeline.",
},
},
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
id, err := uuid.Parse(p.Args["id"].(string))
if err != nil {
return nil, err
}
return db.GetPipelineById(id)
},
},
},
})
mutationType := graphql.NewObject(graphql.ObjectConfig{
Name: "Mutation",
Fields: graphql.Fields{
"createPipeline": &graphql.Field{
Type: pipelineType,
Description: "Create a new pipeline",
Args: graphql.FieldConfigArgument{
"name": &graphql.ArgumentConfig{
Type: graphql.NewNonNull(graphql.String),
},
"url": &graphql.ArgumentConfig{
Type: graphql.NewNonNull(graphql.String),
},
"pollInterval": &graphql.ArgumentConfig{
Type: graphql.Int,
},
},
Resolve: func(params graphql.ResolveParams) (interface{}, error) {
var interval int
if intervalVal, ok := params.Args["pollInterval"]; ok {
interval = intervalVal.(int)
} else {
interval = 0
}
pipeline, err := db.CreatePipeline(
params.Args["name"].(string),
params.Args["url"].(string),
interval,
)
if err != nil {
return nil, err
}
return pipeline, nil
},
},
},
})
schema, err := graphql.NewSchema(graphql.SchemaConfig{
Query: queryType,
Mutation: mutationType,
})
if err != nil {
return schema, fmt.Errorf("Could not create schema: %w", err)
}
return schema, nil
}
func CreateHandler(db database.Database, mux *http.ServeMux) error {
schema, err := createSchema(db)
if err != nil {
return err
}
h := handler.New(&handler.Config{
Schema: &schema,
Pretty: true,
GraphiQL: true,
})
mux.Handle("/graphql", h)
return nil
}
+18 -16
View File
@@ -18,7 +18,7 @@ type Database struct {
Conn *pgx.Conn
}
func LaunchDB(conf config.DBConfig) error {
func LaunchDB(conf config.DBConfig) (Database, error) {
dbURL := fmt.Sprintf(
"postgres://%v:%v@%v:%v/%v",
@@ -50,7 +50,7 @@ func LaunchDB(conf config.DBConfig) error {
}
if err != nil {
return fmt.Errorf("Could not open database: %w", err)
return db, fmt.Errorf("Could not open database: %w", err)
}
log.Infof("Database connected sucessfully!")
@@ -64,7 +64,7 @@ SELECT EXISTS (
var versionTableExists bool
err = db.Conn.QueryRow(context.Background(), versionTableExistsQuery).Scan(&versionTableExists)
if err != nil {
return fmt.Errorf("Could not check if database was initalized: %w", err)
return db, fmt.Errorf("Could not check if database was initalized: %w", err)
}
if versionTableExists {
@@ -73,31 +73,33 @@ SELECT EXISTS (
log.Info("New database found, initializing....")
err = initDB(db.Conn)
if err != nil {
return fmt.Errorf("Could not initalize database: %w", err)
return db, fmt.Errorf("Could not initalize database: %w", err)
}
}
return nil
return db, nil
}
func initDB(conn *pgx.Conn) error {
createTablesQuery := `
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE TABLE version (
version INT NOT NULL
);
CREATE TABLE pipelines (
id SERIAL PRIMARY KEY,
id UUID PRIMARY KEY,
name TEXT NOT NULL,
url TEXT NOT NULL,
poll_interval INTEGER
);
CREATE TABLE webhooks (
id SERIAL PRIMARY KEY,
type TEXT,
secret TEXT,
pipeline INTEGER,
id UUID PRIMARY KEY,
server_type TEXT,
secret TEXT,
pipeline UUID,
CONSTRAINT fk_pipeline
FOREIGN KEY(pipeline)
@@ -105,14 +107,14 @@ CREATE TABLE webhooks (
);
CREATE TABLE runners (
id SERIAL PRIMARY KEY,
id UUID PRIMARY KEY,
name TEXT,
secret TEXT
);
CREATE TABLE runs (
id SERIAL PRIMARY KEY,
pipeline SERIAL,
id UUID PRIMARY KEY,
pipeline UUID,
result BOOLEAN NOT NULL,
CONSTRAINT fk_pipeline
@@ -121,10 +123,10 @@ CREATE TABLE runs (
);
CREATE TABLE command_executions (
id SERIAL PRIMARY KEY,
run_id SERIAL,
id UUID PRIMARY KEY,
run_id UUID,
command TEXT,
return_code TEXT,
return_code INT,
stdout TEXT,
stderr TEXT,
start_time TIMESTAMP,
+124
View File
@@ -0,0 +1,124 @@
package database
import (
"context"
"fmt"
"github.com/google/uuid"
)
func (d *Database) GetPipelineById(id uuid.UUID) (Pipeline, error) {
query := `
SELECT name, url, poll_interval
FROM pipelines
WHERE id=$1;`
pipeline := Pipeline{
Id: id,
}
err := d.Conn.QueryRow(context.Background(), query, id).Scan(&pipeline.Name, &pipeline.Url, &pipeline.PollInterval)
if err != nil {
return pipeline, fmt.Errorf("Could not query database for pipeline with id %v: %w", id.String(), err)
}
return pipeline, nil
}
func (d *Database) CreatePipeline(name string, url string, pollInterval int) (Pipeline, error) {
query := `
INSERT INTO pipelines (id, name, url, poll_interval)
VALUES (uuid_generate_v4(), $1, $2, $3)
RETURNING id, name, url, poll_interval;`
pipeline := Pipeline{}
var idStr string
err := d.Conn.QueryRow(context.Background(), query, name, url, pollInterval).Scan(&idStr, &pipeline.Name, &pipeline.Url, &pipeline.PollInterval)
if err != nil {
return pipeline, err
}
id, err := uuid.Parse(idStr)
if err != nil {
return pipeline, err
}
pipeline.Id = id
return pipeline, nil
}
func (db *Database) GetWebhooksForPipeline(id uuid.UUID) ([]Webhook, error) {
query := `
SELECT id, server_type, secret
FROM webhooks
WHERE pipeline=$1;`
webhooks := make([]Webhook, 0)
rows, err := db.Conn.Query(context.Background(), query, id)
if err != nil {
log.Fatal(err)
}
defer rows.Close()
for rows.Next() {
var webhook Webhook
var idStr string
if err := rows.Scan(&idStr, &webhook.ServerType, &webhook.Secret); err != nil {
return webhooks, err
}
webhook.Id, err = uuid.Parse(idStr)
if err != nil {
return webhooks, err
}
webhooks = append(webhooks, webhook)
}
return webhooks, nil
}
func (d *Database) GetWebhookById(id uuid.UUID) (Webhook, error) {
query := `
SELECT server_type, secret, pipeline
FROM webhooks
WHERE id=$1;`
webhook := Webhook{
Id: id,
}
err := d.Conn.QueryRow(context.Background(), query, id).Scan(&webhook.ServerType, &webhook.Secret, &webhook.Pipeline)
if err != nil {
return webhook, fmt.Errorf("Could not query database for webhook with id %v: %w", id.String(), err)
}
return webhook, nil
}
func (d *Database) CreateWebhook(serverType WebhookSender, pipelineId uuid.UUID) (Webhook, error) {
//WITH secret_val as (select substr(md5(random()::text), 0, 50)),
query := `
INSERT INTO webhooks (id, server_type, secret, pipeline)
VALUES (uuid_generate_v4(), $1, (select substr(md5(random()::text), 0, 50)), $2)
RETURNING id, server_type, secret, pipeline;`
webhook := Webhook{}
var idStr string
err := d.Conn.QueryRow(context.Background(), query, string(serverType), pipelineId).Scan(&idStr, &webhook.ServerType, &webhook.Secret, &webhook.Pipeline)
if err != nil {
return webhook, err
}
id, err := uuid.Parse(idStr)
if err != nil {
return webhook, err
}
webhook.Id = id
return webhook, nil
}
+50
View File
@@ -0,0 +1,50 @@
package database
import (
"time"
"github.com/google/uuid"
)
type Pipeline struct {
Id uuid.UUID
Name string
Url string
PollInterval int
}
type WebhookSender string
const (
Gitea WebhookSender = "gitea"
)
type Webhook struct {
Id uuid.UUID
ServerType WebhookSender
Secret string
Pipeline uuid.UUID
}
type Runner struct {
Id uuid.UUID
Name string
Secret string
}
type Run struct {
Id uuid.UUID
Pipeline uuid.UUID
Result bool
}
type CommandExecution struct {
Id uuid.UUID
RunId uuid.UUID
Command string
ReturnCode int
Stdout string
Stderr string
StartTime time.Time
EndTime time.Time
}
+3 -1
View File
@@ -11,6 +11,8 @@ require (
github.com/go-git/go-git/v5 v5.4.3-0.20220529141257-bc1f419cebcf
github.com/go-playground/webhooks/v6 v6.0.1
github.com/google/uuid v1.3.0
github.com/graphql-go/graphql v0.8.0
github.com/graphql-go/handler v0.2.3
github.com/jackc/pgx/v5 v5.2.0
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7
golang.org/x/net v0.2.0
@@ -27,7 +29,6 @@ require (
github.com/docker/distribution v2.8.1+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/doug-martin/goqu/v9 v9.18.0 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/go-git/gcfg v1.5.0 // indirect
github.com/go-git/go-billy/v5 v5.3.1 // indirect
@@ -50,6 +51,7 @@ require (
github.com/pkg/errors v0.9.1 // indirect
github.com/sergi/go-diff v1.2.0 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/stretchr/testify v1.8.1 // indirect
github.com/xanzy/ssh-agent v0.3.2 // indirect
golang.org/x/crypto v0.2.1-0.20221112162523-6fad3dfc1891 // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
+7 -4
View File
@@ -111,7 +111,6 @@ github.com/Azure/go-autorest v12.0.0+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSW
github.com/Azure/go-ntlmssp v0.0.0-20220621081337-cb9428e4ac1e/go.mod h1:chxPXzSsl7ZWRAuOIE23GDNzjWuZquvFlgA8xmpunjU=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/GeertJohan/go.incremental v1.0.0/go.mod h1:6fAjUhbVuX1KcMD3c8TEgVUqmo4seqhv0i0kdATSkM0=
github.com/GeertJohan/go.rice v1.0.2/go.mod h1:af5vUNlDNkCjOZeSGFgIJxDje9qdjsO6hshx0gTmZt4=
@@ -361,8 +360,6 @@ github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKoh
github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec=
github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw=
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/doug-martin/goqu/v9 v9.18.0 h1:/6bcuEtAe6nsSMVK/M+fOiXUNfyFF3yYtE07DBPFMYY=
github.com/doug-martin/goqu/v9 v9.18.0/go.mod h1:nf0Wc2/hV3gYK9LiyqIrzBEVGlI8qW3GuDCEobC4wBQ=
github.com/dsnet/compress v0.0.2-0.20210315054119-f66993602bf5/go.mod h1:qssHWj60/X5sZFNxpG4HBPDHVqxNm4DfnCKgrbZOT+s=
github.com/dsnet/golib v0.0.0-20171103203638-1ea166775780/go.mod h1:Lj+Z9rebOhdfkVLjJ8T6VcRQv3SXugXy999NBtR9aFY=
github.com/duo-labs/webauthn v0.0.0-20220815211337-00c9fb5711f5/go.mod h1:Jcj7rFNlTknb18v9jpSA58BveX2LDhXqaoy+6YV1N9g=
@@ -712,6 +709,10 @@ github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoA
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/graphql-go/graphql v0.8.0 h1:JHRQMeQjofwqVvGwYnr8JnPTY0AxgVy1HpHSGPLdH0I=
github.com/graphql-go/graphql v0.8.0/go.mod h1:nKiHzRM0qopJEwCITUuIsxk9PlVlwIiiI8pnJEhordQ=
github.com/graphql-go/handler v0.2.3 h1:CANh8WPnl5M9uA25c2GBhPqJhE53Fg0Iue/fRNla71E=
github.com/graphql-go/handler v0.2.3/go.mod h1:leLF6RpV5uZMN1CdImAxuiayrYYhOk33bZciaUGaXeU=
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
github.com/grpc-ecosystem/go-grpc-middleware v1.2.2/go.mod h1:EaizFBKfUKtMIF5iaDEhniwNedqGo9FuLFzppDr3uwI=
@@ -1304,6 +1305,7 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v0.0.0-20170130113145-4d4bfba8f1d1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
@@ -1313,8 +1315,9 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/subosito/gotenv v1.3.0/go.mod h1:YzJjq/33h7nrwdY+iHMhEOEEbW0ovIz0tB6t6PwAXzs=
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
+40 -7
View File
@@ -4,7 +4,10 @@ import (
"fmt"
"net/http"
"git.ohea.xyz/cursorius/server/admin_api"
"git.ohea.xyz/cursorius/server/config"
"git.ohea.xyz/cursorius/server/database"
"git.ohea.xyz/cursorius/server/pipeline_api"
"git.ohea.xyz/cursorius/server/runnermanager"
"git.ohea.xyz/cursorius/server/webhook"
"github.com/op/go-logging"
@@ -15,10 +18,23 @@ import (
var log = logging.MustGetLogger("cursorius-server")
func setupHTTPServer(mux *http.ServeMux, registerCh chan runnermanager.RunnerRegistration,
conf config.Config) {
func setupHTTPServer(
mux *http.ServeMux,
conf config.Config,
db database.Database,
registerCh chan runnermanager.RunnerRegistration,
getRunnerCh chan runnermanager.GetRunnerRequest,
) error {
webhook.CreateWebhookHandler(conf, mux)
pipeline_api.CreateHandler(getRunnerCh, mux)
err := admin_api.CreateHandler(db, mux)
if err != nil {
return fmt.Errorf("Could not create admin api handler: %w", err)
}
mux.HandleFunc("/runner", func(w http.ResponseWriter, r *http.Request) {
conn, err := websocket.Accept(w, r, nil)
if err != nil {
@@ -27,17 +43,34 @@ func setupHTTPServer(mux *http.ServeMux, registerCh chan runnermanager.RunnerReg
}
go runnermanager.RegisterRunner(conn, registerCh)
})
return nil
}
func Listen(mux *http.ServeMux, address string, port int, registerCh chan runnermanager.RunnerRegistration, conf config.Config) {
func Listen(
mux *http.ServeMux,
address string,
port int,
conf config.Config,
db database.Database,
registerCh chan runnermanager.RunnerRegistration,
getRunnerCh chan runnermanager.GetRunnerRequest,
) error {
setupHTTPServer(mux, registerCh, conf)
err := setupHTTPServer(
mux,
conf,
db,
registerCh,
getRunnerCh,
)
if err != nil {
return fmt.Errorf("Could not setup http endpoints: %w", err)
}
connect_string := fmt.Sprintf("%v:%v", address, port)
log.Noticef("Launching HTTP server on %v\n", connect_string)
log.Fatal(http.ListenAndServe(
return http.ListenAndServe(
connect_string,
h2c.NewHandler(mux, &http2.Server{}),
))
)
}
+10 -5
View File
@@ -7,7 +7,6 @@ import (
"git.ohea.xyz/cursorius/server/config"
"git.ohea.xyz/cursorius/server/database"
"git.ohea.xyz/cursorius/server/listen"
"git.ohea.xyz/cursorius/server/pipeline_api"
"git.ohea.xyz/cursorius/server/poll"
"git.ohea.xyz/cursorius/server/runnermanager"
"github.com/op/go-logging"
@@ -35,7 +34,7 @@ func main() {
return
}
err = database.LaunchDB(configData.Config.DBConfig)
db, err := database.LaunchDB(configData.Config.DBConfig)
if err != nil {
log.Errorf("Could not launch db: %v", err)
return
@@ -51,7 +50,13 @@ func main() {
mux := http.NewServeMux()
pipeline_api.CreateHandler(mux, getRunnerCh)
listen.Listen(mux, configData.Config.Address, configData.Config.Port, registerCh, configData.Config)
log.Fatal(listen.Listen(
mux,
configData.Config.Address,
configData.Config.Port,
configData.Config,
db,
registerCh,
getRunnerCh,
))
}
+1 -1
View File
@@ -144,7 +144,7 @@ func (s *ApiServer) RunCommand(
return res, nil
}
func CreateHandler(mux *http.ServeMux, getRunnerCh chan runnermanager.GetRunnerRequest) {
func CreateHandler(getRunnerCh chan runnermanager.GetRunnerRequest, mux *http.ServeMux) {
api_server := &ApiServer{
getRunnerCh: getRunnerCh,
allocatedRunners: make(map[uuid.UUID]*RunnerWrapper),