diff --git a/biz/docker/config.go b/biz/docker/config.go index da6d536..57937a2 100644 --- a/biz/docker/config.go +++ b/biz/docker/config.go @@ -41,6 +41,12 @@ func ConfigCreate(info *model.ConfigCreateInfo) error { spec.Name = info.Name spec.Data = []byte(info.Data) spec.Labels = info.Labels.ToMap() + if info.Template.Name != "" { + spec.Templating = &swarm.Driver{ + Name: info.Template.Name, + Options: info.Template.Options, + } + } _, err = cli.ConfigCreate(ctx, spec) return }) diff --git a/biz/docker/docker.go b/biz/docker/docker.go index c54c7bf..4a792fa 100644 --- a/biz/docker/docker.go +++ b/biz/docker/docker.go @@ -12,7 +12,7 @@ import ( ) const ( - apiVersion = "1.32" + defaultAPIVersion = "1.32" ) var mgr = &manager{} @@ -37,11 +37,15 @@ func (m *manager) Client() (ctx context.Context, cli *client.Client, err error) defer m.locker.Unlock() if m.client == nil { + apiVersion := misc.Options.DockerAPIVersion + if apiVersion == "" { + apiVersion = defaultAPIVersion + } if misc.Options.DockerEndpoint == "" { os.Setenv("DOCKER_API_VERSION", apiVersion) - m.client, err = client.NewEnvClient() + m.client, err = client.NewClientWithOpts(client.FromEnv) } else { - m.client, err = client.NewClient(misc.Options.DockerEndpoint, apiVersion, nil, nil) + m.client, err = client.NewClientWithOpts(client.WithHost(misc.Options.DockerEndpoint), client.WithVersion(apiVersion)) } if err != nil { return diff --git a/biz/docker/secret.go b/biz/docker/secret.go index d67c44c..fd91582 100644 --- a/biz/docker/secret.go +++ b/biz/docker/secret.go @@ -41,6 +41,12 @@ func SecretCreate(info *model.ConfigCreateInfo) error { spec.Name = info.Name spec.Data = []byte(info.Data) spec.Labels = info.Labels.ToMap() + if info.Template.Name != "" { + spec.Templating = &swarm.Driver{ + Name: info.Template.Name, + Options: info.Template.Options, + } + } _, err = cli.SecretCreate(ctx, spec) return }) diff --git a/config/i18n/en.yml b/config/i18n/en.yml index 3bf0368..6b55b82 100644 --- a/config/i18n/en.yml +++ b/config/i18n/en.yml @@ -34,6 +34,7 @@ field.login-name: Login name field.password: Password field.id: ID field.tag: Tags +field.label: Labels field.size: Size field.created-at: Created at field.created-by: Created by @@ -57,6 +58,8 @@ field.title: Title field.legend: Legend field.desc: Description field.dashboard: Dashboard +field.data: Data +field.template: Template # menu menu.home: Home diff --git a/config/i18n/zh.yml b/config/i18n/zh.yml index 3903f44..9fdc7ac 100644 --- a/config/i18n/zh.yml +++ b/config/i18n/zh.yml @@ -34,6 +34,7 @@ field.login-name: 登录名称 field.password: 密码 field.id: ID field.tag: 标签 +field.label: 标签 field.size: 大小 field.created-at: 创建时间 field.created-by: 创建人 @@ -57,6 +58,8 @@ field.title: 标题 field.legend: 图例 field.desc: 描述 field.dashboard: 仪表盘 +field.data: 数据 +field.template: 模板 # menu menu.home: 首页 diff --git a/misc/misc.go b/misc/misc.go index ef3cb12..68c5d02 100644 --- a/misc/misc.go +++ b/misc/misc.go @@ -7,14 +7,16 @@ import ( ) const ( - keyDockerEndpoint = "swirl.docker_endpoint" - keyDBType = "swirl.db_type" - keyDBAddress = "swirl.db_address" - keyAuthTimeout = "swirl.auth_timeout" - envDockerEndpoint = "DOCKER_ENDPOINT" - envDBType = "DB_TYPE" - envDBAddress = "DB_ADDRESS" - envAuthTimeout = "AUTH_TIMEOUT" + keyDockerEndpoint = "swirl.docker_endpoint" + keyDockerAPIVersion = "swirl.docker_api_version" + keyDBType = "swirl.db_type" + keyDBAddress = "swirl.db_address" + keyAuthTimeout = "swirl.auth_timeout" + envDockerEndpoint = "DOCKER_ENDPOINT" + envDockerAPIVersion = "DOCKER_API_VERSION" + envDBType = "DB_TYPE" + envDBAddress = "DB_ADDRESS" + envAuthTimeout = "AUTH_TIMEOUT" ) // TimeZones holds some commonly used time-zones. @@ -51,10 +53,11 @@ var TimeZones = []struct { // Options holds custom options of swirl. var Options = &struct { - DockerEndpoint string - DBType string - DBAddress string - AuthTimeout time.Duration + DockerEndpoint string + DockerAPIVersion string + DBType string + DBAddress string + AuthTimeout time.Duration }{ DBType: "mongo", DBAddress: "localhost:27017/swirl", @@ -64,6 +67,7 @@ var Options = &struct { // BindOptions binds options to environment variables. func BindOptions() { config.BindEnv(keyDockerEndpoint, envDockerEndpoint) + config.BindEnv(keyDockerAPIVersion, envDockerAPIVersion) config.BindEnv(keyDBType, envDBType) config.BindEnv(keyDBAddress, envDBAddress) config.BindEnv(keyAuthTimeout, envAuthTimeout) diff --git a/model/docker.go b/model/docker.go index e7d2155..c7f80d7 100644 --- a/model/docker.go +++ b/model/docker.go @@ -553,10 +553,16 @@ func (pc *PlacementConstraint) ToConstraint() string { return "" } +type Driver struct { + Name string `json:"name,omitempty"` + Options map[string]string `json:"options,omitempty"` +} + type ConfigCreateInfo struct { - Name string `json:"name"` - Data string `json:"data"` - Labels Options `json:"labels"` + Name string `json:"name"` + Data string `json:"data"` + Labels Options `json:"labels"` + Template Driver `json:"template"` } type ConfigUpdateInfo struct { diff --git a/views/config/edit.jet b/views/config/edit.jet index 6e92dde..1b6cecd 100644 --- a/views/config/edit.jet +++ b/views/config/edit.jet @@ -50,16 +50,29 @@
- +
-

Editing is not supported now!

+

Editing is not supported now!

- + {{ yield options(name="label", items=.Config.Spec.Labels) }}
+
+ +
+ {{ if .Config.Spec.Templating }} + {{ yield radio(name="template.name", value="", label="None", disabled=true, checked=.Config.Spec.Templating.Name) }} + {{ yield radio(name="template.name", value="golang", label="Golang", disabled=true, checked=.Config.Spec.Templating.Name) }} + {{ else }} + {{ yield radio(name="template.name", value="", label="None", disabled=true, checked="") }} + {{ yield radio(name="template.name", value="golang", label="Golang", disabled=true) }} + {{ end }} +
+

Template feature needs Docker API version 1.37+

+
{{ yield form_submit(url="/config/") }} diff --git a/views/config/new.jet b/views/config/new.jet index f3cb929..dfa96e8 100644 --- a/views/config/new.jet +++ b/views/config/new.jet @@ -19,52 +19,31 @@

Create config


-
-
- -
-
-
-

- -

-
+
+ +
+
-
-
- -
-
-
-
- -
-
+
+ +
+
-
-
- -
-
-
- {{ yield options(name="label") }} -
-
+
+ + {{ yield options(name="label") }}
-
-
-
-
-
-
- - {{ i18n("button.cancel") }} -
-
+
+ +
+ {{ yield radio(name="template.name", value="", label="None", checked="") }} + {{ yield radio(name="template.name", value="golang", label="Golang") }}
+

Template feature needs Docker API version 1.37+

+ {{ yield form_submit(url="/config/") }} {{ end }} \ No newline at end of file diff --git a/views/secret/edit.jet b/views/secret/edit.jet index 0c519cd..ea98ec1 100644 --- a/views/secret/edit.jet +++ b/views/secret/edit.jet @@ -50,16 +50,29 @@ {*
*} - {**} + {**} {*
*} {**} {*
*} - {*

Editing is not supported now!

*} + {*

Editing is not supported now!

*} {*
*}
- + {{ yield options(name="label", items=.Secret.Spec.Labels) }}
+
+ +
+ {{ if .Secret.Spec.Templating }} + {{ yield radio(name="template.name", value="", label="None", disabled=true, checked=.Secret.Spec.Templating.Name) }} + {{ yield radio(name="template.name", value="golang", label="Golang", disabled=true, checked=.Secret.Spec.Templating.Name) }} + {{ else }} + {{ yield radio(name="template.name", value="", label="None", disabled=true, checked="") }} + {{ yield radio(name="template.name", value="golang", label="Golang", disabled=true) }} + {{ end }} +
+

Template feature needs Docker API version 1.37+

+
{{ yield form_submit(url="/secret/") }}
diff --git a/views/secret/new.jet b/views/secret/new.jet index a57e730..585a753 100644 --- a/views/secret/new.jet +++ b/views/secret/new.jet @@ -19,52 +19,31 @@

Create secret


-
-
- -
-
-
-

- -

-
+
+ +
+
-
-
- -
-
-
-
- -
-
+
+ +
+
-
-
- -
-
-
- {{ yield options(name="label") }} -
-
+
+ + {{ yield options(name="label") }}
-
-
-
-
-
-
- - {{ i18n("button.cancel") }} -
-
+
+ +
+ {{ yield radio(name="template.name", value="", label="None", checked="") }} + {{ yield radio(name="template.name", value="golang", label="Golang") }}
+

Template feature needs Docker API version 1.37+

+ {{ yield form_submit(url="/secret/") }} {{ end }} \ No newline at end of file