Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Client function to create custom image service #100

Merged
merged 3 commits into from
Jun 6, 2024

Conversation

incubator4
Copy link
Contributor

Description (required)

Add Client function CreateCustomService to create custom image service

Related issues & labels (optional)

  • Closes #
  • Suggested label:

@pan93412
Copy link
Member

pan93412 commented Jun 5, 2024

Thanks a lot to your contribution!

Most of them seem great. However, I would prefer to pass the TOML into createPrebuiltService using the rawSchema parameter. CLI users usually prefer to use their existing Prebuilt TOML definitions, like this PostgreSQL TOML definition.

The GraphQL mutation of this method is:

mutation CreatePrebuiltService($projectId: ObjectID!, $rawSchema: String) {
  createPrebuiltService(projectID: $projectId, rawSchema: $rawSchema) {
    _id
  }
}

@incubator4
Copy link
Contributor Author

incubator4 commented Jun 5, 2024

Thanks a lot to your contribution!

Most of them seem great. However, I would prefer to pass the TOML into createPrebuiltService using the rawSchema parameter. CLI users usually prefer to use their existing Prebuilt TOML definitions, like this PostgreSQL TOML definition.

The GraphQL mutation of this method is:

mutation CreatePrebuiltService($projectId: ObjectID!, $rawSchema: String) {
  createPrebuiltService(projectID: $projectId, rawSchema: $rawSchema) {
    _id
  }
}

which means just need to marshal struct to json string ? or keep both function, structured schema can be used more easily like sdk usage

@pan93412
Copy link
Member

pan93412 commented Jun 5, 2024

The general flow of this method would be "Read service.toml", then put the TOML in the parameter.


理論上是讀 service.toml 然後把 TOML 放進去 schemaRaw 裡面。

@incubator4
Copy link
Contributor Author

In some case, what if I just want to use cli package as sdk, it would be more helpful like this.
Although using cli as SDK is not so good, there is currently no package like zeabur/sdk

package main

import (
	"context"
	"fmt"
	"github.com/zeabur/cli/pkg/api"
	"github.com/zeabur/cli/pkg/model"
	"os"
)

func main() {
	ctx := context.Background()
	token := os.Getenv("ZEABUR_API_TOKEN")
	client := api.New(token)

	project, err := client.GetProject(ctx, "", "incubator4", "togitic")
	if err != nil {
		panic(err)
	}

	schema := model.ServiceSpecSchemaInput{
		ID:   "httpbin",
		Name: "httpbin",
		Source: &model.ServiceSpecSourceInput{
			Image: "kennethreitz/httpbin",
		},
	}
	service, err := client.CreateCustomService(ctx, project.ID, schema)
	if err != nil {
		panic(err)
	}
	fmt.Printf("Service: %+v\n", service)
}

@pan93412
Copy link
Member

pan93412 commented Jun 5, 2024

In some case, what if I just want to use cli package as sdk, it would be more helpful like this. Although using cli as SDK is not so good, there is currently no package like zeabur/sdk

package main

import (
	"context"
	"fmt"
	"github.com/zeabur/cli/pkg/api"
	"github.com/zeabur/cli/pkg/model"
	"os"
)

func main() {
	ctx := context.Background()
	token := os.Getenv("ZEABUR_API_TOKEN")
	client := api.New(token)

	project, err := client.GetProject(ctx, "", "incubator4", "togitic")
	if err != nil {
		panic(err)
	}

	schema := model.ServiceSpecSchemaInput{
		ID:   "httpbin",
		Name: "httpbin",
		Source: &model.ServiceSpecSourceInput{
			Image: "kennethreitz/httpbin",
		},
	}
	service, err := client.CreateCustomService(ctx, project.ID, schema)
	if err != nil {
		panic(err)
	}
	fmt.Printf("Service: %+v\n", service)
}

Understand. Seems reasonable. I will approve this.

@incubator4
Copy link
Contributor Author

incubator4 commented Jun 5, 2024

@pan93412 An additional update, rawSchema also be added to Client interface

@pan93412
Copy link
Member

pan93412 commented Jun 5, 2024

"RawService" seems weird. How about "CreatePrebuiltServiceRaw" and "CreatePrebuiltServiceCustom"?

@incubator4
Copy link
Contributor Author

"RawService" seems weird. How about "CreatePrebuiltServiceRaw" and "CreatePrebuiltServiceCustom"?

function name updated

@yuaanlin yuaanlin merged commit 119c03d into zeabur:main Jun 6, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants