Skip to content

Commit

Permalink
Fix curl
Browse files Browse the repository at this point in the history
  • Loading branch information
james03160927 committed Jan 3, 2025
1 parent aa7a13c commit be52a7d
Show file tree
Hide file tree
Showing 10 changed files with 164 additions and 222 deletions.
216 changes: 103 additions & 113 deletions drip/api.gen.go

Large diffs are not rendered by default.

8 changes: 0 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,6 @@ github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y=
github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0=
Expand All @@ -221,8 +219,6 @@ github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
github.com/oapi-codegen/runtime v1.1.1 h1:EXLHh0DXIJnWhdRPN2w4MXAzFyE4CskzhNLUmtpMYro=
github.com/oapi-codegen/runtime v1.1.1/go.mod h1:SK9X900oXmPWilYR5/WKPzt3Kqxn/uS/+lbpREv+eCg=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.1.0-rc5 h1:Ygwkfw9bpDvs+c9E34SdgGOj41dX/cbdlwvlWt0pnFI=
Expand Down Expand Up @@ -251,10 +247,6 @@ github.com/shoenig/test v0.6.4 h1:kVTaSd7WLz5WZ2IaoM0RSzRsUD+m8wRR+5qvntpn4LU=
github.com/shoenig/test v0.6.4/go.mod h1:byHiCGXqrVaflBLAMq/srcZIHynQPQgeyvkvXnjqq0k=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad/go.mod h1:qLr4V1qq6nMqFKkMo8ZTx3f+BZEkzsRUY10Xsm2mwU0=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
Expand Down
3 changes: 1 addition & 2 deletions infrastructure/prod/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ provider "google" {
}

module "node_pack_extract_trigger" {
source = "../modules/node-pack-extract-trigger"
source = "../modules/node-pack-extract-trigger"
providers = {
google = google
}
Expand All @@ -23,5 +23,4 @@ module "node_pack_extract_trigger" {
cloud_build_service_account = "[email protected]"
topic_name = "comfy-registry-event"
registry_backend_url = "https://api.comfy.org"
backfill_job_name = "comfy-node-pack-backfill"
}
3 changes: 1 addition & 2 deletions infrastructure/staging/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ provider "google" {
}

module "node_pack_extract_trigger" {
source = "../modules/node-pack-extract-trigger"
source = "../modules/node-pack-extract-trigger"
providers = {
google = google
}
Expand All @@ -23,5 +23,4 @@ module "node_pack_extract_trigger" {
cloud_build_service_account = "[email protected]"
topic_name = "comfy-registry-event-staging"
registry_backend_url = "https://stagingapi.comfy.org"
backfill_job_name = "comfy-node-pack-backfill-staging"
}
11 changes: 0 additions & 11 deletions integration-tests/registry_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -976,17 +976,6 @@ func TestRegistryComfyNode(t *testing.T) {
}
})

t.Run("Conflict", func(t *testing.T) {
body := drip.CreateComfyNodesJSONRequestBody(comfyNodes)
res, err := withMiddleware(authz, impl.CreateComfyNodes)(ctx, drip.CreateComfyNodesRequestObject{
NodeId: *node.Id,
Version: *nodeVersion.Version,
Body: &body,
})
require.NoError(t, err)
require.IsType(t, drip.CreateComfyNodes409JSONResponse{}, res)
})

t.Run("GetNodeVersion", func(t *testing.T) {
res, err := withMiddleware(authz, impl.GetNodeVersion)(ctx, drip.GetNodeVersionRequestObject{
NodeId: *node.Id,
Expand Down
4 changes: 2 additions & 2 deletions node-pack-extract/cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ steps:
- -c
- gcloud auth print-identity-token --audiences="$_REGISTRY_BACKEND_URL" | tee /workspace/token

- name: "gcr.io/cloud-builders/curl"
entrypoint: "bash"
- name: "curlimages/curl"
entrypoint: "sh"
args:
- -c
- |
Expand Down
6 changes: 0 additions & 6 deletions openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1803,12 +1803,6 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'409':
description: Existing Comfy Nodes exists
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error
content:
Expand Down
36 changes: 14 additions & 22 deletions server/implementation/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package implementation

import (
"context"
"errors"
"registry-backend/drip"
"registry-backend/ent"
"registry-backend/ent/publisher"
Expand Down Expand Up @@ -727,12 +726,6 @@ func (s *DripStrictServerImplementation) InstallNode(

// Install node version
if request.Params.Version == nil {
s.MixpanelService.Track(ctx, []*mixpanel.Event{
s.MixpanelService.NewEvent("Install Node", "", map[string]any{
"Node ID": request.NodeId,
"Version": "latest",
}),
})
nodeVersion, err := s.RegistryService.GetLatestNodeVersion(ctx, s.Client, request.NodeId)
if err == nil && nodeVersion == nil {
log.Ctx(ctx).Error().Msgf("Latest node version not found")
Expand All @@ -743,19 +736,22 @@ func (s *DripStrictServerImplementation) InstallNode(
log.Ctx(ctx).Error().Msgf("Error retrieving latest node version w/ err: %v", err)
return drip.InstallNode500JSONResponse{Message: errMessage}, err
}

_, err = s.RegistryService.RecordNodeInstallation(ctx, s.Client, node)
_, err = s.RegistryService.RecordNodeInstalation(ctx, s.Client, node)
if err != nil {
errMessage := "Failed to get increment number of node version install: " + err.Error()
log.Ctx(ctx).Error().Msgf("Error incrementing number of latest node version install w/ err: %v", err)
return drip.InstallNode500JSONResponse{Message: errMessage}, err
}

s.MixpanelService.Track(ctx, []*mixpanel.Event{
s.MixpanelService.NewEvent("Install Node Latest", "", map[string]any{
"Node ID": request.NodeId,
"Version": nodeVersion.Version,
}),
})
return drip.InstallNode200JSONResponse(
*mapper.DbNodeVersionToApiNodeVersion(nodeVersion),
), nil
} else {

nodeVersion, err := s.RegistryService.GetNodeVersionByVersion(ctx, s.Client, request.NodeId, *request.Params.Version)
if ent.IsNotFound(err) {
log.Ctx(ctx).Error().Msgf("Error retrieving node version w/ err: %v", err)
Expand All @@ -766,18 +762,18 @@ func (s *DripStrictServerImplementation) InstallNode(
log.Ctx(ctx).Error().Msgf("Error retrieving node version w/ err: %v", err)
return drip.InstallNode500JSONResponse{Message: errMessage}, err
}
s.MixpanelService.Track(ctx, []*mixpanel.Event{
s.MixpanelService.NewEvent("Install Node", "", map[string]any{
"Node ID": request.NodeId,
"Version": request.Params.Version,
}),
})
_, err = s.RegistryService.RecordNodeInstallation(ctx, s.Client, node)
_, err = s.RegistryService.RecordNodeInstalation(ctx, s.Client, node)
if err != nil {
errMessage := "Failed to get increment number of node version install: " + err.Error()
log.Ctx(ctx).Error().Msgf("Error incrementing number of latest node version install w/ err: %v", err)
return drip.InstallNode500JSONResponse{Message: errMessage}, err
}
s.MixpanelService.Track(ctx, []*mixpanel.Event{
s.MixpanelService.NewEvent("Install Node", "", map[string]any{
"Node ID": request.NodeId,
"Version": nodeVersion.Version,
}),
})
return drip.InstallNode200JSONResponse(
*mapper.DbNodeVersionToApiNodeVersion(nodeVersion),
), nil
Expand Down Expand Up @@ -1027,10 +1023,6 @@ func (impl *DripStrictServerImplementation) CreateComfyNodes(ctx context.Context
log.Ctx(ctx).Error().Msgf("Node or node version not found w/ err: %v", err)
return drip.CreateComfyNodes404JSONResponse{Message: "Node or node version not found", Error: err.Error()}, nil
}
if errors.Is(err, drip_services.ErrComfyNodesAlreadyExist) {
log.Ctx(ctx).Error().Msgf("Comfy nodes for %s %s exist", request.NodeId, request.Version)
return drip.CreateComfyNodes409JSONResponse{Message: "Comfy nodes already exist", Error: err.Error()}, nil
}
if err != nil {
log.Ctx(ctx).Error().Msgf("Failed to create comfy nodes w/ err: %v", err)
return drip.CreateComfyNodes500JSONResponse{Message: "Failed to create comfy nodes", Error: err.Error()}, nil
Expand Down
1 change: 0 additions & 1 deletion server/middleware/authentication/firebase_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ func FirebaseAuthMiddleware(entClient *ent.Client) echo.MiddlewareFunc {
regexp.MustCompile(`^/publishers/[^/]+/nodes/[^/]+/ban$`): {"POST"},
regexp.MustCompile(`^/nodes/[^/]+/versions/[^/]+/comfy-nodes$`): {"POST"},
regexp.MustCompile(`^/nodes/[^/]+/versions/[^/]+/comfy-nodes/[^/]+$`): {"GET"},
regexp.MustCompile(`^/comfy-nodes/backfill$`): {"POST"},
}

return func(next echo.HandlerFunc) echo.HandlerFunc {
Expand Down
98 changes: 43 additions & 55 deletions services/registry/registry_svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ func (s *RegistryService) UpdateNodeVersion(ctx context.Context, client *ent.Cli
})
}

func (s *RegistryService) RecordNodeInstallation(ctx context.Context, client *ent.Client, node *ent.Node) (*ent.Node, error) {
func (s *RegistryService) RecordNodeInstalation(ctx context.Context, client *ent.Client, node *ent.Node) (*ent.Node, error) {
var n *ent.Node
err := db.WithTx(ctx, client, func(tx *ent.Tx) (err error) {
node, err = tx.Node.UpdateOne(node).AddTotalInstall(1).Save(ctx)
Expand Down Expand Up @@ -626,64 +626,52 @@ func (s *RegistryService) GetLatestNodeVersion(ctx context.Context, client *ent.
return nodeVersion, nil
}

var ErrComfyNodesAlreadyExist = errors.New("comfy nodes already exist")

func (s *RegistryService) CreateComfyNodes(ctx context.Context, client *ent.Client, nodeID string, nodeVersion string, comfyNodes map[string]drip.ComfyNode) (err error) {
return db.WithTx(ctx, client, func(tx *ent.Tx) error {
nv, err := client.NodeVersion.Query().
Where(nodeversion.VersionEQ(nodeVersion)).
Where(nodeversion.NodeIDEQ(nodeID)).
WithComfyNodes().
ForUpdate().
Only(ctx)
if err != nil {
return err
}

if len(nv.Edges.ComfyNodes) > 0 {
return ErrComfyNodesAlreadyExist
}
nv, err := client.NodeVersion.Query().
Where(nodeversion.VersionEQ(nodeVersion)).
Where(nodeversion.NodeIDEQ(nodeID)).Only(ctx)
if err != nil {
return err
}

comfyNodesCreates := make([]*ent.ComfyNodeCreate, 0, len(comfyNodes))
for k, n := range comfyNodes {
comfyNodeCreate := client.ComfyNode.Create().
SetID(k).
SetNodeVersionID(nv.ID)
comfyNodesCreates := make([]*ent.ComfyNodeCreate, 0, len(comfyNodes))
for k, n := range comfyNodes {
comfyNodeCreate := client.ComfyNode.Create().
SetID(k).
SetNodeVersionID(nv.ID)

if n.Category != nil {
comfyNodeCreate.SetCategory(*n.Category)
}
if n.Description != nil {
comfyNodeCreate.SetDescription(*n.Description)
}
if n.InputTypes != nil {
comfyNodeCreate.SetInputTypes(*n.InputTypes)
}
if n.Deprecated != nil {
comfyNodeCreate.SetDeprecated(*n.Deprecated)
}
if n.Experimental != nil {
comfyNodeCreate.SetExperimental(*n.Experimental)
}
if n.OutputIsList != nil {
comfyNodeCreate.SetOutputIsList(*n.OutputIsList)
}
if n.ReturnNames != nil {
comfyNodeCreate.SetReturnNames(*n.ReturnNames)
}
if n.ReturnTypes != nil {
comfyNodeCreate.SetReturnTypes(*n.ReturnTypes)
}
if n.Function != nil {
comfyNodeCreate.SetFunction(*n.Function)
}
comfyNodesCreates = append(comfyNodesCreates, comfyNodeCreate)
if n.Category != nil {
comfyNodeCreate.SetCategory(*n.Category)
}
return client.ComfyNode.
CreateBulk(comfyNodesCreates...).
Exec(ctx)
})

if n.Description != nil {
comfyNodeCreate.SetDescription(*n.Description)
}
if n.InputTypes != nil {
comfyNodeCreate.SetInputTypes(*n.InputTypes)
}
if n.Deprecated != nil {
comfyNodeCreate.SetDeprecated(*n.Deprecated)
}
if n.Experimental != nil {
comfyNodeCreate.SetExperimental(*n.Experimental)
}
if n.OutputIsList != nil {
comfyNodeCreate.SetOutputIsList(*n.OutputIsList)
}
if n.ReturnNames != nil {
comfyNodeCreate.SetReturnNames(*n.ReturnNames)
}
if n.ReturnTypes != nil {
comfyNodeCreate.SetReturnTypes(*n.ReturnTypes)
}
if n.Function != nil {
comfyNodeCreate.SetFunction(*n.Function)
}
comfyNodesCreates = append(comfyNodesCreates, comfyNodeCreate)
}
return client.ComfyNode.
CreateBulk(comfyNodesCreates...).
Exec(ctx)
}

func (s *RegistryService) GetComfyNode(ctx context.Context, client *ent.Client, nodeID string, nodeVersion string, comfyNodeID string) (*ent.ComfyNode, error) {
Expand Down

0 comments on commit be52a7d

Please sign in to comment.