mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 19:13:34 +00:00
generate container name and assign service labels to container
This commit is contained in:
@@ -89,13 +89,20 @@ func (c *Client) RunService(ctx context.Context, opts *ServiceOptions) (RunServi
|
|||||||
serviceName = fmt.Sprintf("%s-%s", imageName, suffix)
|
serviceName = fmt.Sprintf("%s-%s", imageName, suffix)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: generate a container name from the service name.
|
suffix, err := secret.RandomAlphaNumeric(4)
|
||||||
// TODO: set service labels on the container.
|
if err != nil {
|
||||||
|
return resp, fmt.Errorf("generate random suffix: %w", err)
|
||||||
|
}
|
||||||
|
containerName := fmt.Sprintf("%s-%s", serviceName, suffix)
|
||||||
|
|
||||||
config := &container.Config{
|
config := &container.Config{
|
||||||
Image: opts.Image,
|
Image: opts.Image,
|
||||||
|
Labels: map[string]string{
|
||||||
|
"uncloud.service.id": serviceID,
|
||||||
|
"uncloud.service.name": serviceName,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
createResp, err := c.CreateContainer(ctx, config, nil, nil, nil, opts.Name)
|
createResp, err := c.CreateContainer(ctx, config, nil, nil, nil, containerName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return resp, fmt.Errorf("create container: %w", err)
|
return resp, fmt.Errorf("create container: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user