This is an automated email from the ASF dual-hosted git repository.
zhongxjian pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-kubernetes.git
The following commit(s) were added to refs/heads/master by this push:
new 087c57a4 [dubboctl] add image build logic (#576)
087c57a4 is described below
commit 087c57a40da265bdcade14a54f4865a32533b46e
Author: Jian Zhong <[email protected]>
AuthorDate: Mon Feb 3 18:30:52 2025 +0800
[dubboctl] add image build logic (#576)
---
dubboctl/cmd/image.go | 36 ++++++++++++++++++++--------
dubboctl/pkg/builder/builder.go | 36 ----------------------------
dubboctl/pkg/{mirror => hub}/client.go | 2 +-
dubboctl/pkg/hub/cred/cred.go | 34 ++++++++++++++++++++++++++
dubboctl/pkg/{mirror => hub}/ssh/agent.go | 0
dubboctl/pkg/{mirror => hub}/ssh/dialer.go | 1 +
dubboctl/pkg/{mirror => hub}/ssh/terminal.go | 0
7 files changed, 62 insertions(+), 47 deletions(-)
diff --git a/dubboctl/cmd/image.go b/dubboctl/cmd/image.go
index 91cc9892..395bbde5 100644
--- a/dubboctl/cmd/image.go
+++ b/dubboctl/cmd/image.go
@@ -3,6 +3,7 @@ package cmd
import (
"fmt"
"github.com/apache/dubbo-kubernetes/dubboctl/pkg/cli"
+ "github.com/apache/dubbo-kubernetes/dubboctl/pkg/sdk"
"github.com/apache/dubbo-kubernetes/dubboctl/pkg/sdk/dubbo"
"github.com/apache/dubbo-kubernetes/dubboctl/pkg/util"
"github.com/ory/viper"
@@ -12,39 +13,44 @@ import (
"path/filepath"
)
-type BuildConfig struct {
+type buildConfig struct {
Build bool
Path string
}
-type PushConfig struct {
+func (c buildConfig) buildclientOptions() ([]sdk.Option, error) {
+ var do []sdk.Option
+ return do, nil
+}
+
+type pushConfig struct {
Push bool
Path string
}
-type ApplyConfig struct {
+type applyConfig struct {
Apply bool
Path string
}
-func newBuildConfig(cmd *cobra.Command) *BuildConfig {
- bc := &BuildConfig{
+func newBuildConfig(cmd *cobra.Command) *buildConfig {
+ bc := &buildConfig{
Build: viper.GetBool("build"),
Path: viper.GetString("path"),
}
return bc
}
-func newPushConfig(cmd *cobra.Command) *PushConfig {
- pc := &PushConfig{
+func newPushConfig(cmd *cobra.Command) *pushConfig {
+ pc := &pushConfig{
Push: viper.GetBool("push"),
Path: viper.GetString("path"),
}
return pc
}
-func newApplyConfig(cmd *cobra.Command) *ApplyConfig {
- ac := &ApplyConfig{
+func newApplyConfig(cmd *cobra.Command) *applyConfig {
+ ac := &applyConfig{
Apply: viper.GetBool("apply"),
Path: viper.GetString("path"),
}
@@ -83,8 +89,8 @@ func runBuild(cmd *cobra.Command, args []string,
clientFactory ClientFactory) er
if err := util.GetCreatePath(); err != nil {
return err
}
- config := newBuildConfig(cmd)
+ config := newBuildConfig(cmd)
fp, err := dubbo.NewDubboConfig(config.Path)
if err != nil {
return err
@@ -93,6 +99,16 @@ func runBuild(cmd *cobra.Command, args []string,
clientFactory ClientFactory) er
if !fp.Initialized() {
}
+ clientOptions, err := config.buildclientOptions()
+ if err != nil {
+ return err
+ }
+ client, done := clientFactory(clientOptions...)
+ defer done()
+ if fp, err = client.Build(cmd.Context(), fp); err != nil {
+ return err
+ }
+
return fmt.Errorf("TODO")
}
diff --git a/dubboctl/pkg/builder/builder.go b/dubboctl/pkg/builder/builder.go
deleted file mode 100644
index 3fa9e22b..00000000
--- a/dubboctl/pkg/builder/builder.go
+++ /dev/null
@@ -1,36 +0,0 @@
-package builder
-
-import (
- "context"
- "github.com/apache/dubbo-kubernetes/dubboctl/pkg/sdk/dubbo"
-)
-
-type Builder struct{}
-
-func NewBuilder() *Builder {
- return &Builder{}
-}
-
-func (b Builder) Build(ctx context.Context, f *dubbo.DubboConfig) error {
- cli, _, err := docker.NewClient(client.DefaultDockerHost)
- if err != nil {
- return err
- }
- buildOpts := types.ImageBuildOptions{
- Dockerfile: "Dockerfile",
- Tags: []string{f.Image},
- }
-
- buildCtx, _ := archive.TarWithOptions(f.Root, &archive.TarOptions{})
- resp, err := cli.ImageBuild(ctx, buildCtx, buildOpts)
- if err != nil {
- return err
- }
- defer resp.Body.Close()
- termFd, isTerm := term.GetFdInfo(os.Stderr)
- err = jsonmessage.DisplayJSONMessagesStream(resp.Body, os.Stderr,
termFd, isTerm, nil)
- if err != nil {
- return err
- }
- return nil
-}
diff --git a/dubboctl/pkg/mirror/client.go b/dubboctl/pkg/hub/client.go
similarity index 99%
rename from dubboctl/pkg/mirror/client.go
rename to dubboctl/pkg/hub/client.go
index f120fe86..06bb7baf 100644
--- a/dubboctl/pkg/mirror/client.go
+++ b/dubboctl/pkg/hub/client.go
@@ -1,4 +1,4 @@
-package mirror
+package hub
import (
"crypto/tls"
diff --git a/dubboctl/pkg/hub/cred/cred.go b/dubboctl/pkg/hub/cred/cred.go
new file mode 100644
index 00000000..040fce38
--- /dev/null
+++ b/dubboctl/pkg/hub/cred/cred.go
@@ -0,0 +1,34 @@
+package cred
+
+import (
+ "context"
+ "fmt"
+ "github.com/google/go-containerregistry/pkg/authn"
+ "net/http"
+)
+
+type keyChain struct {
+ user string
+ pwd string
+}
+
+func (k keyChain) Resolve(resource authn.Resource) (authn.Authenticator,
error) {
+ return &authn.Basic{
+ Username: k.user,
+ Password: k.pwd,
+ }, nil
+}
+
+func CheckAuth(ctx context.Context, image string, credentials
docker.Credentials, trans http.RoundTripper) error {
+ ref, err := name.ParseReference(image)
+ if err != nil {
+ return fmt.Errorf("cannot parse image reference: %w", err)
+ }
+
+ kc := keyChain{
+ user: credentials.Username,
+ pwd: credentials.Password,
+ }
+
+ return nil
+}
diff --git a/dubboctl/pkg/mirror/ssh/agent.go b/dubboctl/pkg/hub/ssh/agent.go
similarity index 100%
rename from dubboctl/pkg/mirror/ssh/agent.go
rename to dubboctl/pkg/hub/ssh/agent.go
diff --git a/dubboctl/pkg/mirror/ssh/dialer.go b/dubboctl/pkg/hub/ssh/dialer.go
similarity index 99%
rename from dubboctl/pkg/mirror/ssh/dialer.go
rename to dubboctl/pkg/hub/ssh/dialer.go
index dc5ea822..06e6c3ca 100644
--- a/dubboctl/pkg/mirror/ssh/dialer.go
+++ b/dubboctl/pkg/hub/ssh/dialer.go
@@ -75,6 +75,7 @@ func (d *dialer) Close() error {
type ContextDialer interface {
DialContext(ctx context.Context, network, address string) (net.Conn,
error)
}
+
type DialContextFn = func(ctx context.Context, network, addr string)
(net.Conn, error)
func NewDialContext(url *nurl.URL, config Config) (ContextDialer, string,
error) {
diff --git a/dubboctl/pkg/mirror/ssh/terminal.go
b/dubboctl/pkg/hub/ssh/terminal.go
similarity index 100%
rename from dubboctl/pkg/mirror/ssh/terminal.go
rename to dubboctl/pkg/hub/ssh/terminal.go