Skip to content

Commit

Permalink
feat: add Client function to create custom image service (#100)
Browse files Browse the repository at this point in the history
<!-- Thank you for opening a PR! We really appreciate you taking the
time to help out 🙌 -->

#### Description (required)
Add `Client` function `CreateCustomService` to create custom image
service

<!-- Please describe the change you are proposing, and why -->

#### Related issues & labels (optional)

- Closes #<!-- Add an issue number if this PR will close it. -->
- Suggested label: <!-- Help us triage by suggesting one of our labels
that describes your PR -->
  • Loading branch information
yuaanlin authored Jun 6, 2024
2 parents e7c6288 + f76f6e1 commit 119c03d
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/api/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ type (
SuspendService(ctx context.Context, id string, environmentID string) error
ExposeService(ctx context.Context, id string, environmentID string, projectID string, name string) (*model.TempTCPPort, error)
CreatePrebuiltService(ctx context.Context, projectID string, marketplaceCode string) (*model.Service, error)
CreatePrebuiltServiceCustom(ctx context.Context, projectID string, schema model.ServiceSpecSchemaInput) (*model.Service, error)
CreatePrebuiltServiceRaw(ctx context.Context, projectID string, rawSchema string) (*model.Service, error)
CreateService(ctx context.Context, projectID string, name string, repoID int, branchName string) (*model.Service, error)
CreateEmptyService(ctx context.Context, projectID string, name string) (*model.Service, error)
UploadZipToService(ctx context.Context, projectID string, serviceID string, environmentID string, zipBytes []byte) (*model.Service, error)
Expand Down
34 changes: 34 additions & 0 deletions pkg/api/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,40 @@ func (c *client) CreatePrebuiltService(ctx context.Context, projectID string, ma
return &mutation.CreatePrebuiltService, nil
}

func (c *client) CreatePrebuiltServiceRaw(ctx context.Context, projectID string, rawSchema string) (*model.Service, error) {
var mutation struct {
CreateCustomService model.Service `graphql:"createPrebuiltService(projectID: $projectID, rawSchema: $rawSchema)"`
}

err := c.Mutate(ctx, &mutation, V{
"projectID": ObjectID(projectID),
"schema": rawSchema,
})

if err != nil {
return nil, err
}

return &mutation.CreateCustomService, nil
}

func (c *client) CreatePrebuiltServiceCustom(ctx context.Context, projectID string, schema model.ServiceSpecSchemaInput) (*model.Service, error) {
var mutation struct {
CreateCustomService model.Service `graphql:"createPrebuiltService(projectID: $projectID, schema: $schema)"`
}

err := c.Mutate(ctx, &mutation, V{
"projectID": ObjectID(projectID),
"schema": schema,
})

if err != nil {
return nil, err
}

return &mutation.CreateCustomService, nil
}

func (c *client) SearchGitRepositories(ctx context.Context, keyword *string) ([]model.GitRepo, error) {
var query struct {
SearchGitRepositories []model.GitRepo `graphql:"searchGitRepositories(Limit: 5, provider: GITHUB, keyword: $keyword)"`
Expand Down
70 changes: 70 additions & 0 deletions pkg/model/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,73 @@ type ServiceInstruction struct {
Title string `graphql:"title"`
Type ServiceSpecConnectionInstructionType `graphql:"type"`
}

type ServiceSpecSchemaInput struct {
ID string `json:"id" graphql:"id"`
Name string `json:"name" graphql:"name"`
Description string `json:"description" graphql:"description"`
Tags []string `json:"tags" graphql:"tags"`
Icon string `json:"icon" graphql:"icon"`
Docs string `json:"docs" graphql:"docs"`

Source *ServiceSpecSourceInput `json:"source" graphql:"source"`
Ports []ServiceSpecPortInput `json:"ports" graphql:"ports"`
Volumes []ServiceSpecVolumeEntryInput `json:"volumes" graphql:"volumes"`
Instructions []ServiceInstruction `json:"instructions" graphql:"instructions"`
Env []ServiceSpecEnvInput `json:"env" graphql:"env"`
InitRules []ServiceSpecInitRuleInput `json:"initRules" graphql:"initRules"`
Configs []ServiceSpecConfigInput `json:"configs" graphql:"configs"`
}

type ServiceSpecEnvInput struct {
Key string `json:"key" graphql:"key"`
Required bool `json:"required" graphql:"required"`
Default string `json:"default" graphql:"default"`
Expose bool `json:"expose" graphql:"expose"`
Readonly bool `json:"readonly" graphql:"readonly"`
}

type ServiceSpecSourceInput struct {
Image string `json:"image" graphql:"image"`
Command []string `json:"command" graphql:"command"`
Args []string `json:"args" graphql:"args"`

// Git only fields
Source string `json:"source,omitempty" graphql:"source"`
RepoID int `json:"repoID,omitempty" graphql:"repoID"`
Branch string `json:"branch,omitempty" graphql:"branch"`
SubModuleName string `json:"subModuleName,omitempty" graphql:"subModuleName"`
WatchPaths []string `json:"watchPaths,omitempty" graphql:"watchPaths"`
}

type ServiceSpecPortInput struct {
ID string `json:"id" graphql:"id"`
Port int `json:"port" graphql:"port"`
// Type is the type of the port, e.g. TCP, UDP, HTTP.
Type string `json:"type" graphql:"type"`
}

type ServiceSpecVolumeEntryInput struct {
ID string `json:"id" graphql:"id"`
// Dir should be started with `/` (absolute).
Dir string `json:"dir" graphql:"dir"`
}

type ServiceSpecInitVolumeMountInput struct {
ID string `json:"id" graphql:"id"`
MountPath string `json:"mountPath" graphql:"mountPath"`
SubPath string `json:"subPath" graphql:"subPath"`
}

type ServiceSpecInitRuleInput struct {
ID string `json:"id" graphql:"id"`
Image string `json:"image" graphql:"image"`
Command []string `json:"command" graphql:"command"`

Volumes []ServiceSpecInitVolumeMountInput `json:"volumes" graphql:"volumes"`
}

type ServiceSpecConfigInput struct {
Path string `json:"path" graphql:"path"`
Template string `json:"template" graphql:"template"`
}

0 comments on commit 119c03d

Please sign in to comment.