id int32 0 167k | repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
159,600 | docker/cli | cli/command/stack/kubernetes/stack.go | createFileBasedConfigMaps | func (s *Stack) createFileBasedConfigMaps(configMaps corev1.ConfigMapInterface) ([]childResource, error) {
var resources []childResource
for name, config := range s.Spec.Configs {
if config.File == "" {
continue
}
fileName := filepath.Base(config.File)
content, err := ioutil.ReadFile(config.File)
if err != nil {
return resources, err
}
configMap, err := configMaps.Create(toConfigMap(s.Name, name, fileName, content))
if err != nil {
return resources, err
}
resources = append(resources, &configMapChildResource{client: configMaps, configMap: configMap})
}
return resources, nil
} | go | func (s *Stack) createFileBasedConfigMaps(configMaps corev1.ConfigMapInterface) ([]childResource, error) {
var resources []childResource
for name, config := range s.Spec.Configs {
if config.File == "" {
continue
}
fileName := filepath.Base(config.File)
content, err := ioutil.ReadFile(config.File)
if err != nil {
return resources, err
}
configMap, err := configMaps.Create(toConfigMap(s.Name, name, fileName, content))
if err != nil {
return resources, err
}
resources = append(resources, &configMapChildResource{client: configMaps, configMap: configMap})
}
return resources, nil
} | [
"func",
"(",
"s",
"*",
"Stack",
")",
"createFileBasedConfigMaps",
"(",
"configMaps",
"corev1",
".",
"ConfigMapInterface",
")",
"(",
"[",
"]",
"childResource",
",",
"error",
")",
"{",
"var",
"resources",
"[",
"]",
"childResource",
"\n",
"for",
"name",
",",
... | // createFileBasedConfigMaps creates a Kubernetes ConfigMap for each Compose global file-based config. | [
"createFileBasedConfigMaps",
"creates",
"a",
"Kubernetes",
"ConfigMap",
"for",
"each",
"Compose",
"global",
"file",
"-",
"based",
"config",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/stack/kubernetes/stack.go#L54-L74 |
159,601 | docker/cli | cli/command/stack/kubernetes/stack.go | toConfigMap | func toConfigMap(stackName, name, key string, content []byte) *apiv1.ConfigMap {
return &apiv1.ConfigMap{
TypeMeta: metav1.TypeMeta{
Kind: "ConfigMap",
APIVersion: "v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: name,
Labels: map[string]string{
labels.ForStackName: stackName,
},
},
Data: map[string]string{
key: string(content),
},
}
} | go | func toConfigMap(stackName, name, key string, content []byte) *apiv1.ConfigMap {
return &apiv1.ConfigMap{
TypeMeta: metav1.TypeMeta{
Kind: "ConfigMap",
APIVersion: "v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: name,
Labels: map[string]string{
labels.ForStackName: stackName,
},
},
Data: map[string]string{
key: string(content),
},
}
} | [
"func",
"toConfigMap",
"(",
"stackName",
",",
"name",
",",
"key",
"string",
",",
"content",
"[",
"]",
"byte",
")",
"*",
"apiv1",
".",
"ConfigMap",
"{",
"return",
"&",
"apiv1",
".",
"ConfigMap",
"{",
"TypeMeta",
":",
"metav1",
".",
"TypeMeta",
"{",
"Kin... | // toConfigMap converts a Compose Config to a Kube ConfigMap. | [
"toConfigMap",
"converts",
"a",
"Compose",
"Config",
"to",
"a",
"Kube",
"ConfigMap",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/stack/kubernetes/stack.go#L92-L108 |
159,602 | docker/cli | cli/command/stack/kubernetes/stack.go | createFileBasedSecrets | func (s *Stack) createFileBasedSecrets(secrets corev1.SecretInterface) ([]childResource, error) {
var resources []childResource
for name, secret := range s.Spec.Secrets {
if secret.File == "" {
continue
}
fileName := filepath.Base(secret.File)
content, err := ioutil.ReadFile(secret.File)
if err != nil {
return resources, err
}
secret, err := secrets.Create(toSecret(s.Name, name, fileName, content))
if err != nil {
return resources, err
}
resources = append(resources, &secretChildResource{client: secrets, secret: secret})
}
return resources, nil
} | go | func (s *Stack) createFileBasedSecrets(secrets corev1.SecretInterface) ([]childResource, error) {
var resources []childResource
for name, secret := range s.Spec.Secrets {
if secret.File == "" {
continue
}
fileName := filepath.Base(secret.File)
content, err := ioutil.ReadFile(secret.File)
if err != nil {
return resources, err
}
secret, err := secrets.Create(toSecret(s.Name, name, fileName, content))
if err != nil {
return resources, err
}
resources = append(resources, &secretChildResource{client: secrets, secret: secret})
}
return resources, nil
} | [
"func",
"(",
"s",
"*",
"Stack",
")",
"createFileBasedSecrets",
"(",
"secrets",
"corev1",
".",
"SecretInterface",
")",
"(",
"[",
"]",
"childResource",
",",
"error",
")",
"{",
"var",
"resources",
"[",
"]",
"childResource",
"\n",
"for",
"name",
",",
"secret",... | // createFileBasedSecrets creates a Kubernetes Secret for each Compose global file-based secret. | [
"createFileBasedSecrets",
"creates",
"a",
"Kubernetes",
"Secret",
"for",
"each",
"Compose",
"global",
"file",
"-",
"based",
"secret",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/stack/kubernetes/stack.go#L111-L131 |
159,603 | docker/cli | cli/command/stack/kubernetes/stack.go | toSecret | func toSecret(stackName, name, key string, content []byte) *apiv1.Secret {
return &apiv1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Labels: map[string]string{
labels.ForStackName: stackName,
},
},
Data: map[string][]byte{
key: content,
},
}
} | go | func toSecret(stackName, name, key string, content []byte) *apiv1.Secret {
return &apiv1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Labels: map[string]string{
labels.ForStackName: stackName,
},
},
Data: map[string][]byte{
key: content,
},
}
} | [
"func",
"toSecret",
"(",
"stackName",
",",
"name",
",",
"key",
"string",
",",
"content",
"[",
"]",
"byte",
")",
"*",
"apiv1",
".",
"Secret",
"{",
"return",
"&",
"apiv1",
".",
"Secret",
"{",
"ObjectMeta",
":",
"metav1",
".",
"ObjectMeta",
"{",
"Name",
... | // toSecret converts a Compose Secret to a Kube Secret. | [
"toSecret",
"converts",
"a",
"Compose",
"Secret",
"to",
"a",
"Kube",
"Secret",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/stack/kubernetes/stack.go#L149-L161 |
159,604 | docker/cli | cli/command/defaultcontextstore.go | resolveDefaultContext | func resolveDefaultContext(opts *cliflags.CommonOptions, config *configfile.ConfigFile, stderr io.Writer) (*DefaultContext, error) {
stackOrchestrator, err := GetStackOrchestrator("", "", config.StackOrchestrator, stderr)
if err != nil {
return nil, err
}
contextTLSData := store.ContextTLSData{
Endpoints: make(map[string]store.EndpointTLSData),
}
contextMetadata := store.Metadata{
Endpoints: make(map[string]interface{}),
Metadata: DockerContext{
Description: "",
StackOrchestrator: stackOrchestrator,
},
Name: DefaultContextName,
}
dockerEP, err := resolveDefaultDockerEndpoint(opts)
if err != nil {
return nil, err
}
contextMetadata.Endpoints[docker.DockerEndpoint] = dockerEP.EndpointMeta
if dockerEP.TLSData != nil {
contextTLSData.Endpoints[docker.DockerEndpoint] = *dockerEP.TLSData.ToStoreTLSData()
}
// Default context uses env-based kubeconfig for Kubernetes endpoint configuration
kubeconfig := os.Getenv("KUBECONFIG")
if kubeconfig == "" {
kubeconfig = filepath.Join(homedir.Get(), ".kube/config")
}
kubeEP, err := kubernetes.FromKubeConfig(kubeconfig, "", "")
if (stackOrchestrator == OrchestratorKubernetes || stackOrchestrator == OrchestratorAll) && err != nil {
return nil, errors.Wrapf(err, "default orchestrator is %s but kubernetes endpoint could not be found", stackOrchestrator)
}
if err == nil {
contextMetadata.Endpoints[kubernetes.KubernetesEndpoint] = kubeEP.EndpointMeta
if kubeEP.TLSData != nil {
contextTLSData.Endpoints[kubernetes.KubernetesEndpoint] = *kubeEP.TLSData.ToStoreTLSData()
}
}
return &DefaultContext{Meta: contextMetadata, TLS: contextTLSData}, nil
} | go | func resolveDefaultContext(opts *cliflags.CommonOptions, config *configfile.ConfigFile, stderr io.Writer) (*DefaultContext, error) {
stackOrchestrator, err := GetStackOrchestrator("", "", config.StackOrchestrator, stderr)
if err != nil {
return nil, err
}
contextTLSData := store.ContextTLSData{
Endpoints: make(map[string]store.EndpointTLSData),
}
contextMetadata := store.Metadata{
Endpoints: make(map[string]interface{}),
Metadata: DockerContext{
Description: "",
StackOrchestrator: stackOrchestrator,
},
Name: DefaultContextName,
}
dockerEP, err := resolveDefaultDockerEndpoint(opts)
if err != nil {
return nil, err
}
contextMetadata.Endpoints[docker.DockerEndpoint] = dockerEP.EndpointMeta
if dockerEP.TLSData != nil {
contextTLSData.Endpoints[docker.DockerEndpoint] = *dockerEP.TLSData.ToStoreTLSData()
}
// Default context uses env-based kubeconfig for Kubernetes endpoint configuration
kubeconfig := os.Getenv("KUBECONFIG")
if kubeconfig == "" {
kubeconfig = filepath.Join(homedir.Get(), ".kube/config")
}
kubeEP, err := kubernetes.FromKubeConfig(kubeconfig, "", "")
if (stackOrchestrator == OrchestratorKubernetes || stackOrchestrator == OrchestratorAll) && err != nil {
return nil, errors.Wrapf(err, "default orchestrator is %s but kubernetes endpoint could not be found", stackOrchestrator)
}
if err == nil {
contextMetadata.Endpoints[kubernetes.KubernetesEndpoint] = kubeEP.EndpointMeta
if kubeEP.TLSData != nil {
contextTLSData.Endpoints[kubernetes.KubernetesEndpoint] = *kubeEP.TLSData.ToStoreTLSData()
}
}
return &DefaultContext{Meta: contextMetadata, TLS: contextTLSData}, nil
} | [
"func",
"resolveDefaultContext",
"(",
"opts",
"*",
"cliflags",
".",
"CommonOptions",
",",
"config",
"*",
"configfile",
".",
"ConfigFile",
",",
"stderr",
"io",
".",
"Writer",
")",
"(",
"*",
"DefaultContext",
",",
"error",
")",
"{",
"stackOrchestrator",
",",
"... | // resolveDefaultContext creates a Metadata for the current CLI invocation parameters | [
"resolveDefaultContext",
"creates",
"a",
"Metadata",
"for",
"the",
"current",
"CLI",
"invocation",
"parameters"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/defaultcontextstore.go#L39-L82 |
159,605 | docker/cli | cli/command/defaultcontextstore.go | List | func (s *ContextStoreWithDefault) List() ([]store.Metadata, error) {
contextList, err := s.Store.List()
if err != nil {
return nil, err
}
defaultContext, err := s.Resolver()
if err != nil {
return nil, err
}
return append(contextList, defaultContext.Meta), nil
} | go | func (s *ContextStoreWithDefault) List() ([]store.Metadata, error) {
contextList, err := s.Store.List()
if err != nil {
return nil, err
}
defaultContext, err := s.Resolver()
if err != nil {
return nil, err
}
return append(contextList, defaultContext.Meta), nil
} | [
"func",
"(",
"s",
"*",
"ContextStoreWithDefault",
")",
"List",
"(",
")",
"(",
"[",
"]",
"store",
".",
"Metadata",
",",
"error",
")",
"{",
"contextList",
",",
"err",
":=",
"s",
".",
"Store",
".",
"List",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"... | // List implements store.Store's List | [
"List",
"implements",
"store",
".",
"Store",
"s",
"List"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/defaultcontextstore.go#L85-L95 |
159,606 | docker/cli | cli/command/defaultcontextstore.go | CreateOrUpdate | func (s *ContextStoreWithDefault) CreateOrUpdate(meta store.Metadata) error {
if meta.Name == DefaultContextName {
return errors.New("default context cannot be created nor updated")
}
return s.Store.CreateOrUpdate(meta)
} | go | func (s *ContextStoreWithDefault) CreateOrUpdate(meta store.Metadata) error {
if meta.Name == DefaultContextName {
return errors.New("default context cannot be created nor updated")
}
return s.Store.CreateOrUpdate(meta)
} | [
"func",
"(",
"s",
"*",
"ContextStoreWithDefault",
")",
"CreateOrUpdate",
"(",
"meta",
"store",
".",
"Metadata",
")",
"error",
"{",
"if",
"meta",
".",
"Name",
"==",
"DefaultContextName",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}"... | // CreateOrUpdate is not allowed for the default context and fails | [
"CreateOrUpdate",
"is",
"not",
"allowed",
"for",
"the",
"default",
"context",
"and",
"fails"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/defaultcontextstore.go#L98-L103 |
159,607 | docker/cli | cli/command/defaultcontextstore.go | Remove | func (s *ContextStoreWithDefault) Remove(name string) error {
if name == DefaultContextName {
return errors.New("default context cannot be removed")
}
return s.Store.Remove(name)
} | go | func (s *ContextStoreWithDefault) Remove(name string) error {
if name == DefaultContextName {
return errors.New("default context cannot be removed")
}
return s.Store.Remove(name)
} | [
"func",
"(",
"s",
"*",
"ContextStoreWithDefault",
")",
"Remove",
"(",
"name",
"string",
")",
"error",
"{",
"if",
"name",
"==",
"DefaultContextName",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"s",
".",
"Store"... | // Remove is not allowed for the default context and fails | [
"Remove",
"is",
"not",
"allowed",
"for",
"the",
"default",
"context",
"and",
"fails"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/defaultcontextstore.go#L106-L111 |
159,608 | docker/cli | cli/command/defaultcontextstore.go | GetMetadata | func (s *ContextStoreWithDefault) GetMetadata(name string) (store.Metadata, error) {
if name == DefaultContextName {
defaultContext, err := s.Resolver()
if err != nil {
return store.Metadata{}, err
}
return defaultContext.Meta, nil
}
return s.Store.GetMetadata(name)
} | go | func (s *ContextStoreWithDefault) GetMetadata(name string) (store.Metadata, error) {
if name == DefaultContextName {
defaultContext, err := s.Resolver()
if err != nil {
return store.Metadata{}, err
}
return defaultContext.Meta, nil
}
return s.Store.GetMetadata(name)
} | [
"func",
"(",
"s",
"*",
"ContextStoreWithDefault",
")",
"GetMetadata",
"(",
"name",
"string",
")",
"(",
"store",
".",
"Metadata",
",",
"error",
")",
"{",
"if",
"name",
"==",
"DefaultContextName",
"{",
"defaultContext",
",",
"err",
":=",
"s",
".",
"Resolver"... | // GetMetadata implements store.Store's GetMetadata | [
"GetMetadata",
"implements",
"store",
".",
"Store",
"s",
"GetMetadata"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/defaultcontextstore.go#L114-L123 |
159,609 | docker/cli | cli/command/defaultcontextstore.go | ResetTLSMaterial | func (s *ContextStoreWithDefault) ResetTLSMaterial(name string, data *store.ContextTLSData) error {
if name == DefaultContextName {
return errors.New("The default context store does not support ResetTLSMaterial")
}
return s.Store.ResetTLSMaterial(name, data)
} | go | func (s *ContextStoreWithDefault) ResetTLSMaterial(name string, data *store.ContextTLSData) error {
if name == DefaultContextName {
return errors.New("The default context store does not support ResetTLSMaterial")
}
return s.Store.ResetTLSMaterial(name, data)
} | [
"func",
"(",
"s",
"*",
"ContextStoreWithDefault",
")",
"ResetTLSMaterial",
"(",
"name",
"string",
",",
"data",
"*",
"store",
".",
"ContextTLSData",
")",
"error",
"{",
"if",
"name",
"==",
"DefaultContextName",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
... | // ResetTLSMaterial is not implemented for default context and fails | [
"ResetTLSMaterial",
"is",
"not",
"implemented",
"for",
"default",
"context",
"and",
"fails"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/defaultcontextstore.go#L126-L131 |
159,610 | docker/cli | cli/command/defaultcontextstore.go | ResetEndpointTLSMaterial | func (s *ContextStoreWithDefault) ResetEndpointTLSMaterial(contextName string, endpointName string, data *store.EndpointTLSData) error {
if contextName == DefaultContextName {
return errors.New("The default context store does not support ResetEndpointTLSMaterial")
}
return s.Store.ResetEndpointTLSMaterial(contextName, endpointName, data)
} | go | func (s *ContextStoreWithDefault) ResetEndpointTLSMaterial(contextName string, endpointName string, data *store.EndpointTLSData) error {
if contextName == DefaultContextName {
return errors.New("The default context store does not support ResetEndpointTLSMaterial")
}
return s.Store.ResetEndpointTLSMaterial(contextName, endpointName, data)
} | [
"func",
"(",
"s",
"*",
"ContextStoreWithDefault",
")",
"ResetEndpointTLSMaterial",
"(",
"contextName",
"string",
",",
"endpointName",
"string",
",",
"data",
"*",
"store",
".",
"EndpointTLSData",
")",
"error",
"{",
"if",
"contextName",
"==",
"DefaultContextName",
"... | // ResetEndpointTLSMaterial is not implemented for default context and fails | [
"ResetEndpointTLSMaterial",
"is",
"not",
"implemented",
"for",
"default",
"context",
"and",
"fails"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/defaultcontextstore.go#L134-L139 |
159,611 | docker/cli | cli/command/defaultcontextstore.go | ListTLSFiles | func (s *ContextStoreWithDefault) ListTLSFiles(name string) (map[string]store.EndpointFiles, error) {
if name == DefaultContextName {
defaultContext, err := s.Resolver()
if err != nil {
return nil, err
}
tlsfiles := make(map[string]store.EndpointFiles)
for epName, epTLSData := range defaultContext.TLS.Endpoints {
var files store.EndpointFiles
for filename := range epTLSData.Files {
files = append(files, filename)
}
tlsfiles[epName] = files
}
return tlsfiles, nil
}
return s.Store.ListTLSFiles(name)
} | go | func (s *ContextStoreWithDefault) ListTLSFiles(name string) (map[string]store.EndpointFiles, error) {
if name == DefaultContextName {
defaultContext, err := s.Resolver()
if err != nil {
return nil, err
}
tlsfiles := make(map[string]store.EndpointFiles)
for epName, epTLSData := range defaultContext.TLS.Endpoints {
var files store.EndpointFiles
for filename := range epTLSData.Files {
files = append(files, filename)
}
tlsfiles[epName] = files
}
return tlsfiles, nil
}
return s.Store.ListTLSFiles(name)
} | [
"func",
"(",
"s",
"*",
"ContextStoreWithDefault",
")",
"ListTLSFiles",
"(",
"name",
"string",
")",
"(",
"map",
"[",
"string",
"]",
"store",
".",
"EndpointFiles",
",",
"error",
")",
"{",
"if",
"name",
"==",
"DefaultContextName",
"{",
"defaultContext",
",",
... | // ListTLSFiles implements store.Store's ListTLSFiles | [
"ListTLSFiles",
"implements",
"store",
".",
"Store",
"s",
"ListTLSFiles"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/defaultcontextstore.go#L142-L159 |
159,612 | docker/cli | cli/command/defaultcontextstore.go | GetTLSData | func (s *ContextStoreWithDefault) GetTLSData(contextName, endpointName, fileName string) ([]byte, error) {
if contextName == DefaultContextName {
defaultContext, err := s.Resolver()
if err != nil {
return nil, err
}
if defaultContext.TLS.Endpoints[endpointName].Files[fileName] == nil {
return nil, &noDefaultTLSDataError{endpointName: endpointName, fileName: fileName}
}
return defaultContext.TLS.Endpoints[endpointName].Files[fileName], nil
}
return s.Store.GetTLSData(contextName, endpointName, fileName)
} | go | func (s *ContextStoreWithDefault) GetTLSData(contextName, endpointName, fileName string) ([]byte, error) {
if contextName == DefaultContextName {
defaultContext, err := s.Resolver()
if err != nil {
return nil, err
}
if defaultContext.TLS.Endpoints[endpointName].Files[fileName] == nil {
return nil, &noDefaultTLSDataError{endpointName: endpointName, fileName: fileName}
}
return defaultContext.TLS.Endpoints[endpointName].Files[fileName], nil
}
return s.Store.GetTLSData(contextName, endpointName, fileName)
} | [
"func",
"(",
"s",
"*",
"ContextStoreWithDefault",
")",
"GetTLSData",
"(",
"contextName",
",",
"endpointName",
",",
"fileName",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"contextName",
"==",
"DefaultContextName",
"{",
"defaultContext",... | // GetTLSData implements store.Store's GetTLSData | [
"GetTLSData",
"implements",
"store",
".",
"Store",
"s",
"GetTLSData"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/defaultcontextstore.go#L162-L175 |
159,613 | docker/cli | cli/command/defaultcontextstore.go | GetStorageInfo | func (s *ContextStoreWithDefault) GetStorageInfo(contextName string) store.StorageInfo {
if contextName == DefaultContextName {
return store.StorageInfo{MetadataPath: "<IN MEMORY>", TLSPath: "<IN MEMORY>"}
}
return s.Store.GetStorageInfo(contextName)
} | go | func (s *ContextStoreWithDefault) GetStorageInfo(contextName string) store.StorageInfo {
if contextName == DefaultContextName {
return store.StorageInfo{MetadataPath: "<IN MEMORY>", TLSPath: "<IN MEMORY>"}
}
return s.Store.GetStorageInfo(contextName)
} | [
"func",
"(",
"s",
"*",
"ContextStoreWithDefault",
")",
"GetStorageInfo",
"(",
"contextName",
"string",
")",
"store",
".",
"StorageInfo",
"{",
"if",
"contextName",
"==",
"DefaultContextName",
"{",
"return",
"store",
".",
"StorageInfo",
"{",
"MetadataPath",
":",
"... | // GetStorageInfo implements store.Store's GetStorageInfo | [
"GetStorageInfo",
"implements",
"store",
".",
"Store",
"s",
"GetStorageInfo"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/defaultcontextstore.go#L193-L198 |
159,614 | docker/cli | cli/command/secret/formatter.go | NewFormat | func NewFormat(source string, quiet bool) formatter.Format {
switch source {
case formatter.PrettyFormatKey:
return secretInspectPrettyTemplate
case formatter.TableFormatKey:
if quiet {
return formatter.DefaultQuietFormat
}
return defaultSecretTableFormat
}
return formatter.Format(source)
} | go | func NewFormat(source string, quiet bool) formatter.Format {
switch source {
case formatter.PrettyFormatKey:
return secretInspectPrettyTemplate
case formatter.TableFormatKey:
if quiet {
return formatter.DefaultQuietFormat
}
return defaultSecretTableFormat
}
return formatter.Format(source)
} | [
"func",
"NewFormat",
"(",
"source",
"string",
",",
"quiet",
"bool",
")",
"formatter",
".",
"Format",
"{",
"switch",
"source",
"{",
"case",
"formatter",
".",
"PrettyFormatKey",
":",
"return",
"secretInspectPrettyTemplate",
"\n",
"case",
"formatter",
".",
"TableFo... | // NewFormat returns a Format for rendering using a secret Context | [
"NewFormat",
"returns",
"a",
"Format",
"for",
"rendering",
"using",
"a",
"secret",
"Context"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/secret/formatter.go#L33-L44 |
159,615 | docker/cli | cli/command/secret/formatter.go | InspectFormatWrite | func InspectFormatWrite(ctx formatter.Context, refs []string, getRef inspect.GetRefFunc) error {
if ctx.Format != secretInspectPrettyTemplate {
return inspect.Inspect(ctx.Output, refs, string(ctx.Format), getRef)
}
render := func(format func(subContext formatter.SubContext) error) error {
for _, ref := range refs {
secretI, _, err := getRef(ref)
if err != nil {
return err
}
secret, ok := secretI.(swarm.Secret)
if !ok {
return fmt.Errorf("got wrong object to inspect :%v", ok)
}
if err := format(&secretInspectContext{Secret: secret}); err != nil {
return err
}
}
return nil
}
return ctx.Write(&secretInspectContext{}, render)
} | go | func InspectFormatWrite(ctx formatter.Context, refs []string, getRef inspect.GetRefFunc) error {
if ctx.Format != secretInspectPrettyTemplate {
return inspect.Inspect(ctx.Output, refs, string(ctx.Format), getRef)
}
render := func(format func(subContext formatter.SubContext) error) error {
for _, ref := range refs {
secretI, _, err := getRef(ref)
if err != nil {
return err
}
secret, ok := secretI.(swarm.Secret)
if !ok {
return fmt.Errorf("got wrong object to inspect :%v", ok)
}
if err := format(&secretInspectContext{Secret: secret}); err != nil {
return err
}
}
return nil
}
return ctx.Write(&secretInspectContext{}, render)
} | [
"func",
"InspectFormatWrite",
"(",
"ctx",
"formatter",
".",
"Context",
",",
"refs",
"[",
"]",
"string",
",",
"getRef",
"inspect",
".",
"GetRefFunc",
")",
"error",
"{",
"if",
"ctx",
".",
"Format",
"!=",
"secretInspectPrettyTemplate",
"{",
"return",
"inspect",
... | // InspectFormatWrite renders the context for a list of secrets | [
"InspectFormatWrite",
"renders",
"the",
"context",
"for",
"a",
"list",
"of",
"secrets"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/secret/formatter.go#L126-L147 |
159,616 | docker/cli | opts/opts.go | ValidateMACAddress | func ValidateMACAddress(val string) (string, error) {
_, err := net.ParseMAC(strings.TrimSpace(val))
if err != nil {
return "", err
}
return val, nil
} | go | func ValidateMACAddress(val string) (string, error) {
_, err := net.ParseMAC(strings.TrimSpace(val))
if err != nil {
return "", err
}
return val, nil
} | [
"func",
"ValidateMACAddress",
"(",
"val",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"_",
",",
"err",
":=",
"net",
".",
"ParseMAC",
"(",
"strings",
".",
"TrimSpace",
"(",
"val",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\... | // ValidateMACAddress validates a MAC address. | [
"ValidateMACAddress",
"validates",
"a",
"MAC",
"address",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/opts/opts.go#L241-L247 |
159,617 | docker/cli | opts/opts.go | ValidateSysctl | func ValidateSysctl(val string) (string, error) {
validSysctlMap := map[string]bool{
"kernel.msgmax": true,
"kernel.msgmnb": true,
"kernel.msgmni": true,
"kernel.sem": true,
"kernel.shmall": true,
"kernel.shmmax": true,
"kernel.shmmni": true,
"kernel.shm_rmid_forced": true,
}
validSysctlPrefixes := []string{
"net.",
"fs.mqueue.",
}
arr := strings.Split(val, "=")
if len(arr) < 2 {
return "", fmt.Errorf("sysctl '%s' is not whitelisted", val)
}
if validSysctlMap[arr[0]] {
return val, nil
}
for _, vp := range validSysctlPrefixes {
if strings.HasPrefix(arr[0], vp) {
return val, nil
}
}
return "", fmt.Errorf("sysctl '%s' is not whitelisted", val)
} | go | func ValidateSysctl(val string) (string, error) {
validSysctlMap := map[string]bool{
"kernel.msgmax": true,
"kernel.msgmnb": true,
"kernel.msgmni": true,
"kernel.sem": true,
"kernel.shmall": true,
"kernel.shmmax": true,
"kernel.shmmni": true,
"kernel.shm_rmid_forced": true,
}
validSysctlPrefixes := []string{
"net.",
"fs.mqueue.",
}
arr := strings.Split(val, "=")
if len(arr) < 2 {
return "", fmt.Errorf("sysctl '%s' is not whitelisted", val)
}
if validSysctlMap[arr[0]] {
return val, nil
}
for _, vp := range validSysctlPrefixes {
if strings.HasPrefix(arr[0], vp) {
return val, nil
}
}
return "", fmt.Errorf("sysctl '%s' is not whitelisted", val)
} | [
"func",
"ValidateSysctl",
"(",
"val",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"validSysctlMap",
":=",
"map",
"[",
"string",
"]",
"bool",
"{",
"\"",
"\"",
":",
"true",
",",
"\"",
"\"",
":",
"true",
",",
"\"",
"\"",
":",
"true",
",",
... | // ValidateSysctl validates a sysctl and returns it. | [
"ValidateSysctl",
"validates",
"a",
"sysctl",
"and",
"returns",
"it",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/opts/opts.go#L293-L322 |
159,618 | docker/cli | opts/opts.go | String | func (c *NanoCPUs) String() string {
if *c == 0 {
return ""
}
return big.NewRat(c.Value(), 1e9).FloatString(3)
} | go | func (c *NanoCPUs) String() string {
if *c == 0 {
return ""
}
return big.NewRat(c.Value(), 1e9).FloatString(3)
} | [
"func",
"(",
"c",
"*",
"NanoCPUs",
")",
"String",
"(",
")",
"string",
"{",
"if",
"*",
"c",
"==",
"0",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"big",
".",
"NewRat",
"(",
"c",
".",
"Value",
"(",
")",
",",
"1e9",
")",
".",
"FloatSt... | // String returns the string format of the number | [
"String",
"returns",
"the",
"string",
"format",
"of",
"the",
"number"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/opts/opts.go#L383-L388 |
159,619 | docker/cli | opts/opts.go | Set | func (c *NanoCPUs) Set(value string) error {
cpus, err := ParseCPUs(value)
*c = NanoCPUs(cpus)
return err
} | go | func (c *NanoCPUs) Set(value string) error {
cpus, err := ParseCPUs(value)
*c = NanoCPUs(cpus)
return err
} | [
"func",
"(",
"c",
"*",
"NanoCPUs",
")",
"Set",
"(",
"value",
"string",
")",
"error",
"{",
"cpus",
",",
"err",
":=",
"ParseCPUs",
"(",
"value",
")",
"\n",
"*",
"c",
"=",
"NanoCPUs",
"(",
"cpus",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // Set sets the value of the NanoCPU by passing a string | [
"Set",
"sets",
"the",
"value",
"of",
"the",
"NanoCPU",
"by",
"passing",
"a",
"string"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/opts/opts.go#L391-L395 |
159,620 | docker/cli | opts/opts.go | ParseCPUs | func ParseCPUs(value string) (int64, error) {
cpu, ok := new(big.Rat).SetString(value)
if !ok {
return 0, fmt.Errorf("failed to parse %v as a rational number", value)
}
nano := cpu.Mul(cpu, big.NewRat(1e9, 1))
if !nano.IsInt() {
return 0, fmt.Errorf("value is too precise")
}
return nano.Num().Int64(), nil
} | go | func ParseCPUs(value string) (int64, error) {
cpu, ok := new(big.Rat).SetString(value)
if !ok {
return 0, fmt.Errorf("failed to parse %v as a rational number", value)
}
nano := cpu.Mul(cpu, big.NewRat(1e9, 1))
if !nano.IsInt() {
return 0, fmt.Errorf("value is too precise")
}
return nano.Num().Int64(), nil
} | [
"func",
"ParseCPUs",
"(",
"value",
"string",
")",
"(",
"int64",
",",
"error",
")",
"{",
"cpu",
",",
"ok",
":=",
"new",
"(",
"big",
".",
"Rat",
")",
".",
"SetString",
"(",
"value",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"0",
",",
"fmt",
".",... | // ParseCPUs takes a string ratio and returns an integer value of nano cpus | [
"ParseCPUs",
"takes",
"a",
"string",
"ratio",
"and",
"returns",
"an",
"integer",
"value",
"of",
"nano",
"cpus"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/opts/opts.go#L408-L418 |
159,621 | docker/cli | opts/opts.go | Set | func (m *MemSwapBytes) Set(value string) error {
if value == "-1" {
*m = MemSwapBytes(-1)
return nil
}
val, err := units.RAMInBytes(value)
*m = MemSwapBytes(val)
return err
} | go | func (m *MemSwapBytes) Set(value string) error {
if value == "-1" {
*m = MemSwapBytes(-1)
return nil
}
val, err := units.RAMInBytes(value)
*m = MemSwapBytes(val)
return err
} | [
"func",
"(",
"m",
"*",
"MemSwapBytes",
")",
"Set",
"(",
"value",
"string",
")",
"error",
"{",
"if",
"value",
"==",
"\"",
"\"",
"{",
"*",
"m",
"=",
"MemSwapBytes",
"(",
"-",
"1",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"val",
",",
"err",
":... | // Set sets the value of the MemSwapBytes by passing a string | [
"Set",
"sets",
"the",
"value",
"of",
"the",
"MemSwapBytes",
"by",
"passing",
"a",
"string"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/opts/opts.go#L494-L502 |
159,622 | docker/cli | opts/opts.go | UnmarshalJSON | func (m *MemSwapBytes) UnmarshalJSON(s []byte) error {
b := MemBytes(*m)
return b.UnmarshalJSON(s)
} | go | func (m *MemSwapBytes) UnmarshalJSON(s []byte) error {
b := MemBytes(*m)
return b.UnmarshalJSON(s)
} | [
"func",
"(",
"m",
"*",
"MemSwapBytes",
")",
"UnmarshalJSON",
"(",
"s",
"[",
"]",
"byte",
")",
"error",
"{",
"b",
":=",
"MemBytes",
"(",
"*",
"m",
")",
"\n",
"return",
"b",
".",
"UnmarshalJSON",
"(",
"s",
")",
"\n",
"}"
] | // UnmarshalJSON is the customized unmarshaler for MemSwapBytes | [
"UnmarshalJSON",
"is",
"the",
"customized",
"unmarshaler",
"for",
"MemSwapBytes"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/opts/opts.go#L520-L523 |
159,623 | docker/cli | cli/command/context/cmd.go | NewContextCommand | func NewContextCommand(dockerCli command.Cli) *cobra.Command {
cmd := &cobra.Command{
Use: "context",
Short: "Manage contexts",
Args: cli.NoArgs,
RunE: command.ShowHelp(dockerCli.Err()),
}
cmd.AddCommand(
newCreateCommand(dockerCli),
newListCommand(dockerCli),
newUseCommand(dockerCli),
newExportCommand(dockerCli),
newImportCommand(dockerCli),
newRemoveCommand(dockerCli),
newUpdateCommand(dockerCli),
newInspectCommand(dockerCli),
)
return cmd
} | go | func NewContextCommand(dockerCli command.Cli) *cobra.Command {
cmd := &cobra.Command{
Use: "context",
Short: "Manage contexts",
Args: cli.NoArgs,
RunE: command.ShowHelp(dockerCli.Err()),
}
cmd.AddCommand(
newCreateCommand(dockerCli),
newListCommand(dockerCli),
newUseCommand(dockerCli),
newExportCommand(dockerCli),
newImportCommand(dockerCli),
newRemoveCommand(dockerCli),
newUpdateCommand(dockerCli),
newInspectCommand(dockerCli),
)
return cmd
} | [
"func",
"NewContextCommand",
"(",
"dockerCli",
"command",
".",
"Cli",
")",
"*",
"cobra",
".",
"Command",
"{",
"cmd",
":=",
"&",
"cobra",
".",
"Command",
"{",
"Use",
":",
"\"",
"\"",
",",
"Short",
":",
"\"",
"\"",
",",
"Args",
":",
"cli",
".",
"NoAr... | // NewContextCommand returns the context cli subcommand | [
"NewContextCommand",
"returns",
"the",
"context",
"cli",
"subcommand"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/context/cmd.go#L14-L32 |
159,624 | docker/cli | cli/command/container/commit.go | NewCommitCommand | func NewCommitCommand(dockerCli command.Cli) *cobra.Command {
var options commitOptions
cmd := &cobra.Command{
Use: "commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]",
Short: "Create a new image from a container's changes",
Args: cli.RequiresRangeArgs(1, 2),
RunE: func(cmd *cobra.Command, args []string) error {
options.container = args[0]
if len(args) > 1 {
options.reference = args[1]
}
return runCommit(dockerCli, &options)
},
}
flags := cmd.Flags()
flags.SetInterspersed(false)
flags.BoolVarP(&options.pause, "pause", "p", true, "Pause container during commit")
flags.StringVarP(&options.comment, "message", "m", "", "Commit message")
flags.StringVarP(&options.author, "author", "a", "", "Author (e.g., \"John Hannibal Smith <hannibal@a-team.com>\")")
options.changes = opts.NewListOpts(nil)
flags.VarP(&options.changes, "change", "c", "Apply Dockerfile instruction to the created image")
return cmd
} | go | func NewCommitCommand(dockerCli command.Cli) *cobra.Command {
var options commitOptions
cmd := &cobra.Command{
Use: "commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]",
Short: "Create a new image from a container's changes",
Args: cli.RequiresRangeArgs(1, 2),
RunE: func(cmd *cobra.Command, args []string) error {
options.container = args[0]
if len(args) > 1 {
options.reference = args[1]
}
return runCommit(dockerCli, &options)
},
}
flags := cmd.Flags()
flags.SetInterspersed(false)
flags.BoolVarP(&options.pause, "pause", "p", true, "Pause container during commit")
flags.StringVarP(&options.comment, "message", "m", "", "Commit message")
flags.StringVarP(&options.author, "author", "a", "", "Author (e.g., \"John Hannibal Smith <hannibal@a-team.com>\")")
options.changes = opts.NewListOpts(nil)
flags.VarP(&options.changes, "change", "c", "Apply Dockerfile instruction to the created image")
return cmd
} | [
"func",
"NewCommitCommand",
"(",
"dockerCli",
"command",
".",
"Cli",
")",
"*",
"cobra",
".",
"Command",
"{",
"var",
"options",
"commitOptions",
"\n\n",
"cmd",
":=",
"&",
"cobra",
".",
"Command",
"{",
"Use",
":",
"\"",
"\"",
",",
"Short",
":",
"\"",
"\"... | // NewCommitCommand creates a new cobra.Command for `docker commit` | [
"NewCommitCommand",
"creates",
"a",
"new",
"cobra",
".",
"Command",
"for",
"docker",
"commit"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/container/commit.go#L25-L52 |
159,625 | docker/cli | cli/config/credentials/native_store.go | NewNativeStore | func NewNativeStore(file store, helperSuffix string) Store {
name := remoteCredentialsPrefix + helperSuffix
return &nativeStore{
programFunc: client.NewShellProgramFunc(name),
fileStore: NewFileStore(file),
}
} | go | func NewNativeStore(file store, helperSuffix string) Store {
name := remoteCredentialsPrefix + helperSuffix
return &nativeStore{
programFunc: client.NewShellProgramFunc(name),
fileStore: NewFileStore(file),
}
} | [
"func",
"NewNativeStore",
"(",
"file",
"store",
",",
"helperSuffix",
"string",
")",
"Store",
"{",
"name",
":=",
"remoteCredentialsPrefix",
"+",
"helperSuffix",
"\n",
"return",
"&",
"nativeStore",
"{",
"programFunc",
":",
"client",
".",
"NewShellProgramFunc",
"(",
... | // NewNativeStore creates a new native store that
// uses a remote helper program to manage credentials. | [
"NewNativeStore",
"creates",
"a",
"new",
"native",
"store",
"that",
"uses",
"a",
"remote",
"helper",
"program",
"to",
"manage",
"credentials",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/config/credentials/native_store.go#L24-L30 |
159,626 | docker/cli | cli/config/credentials/native_store.go | Erase | func (c *nativeStore) Erase(serverAddress string) error {
if err := client.Erase(c.programFunc, serverAddress); err != nil {
return err
}
// Fallback to plain text store to remove email
return c.fileStore.Erase(serverAddress)
} | go | func (c *nativeStore) Erase(serverAddress string) error {
if err := client.Erase(c.programFunc, serverAddress); err != nil {
return err
}
// Fallback to plain text store to remove email
return c.fileStore.Erase(serverAddress)
} | [
"func",
"(",
"c",
"*",
"nativeStore",
")",
"Erase",
"(",
"serverAddress",
"string",
")",
"error",
"{",
"if",
"err",
":=",
"client",
".",
"Erase",
"(",
"c",
".",
"programFunc",
",",
"serverAddress",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
... | // Erase removes the given credentials from the native store. | [
"Erase",
"removes",
"the",
"given",
"credentials",
"from",
"the",
"native",
"store",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/config/credentials/native_store.go#L33-L40 |
159,627 | docker/cli | cli/config/credentials/native_store.go | Get | func (c *nativeStore) Get(serverAddress string) (types.AuthConfig, error) {
// load user email if it exist or an empty auth config.
auth, _ := c.fileStore.Get(serverAddress)
creds, err := c.getCredentialsFromStore(serverAddress)
if err != nil {
return auth, err
}
auth.Username = creds.Username
auth.IdentityToken = creds.IdentityToken
auth.Password = creds.Password
return auth, nil
} | go | func (c *nativeStore) Get(serverAddress string) (types.AuthConfig, error) {
// load user email if it exist or an empty auth config.
auth, _ := c.fileStore.Get(serverAddress)
creds, err := c.getCredentialsFromStore(serverAddress)
if err != nil {
return auth, err
}
auth.Username = creds.Username
auth.IdentityToken = creds.IdentityToken
auth.Password = creds.Password
return auth, nil
} | [
"func",
"(",
"c",
"*",
"nativeStore",
")",
"Get",
"(",
"serverAddress",
"string",
")",
"(",
"types",
".",
"AuthConfig",
",",
"error",
")",
"{",
"// load user email if it exist or an empty auth config.",
"auth",
",",
"_",
":=",
"c",
".",
"fileStore",
".",
"Get"... | // Get retrieves credentials for a specific server from the native store. | [
"Get",
"retrieves",
"credentials",
"for",
"a",
"specific",
"server",
"from",
"the",
"native",
"store",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/config/credentials/native_store.go#L43-L56 |
159,628 | docker/cli | cli/config/credentials/native_store.go | GetAll | func (c *nativeStore) GetAll() (map[string]types.AuthConfig, error) {
auths, err := c.listCredentialsInStore()
if err != nil {
return nil, err
}
// Emails are only stored in the file store.
// This call can be safely eliminated when emails are removed.
fileConfigs, _ := c.fileStore.GetAll()
authConfigs := make(map[string]types.AuthConfig)
for registry := range auths {
creds, err := c.getCredentialsFromStore(registry)
if err != nil {
return nil, err
}
ac := fileConfigs[registry] // might contain Email
ac.Username = creds.Username
ac.Password = creds.Password
ac.IdentityToken = creds.IdentityToken
authConfigs[registry] = ac
}
return authConfigs, nil
} | go | func (c *nativeStore) GetAll() (map[string]types.AuthConfig, error) {
auths, err := c.listCredentialsInStore()
if err != nil {
return nil, err
}
// Emails are only stored in the file store.
// This call can be safely eliminated when emails are removed.
fileConfigs, _ := c.fileStore.GetAll()
authConfigs := make(map[string]types.AuthConfig)
for registry := range auths {
creds, err := c.getCredentialsFromStore(registry)
if err != nil {
return nil, err
}
ac := fileConfigs[registry] // might contain Email
ac.Username = creds.Username
ac.Password = creds.Password
ac.IdentityToken = creds.IdentityToken
authConfigs[registry] = ac
}
return authConfigs, nil
} | [
"func",
"(",
"c",
"*",
"nativeStore",
")",
"GetAll",
"(",
")",
"(",
"map",
"[",
"string",
"]",
"types",
".",
"AuthConfig",
",",
"error",
")",
"{",
"auths",
",",
"err",
":=",
"c",
".",
"listCredentialsInStore",
"(",
")",
"\n",
"if",
"err",
"!=",
"ni... | // GetAll retrieves all the credentials from the native store. | [
"GetAll",
"retrieves",
"all",
"the",
"credentials",
"from",
"the",
"native",
"store",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/config/credentials/native_store.go#L59-L83 |
159,629 | docker/cli | cli/config/credentials/native_store.go | storeCredentialsInStore | func (c *nativeStore) storeCredentialsInStore(config types.AuthConfig) error {
creds := &credentials.Credentials{
ServerURL: config.ServerAddress,
Username: config.Username,
Secret: config.Password,
}
if config.IdentityToken != "" {
creds.Username = tokenUsername
creds.Secret = config.IdentityToken
}
return client.Store(c.programFunc, creds)
} | go | func (c *nativeStore) storeCredentialsInStore(config types.AuthConfig) error {
creds := &credentials.Credentials{
ServerURL: config.ServerAddress,
Username: config.Username,
Secret: config.Password,
}
if config.IdentityToken != "" {
creds.Username = tokenUsername
creds.Secret = config.IdentityToken
}
return client.Store(c.programFunc, creds)
} | [
"func",
"(",
"c",
"*",
"nativeStore",
")",
"storeCredentialsInStore",
"(",
"config",
"types",
".",
"AuthConfig",
")",
"error",
"{",
"creds",
":=",
"&",
"credentials",
".",
"Credentials",
"{",
"ServerURL",
":",
"config",
".",
"ServerAddress",
",",
"Username",
... | // storeCredentialsInStore executes the command to store the credentials in the native store. | [
"storeCredentialsInStore",
"executes",
"the",
"command",
"to",
"store",
"the",
"credentials",
"in",
"the",
"native",
"store",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/config/credentials/native_store.go#L99-L112 |
159,630 | docker/cli | cli/config/credentials/native_store.go | getCredentialsFromStore | func (c *nativeStore) getCredentialsFromStore(serverAddress string) (types.AuthConfig, error) {
var ret types.AuthConfig
creds, err := client.Get(c.programFunc, serverAddress)
if err != nil {
if credentials.IsErrCredentialsNotFound(err) {
// do not return an error if the credentials are not
// in the keychain. Let docker ask for new credentials.
return ret, nil
}
return ret, err
}
if creds.Username == tokenUsername {
ret.IdentityToken = creds.Secret
} else {
ret.Password = creds.Secret
ret.Username = creds.Username
}
ret.ServerAddress = serverAddress
return ret, nil
} | go | func (c *nativeStore) getCredentialsFromStore(serverAddress string) (types.AuthConfig, error) {
var ret types.AuthConfig
creds, err := client.Get(c.programFunc, serverAddress)
if err != nil {
if credentials.IsErrCredentialsNotFound(err) {
// do not return an error if the credentials are not
// in the keychain. Let docker ask for new credentials.
return ret, nil
}
return ret, err
}
if creds.Username == tokenUsername {
ret.IdentityToken = creds.Secret
} else {
ret.Password = creds.Secret
ret.Username = creds.Username
}
ret.ServerAddress = serverAddress
return ret, nil
} | [
"func",
"(",
"c",
"*",
"nativeStore",
")",
"getCredentialsFromStore",
"(",
"serverAddress",
"string",
")",
"(",
"types",
".",
"AuthConfig",
",",
"error",
")",
"{",
"var",
"ret",
"types",
".",
"AuthConfig",
"\n\n",
"creds",
",",
"err",
":=",
"client",
".",
... | // getCredentialsFromStore executes the command to get the credentials from the native store. | [
"getCredentialsFromStore",
"executes",
"the",
"command",
"to",
"get",
"the",
"credentials",
"from",
"the",
"native",
"store",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/config/credentials/native_store.go#L115-L137 |
159,631 | docker/cli | cli/config/credentials/native_store.go | listCredentialsInStore | func (c *nativeStore) listCredentialsInStore() (map[string]string, error) {
return client.List(c.programFunc)
} | go | func (c *nativeStore) listCredentialsInStore() (map[string]string, error) {
return client.List(c.programFunc)
} | [
"func",
"(",
"c",
"*",
"nativeStore",
")",
"listCredentialsInStore",
"(",
")",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"return",
"client",
".",
"List",
"(",
"c",
".",
"programFunc",
")",
"\n",
"}"
] | // listCredentialsInStore returns a listing of stored credentials as a map of
// URL -> username. | [
"listCredentialsInStore",
"returns",
"a",
"listing",
"of",
"stored",
"credentials",
"as",
"a",
"map",
"of",
"URL",
"-",
">",
"username",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/config/credentials/native_store.go#L141-L143 |
159,632 | docker/cli | internal/versions/versions.go | GetEngineVersions | func GetEngineVersions(ctx context.Context, registryClient registryclient.RegistryClient, registryPrefix, imageName, versionString string) (clitypes.AvailableVersions, error) {
if imageName == "" {
var err error
localMetadata, err := GetCurrentRuntimeMetadata("")
if err != nil {
return clitypes.AvailableVersions{}, err
}
imageName = localMetadata.EngineImage
}
imageRef, err := reference.ParseNormalizedNamed(path.Join(registryPrefix, imageName))
if err != nil {
return clitypes.AvailableVersions{}, err
}
tags, err := registryClient.GetTags(ctx, imageRef)
if err != nil {
return clitypes.AvailableVersions{}, err
}
return parseTags(tags, versionString)
} | go | func GetEngineVersions(ctx context.Context, registryClient registryclient.RegistryClient, registryPrefix, imageName, versionString string) (clitypes.AvailableVersions, error) {
if imageName == "" {
var err error
localMetadata, err := GetCurrentRuntimeMetadata("")
if err != nil {
return clitypes.AvailableVersions{}, err
}
imageName = localMetadata.EngineImage
}
imageRef, err := reference.ParseNormalizedNamed(path.Join(registryPrefix, imageName))
if err != nil {
return clitypes.AvailableVersions{}, err
}
tags, err := registryClient.GetTags(ctx, imageRef)
if err != nil {
return clitypes.AvailableVersions{}, err
}
return parseTags(tags, versionString)
} | [
"func",
"GetEngineVersions",
"(",
"ctx",
"context",
".",
"Context",
",",
"registryClient",
"registryclient",
".",
"RegistryClient",
",",
"registryPrefix",
",",
"imageName",
",",
"versionString",
"string",
")",
"(",
"clitypes",
".",
"AvailableVersions",
",",
"error",... | // GetEngineVersions reports the versions of the engine that are available | [
"GetEngineVersions",
"reports",
"the",
"versions",
"of",
"the",
"engine",
"that",
"are",
"available"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/internal/versions/versions.go#L26-L47 |
159,633 | docker/cli | internal/versions/versions.go | GetCurrentRuntimeMetadata | func GetCurrentRuntimeMetadata(metadataDir string) (*clitypes.RuntimeMetadata, error) {
if metadataDir == "" {
metadataDir = defaultRuntimeMetadataDir
}
filename := filepath.Join(metadataDir, clitypes.RuntimeMetadataName+".json")
data, err := ioutil.ReadFile(filename)
if err != nil {
return nil, err
}
var res clitypes.RuntimeMetadata
err = json.Unmarshal(data, &res)
if err != nil {
return nil, errors.Wrapf(err, "malformed runtime metadata file %s", filename)
}
return &res, nil
} | go | func GetCurrentRuntimeMetadata(metadataDir string) (*clitypes.RuntimeMetadata, error) {
if metadataDir == "" {
metadataDir = defaultRuntimeMetadataDir
}
filename := filepath.Join(metadataDir, clitypes.RuntimeMetadataName+".json")
data, err := ioutil.ReadFile(filename)
if err != nil {
return nil, err
}
var res clitypes.RuntimeMetadata
err = json.Unmarshal(data, &res)
if err != nil {
return nil, errors.Wrapf(err, "malformed runtime metadata file %s", filename)
}
return &res, nil
} | [
"func",
"GetCurrentRuntimeMetadata",
"(",
"metadataDir",
"string",
")",
"(",
"*",
"clitypes",
".",
"RuntimeMetadata",
",",
"error",
")",
"{",
"if",
"metadataDir",
"==",
"\"",
"\"",
"{",
"metadataDir",
"=",
"defaultRuntimeMetadataDir",
"\n",
"}",
"\n",
"filename"... | // GetCurrentRuntimeMetadata loads the current daemon runtime metadata information from the local host | [
"GetCurrentRuntimeMetadata",
"loads",
"the",
"current",
"daemon",
"runtime",
"metadata",
"information",
"from",
"the",
"local",
"host"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/internal/versions/versions.go#L95-L111 |
159,634 | docker/cli | internal/versions/versions.go | WriteRuntimeMetadata | func WriteRuntimeMetadata(metadataDir string, metadata *clitypes.RuntimeMetadata) error {
if metadataDir == "" {
metadataDir = defaultRuntimeMetadataDir
}
filename := filepath.Join(metadataDir, clitypes.RuntimeMetadataName+".json")
data, err := json.Marshal(metadata)
if err != nil {
return err
}
os.Remove(filename)
return ioutil.WriteFile(filename, data, 0644)
} | go | func WriteRuntimeMetadata(metadataDir string, metadata *clitypes.RuntimeMetadata) error {
if metadataDir == "" {
metadataDir = defaultRuntimeMetadataDir
}
filename := filepath.Join(metadataDir, clitypes.RuntimeMetadataName+".json")
data, err := json.Marshal(metadata)
if err != nil {
return err
}
os.Remove(filename)
return ioutil.WriteFile(filename, data, 0644)
} | [
"func",
"WriteRuntimeMetadata",
"(",
"metadataDir",
"string",
",",
"metadata",
"*",
"clitypes",
".",
"RuntimeMetadata",
")",
"error",
"{",
"if",
"metadataDir",
"==",
"\"",
"\"",
"{",
"metadataDir",
"=",
"defaultRuntimeMetadataDir",
"\n",
"}",
"\n",
"filename",
"... | // WriteRuntimeMetadata stores the metadata on the local system | [
"WriteRuntimeMetadata",
"stores",
"the",
"metadata",
"on",
"the",
"local",
"system"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/internal/versions/versions.go#L114-L127 |
159,635 | docker/cli | cli/command/system/prune.go | newPruneCommand | func newPruneCommand(dockerCli command.Cli) *cobra.Command {
options := pruneOptions{filter: opts.NewFilterOpt()}
cmd := &cobra.Command{
Use: "prune [OPTIONS]",
Short: "Remove unused data",
Args: cli.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
options.pruneBuildCache = versions.GreaterThanOrEqualTo(dockerCli.Client().ClientVersion(), "1.31")
return runPrune(dockerCli, options)
},
Annotations: map[string]string{"version": "1.25"},
}
flags := cmd.Flags()
flags.BoolVarP(&options.force, "force", "f", false, "Do not prompt for confirmation")
flags.BoolVarP(&options.all, "all", "a", false, "Remove all unused images not just dangling ones")
flags.BoolVar(&options.pruneVolumes, "volumes", false, "Prune volumes")
flags.Var(&options.filter, "filter", "Provide filter values (e.g. 'label=<key>=<value>')")
// "filter" flag is available in 1.28 (docker 17.04) and up
flags.SetAnnotation("filter", "version", []string{"1.28"})
return cmd
} | go | func newPruneCommand(dockerCli command.Cli) *cobra.Command {
options := pruneOptions{filter: opts.NewFilterOpt()}
cmd := &cobra.Command{
Use: "prune [OPTIONS]",
Short: "Remove unused data",
Args: cli.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
options.pruneBuildCache = versions.GreaterThanOrEqualTo(dockerCli.Client().ClientVersion(), "1.31")
return runPrune(dockerCli, options)
},
Annotations: map[string]string{"version": "1.25"},
}
flags := cmd.Flags()
flags.BoolVarP(&options.force, "force", "f", false, "Do not prompt for confirmation")
flags.BoolVarP(&options.all, "all", "a", false, "Remove all unused images not just dangling ones")
flags.BoolVar(&options.pruneVolumes, "volumes", false, "Prune volumes")
flags.Var(&options.filter, "filter", "Provide filter values (e.g. 'label=<key>=<value>')")
// "filter" flag is available in 1.28 (docker 17.04) and up
flags.SetAnnotation("filter", "version", []string{"1.28"})
return cmd
} | [
"func",
"newPruneCommand",
"(",
"dockerCli",
"command",
".",
"Cli",
")",
"*",
"cobra",
".",
"Command",
"{",
"options",
":=",
"pruneOptions",
"{",
"filter",
":",
"opts",
".",
"NewFilterOpt",
"(",
")",
"}",
"\n\n",
"cmd",
":=",
"&",
"cobra",
".",
"Command"... | // newPruneCommand creates a new cobra.Command for `docker prune` | [
"newPruneCommand",
"creates",
"a",
"new",
"cobra",
".",
"Command",
"for",
"docker",
"prune"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/system/prune.go#L32-L55 |
159,636 | docker/cli | cli/command/system/prune.go | confirmationMessage | func confirmationMessage(dockerCli command.Cli, options pruneOptions) string {
t := template.Must(template.New("confirmation message").Parse(confirmationTemplate))
warnings := []string{
"all stopped containers",
"all networks not used by at least one container",
}
if options.pruneVolumes {
warnings = append(warnings, "all volumes not used by at least one container")
}
if options.all {
warnings = append(warnings, "all images without at least one container associated to them")
} else {
warnings = append(warnings, "all dangling images")
}
if options.pruneBuildCache {
if options.all {
warnings = append(warnings, "all build cache")
} else {
warnings = append(warnings, "all dangling build cache")
}
}
var filters []string
pruneFilters := command.PruneFilters(dockerCli, options.filter.Value())
if pruneFilters.Len() > 0 {
// TODO remove fixed list of filters, and print all filters instead,
// because the list of filters that is supported by the engine may evolve over time.
for _, name := range []string{"label", "label!", "until"} {
for _, v := range pruneFilters.Get(name) {
filters = append(filters, name+"="+v)
}
}
sort.Slice(filters, func(i, j int) bool {
return sortorder.NaturalLess(filters[i], filters[j])
})
}
var buffer bytes.Buffer
t.Execute(&buffer, map[string][]string{"warnings": warnings, "filters": filters})
return buffer.String()
} | go | func confirmationMessage(dockerCli command.Cli, options pruneOptions) string {
t := template.Must(template.New("confirmation message").Parse(confirmationTemplate))
warnings := []string{
"all stopped containers",
"all networks not used by at least one container",
}
if options.pruneVolumes {
warnings = append(warnings, "all volumes not used by at least one container")
}
if options.all {
warnings = append(warnings, "all images without at least one container associated to them")
} else {
warnings = append(warnings, "all dangling images")
}
if options.pruneBuildCache {
if options.all {
warnings = append(warnings, "all build cache")
} else {
warnings = append(warnings, "all dangling build cache")
}
}
var filters []string
pruneFilters := command.PruneFilters(dockerCli, options.filter.Value())
if pruneFilters.Len() > 0 {
// TODO remove fixed list of filters, and print all filters instead,
// because the list of filters that is supported by the engine may evolve over time.
for _, name := range []string{"label", "label!", "until"} {
for _, v := range pruneFilters.Get(name) {
filters = append(filters, name+"="+v)
}
}
sort.Slice(filters, func(i, j int) bool {
return sortorder.NaturalLess(filters[i], filters[j])
})
}
var buffer bytes.Buffer
t.Execute(&buffer, map[string][]string{"warnings": warnings, "filters": filters})
return buffer.String()
} | [
"func",
"confirmationMessage",
"(",
"dockerCli",
"command",
".",
"Cli",
",",
"options",
"pruneOptions",
")",
"string",
"{",
"t",
":=",
"template",
".",
"Must",
"(",
"template",
".",
"New",
"(",
"\"",
"\"",
")",
".",
"Parse",
"(",
"confirmationTemplate",
")... | // confirmationMessage constructs a confirmation message that depends on the cli options. | [
"confirmationMessage",
"constructs",
"a",
"confirmation",
"message",
"that",
"depends",
"on",
"the",
"cli",
"options",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/system/prune.go#L107-L148 |
159,637 | docker/cli | e2e/internal/fixtures/fixtures.go | SetupConfigFile | func SetupConfigFile(t *testing.T) fs.Dir {
t.Helper()
return SetupConfigWithNotaryURL(t, "trust_test", NotaryURL)
} | go | func SetupConfigFile(t *testing.T) fs.Dir {
t.Helper()
return SetupConfigWithNotaryURL(t, "trust_test", NotaryURL)
} | [
"func",
"SetupConfigFile",
"(",
"t",
"*",
"testing",
".",
"T",
")",
"fs",
".",
"Dir",
"{",
"t",
".",
"Helper",
"(",
")",
"\n",
"return",
"SetupConfigWithNotaryURL",
"(",
"t",
",",
"\"",
"\"",
",",
"NotaryURL",
")",
"\n",
"}"
] | //SetupConfigFile creates a config.json file for testing | [
"SetupConfigFile",
"creates",
"a",
"config",
".",
"json",
"file",
"for",
"testing"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/e2e/internal/fixtures/fixtures.go#L28-L31 |
159,638 | docker/cli | e2e/internal/fixtures/fixtures.go | SetupConfigWithNotaryURL | func SetupConfigWithNotaryURL(t *testing.T, path, notaryURL string) fs.Dir {
t.Helper()
dir := fs.NewDir(t, path, fs.WithMode(0700), fs.WithFile("config.json", fmt.Sprintf(`
{
"auths": {
"registry:5000": {
"auth": "ZWlhaXM6cGFzc3dvcmQK"
},
"%s": {
"auth": "ZWlhaXM6cGFzc3dvcmQK"
}
},
"experimental": "enabled"
}
`, notaryURL)), fs.WithDir("trust", fs.WithDir("private")))
return *dir
} | go | func SetupConfigWithNotaryURL(t *testing.T, path, notaryURL string) fs.Dir {
t.Helper()
dir := fs.NewDir(t, path, fs.WithMode(0700), fs.WithFile("config.json", fmt.Sprintf(`
{
"auths": {
"registry:5000": {
"auth": "ZWlhaXM6cGFzc3dvcmQK"
},
"%s": {
"auth": "ZWlhaXM6cGFzc3dvcmQK"
}
},
"experimental": "enabled"
}
`, notaryURL)), fs.WithDir("trust", fs.WithDir("private")))
return *dir
} | [
"func",
"SetupConfigWithNotaryURL",
"(",
"t",
"*",
"testing",
".",
"T",
",",
"path",
",",
"notaryURL",
"string",
")",
"fs",
".",
"Dir",
"{",
"t",
".",
"Helper",
"(",
")",
"\n",
"dir",
":=",
"fs",
".",
"NewDir",
"(",
"t",
",",
"path",
",",
"fs",
"... | //SetupConfigWithNotaryURL creates a config.json file for testing in the given path
//with the given notaryURL | [
"SetupConfigWithNotaryURL",
"creates",
"a",
"config",
".",
"json",
"file",
"for",
"testing",
"in",
"the",
"given",
"path",
"with",
"the",
"given",
"notaryURL"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/e2e/internal/fixtures/fixtures.go#L35-L51 |
159,639 | docker/cli | e2e/internal/fixtures/fixtures.go | WithConfig | func WithConfig(dir string) func(cmd *icmd.Cmd) {
return func(cmd *icmd.Cmd) {
env := append(os.Environ(),
"DOCKER_CONFIG="+dir,
)
cmd.Env = append(cmd.Env, env...)
}
} | go | func WithConfig(dir string) func(cmd *icmd.Cmd) {
return func(cmd *icmd.Cmd) {
env := append(os.Environ(),
"DOCKER_CONFIG="+dir,
)
cmd.Env = append(cmd.Env, env...)
}
} | [
"func",
"WithConfig",
"(",
"dir",
"string",
")",
"func",
"(",
"cmd",
"*",
"icmd",
".",
"Cmd",
")",
"{",
"return",
"func",
"(",
"cmd",
"*",
"icmd",
".",
"Cmd",
")",
"{",
"env",
":=",
"append",
"(",
"os",
".",
"Environ",
"(",
")",
",",
"\"",
"\""... | //WithConfig sets an environment variable for the docker config location | [
"WithConfig",
"sets",
"an",
"environment",
"variable",
"for",
"the",
"docker",
"config",
"location"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/e2e/internal/fixtures/fixtures.go#L54-L61 |
159,640 | docker/cli | e2e/internal/fixtures/fixtures.go | WithPassphrase | func WithPassphrase(rootPwd, repositoryPwd string) func(cmd *icmd.Cmd) {
return func(cmd *icmd.Cmd) {
env := append(os.Environ(),
"DOCKER_CONTENT_TRUST_ROOT_PASSPHRASE="+rootPwd,
"DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE="+repositoryPwd,
)
cmd.Env = append(cmd.Env, env...)
}
} | go | func WithPassphrase(rootPwd, repositoryPwd string) func(cmd *icmd.Cmd) {
return func(cmd *icmd.Cmd) {
env := append(os.Environ(),
"DOCKER_CONTENT_TRUST_ROOT_PASSPHRASE="+rootPwd,
"DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE="+repositoryPwd,
)
cmd.Env = append(cmd.Env, env...)
}
} | [
"func",
"WithPassphrase",
"(",
"rootPwd",
",",
"repositoryPwd",
"string",
")",
"func",
"(",
"cmd",
"*",
"icmd",
".",
"Cmd",
")",
"{",
"return",
"func",
"(",
"cmd",
"*",
"icmd",
".",
"Cmd",
")",
"{",
"env",
":=",
"append",
"(",
"os",
".",
"Environ",
... | //WithPassphrase sets environment variables for passphrases | [
"WithPassphrase",
"sets",
"environment",
"variables",
"for",
"passphrases"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/e2e/internal/fixtures/fixtures.go#L64-L72 |
159,641 | docker/cli | e2e/internal/fixtures/fixtures.go | WithTrust | func WithTrust(cmd *icmd.Cmd) {
env := append(os.Environ(),
"DOCKER_CONTENT_TRUST=1",
)
cmd.Env = append(cmd.Env, env...)
} | go | func WithTrust(cmd *icmd.Cmd) {
env := append(os.Environ(),
"DOCKER_CONTENT_TRUST=1",
)
cmd.Env = append(cmd.Env, env...)
} | [
"func",
"WithTrust",
"(",
"cmd",
"*",
"icmd",
".",
"Cmd",
")",
"{",
"env",
":=",
"append",
"(",
"os",
".",
"Environ",
"(",
")",
",",
"\"",
"\"",
",",
")",
"\n",
"cmd",
".",
"Env",
"=",
"append",
"(",
"cmd",
".",
"Env",
",",
"env",
"...",
")",... | //WithTrust sets DOCKER_CONTENT_TRUST to 1 | [
"WithTrust",
"sets",
"DOCKER_CONTENT_TRUST",
"to",
"1"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/e2e/internal/fixtures/fixtures.go#L75-L80 |
159,642 | docker/cli | e2e/internal/fixtures/fixtures.go | WithNotary | func WithNotary(cmd *icmd.Cmd) {
env := append(os.Environ(),
"DOCKER_CONTENT_TRUST_SERVER="+NotaryURL,
)
cmd.Env = append(cmd.Env, env...)
} | go | func WithNotary(cmd *icmd.Cmd) {
env := append(os.Environ(),
"DOCKER_CONTENT_TRUST_SERVER="+NotaryURL,
)
cmd.Env = append(cmd.Env, env...)
} | [
"func",
"WithNotary",
"(",
"cmd",
"*",
"icmd",
".",
"Cmd",
")",
"{",
"env",
":=",
"append",
"(",
"os",
".",
"Environ",
"(",
")",
",",
"\"",
"\"",
"+",
"NotaryURL",
",",
")",
"\n",
"cmd",
".",
"Env",
"=",
"append",
"(",
"cmd",
".",
"Env",
",",
... | //WithNotary sets the location of the notary server | [
"WithNotary",
"sets",
"the",
"location",
"of",
"the",
"notary",
"server"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/e2e/internal/fixtures/fixtures.go#L83-L88 |
159,643 | docker/cli | e2e/internal/fixtures/fixtures.go | WithHome | func WithHome(path string) func(*icmd.Cmd) {
return func(cmd *icmd.Cmd) {
cmd.Env = append(cmd.Env, "HOME="+path)
}
} | go | func WithHome(path string) func(*icmd.Cmd) {
return func(cmd *icmd.Cmd) {
cmd.Env = append(cmd.Env, "HOME="+path)
}
} | [
"func",
"WithHome",
"(",
"path",
"string",
")",
"func",
"(",
"*",
"icmd",
".",
"Cmd",
")",
"{",
"return",
"func",
"(",
"cmd",
"*",
"icmd",
".",
"Cmd",
")",
"{",
"cmd",
".",
"Env",
"=",
"append",
"(",
"cmd",
".",
"Env",
",",
"\"",
"\"",
"+",
"... | //WithHome sets the HOME environment variable | [
"WithHome",
"sets",
"the",
"HOME",
"environment",
"variable"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/e2e/internal/fixtures/fixtures.go#L91-L95 |
159,644 | docker/cli | e2e/internal/fixtures/fixtures.go | WithNotaryServer | func WithNotaryServer(notaryURL string) func(*icmd.Cmd) {
return func(cmd *icmd.Cmd) {
env := append(os.Environ(),
"DOCKER_CONTENT_TRUST_SERVER="+notaryURL,
)
cmd.Env = append(cmd.Env, env...)
}
} | go | func WithNotaryServer(notaryURL string) func(*icmd.Cmd) {
return func(cmd *icmd.Cmd) {
env := append(os.Environ(),
"DOCKER_CONTENT_TRUST_SERVER="+notaryURL,
)
cmd.Env = append(cmd.Env, env...)
}
} | [
"func",
"WithNotaryServer",
"(",
"notaryURL",
"string",
")",
"func",
"(",
"*",
"icmd",
".",
"Cmd",
")",
"{",
"return",
"func",
"(",
"cmd",
"*",
"icmd",
".",
"Cmd",
")",
"{",
"env",
":=",
"append",
"(",
"os",
".",
"Environ",
"(",
")",
",",
"\"",
"... | //WithNotaryServer sets the location of the notary server | [
"WithNotaryServer",
"sets",
"the",
"location",
"of",
"the",
"notary",
"server"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/e2e/internal/fixtures/fixtures.go#L98-L105 |
159,645 | docker/cli | e2e/internal/fixtures/fixtures.go | CreateMaskedTrustedRemoteImage | func CreateMaskedTrustedRemoteImage(t *testing.T, registryPrefix, repo, tag string) string {
t.Helper()
image := createTrustedRemoteImage(t, registryPrefix, repo, tag)
createNamedUnsignedImageFromBusyBox(t, image)
return image
} | go | func CreateMaskedTrustedRemoteImage(t *testing.T, registryPrefix, repo, tag string) string {
t.Helper()
image := createTrustedRemoteImage(t, registryPrefix, repo, tag)
createNamedUnsignedImageFromBusyBox(t, image)
return image
} | [
"func",
"CreateMaskedTrustedRemoteImage",
"(",
"t",
"*",
"testing",
".",
"T",
",",
"registryPrefix",
",",
"repo",
",",
"tag",
"string",
")",
"string",
"{",
"t",
".",
"Helper",
"(",
")",
"\n",
"image",
":=",
"createTrustedRemoteImage",
"(",
"t",
",",
"regis... | // CreateMaskedTrustedRemoteImage creates a remote image that is signed with
// content trust, then pushes a different untrusted image at the same tag. | [
"CreateMaskedTrustedRemoteImage",
"creates",
"a",
"remote",
"image",
"that",
"is",
"signed",
"with",
"content",
"trust",
"then",
"pushes",
"a",
"different",
"untrusted",
"image",
"at",
"the",
"same",
"tag",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/e2e/internal/fixtures/fixtures.go#L109-L114 |
159,646 | docker/cli | cli/command/context/use.go | RunUse | func RunUse(dockerCli command.Cli, name string) error {
if err := validateContextName(name); err != nil && name != "default" {
return err
}
if _, err := dockerCli.ContextStore().GetMetadata(name); err != nil && name != "default" {
return err
}
configValue := name
if configValue == "default" {
configValue = ""
}
dockerConfig := dockerCli.ConfigFile()
dockerConfig.CurrentContext = configValue
if err := dockerConfig.Save(); err != nil {
return err
}
fmt.Fprintln(dockerCli.Out(), name)
fmt.Fprintf(dockerCli.Err(), "Current context is now %q\n", name)
if os.Getenv("DOCKER_HOST") != "" {
fmt.Fprintf(dockerCli.Err(), "Warning: DOCKER_HOST environment variable overrides the active context. "+
"To use %q, either set the global --context flag, or unset DOCKER_HOST environment variable.\n", name)
}
return nil
} | go | func RunUse(dockerCli command.Cli, name string) error {
if err := validateContextName(name); err != nil && name != "default" {
return err
}
if _, err := dockerCli.ContextStore().GetMetadata(name); err != nil && name != "default" {
return err
}
configValue := name
if configValue == "default" {
configValue = ""
}
dockerConfig := dockerCli.ConfigFile()
dockerConfig.CurrentContext = configValue
if err := dockerConfig.Save(); err != nil {
return err
}
fmt.Fprintln(dockerCli.Out(), name)
fmt.Fprintf(dockerCli.Err(), "Current context is now %q\n", name)
if os.Getenv("DOCKER_HOST") != "" {
fmt.Fprintf(dockerCli.Err(), "Warning: DOCKER_HOST environment variable overrides the active context. "+
"To use %q, either set the global --context flag, or unset DOCKER_HOST environment variable.\n", name)
}
return nil
} | [
"func",
"RunUse",
"(",
"dockerCli",
"command",
".",
"Cli",
",",
"name",
"string",
")",
"error",
"{",
"if",
"err",
":=",
"validateContextName",
"(",
"name",
")",
";",
"err",
"!=",
"nil",
"&&",
"name",
"!=",
"\"",
"\"",
"{",
"return",
"err",
"\n",
"}",... | // RunUse set the current Docker context | [
"RunUse",
"set",
"the",
"current",
"Docker",
"context"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/context/use.go#L25-L48 |
159,647 | docker/cli | cli/command/image/build/context.go | ValidateContextDirectory | func ValidateContextDirectory(srcPath string, excludes []string) error {
contextRoot, err := getContextRoot(srcPath)
if err != nil {
return err
}
pm, err := fileutils.NewPatternMatcher(excludes)
if err != nil {
return err
}
return filepath.Walk(contextRoot, func(filePath string, f os.FileInfo, err error) error {
if err != nil {
if os.IsPermission(err) {
return errors.Errorf("can't stat '%s'", filePath)
}
if os.IsNotExist(err) {
return errors.Errorf("file ('%s') not found or excluded by .dockerignore", filePath)
}
return err
}
// skip this directory/file if it's not in the path, it won't get added to the context
if relFilePath, err := filepath.Rel(contextRoot, filePath); err != nil {
return err
} else if skip, err := filepathMatches(pm, relFilePath); err != nil {
return err
} else if skip {
if f.IsDir() {
return filepath.SkipDir
}
return nil
}
// skip checking if symlinks point to non-existing files, such symlinks can be useful
// also skip named pipes, because they hanging on open
if f.Mode()&(os.ModeSymlink|os.ModeNamedPipe) != 0 {
return nil
}
if !f.IsDir() {
currentFile, err := os.Open(filePath)
if err != nil && os.IsPermission(err) {
return errors.Errorf("no permission to read from '%s'", filePath)
}
currentFile.Close()
}
return nil
})
} | go | func ValidateContextDirectory(srcPath string, excludes []string) error {
contextRoot, err := getContextRoot(srcPath)
if err != nil {
return err
}
pm, err := fileutils.NewPatternMatcher(excludes)
if err != nil {
return err
}
return filepath.Walk(contextRoot, func(filePath string, f os.FileInfo, err error) error {
if err != nil {
if os.IsPermission(err) {
return errors.Errorf("can't stat '%s'", filePath)
}
if os.IsNotExist(err) {
return errors.Errorf("file ('%s') not found or excluded by .dockerignore", filePath)
}
return err
}
// skip this directory/file if it's not in the path, it won't get added to the context
if relFilePath, err := filepath.Rel(contextRoot, filePath); err != nil {
return err
} else if skip, err := filepathMatches(pm, relFilePath); err != nil {
return err
} else if skip {
if f.IsDir() {
return filepath.SkipDir
}
return nil
}
// skip checking if symlinks point to non-existing files, such symlinks can be useful
// also skip named pipes, because they hanging on open
if f.Mode()&(os.ModeSymlink|os.ModeNamedPipe) != 0 {
return nil
}
if !f.IsDir() {
currentFile, err := os.Open(filePath)
if err != nil && os.IsPermission(err) {
return errors.Errorf("no permission to read from '%s'", filePath)
}
currentFile.Close()
}
return nil
})
} | [
"func",
"ValidateContextDirectory",
"(",
"srcPath",
"string",
",",
"excludes",
"[",
"]",
"string",
")",
"error",
"{",
"contextRoot",
",",
"err",
":=",
"getContextRoot",
"(",
"srcPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
... | // ValidateContextDirectory checks if all the contents of the directory
// can be read and returns an error if some files can't be read
// symlinks which point to non-existing files don't trigger an error | [
"ValidateContextDirectory",
"checks",
"if",
"all",
"the",
"contents",
"of",
"the",
"directory",
"can",
"be",
"read",
"and",
"returns",
"an",
"error",
"if",
"some",
"files",
"can",
"t",
"be",
"read",
"symlinks",
"which",
"point",
"to",
"non",
"-",
"existing",... | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/image/build/context.go#L39-L88 |
159,648 | docker/cli | cli/command/image/build/context.go | DetectArchiveReader | func DetectArchiveReader(input io.ReadCloser) (rc io.ReadCloser, isArchive bool, err error) {
buf := bufio.NewReader(input)
magic, err := buf.Peek(archiveHeaderSize * 2)
if err != nil && err != io.EOF {
return nil, false, errors.Errorf("failed to peek context header from STDIN: %v", err)
}
return ioutils.NewReadCloserWrapper(buf, func() error { return input.Close() }), IsArchive(magic), nil
} | go | func DetectArchiveReader(input io.ReadCloser) (rc io.ReadCloser, isArchive bool, err error) {
buf := bufio.NewReader(input)
magic, err := buf.Peek(archiveHeaderSize * 2)
if err != nil && err != io.EOF {
return nil, false, errors.Errorf("failed to peek context header from STDIN: %v", err)
}
return ioutils.NewReadCloserWrapper(buf, func() error { return input.Close() }), IsArchive(magic), nil
} | [
"func",
"DetectArchiveReader",
"(",
"input",
"io",
".",
"ReadCloser",
")",
"(",
"rc",
"io",
".",
"ReadCloser",
",",
"isArchive",
"bool",
",",
"err",
"error",
")",
"{",
"buf",
":=",
"bufio",
".",
"NewReader",
"(",
"input",
")",
"\n\n",
"magic",
",",
"er... | // DetectArchiveReader detects whether the input stream is an archive or a
// Dockerfile and returns a buffered version of input, safe to consume in lieu
// of input. If an archive is detected, isArchive is set to true, and to false
// otherwise, in which case it is safe to assume input represents the contents
// of a Dockerfile. | [
"DetectArchiveReader",
"detects",
"whether",
"the",
"input",
"stream",
"is",
"an",
"archive",
"or",
"a",
"Dockerfile",
"and",
"returns",
"a",
"buffered",
"version",
"of",
"input",
"safe",
"to",
"consume",
"in",
"lieu",
"of",
"input",
".",
"If",
"an",
"archiv... | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/image/build/context.go#L104-L113 |
159,649 | docker/cli | cli/command/image/build/context.go | WriteTempDockerfile | func WriteTempDockerfile(rc io.ReadCloser) (dockerfileDir string, err error) {
// err is a named return value, due to the defer call below.
dockerfileDir, err = ioutil.TempDir("", "docker-build-tempdockerfile-")
if err != nil {
return "", errors.Errorf("unable to create temporary context directory: %v", err)
}
defer func() {
if err != nil {
os.RemoveAll(dockerfileDir)
}
}()
f, err := os.Create(filepath.Join(dockerfileDir, DefaultDockerfileName))
if err != nil {
return "", err
}
defer f.Close()
if _, err := io.Copy(f, rc); err != nil {
return "", err
}
return dockerfileDir, rc.Close()
} | go | func WriteTempDockerfile(rc io.ReadCloser) (dockerfileDir string, err error) {
// err is a named return value, due to the defer call below.
dockerfileDir, err = ioutil.TempDir("", "docker-build-tempdockerfile-")
if err != nil {
return "", errors.Errorf("unable to create temporary context directory: %v", err)
}
defer func() {
if err != nil {
os.RemoveAll(dockerfileDir)
}
}()
f, err := os.Create(filepath.Join(dockerfileDir, DefaultDockerfileName))
if err != nil {
return "", err
}
defer f.Close()
if _, err := io.Copy(f, rc); err != nil {
return "", err
}
return dockerfileDir, rc.Close()
} | [
"func",
"WriteTempDockerfile",
"(",
"rc",
"io",
".",
"ReadCloser",
")",
"(",
"dockerfileDir",
"string",
",",
"err",
"error",
")",
"{",
"// err is a named return value, due to the defer call below.",
"dockerfileDir",
",",
"err",
"=",
"ioutil",
".",
"TempDir",
"(",
"\... | // WriteTempDockerfile writes a Dockerfile stream to a temporary file with a
// name specified by DefaultDockerfileName and returns the path to the
// temporary directory containing the Dockerfile. | [
"WriteTempDockerfile",
"writes",
"a",
"Dockerfile",
"stream",
"to",
"a",
"temporary",
"file",
"with",
"a",
"name",
"specified",
"by",
"DefaultDockerfileName",
"and",
"returns",
"the",
"path",
"to",
"the",
"temporary",
"directory",
"containing",
"the",
"Dockerfile",
... | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/image/build/context.go#L118-L139 |
159,650 | docker/cli | cli/command/image/build/context.go | GetContextFromReader | func GetContextFromReader(rc io.ReadCloser, dockerfileName string) (out io.ReadCloser, relDockerfile string, err error) {
rc, isArchive, err := DetectArchiveReader(rc)
if err != nil {
return nil, "", err
}
if isArchive {
return rc, dockerfileName, nil
}
// Input should be read as a Dockerfile.
if dockerfileName == "-" {
return nil, "", errors.New("build context is not an archive")
}
dockerfileDir, err := WriteTempDockerfile(rc)
if err != nil {
return nil, "", err
}
tar, err := archive.Tar(dockerfileDir, archive.Uncompressed)
if err != nil {
return nil, "", err
}
return ioutils.NewReadCloserWrapper(tar, func() error {
err := tar.Close()
os.RemoveAll(dockerfileDir)
return err
}), DefaultDockerfileName, nil
} | go | func GetContextFromReader(rc io.ReadCloser, dockerfileName string) (out io.ReadCloser, relDockerfile string, err error) {
rc, isArchive, err := DetectArchiveReader(rc)
if err != nil {
return nil, "", err
}
if isArchive {
return rc, dockerfileName, nil
}
// Input should be read as a Dockerfile.
if dockerfileName == "-" {
return nil, "", errors.New("build context is not an archive")
}
dockerfileDir, err := WriteTempDockerfile(rc)
if err != nil {
return nil, "", err
}
tar, err := archive.Tar(dockerfileDir, archive.Uncompressed)
if err != nil {
return nil, "", err
}
return ioutils.NewReadCloserWrapper(tar, func() error {
err := tar.Close()
os.RemoveAll(dockerfileDir)
return err
}), DefaultDockerfileName, nil
} | [
"func",
"GetContextFromReader",
"(",
"rc",
"io",
".",
"ReadCloser",
",",
"dockerfileName",
"string",
")",
"(",
"out",
"io",
".",
"ReadCloser",
",",
"relDockerfile",
"string",
",",
"err",
"error",
")",
"{",
"rc",
",",
"isArchive",
",",
"err",
":=",
"DetectA... | // GetContextFromReader will read the contents of the given reader as either a
// Dockerfile or tar archive. Returns a tar archive used as a context and a
// path to the Dockerfile inside the tar. | [
"GetContextFromReader",
"will",
"read",
"the",
"contents",
"of",
"the",
"given",
"reader",
"as",
"either",
"a",
"Dockerfile",
"or",
"tar",
"archive",
".",
"Returns",
"a",
"tar",
"archive",
"used",
"as",
"a",
"context",
"and",
"a",
"path",
"to",
"the",
"Doc... | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/image/build/context.go#L144-L175 |
159,651 | docker/cli | cli/command/image/build/context.go | IsArchive | func IsArchive(header []byte) bool {
compression := archive.DetectCompression(header)
if compression != archive.Uncompressed {
return true
}
r := tar.NewReader(bytes.NewBuffer(header))
_, err := r.Next()
return err == nil
} | go | func IsArchive(header []byte) bool {
compression := archive.DetectCompression(header)
if compression != archive.Uncompressed {
return true
}
r := tar.NewReader(bytes.NewBuffer(header))
_, err := r.Next()
return err == nil
} | [
"func",
"IsArchive",
"(",
"header",
"[",
"]",
"byte",
")",
"bool",
"{",
"compression",
":=",
"archive",
".",
"DetectCompression",
"(",
"header",
")",
"\n",
"if",
"compression",
"!=",
"archive",
".",
"Uncompressed",
"{",
"return",
"true",
"\n",
"}",
"\n",
... | // IsArchive checks for the magic bytes of a tar or any supported compression
// algorithm. | [
"IsArchive",
"checks",
"for",
"the",
"magic",
"bytes",
"of",
"a",
"tar",
"or",
"any",
"supported",
"compression",
"algorithm",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/image/build/context.go#L179-L187 |
159,652 | docker/cli | cli/command/image/build/context.go | GetContextFromGitURL | func GetContextFromGitURL(gitURL, dockerfileName string) (string, string, error) {
if _, err := exec.LookPath("git"); err != nil {
return "", "", errors.Wrapf(err, "unable to find 'git'")
}
absContextDir, err := git.Clone(gitURL)
if err != nil {
return "", "", errors.Wrapf(err, "unable to 'git clone' to temporary context directory")
}
absContextDir, err = ResolveAndValidateContextPath(absContextDir)
if err != nil {
return "", "", err
}
relDockerfile, err := getDockerfileRelPath(absContextDir, dockerfileName)
if err == nil && strings.HasPrefix(relDockerfile, ".."+string(filepath.Separator)) {
return "", "", errors.Errorf("the Dockerfile (%s) must be within the build context", dockerfileName)
}
return absContextDir, relDockerfile, err
} | go | func GetContextFromGitURL(gitURL, dockerfileName string) (string, string, error) {
if _, err := exec.LookPath("git"); err != nil {
return "", "", errors.Wrapf(err, "unable to find 'git'")
}
absContextDir, err := git.Clone(gitURL)
if err != nil {
return "", "", errors.Wrapf(err, "unable to 'git clone' to temporary context directory")
}
absContextDir, err = ResolveAndValidateContextPath(absContextDir)
if err != nil {
return "", "", err
}
relDockerfile, err := getDockerfileRelPath(absContextDir, dockerfileName)
if err == nil && strings.HasPrefix(relDockerfile, ".."+string(filepath.Separator)) {
return "", "", errors.Errorf("the Dockerfile (%s) must be within the build context", dockerfileName)
}
return absContextDir, relDockerfile, err
} | [
"func",
"GetContextFromGitURL",
"(",
"gitURL",
",",
"dockerfileName",
"string",
")",
"(",
"string",
",",
"string",
",",
"error",
")",
"{",
"if",
"_",
",",
"err",
":=",
"exec",
".",
"LookPath",
"(",
"\"",
"\"",
")",
";",
"err",
"!=",
"nil",
"{",
"retu... | // GetContextFromGitURL uses a Git URL as context for a `docker build`. The
// git repo is cloned into a temporary directory used as the context directory.
// Returns the absolute path to the temporary context directory, the relative
// path of the dockerfile in that context directory, and a non-nil error on
// success. | [
"GetContextFromGitURL",
"uses",
"a",
"Git",
"URL",
"as",
"context",
"for",
"a",
"docker",
"build",
".",
"The",
"git",
"repo",
"is",
"cloned",
"into",
"a",
"temporary",
"directory",
"used",
"as",
"the",
"context",
"directory",
".",
"Returns",
"the",
"absolute... | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/image/build/context.go#L194-L213 |
159,653 | docker/cli | cli/command/image/build/context.go | GetContextFromURL | func GetContextFromURL(out io.Writer, remoteURL, dockerfileName string) (io.ReadCloser, string, error) {
response, err := getWithStatusError(remoteURL)
if err != nil {
return nil, "", errors.Errorf("unable to download remote context %s: %v", remoteURL, err)
}
progressOutput := streamformatter.NewProgressOutput(out)
// Pass the response body through a progress reader.
progReader := progress.NewProgressReader(response.Body, progressOutput, response.ContentLength, "", fmt.Sprintf("Downloading build context from remote url: %s", remoteURL))
return GetContextFromReader(ioutils.NewReadCloserWrapper(progReader, func() error { return response.Body.Close() }), dockerfileName)
} | go | func GetContextFromURL(out io.Writer, remoteURL, dockerfileName string) (io.ReadCloser, string, error) {
response, err := getWithStatusError(remoteURL)
if err != nil {
return nil, "", errors.Errorf("unable to download remote context %s: %v", remoteURL, err)
}
progressOutput := streamformatter.NewProgressOutput(out)
// Pass the response body through a progress reader.
progReader := progress.NewProgressReader(response.Body, progressOutput, response.ContentLength, "", fmt.Sprintf("Downloading build context from remote url: %s", remoteURL))
return GetContextFromReader(ioutils.NewReadCloserWrapper(progReader, func() error { return response.Body.Close() }), dockerfileName)
} | [
"func",
"GetContextFromURL",
"(",
"out",
"io",
".",
"Writer",
",",
"remoteURL",
",",
"dockerfileName",
"string",
")",
"(",
"io",
".",
"ReadCloser",
",",
"string",
",",
"error",
")",
"{",
"response",
",",
"err",
":=",
"getWithStatusError",
"(",
"remoteURL",
... | // GetContextFromURL uses a remote URL as context for a `docker build`. The
// remote resource is downloaded as either a Dockerfile or a tar archive.
// Returns the tar archive used for the context and a path of the
// dockerfile inside the tar. | [
"GetContextFromURL",
"uses",
"a",
"remote",
"URL",
"as",
"context",
"for",
"a",
"docker",
"build",
".",
"The",
"remote",
"resource",
"is",
"downloaded",
"as",
"either",
"a",
"Dockerfile",
"or",
"a",
"tar",
"archive",
".",
"Returns",
"the",
"tar",
"archive",
... | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/image/build/context.go#L219-L230 |
159,654 | docker/cli | cli/command/image/build/context.go | GetContextFromLocalDir | func GetContextFromLocalDir(localDir, dockerfileName string) (string, string, error) {
localDir, err := ResolveAndValidateContextPath(localDir)
if err != nil {
return "", "", err
}
// When using a local context directory, and the Dockerfile is specified
// with the `-f/--file` option then it is considered relative to the
// current directory and not the context directory.
if dockerfileName != "" && dockerfileName != "-" {
if dockerfileName, err = filepath.Abs(dockerfileName); err != nil {
return "", "", errors.Errorf("unable to get absolute path to Dockerfile: %v", err)
}
}
relDockerfile, err := getDockerfileRelPath(localDir, dockerfileName)
return localDir, relDockerfile, err
} | go | func GetContextFromLocalDir(localDir, dockerfileName string) (string, string, error) {
localDir, err := ResolveAndValidateContextPath(localDir)
if err != nil {
return "", "", err
}
// When using a local context directory, and the Dockerfile is specified
// with the `-f/--file` option then it is considered relative to the
// current directory and not the context directory.
if dockerfileName != "" && dockerfileName != "-" {
if dockerfileName, err = filepath.Abs(dockerfileName); err != nil {
return "", "", errors.Errorf("unable to get absolute path to Dockerfile: %v", err)
}
}
relDockerfile, err := getDockerfileRelPath(localDir, dockerfileName)
return localDir, relDockerfile, err
} | [
"func",
"GetContextFromLocalDir",
"(",
"localDir",
",",
"dockerfileName",
"string",
")",
"(",
"string",
",",
"string",
",",
"error",
")",
"{",
"localDir",
",",
"err",
":=",
"ResolveAndValidateContextPath",
"(",
"localDir",
")",
"\n",
"if",
"err",
"!=",
"nil",
... | // GetContextFromLocalDir uses the given local directory as context for a
// `docker build`. Returns the absolute path to the local context directory,
// the relative path of the dockerfile in that context directory, and a non-nil
// error on success. | [
"GetContextFromLocalDir",
"uses",
"the",
"given",
"local",
"directory",
"as",
"context",
"for",
"a",
"docker",
"build",
".",
"Returns",
"the",
"absolute",
"path",
"to",
"the",
"local",
"context",
"directory",
"the",
"relative",
"path",
"of",
"the",
"dockerfile",... | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/image/build/context.go#L254-L271 |
159,655 | docker/cli | cli/command/image/build/context.go | ResolveAndValidateContextPath | func ResolveAndValidateContextPath(givenContextDir string) (string, error) {
absContextDir, err := filepath.Abs(givenContextDir)
if err != nil {
return "", errors.Errorf("unable to get absolute context directory of given context directory %q: %v", givenContextDir, err)
}
// The context dir might be a symbolic link, so follow it to the actual
// target directory.
//
// FIXME. We use isUNC (always false on non-Windows platforms) to workaround
// an issue in golang. On Windows, EvalSymLinks does not work on UNC file
// paths (those starting with \\). This hack means that when using links
// on UNC paths, they will not be followed.
if !isUNC(absContextDir) {
absContextDir, err = filepath.EvalSymlinks(absContextDir)
if err != nil {
return "", errors.Errorf("unable to evaluate symlinks in context path: %v", err)
}
}
stat, err := os.Lstat(absContextDir)
if err != nil {
return "", errors.Errorf("unable to stat context directory %q: %v", absContextDir, err)
}
if !stat.IsDir() {
return "", errors.Errorf("context must be a directory: %s", absContextDir)
}
return absContextDir, err
} | go | func ResolveAndValidateContextPath(givenContextDir string) (string, error) {
absContextDir, err := filepath.Abs(givenContextDir)
if err != nil {
return "", errors.Errorf("unable to get absolute context directory of given context directory %q: %v", givenContextDir, err)
}
// The context dir might be a symbolic link, so follow it to the actual
// target directory.
//
// FIXME. We use isUNC (always false on non-Windows platforms) to workaround
// an issue in golang. On Windows, EvalSymLinks does not work on UNC file
// paths (those starting with \\). This hack means that when using links
// on UNC paths, they will not be followed.
if !isUNC(absContextDir) {
absContextDir, err = filepath.EvalSymlinks(absContextDir)
if err != nil {
return "", errors.Errorf("unable to evaluate symlinks in context path: %v", err)
}
}
stat, err := os.Lstat(absContextDir)
if err != nil {
return "", errors.Errorf("unable to stat context directory %q: %v", absContextDir, err)
}
if !stat.IsDir() {
return "", errors.Errorf("context must be a directory: %s", absContextDir)
}
return absContextDir, err
} | [
"func",
"ResolveAndValidateContextPath",
"(",
"givenContextDir",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"absContextDir",
",",
"err",
":=",
"filepath",
".",
"Abs",
"(",
"givenContextDir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\""... | // ResolveAndValidateContextPath uses the given context directory for a `docker build`
// and returns the absolute path to the context directory. | [
"ResolveAndValidateContextPath",
"uses",
"the",
"given",
"context",
"directory",
"for",
"a",
"docker",
"build",
"and",
"returns",
"the",
"absolute",
"path",
"to",
"the",
"context",
"directory",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/image/build/context.go#L275-L304 |
159,656 | docker/cli | cli/command/image/build/context.go | getDockerfileRelPath | func getDockerfileRelPath(absContextDir, givenDockerfile string) (string, error) {
var err error
if givenDockerfile == "-" {
return givenDockerfile, nil
}
absDockerfile := givenDockerfile
if absDockerfile == "" {
// No -f/--file was specified so use the default relative to the
// context directory.
absDockerfile = filepath.Join(absContextDir, DefaultDockerfileName)
// Just to be nice ;-) look for 'dockerfile' too but only
// use it if we found it, otherwise ignore this check
if _, err = os.Lstat(absDockerfile); os.IsNotExist(err) {
altPath := filepath.Join(absContextDir, strings.ToLower(DefaultDockerfileName))
if _, err = os.Lstat(altPath); err == nil {
absDockerfile = altPath
}
}
}
// If not already an absolute path, the Dockerfile path should be joined to
// the base directory.
if !filepath.IsAbs(absDockerfile) {
absDockerfile = filepath.Join(absContextDir, absDockerfile)
}
// Evaluate symlinks in the path to the Dockerfile too.
//
// FIXME. We use isUNC (always false on non-Windows platforms) to workaround
// an issue in golang. On Windows, EvalSymLinks does not work on UNC file
// paths (those starting with \\). This hack means that when using links
// on UNC paths, they will not be followed.
if !isUNC(absDockerfile) {
absDockerfile, err = filepath.EvalSymlinks(absDockerfile)
if err != nil {
return "", errors.Errorf("unable to evaluate symlinks in Dockerfile path: %v", err)
}
}
if _, err := os.Lstat(absDockerfile); err != nil {
if os.IsNotExist(err) {
return "", errors.Errorf("Cannot locate Dockerfile: %q", absDockerfile)
}
return "", errors.Errorf("unable to stat Dockerfile: %v", err)
}
relDockerfile, err := filepath.Rel(absContextDir, absDockerfile)
if err != nil {
return "", errors.Errorf("unable to get relative Dockerfile path: %v", err)
}
return relDockerfile, nil
} | go | func getDockerfileRelPath(absContextDir, givenDockerfile string) (string, error) {
var err error
if givenDockerfile == "-" {
return givenDockerfile, nil
}
absDockerfile := givenDockerfile
if absDockerfile == "" {
// No -f/--file was specified so use the default relative to the
// context directory.
absDockerfile = filepath.Join(absContextDir, DefaultDockerfileName)
// Just to be nice ;-) look for 'dockerfile' too but only
// use it if we found it, otherwise ignore this check
if _, err = os.Lstat(absDockerfile); os.IsNotExist(err) {
altPath := filepath.Join(absContextDir, strings.ToLower(DefaultDockerfileName))
if _, err = os.Lstat(altPath); err == nil {
absDockerfile = altPath
}
}
}
// If not already an absolute path, the Dockerfile path should be joined to
// the base directory.
if !filepath.IsAbs(absDockerfile) {
absDockerfile = filepath.Join(absContextDir, absDockerfile)
}
// Evaluate symlinks in the path to the Dockerfile too.
//
// FIXME. We use isUNC (always false on non-Windows platforms) to workaround
// an issue in golang. On Windows, EvalSymLinks does not work on UNC file
// paths (those starting with \\). This hack means that when using links
// on UNC paths, they will not be followed.
if !isUNC(absDockerfile) {
absDockerfile, err = filepath.EvalSymlinks(absDockerfile)
if err != nil {
return "", errors.Errorf("unable to evaluate symlinks in Dockerfile path: %v", err)
}
}
if _, err := os.Lstat(absDockerfile); err != nil {
if os.IsNotExist(err) {
return "", errors.Errorf("Cannot locate Dockerfile: %q", absDockerfile)
}
return "", errors.Errorf("unable to stat Dockerfile: %v", err)
}
relDockerfile, err := filepath.Rel(absContextDir, absDockerfile)
if err != nil {
return "", errors.Errorf("unable to get relative Dockerfile path: %v", err)
}
return relDockerfile, nil
} | [
"func",
"getDockerfileRelPath",
"(",
"absContextDir",
",",
"givenDockerfile",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"if",
"givenDockerfile",
"==",
"\"",
"\"",
"{",
"return",
"givenDockerfile",
",",
"nil",
"\n",
... | // getDockerfileRelPath returns the dockerfile path relative to the context
// directory | [
"getDockerfileRelPath",
"returns",
"the",
"dockerfile",
"path",
"relative",
"to",
"the",
"context",
"directory"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/image/build/context.go#L308-L364 |
159,657 | docker/cli | cli/command/image/build/context.go | AddDockerfileToBuildContext | func AddDockerfileToBuildContext(dockerfileCtx io.ReadCloser, buildCtx io.ReadCloser) (io.ReadCloser, string, error) {
file, err := ioutil.ReadAll(dockerfileCtx)
dockerfileCtx.Close()
if err != nil {
return nil, "", err
}
now := time.Now()
hdrTmpl := &tar.Header{
Mode: 0600,
Uid: 0,
Gid: 0,
ModTime: now,
Typeflag: tar.TypeReg,
AccessTime: now,
ChangeTime: now,
}
randomName := ".dockerfile." + stringid.GenerateRandomID()[:20]
buildCtx = archive.ReplaceFileTarWrapper(buildCtx, map[string]archive.TarModifierFunc{
// Add the dockerfile with a random filename
randomName: func(_ string, h *tar.Header, content io.Reader) (*tar.Header, []byte, error) {
return hdrTmpl, file, nil
},
// Update .dockerignore to include the random filename
".dockerignore": func(_ string, h *tar.Header, content io.Reader) (*tar.Header, []byte, error) {
if h == nil {
h = hdrTmpl
}
b := &bytes.Buffer{}
if content != nil {
if _, err := b.ReadFrom(content); err != nil {
return nil, nil, err
}
} else {
b.WriteString(".dockerignore")
}
b.WriteString("\n" + randomName + "\n")
return h, b.Bytes(), nil
},
})
return buildCtx, randomName, nil
} | go | func AddDockerfileToBuildContext(dockerfileCtx io.ReadCloser, buildCtx io.ReadCloser) (io.ReadCloser, string, error) {
file, err := ioutil.ReadAll(dockerfileCtx)
dockerfileCtx.Close()
if err != nil {
return nil, "", err
}
now := time.Now()
hdrTmpl := &tar.Header{
Mode: 0600,
Uid: 0,
Gid: 0,
ModTime: now,
Typeflag: tar.TypeReg,
AccessTime: now,
ChangeTime: now,
}
randomName := ".dockerfile." + stringid.GenerateRandomID()[:20]
buildCtx = archive.ReplaceFileTarWrapper(buildCtx, map[string]archive.TarModifierFunc{
// Add the dockerfile with a random filename
randomName: func(_ string, h *tar.Header, content io.Reader) (*tar.Header, []byte, error) {
return hdrTmpl, file, nil
},
// Update .dockerignore to include the random filename
".dockerignore": func(_ string, h *tar.Header, content io.Reader) (*tar.Header, []byte, error) {
if h == nil {
h = hdrTmpl
}
b := &bytes.Buffer{}
if content != nil {
if _, err := b.ReadFrom(content); err != nil {
return nil, nil, err
}
} else {
b.WriteString(".dockerignore")
}
b.WriteString("\n" + randomName + "\n")
return h, b.Bytes(), nil
},
})
return buildCtx, randomName, nil
} | [
"func",
"AddDockerfileToBuildContext",
"(",
"dockerfileCtx",
"io",
".",
"ReadCloser",
",",
"buildCtx",
"io",
".",
"ReadCloser",
")",
"(",
"io",
".",
"ReadCloser",
",",
"string",
",",
"error",
")",
"{",
"file",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(... | // AddDockerfileToBuildContext from a ReadCloser, returns a new archive and
// the relative path to the dockerfile in the context. | [
"AddDockerfileToBuildContext",
"from",
"a",
"ReadCloser",
"returns",
"a",
"new",
"archive",
"and",
"the",
"relative",
"path",
"to",
"the",
"dockerfile",
"in",
"the",
"context",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/image/build/context.go#L374-L416 |
159,658 | docker/cli | cli/command/image/build/context.go | Compress | func Compress(buildCtx io.ReadCloser) (io.ReadCloser, error) {
pipeReader, pipeWriter := io.Pipe()
go func() {
compressWriter, err := archive.CompressStream(pipeWriter, archive.Gzip)
if err != nil {
pipeWriter.CloseWithError(err)
}
defer buildCtx.Close()
if _, err := pools.Copy(compressWriter, buildCtx); err != nil {
pipeWriter.CloseWithError(
errors.Wrap(err, "failed to compress context"))
compressWriter.Close()
return
}
compressWriter.Close()
pipeWriter.Close()
}()
return pipeReader, nil
} | go | func Compress(buildCtx io.ReadCloser) (io.ReadCloser, error) {
pipeReader, pipeWriter := io.Pipe()
go func() {
compressWriter, err := archive.CompressStream(pipeWriter, archive.Gzip)
if err != nil {
pipeWriter.CloseWithError(err)
}
defer buildCtx.Close()
if _, err := pools.Copy(compressWriter, buildCtx); err != nil {
pipeWriter.CloseWithError(
errors.Wrap(err, "failed to compress context"))
compressWriter.Close()
return
}
compressWriter.Close()
pipeWriter.Close()
}()
return pipeReader, nil
} | [
"func",
"Compress",
"(",
"buildCtx",
"io",
".",
"ReadCloser",
")",
"(",
"io",
".",
"ReadCloser",
",",
"error",
")",
"{",
"pipeReader",
",",
"pipeWriter",
":=",
"io",
".",
"Pipe",
"(",
")",
"\n\n",
"go",
"func",
"(",
")",
"{",
"compressWriter",
",",
"... | // Compress the build context for sending to the API | [
"Compress",
"the",
"build",
"context",
"for",
"sending",
"to",
"the",
"API"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/image/build/context.go#L419-L440 |
159,659 | docker/cli | cli/command/registry/search.go | NewSearchCommand | func NewSearchCommand(dockerCli command.Cli) *cobra.Command {
options := searchOptions{filter: opts.NewFilterOpt()}
cmd := &cobra.Command{
Use: "search [OPTIONS] TERM",
Short: "Search the Docker Hub for images",
Args: cli.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
options.term = args[0]
return runSearch(dockerCli, options)
},
}
flags := cmd.Flags()
flags.BoolVar(&options.noTrunc, "no-trunc", false, "Don't truncate output")
flags.VarP(&options.filter, "filter", "f", "Filter output based on conditions provided")
flags.IntVar(&options.limit, "limit", registry.DefaultSearchLimit, "Max number of search results")
flags.StringVar(&options.format, "format", "", "Pretty-print search using a Go template")
flags.BoolVar(&options.automated, "automated", false, "Only show automated builds")
flags.UintVarP(&options.stars, "stars", "s", 0, "Only displays with at least x stars")
flags.MarkDeprecated("automated", "use --filter=is-automated=true instead")
flags.MarkDeprecated("stars", "use --filter=stars=3 instead")
return cmd
} | go | func NewSearchCommand(dockerCli command.Cli) *cobra.Command {
options := searchOptions{filter: opts.NewFilterOpt()}
cmd := &cobra.Command{
Use: "search [OPTIONS] TERM",
Short: "Search the Docker Hub for images",
Args: cli.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
options.term = args[0]
return runSearch(dockerCli, options)
},
}
flags := cmd.Flags()
flags.BoolVar(&options.noTrunc, "no-trunc", false, "Don't truncate output")
flags.VarP(&options.filter, "filter", "f", "Filter output based on conditions provided")
flags.IntVar(&options.limit, "limit", registry.DefaultSearchLimit, "Max number of search results")
flags.StringVar(&options.format, "format", "", "Pretty-print search using a Go template")
flags.BoolVar(&options.automated, "automated", false, "Only show automated builds")
flags.UintVarP(&options.stars, "stars", "s", 0, "Only displays with at least x stars")
flags.MarkDeprecated("automated", "use --filter=is-automated=true instead")
flags.MarkDeprecated("stars", "use --filter=stars=3 instead")
return cmd
} | [
"func",
"NewSearchCommand",
"(",
"dockerCli",
"command",
".",
"Cli",
")",
"*",
"cobra",
".",
"Command",
"{",
"options",
":=",
"searchOptions",
"{",
"filter",
":",
"opts",
".",
"NewFilterOpt",
"(",
")",
"}",
"\n\n",
"cmd",
":=",
"&",
"cobra",
".",
"Comman... | // NewSearchCommand creates a new `docker search` command | [
"NewSearchCommand",
"creates",
"a",
"new",
"docker",
"search",
"command"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/registry/search.go#L29-L56 |
159,660 | docker/cli | cli/command/image/cmd.go | NewImageCommand | func NewImageCommand(dockerCli command.Cli) *cobra.Command {
cmd := &cobra.Command{
Use: "image",
Short: "Manage images",
Args: cli.NoArgs,
RunE: command.ShowHelp(dockerCli.Err()),
}
cmd.AddCommand(
NewBuildCommand(dockerCli),
NewHistoryCommand(dockerCli),
NewImportCommand(dockerCli),
NewLoadCommand(dockerCli),
NewPullCommand(dockerCli),
NewPushCommand(dockerCli),
NewSaveCommand(dockerCli),
NewTagCommand(dockerCli),
newListCommand(dockerCli),
newRemoveCommand(dockerCli),
newInspectCommand(dockerCli),
NewPruneCommand(dockerCli),
)
return cmd
} | go | func NewImageCommand(dockerCli command.Cli) *cobra.Command {
cmd := &cobra.Command{
Use: "image",
Short: "Manage images",
Args: cli.NoArgs,
RunE: command.ShowHelp(dockerCli.Err()),
}
cmd.AddCommand(
NewBuildCommand(dockerCli),
NewHistoryCommand(dockerCli),
NewImportCommand(dockerCli),
NewLoadCommand(dockerCli),
NewPullCommand(dockerCli),
NewPushCommand(dockerCli),
NewSaveCommand(dockerCli),
NewTagCommand(dockerCli),
newListCommand(dockerCli),
newRemoveCommand(dockerCli),
newInspectCommand(dockerCli),
NewPruneCommand(dockerCli),
)
return cmd
} | [
"func",
"NewImageCommand",
"(",
"dockerCli",
"command",
".",
"Cli",
")",
"*",
"cobra",
".",
"Command",
"{",
"cmd",
":=",
"&",
"cobra",
".",
"Command",
"{",
"Use",
":",
"\"",
"\"",
",",
"Short",
":",
"\"",
"\"",
",",
"Args",
":",
"cli",
".",
"NoArgs... | // NewImageCommand returns a cobra command for `image` subcommands | [
"NewImageCommand",
"returns",
"a",
"cobra",
"command",
"for",
"image",
"subcommands"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/image/cmd.go#L11-L33 |
159,661 | docker/cli | cli/command/container/pause.go | NewPauseCommand | func NewPauseCommand(dockerCli command.Cli) *cobra.Command {
var opts pauseOptions
return &cobra.Command{
Use: "pause CONTAINER [CONTAINER...]",
Short: "Pause all processes within one or more containers",
Args: cli.RequiresMinArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
opts.containers = args
return runPause(dockerCli, &opts)
},
}
} | go | func NewPauseCommand(dockerCli command.Cli) *cobra.Command {
var opts pauseOptions
return &cobra.Command{
Use: "pause CONTAINER [CONTAINER...]",
Short: "Pause all processes within one or more containers",
Args: cli.RequiresMinArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
opts.containers = args
return runPause(dockerCli, &opts)
},
}
} | [
"func",
"NewPauseCommand",
"(",
"dockerCli",
"command",
".",
"Cli",
")",
"*",
"cobra",
".",
"Command",
"{",
"var",
"opts",
"pauseOptions",
"\n\n",
"return",
"&",
"cobra",
".",
"Command",
"{",
"Use",
":",
"\"",
"\"",
",",
"Short",
":",
"\"",
"\"",
",",
... | // NewPauseCommand creates a new cobra.Command for `docker pause` | [
"NewPauseCommand",
"creates",
"a",
"new",
"cobra",
".",
"Command",
"for",
"docker",
"pause"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/container/pause.go#L19-L31 |
159,662 | docker/cli | cli-plugins/manager/manager.go | ListPlugins | func ListPlugins(dockerCli command.Cli, rootcmd *cobra.Command) ([]Plugin, error) {
pluginDirs, err := getPluginDirs(dockerCli)
if err != nil {
return nil, err
}
candidates, err := listPluginCandidates(pluginDirs)
if err != nil {
return nil, err
}
var plugins []Plugin
for _, paths := range candidates {
if len(paths) == 0 {
continue
}
c := &candidate{paths[0]}
p, err := newPlugin(c, rootcmd)
if err != nil {
return nil, err
}
p.ShadowedPaths = paths[1:]
plugins = append(plugins, p)
}
return plugins, nil
} | go | func ListPlugins(dockerCli command.Cli, rootcmd *cobra.Command) ([]Plugin, error) {
pluginDirs, err := getPluginDirs(dockerCli)
if err != nil {
return nil, err
}
candidates, err := listPluginCandidates(pluginDirs)
if err != nil {
return nil, err
}
var plugins []Plugin
for _, paths := range candidates {
if len(paths) == 0 {
continue
}
c := &candidate{paths[0]}
p, err := newPlugin(c, rootcmd)
if err != nil {
return nil, err
}
p.ShadowedPaths = paths[1:]
plugins = append(plugins, p)
}
return plugins, nil
} | [
"func",
"ListPlugins",
"(",
"dockerCli",
"command",
".",
"Cli",
",",
"rootcmd",
"*",
"cobra",
".",
"Command",
")",
"(",
"[",
"]",
"Plugin",
",",
"error",
")",
"{",
"pluginDirs",
",",
"err",
":=",
"getPluginDirs",
"(",
"dockerCli",
")",
"\n",
"if",
"err... | // ListPlugins produces a list of the plugins available on the system | [
"ListPlugins",
"produces",
"a",
"list",
"of",
"the",
"plugins",
"available",
"on",
"the",
"system"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli-plugins/manager/manager.go#L103-L129 |
159,663 | docker/cli | cli/command/formatter/container.go | NewContainerFormat | func NewContainerFormat(source string, quiet bool, size bool) Format {
switch source {
case TableFormatKey:
if quiet {
return DefaultQuietFormat
}
format := defaultContainerTableFormat
if size {
format += `\t{{.Size}}`
}
return Format(format)
case RawFormatKey:
if quiet {
return `container_id: {{.ID}}`
}
format := `container_id: {{.ID}}
image: {{.Image}}
command: {{.Command}}
created_at: {{.CreatedAt}}
status: {{- pad .Status 1 0}}
names: {{.Names}}
labels: {{- pad .Labels 1 0}}
ports: {{- pad .Ports 1 0}}
`
if size {
format += `size: {{.Size}}\n`
}
return Format(format)
}
return Format(source)
} | go | func NewContainerFormat(source string, quiet bool, size bool) Format {
switch source {
case TableFormatKey:
if quiet {
return DefaultQuietFormat
}
format := defaultContainerTableFormat
if size {
format += `\t{{.Size}}`
}
return Format(format)
case RawFormatKey:
if quiet {
return `container_id: {{.ID}}`
}
format := `container_id: {{.ID}}
image: {{.Image}}
command: {{.Command}}
created_at: {{.CreatedAt}}
status: {{- pad .Status 1 0}}
names: {{.Names}}
labels: {{- pad .Labels 1 0}}
ports: {{- pad .Ports 1 0}}
`
if size {
format += `size: {{.Size}}\n`
}
return Format(format)
}
return Format(source)
} | [
"func",
"NewContainerFormat",
"(",
"source",
"string",
",",
"quiet",
"bool",
",",
"size",
"bool",
")",
"Format",
"{",
"switch",
"source",
"{",
"case",
"TableFormatKey",
":",
"if",
"quiet",
"{",
"return",
"DefaultQuietFormat",
"\n",
"}",
"\n",
"format",
":=",... | // NewContainerFormat returns a Format for rendering using a Context | [
"NewContainerFormat",
"returns",
"a",
"Format",
"for",
"rendering",
"using",
"a",
"Context"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/formatter/container.go#L28-L58 |
159,664 | docker/cli | cli/command/formatter/container.go | ContainerWrite | func ContainerWrite(ctx Context, containers []types.Container) error {
render := func(format func(subContext SubContext) error) error {
for _, container := range containers {
err := format(&containerContext{trunc: ctx.Trunc, c: container})
if err != nil {
return err
}
}
return nil
}
return ctx.Write(newContainerContext(), render)
} | go | func ContainerWrite(ctx Context, containers []types.Container) error {
render := func(format func(subContext SubContext) error) error {
for _, container := range containers {
err := format(&containerContext{trunc: ctx.Trunc, c: container})
if err != nil {
return err
}
}
return nil
}
return ctx.Write(newContainerContext(), render)
} | [
"func",
"ContainerWrite",
"(",
"ctx",
"Context",
",",
"containers",
"[",
"]",
"types",
".",
"Container",
")",
"error",
"{",
"render",
":=",
"func",
"(",
"format",
"func",
"(",
"subContext",
"SubContext",
")",
"error",
")",
"error",
"{",
"for",
"_",
",",
... | // ContainerWrite renders the context for a list of containers | [
"ContainerWrite",
"renders",
"the",
"context",
"for",
"a",
"list",
"of",
"containers"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/formatter/container.go#L61-L72 |
159,665 | docker/cli | cli/command/stack/kubernetes/stackclient.go | IsColliding | func (s *stackV1Beta1) IsColliding(servicesClient corev1.ServiceInterface, st Stack) error {
for _, srv := range st.getServices() {
if err := verify(servicesClient, st.Name, srv); err != nil {
return err
}
}
return nil
} | go | func (s *stackV1Beta1) IsColliding(servicesClient corev1.ServiceInterface, st Stack) error {
for _, srv := range st.getServices() {
if err := verify(servicesClient, st.Name, srv); err != nil {
return err
}
}
return nil
} | [
"func",
"(",
"s",
"*",
"stackV1Beta1",
")",
"IsColliding",
"(",
"servicesClient",
"corev1",
".",
"ServiceInterface",
",",
"st",
"Stack",
")",
"error",
"{",
"for",
"_",
",",
"srv",
":=",
"range",
"st",
".",
"getServices",
"(",
")",
"{",
"if",
"err",
":=... | // IsColliding verifies that services defined in the stack collides with already deployed services | [
"IsColliding",
"verifies",
"that",
"services",
"defined",
"in",
"the",
"stack",
"collides",
"with",
"already",
"deployed",
"services"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/stack/kubernetes/stackclient.go#L100-L107 |
159,666 | docker/cli | cli/command/stack/kubernetes/stackclient.go | IsColliding | func (s *stackV1Beta2) IsColliding(servicesClient corev1.ServiceInterface, st Stack) error {
return nil
} | go | func (s *stackV1Beta2) IsColliding(servicesClient corev1.ServiceInterface, st Stack) error {
return nil
} | [
"func",
"(",
"s",
"*",
"stackV1Beta2",
")",
"IsColliding",
"(",
"servicesClient",
"corev1",
".",
"ServiceInterface",
",",
"st",
"Stack",
")",
"error",
"{",
"return",
"nil",
"\n",
"}"
] | // IsColliding is handle server side with the compose api v1beta2, so nothing to do here | [
"IsColliding",
"is",
"handle",
"server",
"side",
"with",
"the",
"compose",
"api",
"v1beta2",
"so",
"nothing",
"to",
"do",
"here"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/stack/kubernetes/stackclient.go#L200-L202 |
159,667 | docker/cli | cli/command/config/remove.go | RunConfigRemove | func RunConfigRemove(dockerCli command.Cli, opts RemoveOptions) error {
client := dockerCli.Client()
ctx := context.Background()
var errs []string
for _, name := range opts.Names {
if err := client.ConfigRemove(ctx, name); err != nil {
errs = append(errs, err.Error())
continue
}
fmt.Fprintln(dockerCli.Out(), name)
}
if len(errs) > 0 {
return errors.Errorf("%s", strings.Join(errs, "\n"))
}
return nil
} | go | func RunConfigRemove(dockerCli command.Cli, opts RemoveOptions) error {
client := dockerCli.Client()
ctx := context.Background()
var errs []string
for _, name := range opts.Names {
if err := client.ConfigRemove(ctx, name); err != nil {
errs = append(errs, err.Error())
continue
}
fmt.Fprintln(dockerCli.Out(), name)
}
if len(errs) > 0 {
return errors.Errorf("%s", strings.Join(errs, "\n"))
}
return nil
} | [
"func",
"RunConfigRemove",
"(",
"dockerCli",
"command",
".",
"Cli",
",",
"opts",
"RemoveOptions",
")",
"error",
"{",
"client",
":=",
"dockerCli",
".",
"Client",
"(",
")",
"\n",
"ctx",
":=",
"context",
".",
"Background",
"(",
")",
"\n\n",
"var",
"errs",
"... | // RunConfigRemove removes the given Swarm configs. | [
"RunConfigRemove",
"removes",
"the",
"given",
"Swarm",
"configs",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/config/remove.go#L35-L55 |
159,668 | docker/cli | cli/registry/client/endpoint.go | Name | func (r repositoryEndpoint) Name() string {
repoName := r.info.Name.Name()
// If endpoint does not support CanonicalName, use the RemoteName instead
if r.endpoint.TrimHostname {
repoName = reference.Path(r.info.Name)
}
return repoName
} | go | func (r repositoryEndpoint) Name() string {
repoName := r.info.Name.Name()
// If endpoint does not support CanonicalName, use the RemoteName instead
if r.endpoint.TrimHostname {
repoName = reference.Path(r.info.Name)
}
return repoName
} | [
"func",
"(",
"r",
"repositoryEndpoint",
")",
"Name",
"(",
")",
"string",
"{",
"repoName",
":=",
"r",
".",
"info",
".",
"Name",
".",
"Name",
"(",
")",
"\n",
"// If endpoint does not support CanonicalName, use the RemoteName instead",
"if",
"r",
".",
"endpoint",
"... | // Name returns the repository name | [
"Name",
"returns",
"the",
"repository",
"name"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/registry/client/endpoint.go#L23-L30 |
159,669 | docker/cli | cli/registry/client/endpoint.go | getHTTPTransport | func getHTTPTransport(authConfig authtypes.AuthConfig, endpoint registry.APIEndpoint, repoName string, userAgent string) (http.RoundTripper, error) {
// get the http transport, this will be used in a client to upload manifest
base := &http.Transport{
Proxy: http.ProxyFromEnvironment,
Dial: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
DualStack: true,
}).Dial,
TLSHandshakeTimeout: 10 * time.Second,
TLSClientConfig: endpoint.TLSConfig,
DisableKeepAlives: true,
}
modifiers := registry.Headers(userAgent, http.Header{})
authTransport := transport.NewTransport(base, modifiers...)
challengeManager, confirmedV2, err := registry.PingV2Registry(endpoint.URL, authTransport)
if err != nil {
return nil, errors.Wrap(err, "error pinging v2 registry")
}
if !confirmedV2 {
return nil, fmt.Errorf("unsupported registry version")
}
if authConfig.RegistryToken != "" {
passThruTokenHandler := &existingTokenHandler{token: authConfig.RegistryToken}
modifiers = append(modifiers, auth.NewAuthorizer(challengeManager, passThruTokenHandler))
} else {
creds := registry.NewStaticCredentialStore(&authConfig)
tokenHandler := auth.NewTokenHandler(authTransport, creds, repoName, "push", "pull")
basicHandler := auth.NewBasicHandler(creds)
modifiers = append(modifiers, auth.NewAuthorizer(challengeManager, tokenHandler, basicHandler))
}
return transport.NewTransport(base, modifiers...), nil
} | go | func getHTTPTransport(authConfig authtypes.AuthConfig, endpoint registry.APIEndpoint, repoName string, userAgent string) (http.RoundTripper, error) {
// get the http transport, this will be used in a client to upload manifest
base := &http.Transport{
Proxy: http.ProxyFromEnvironment,
Dial: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
DualStack: true,
}).Dial,
TLSHandshakeTimeout: 10 * time.Second,
TLSClientConfig: endpoint.TLSConfig,
DisableKeepAlives: true,
}
modifiers := registry.Headers(userAgent, http.Header{})
authTransport := transport.NewTransport(base, modifiers...)
challengeManager, confirmedV2, err := registry.PingV2Registry(endpoint.URL, authTransport)
if err != nil {
return nil, errors.Wrap(err, "error pinging v2 registry")
}
if !confirmedV2 {
return nil, fmt.Errorf("unsupported registry version")
}
if authConfig.RegistryToken != "" {
passThruTokenHandler := &existingTokenHandler{token: authConfig.RegistryToken}
modifiers = append(modifiers, auth.NewAuthorizer(challengeManager, passThruTokenHandler))
} else {
creds := registry.NewStaticCredentialStore(&authConfig)
tokenHandler := auth.NewTokenHandler(authTransport, creds, repoName, "push", "pull")
basicHandler := auth.NewBasicHandler(creds)
modifiers = append(modifiers, auth.NewAuthorizer(challengeManager, tokenHandler, basicHandler))
}
return transport.NewTransport(base, modifiers...), nil
} | [
"func",
"getHTTPTransport",
"(",
"authConfig",
"authtypes",
".",
"AuthConfig",
",",
"endpoint",
"registry",
".",
"APIEndpoint",
",",
"repoName",
"string",
",",
"userAgent",
"string",
")",
"(",
"http",
".",
"RoundTripper",
",",
"error",
")",
"{",
"// get the http... | // getHTTPTransport builds a transport for use in communicating with a registry | [
"getHTTPTransport",
"builds",
"a",
"transport",
"for",
"use",
"in",
"communicating",
"with",
"a",
"registry"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/registry/client/endpoint.go#L77-L110 |
159,670 | docker/cli | cli/registry/client/endpoint.go | RepoNameForReference | func RepoNameForReference(ref reference.Named) (string, error) {
// insecure is fine since this only returns the name
repo, err := newDefaultRepositoryEndpoint(ref, false)
if err != nil {
return "", err
}
return repo.Name(), nil
} | go | func RepoNameForReference(ref reference.Named) (string, error) {
// insecure is fine since this only returns the name
repo, err := newDefaultRepositoryEndpoint(ref, false)
if err != nil {
return "", err
}
return repo.Name(), nil
} | [
"func",
"RepoNameForReference",
"(",
"ref",
"reference",
".",
"Named",
")",
"(",
"string",
",",
"error",
")",
"{",
"// insecure is fine since this only returns the name",
"repo",
",",
"err",
":=",
"newDefaultRepositoryEndpoint",
"(",
"ref",
",",
"false",
")",
"\n",
... | // RepoNameForReference returns the repository name from a reference | [
"RepoNameForReference",
"returns",
"the",
"repository",
"name",
"from",
"a",
"reference"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/registry/client/endpoint.go#L113-L120 |
159,671 | docker/cli | cli/command/bundlefile/bundlefile.go | LoadFile | func LoadFile(reader io.Reader) (*Bundlefile, error) {
bundlefile := &Bundlefile{}
decoder := json.NewDecoder(reader)
if err := decoder.Decode(bundlefile); err != nil {
switch jsonErr := err.(type) {
case *json.SyntaxError:
return nil, errors.Errorf(
"JSON syntax error at byte %v: %s",
jsonErr.Offset,
jsonErr.Error())
case *json.UnmarshalTypeError:
return nil, errors.Errorf(
"Unexpected type at byte %v. Expected %s but received %s.",
jsonErr.Offset,
jsonErr.Type,
jsonErr.Value)
}
return nil, err
}
return bundlefile, nil
} | go | func LoadFile(reader io.Reader) (*Bundlefile, error) {
bundlefile := &Bundlefile{}
decoder := json.NewDecoder(reader)
if err := decoder.Decode(bundlefile); err != nil {
switch jsonErr := err.(type) {
case *json.SyntaxError:
return nil, errors.Errorf(
"JSON syntax error at byte %v: %s",
jsonErr.Offset,
jsonErr.Error())
case *json.UnmarshalTypeError:
return nil, errors.Errorf(
"Unexpected type at byte %v. Expected %s but received %s.",
jsonErr.Offset,
jsonErr.Type,
jsonErr.Value)
}
return nil, err
}
return bundlefile, nil
} | [
"func",
"LoadFile",
"(",
"reader",
"io",
".",
"Reader",
")",
"(",
"*",
"Bundlefile",
",",
"error",
")",
"{",
"bundlefile",
":=",
"&",
"Bundlefile",
"{",
"}",
"\n\n",
"decoder",
":=",
"json",
".",
"NewDecoder",
"(",
"reader",
")",
"\n",
"if",
"err",
"... | // LoadFile loads a bundlefile from a path to the file | [
"LoadFile",
"loads",
"a",
"bundlefile",
"from",
"a",
"path",
"to",
"the",
"file"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/bundlefile/bundlefile.go#L36-L58 |
159,672 | docker/cli | cli/command/bundlefile/bundlefile.go | Print | func Print(out io.Writer, bundle *Bundlefile) error {
bytes, err := json.MarshalIndent(*bundle, "", " ")
if err != nil {
return err
}
_, err = out.Write(bytes)
return err
} | go | func Print(out io.Writer, bundle *Bundlefile) error {
bytes, err := json.MarshalIndent(*bundle, "", " ")
if err != nil {
return err
}
_, err = out.Write(bytes)
return err
} | [
"func",
"Print",
"(",
"out",
"io",
".",
"Writer",
",",
"bundle",
"*",
"Bundlefile",
")",
"error",
"{",
"bytes",
",",
"err",
":=",
"json",
".",
"MarshalIndent",
"(",
"*",
"bundle",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"n... | // Print writes the contents of the bundlefile to the output writer
// as human readable json | [
"Print",
"writes",
"the",
"contents",
"of",
"the",
"bundlefile",
"to",
"the",
"output",
"writer",
"as",
"human",
"readable",
"json"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/bundlefile/bundlefile.go#L62-L70 |
159,673 | docker/cli | cli/command/task/print.go | DefaultFormat | func DefaultFormat(configFile *configfile.ConfigFile, quiet bool) string {
if len(configFile.TasksFormat) > 0 && !quiet {
return configFile.TasksFormat
}
return formatter.TableFormatKey
} | go | func DefaultFormat(configFile *configfile.ConfigFile, quiet bool) string {
if len(configFile.TasksFormat) > 0 && !quiet {
return configFile.TasksFormat
}
return formatter.TableFormatKey
} | [
"func",
"DefaultFormat",
"(",
"configFile",
"*",
"configfile",
".",
"ConfigFile",
",",
"quiet",
"bool",
")",
"string",
"{",
"if",
"len",
"(",
"configFile",
".",
"TasksFormat",
")",
">",
"0",
"&&",
"!",
"quiet",
"{",
"return",
"configFile",
".",
"TasksForma... | // DefaultFormat returns the default format from the config file, or table
// format if nothing is set in the config. | [
"DefaultFormat",
"returns",
"the",
"default",
"format",
"from",
"the",
"config",
"file",
"or",
"table",
"format",
"if",
"nothing",
"is",
"set",
"in",
"the",
"config",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/task/print.go#L88-L93 |
159,674 | docker/cli | cli/command/image/build/dockerignore.go | ReadDockerignore | func ReadDockerignore(contextDir string) ([]string, error) {
var excludes []string
f, err := os.Open(filepath.Join(contextDir, ".dockerignore"))
switch {
case os.IsNotExist(err):
return excludes, nil
case err != nil:
return nil, err
}
defer f.Close()
return dockerignore.ReadAll(f)
} | go | func ReadDockerignore(contextDir string) ([]string, error) {
var excludes []string
f, err := os.Open(filepath.Join(contextDir, ".dockerignore"))
switch {
case os.IsNotExist(err):
return excludes, nil
case err != nil:
return nil, err
}
defer f.Close()
return dockerignore.ReadAll(f)
} | [
"func",
"ReadDockerignore",
"(",
"contextDir",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"var",
"excludes",
"[",
"]",
"string",
"\n\n",
"f",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"filepath",
".",
"Join",
"(",
"contextDir",
"... | // ReadDockerignore reads the .dockerignore file in the context directory and
// returns the list of paths to exclude | [
"ReadDockerignore",
"reads",
"the",
".",
"dockerignore",
"file",
"in",
"the",
"context",
"directory",
"and",
"returns",
"the",
"list",
"of",
"paths",
"to",
"exclude"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/image/build/dockerignore.go#L13-L26 |
159,675 | docker/cli | cli/command/image/build/dockerignore.go | TrimBuildFilesFromExcludes | func TrimBuildFilesFromExcludes(excludes []string, dockerfile string, dockerfileFromStdin bool) []string {
if keep, _ := fileutils.Matches(".dockerignore", excludes); keep {
excludes = append(excludes, "!.dockerignore")
}
if keep, _ := fileutils.Matches(dockerfile, excludes); keep && !dockerfileFromStdin {
excludes = append(excludes, "!"+dockerfile)
}
return excludes
} | go | func TrimBuildFilesFromExcludes(excludes []string, dockerfile string, dockerfileFromStdin bool) []string {
if keep, _ := fileutils.Matches(".dockerignore", excludes); keep {
excludes = append(excludes, "!.dockerignore")
}
if keep, _ := fileutils.Matches(dockerfile, excludes); keep && !dockerfileFromStdin {
excludes = append(excludes, "!"+dockerfile)
}
return excludes
} | [
"func",
"TrimBuildFilesFromExcludes",
"(",
"excludes",
"[",
"]",
"string",
",",
"dockerfile",
"string",
",",
"dockerfileFromStdin",
"bool",
")",
"[",
"]",
"string",
"{",
"if",
"keep",
",",
"_",
":=",
"fileutils",
".",
"Matches",
"(",
"\"",
"\"",
",",
"excl... | // TrimBuildFilesFromExcludes removes the named Dockerfile and .dockerignore from
// the list of excluded files. The daemon will remove them from the final context
// but they must be in available in the context when passed to the API. | [
"TrimBuildFilesFromExcludes",
"removes",
"the",
"named",
"Dockerfile",
"and",
".",
"dockerignore",
"from",
"the",
"list",
"of",
"excluded",
"files",
".",
"The",
"daemon",
"will",
"remove",
"them",
"from",
"the",
"final",
"context",
"but",
"they",
"must",
"be",
... | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/image/build/dockerignore.go#L31-L39 |
159,676 | docker/cli | cli/command/trust/signer.go | newTrustSignerCommand | func newTrustSignerCommand(dockerCli command.Cli) *cobra.Command {
cmd := &cobra.Command{
Use: "signer",
Short: "Manage entities who can sign Docker images",
Args: cli.NoArgs,
RunE: command.ShowHelp(dockerCli.Err()),
}
cmd.AddCommand(
newSignerAddCommand(dockerCli),
newSignerRemoveCommand(dockerCli),
)
return cmd
} | go | func newTrustSignerCommand(dockerCli command.Cli) *cobra.Command {
cmd := &cobra.Command{
Use: "signer",
Short: "Manage entities who can sign Docker images",
Args: cli.NoArgs,
RunE: command.ShowHelp(dockerCli.Err()),
}
cmd.AddCommand(
newSignerAddCommand(dockerCli),
newSignerRemoveCommand(dockerCli),
)
return cmd
} | [
"func",
"newTrustSignerCommand",
"(",
"dockerCli",
"command",
".",
"Cli",
")",
"*",
"cobra",
".",
"Command",
"{",
"cmd",
":=",
"&",
"cobra",
".",
"Command",
"{",
"Use",
":",
"\"",
"\"",
",",
"Short",
":",
"\"",
"\"",
",",
"Args",
":",
"cli",
".",
"... | // newTrustSignerCommand returns a cobra command for `trust signer` subcommands | [
"newTrustSignerCommand",
"returns",
"a",
"cobra",
"command",
"for",
"trust",
"signer",
"subcommands"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/trust/signer.go#L10-L22 |
159,677 | docker/cli | cli/command/service/parse.go | ParseSecrets | func ParseSecrets(client client.SecretAPIClient, requestedSecrets []*swarmtypes.SecretReference) ([]*swarmtypes.SecretReference, error) {
if len(requestedSecrets) == 0 {
return []*swarmtypes.SecretReference{}, nil
}
secretRefs := make(map[string]*swarmtypes.SecretReference)
ctx := context.Background()
for _, secret := range requestedSecrets {
if _, exists := secretRefs[secret.File.Name]; exists {
return nil, errors.Errorf("duplicate secret target for %s not allowed", secret.SecretName)
}
secretRef := new(swarmtypes.SecretReference)
*secretRef = *secret
secretRefs[secret.File.Name] = secretRef
}
args := filters.NewArgs()
for _, s := range secretRefs {
args.Add("name", s.SecretName)
}
secrets, err := client.SecretList(ctx, types.SecretListOptions{
Filters: args,
})
if err != nil {
return nil, err
}
foundSecrets := make(map[string]string)
for _, secret := range secrets {
foundSecrets[secret.Spec.Annotations.Name] = secret.ID
}
addedSecrets := []*swarmtypes.SecretReference{}
for _, ref := range secretRefs {
id, ok := foundSecrets[ref.SecretName]
if !ok {
return nil, errors.Errorf("secret not found: %s", ref.SecretName)
}
// set the id for the ref to properly assign in swarm
// since swarm needs the ID instead of the name
ref.SecretID = id
addedSecrets = append(addedSecrets, ref)
}
return addedSecrets, nil
} | go | func ParseSecrets(client client.SecretAPIClient, requestedSecrets []*swarmtypes.SecretReference) ([]*swarmtypes.SecretReference, error) {
if len(requestedSecrets) == 0 {
return []*swarmtypes.SecretReference{}, nil
}
secretRefs := make(map[string]*swarmtypes.SecretReference)
ctx := context.Background()
for _, secret := range requestedSecrets {
if _, exists := secretRefs[secret.File.Name]; exists {
return nil, errors.Errorf("duplicate secret target for %s not allowed", secret.SecretName)
}
secretRef := new(swarmtypes.SecretReference)
*secretRef = *secret
secretRefs[secret.File.Name] = secretRef
}
args := filters.NewArgs()
for _, s := range secretRefs {
args.Add("name", s.SecretName)
}
secrets, err := client.SecretList(ctx, types.SecretListOptions{
Filters: args,
})
if err != nil {
return nil, err
}
foundSecrets := make(map[string]string)
for _, secret := range secrets {
foundSecrets[secret.Spec.Annotations.Name] = secret.ID
}
addedSecrets := []*swarmtypes.SecretReference{}
for _, ref := range secretRefs {
id, ok := foundSecrets[ref.SecretName]
if !ok {
return nil, errors.Errorf("secret not found: %s", ref.SecretName)
}
// set the id for the ref to properly assign in swarm
// since swarm needs the ID instead of the name
ref.SecretID = id
addedSecrets = append(addedSecrets, ref)
}
return addedSecrets, nil
} | [
"func",
"ParseSecrets",
"(",
"client",
"client",
".",
"SecretAPIClient",
",",
"requestedSecrets",
"[",
"]",
"*",
"swarmtypes",
".",
"SecretReference",
")",
"(",
"[",
"]",
"*",
"swarmtypes",
".",
"SecretReference",
",",
"error",
")",
"{",
"if",
"len",
"(",
... | // ParseSecrets retrieves the secrets with the requested names and fills
// secret IDs into the secret references. | [
"ParseSecrets",
"retrieves",
"the",
"secrets",
"with",
"the",
"requested",
"names",
"and",
"fills",
"secret",
"IDs",
"into",
"the",
"secret",
"references",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/service/parse.go#L15-L64 |
159,678 | docker/cli | cli/command/context/create.go | RunCreate | func RunCreate(cli command.Cli, o *CreateOptions) error {
s := cli.ContextStore()
if err := checkContextNameForCreation(s, o.Name); err != nil {
return err
}
stackOrchestrator, err := command.NormalizeOrchestrator(o.DefaultStackOrchestrator)
if err != nil {
return errors.Wrap(err, "unable to parse default-stack-orchestrator")
}
if o.From == "" && o.Docker == nil && o.Kubernetes == nil {
return createFromExistingContext(s, cli.CurrentContext(), stackOrchestrator, o)
}
if o.From != "" {
return createFromExistingContext(s, o.From, stackOrchestrator, o)
}
return createNewContext(o, stackOrchestrator, cli, s)
} | go | func RunCreate(cli command.Cli, o *CreateOptions) error {
s := cli.ContextStore()
if err := checkContextNameForCreation(s, o.Name); err != nil {
return err
}
stackOrchestrator, err := command.NormalizeOrchestrator(o.DefaultStackOrchestrator)
if err != nil {
return errors.Wrap(err, "unable to parse default-stack-orchestrator")
}
if o.From == "" && o.Docker == nil && o.Kubernetes == nil {
return createFromExistingContext(s, cli.CurrentContext(), stackOrchestrator, o)
}
if o.From != "" {
return createFromExistingContext(s, o.From, stackOrchestrator, o)
}
return createNewContext(o, stackOrchestrator, cli, s)
} | [
"func",
"RunCreate",
"(",
"cli",
"command",
".",
"Cli",
",",
"o",
"*",
"CreateOptions",
")",
"error",
"{",
"s",
":=",
"cli",
".",
"ContextStore",
"(",
")",
"\n",
"if",
"err",
":=",
"checkContextNameForCreation",
"(",
"s",
",",
"o",
".",
"Name",
")",
... | // RunCreate creates a Docker context | [
"RunCreate",
"creates",
"a",
"Docker",
"context"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/context/create.go#L72-L88 |
159,679 | docker/cli | cli/command/container/rm.go | NewRmCommand | func NewRmCommand(dockerCli command.Cli) *cobra.Command {
var opts rmOptions
cmd := &cobra.Command{
Use: "rm [OPTIONS] CONTAINER [CONTAINER...]",
Short: "Remove one or more containers",
Args: cli.RequiresMinArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
opts.containers = args
return runRm(dockerCli, &opts)
},
}
flags := cmd.Flags()
flags.BoolVarP(&opts.rmVolumes, "volumes", "v", false, "Remove the volumes associated with the container")
flags.BoolVarP(&opts.rmLink, "link", "l", false, "Remove the specified link")
flags.BoolVarP(&opts.force, "force", "f", false, "Force the removal of a running container (uses SIGKILL)")
return cmd
} | go | func NewRmCommand(dockerCli command.Cli) *cobra.Command {
var opts rmOptions
cmd := &cobra.Command{
Use: "rm [OPTIONS] CONTAINER [CONTAINER...]",
Short: "Remove one or more containers",
Args: cli.RequiresMinArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
opts.containers = args
return runRm(dockerCli, &opts)
},
}
flags := cmd.Flags()
flags.BoolVarP(&opts.rmVolumes, "volumes", "v", false, "Remove the volumes associated with the container")
flags.BoolVarP(&opts.rmLink, "link", "l", false, "Remove the specified link")
flags.BoolVarP(&opts.force, "force", "f", false, "Force the removal of a running container (uses SIGKILL)")
return cmd
} | [
"func",
"NewRmCommand",
"(",
"dockerCli",
"command",
".",
"Cli",
")",
"*",
"cobra",
".",
"Command",
"{",
"var",
"opts",
"rmOptions",
"\n\n",
"cmd",
":=",
"&",
"cobra",
".",
"Command",
"{",
"Use",
":",
"\"",
"\"",
",",
"Short",
":",
"\"",
"\"",
",",
... | // NewRmCommand creates a new cobra.Command for `docker rm` | [
"NewRmCommand",
"creates",
"a",
"new",
"cobra",
".",
"Command",
"for",
"docker",
"rm"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/container/rm.go#L24-L42 |
159,680 | docker/cli | cli/command/service/list.go | GetServicesStatus | func GetServicesStatus(services []swarm.Service, nodes []swarm.Node, tasks []swarm.Task) map[string]ListInfo {
running := map[string]int{}
tasksNoShutdown := map[string]int{}
activeNodes := make(map[string]struct{})
for _, n := range nodes {
if n.Status.State != swarm.NodeStateDown {
activeNodes[n.ID] = struct{}{}
}
}
for _, task := range tasks {
if task.DesiredState != swarm.TaskStateShutdown {
tasksNoShutdown[task.ServiceID]++
}
if _, nodeActive := activeNodes[task.NodeID]; nodeActive && task.Status.State == swarm.TaskStateRunning {
running[task.ServiceID]++
}
}
info := map[string]ListInfo{}
for _, service := range services {
info[service.ID] = ListInfo{}
if service.Spec.Mode.Replicated != nil && service.Spec.Mode.Replicated.Replicas != nil {
if service.Spec.TaskTemplate.Placement != nil && service.Spec.TaskTemplate.Placement.MaxReplicas > 0 {
info[service.ID] = ListInfo{
Mode: "replicated",
Replicas: fmt.Sprintf("%d/%d (max %d per node)", running[service.ID], *service.Spec.Mode.Replicated.Replicas, service.Spec.TaskTemplate.Placement.MaxReplicas),
}
} else {
info[service.ID] = ListInfo{
Mode: "replicated",
Replicas: fmt.Sprintf("%d/%d", running[service.ID], *service.Spec.Mode.Replicated.Replicas),
}
}
} else if service.Spec.Mode.Global != nil {
info[service.ID] = ListInfo{
Mode: "global",
Replicas: fmt.Sprintf("%d/%d", running[service.ID], tasksNoShutdown[service.ID]),
}
}
}
return info
} | go | func GetServicesStatus(services []swarm.Service, nodes []swarm.Node, tasks []swarm.Task) map[string]ListInfo {
running := map[string]int{}
tasksNoShutdown := map[string]int{}
activeNodes := make(map[string]struct{})
for _, n := range nodes {
if n.Status.State != swarm.NodeStateDown {
activeNodes[n.ID] = struct{}{}
}
}
for _, task := range tasks {
if task.DesiredState != swarm.TaskStateShutdown {
tasksNoShutdown[task.ServiceID]++
}
if _, nodeActive := activeNodes[task.NodeID]; nodeActive && task.Status.State == swarm.TaskStateRunning {
running[task.ServiceID]++
}
}
info := map[string]ListInfo{}
for _, service := range services {
info[service.ID] = ListInfo{}
if service.Spec.Mode.Replicated != nil && service.Spec.Mode.Replicated.Replicas != nil {
if service.Spec.TaskTemplate.Placement != nil && service.Spec.TaskTemplate.Placement.MaxReplicas > 0 {
info[service.ID] = ListInfo{
Mode: "replicated",
Replicas: fmt.Sprintf("%d/%d (max %d per node)", running[service.ID], *service.Spec.Mode.Replicated.Replicas, service.Spec.TaskTemplate.Placement.MaxReplicas),
}
} else {
info[service.ID] = ListInfo{
Mode: "replicated",
Replicas: fmt.Sprintf("%d/%d", running[service.ID], *service.Spec.Mode.Replicated.Replicas),
}
}
} else if service.Spec.Mode.Global != nil {
info[service.ID] = ListInfo{
Mode: "global",
Replicas: fmt.Sprintf("%d/%d", running[service.ID], tasksNoShutdown[service.ID]),
}
}
}
return info
} | [
"func",
"GetServicesStatus",
"(",
"services",
"[",
"]",
"swarm",
".",
"Service",
",",
"nodes",
"[",
"]",
"swarm",
".",
"Node",
",",
"tasks",
"[",
"]",
"swarm",
".",
"Task",
")",
"map",
"[",
"string",
"]",
"ListInfo",
"{",
"running",
":=",
"map",
"[",... | // GetServicesStatus returns a map of mode and replicas | [
"GetServicesStatus",
"returns",
"a",
"map",
"of",
"mode",
"and",
"replicas"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/service/list.go#L98-L142 |
159,681 | docker/cli | cli-plugins/manager/error.go | MarshalText | func (e *pluginError) MarshalText() (text []byte, err error) {
return []byte(e.cause.Error()), nil
} | go | func (e *pluginError) MarshalText() (text []byte, err error) {
return []byte(e.cause.Error()), nil
} | [
"func",
"(",
"e",
"*",
"pluginError",
")",
"MarshalText",
"(",
")",
"(",
"text",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"return",
"[",
"]",
"byte",
"(",
"e",
".",
"cause",
".",
"Error",
"(",
")",
")",
",",
"nil",
"\n",
"}"
] | // MarshalText marshalls the pluginError into a textual form. | [
"MarshalText",
"marshalls",
"the",
"pluginError",
"into",
"a",
"textual",
"form",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli-plugins/manager/error.go#L29-L31 |
159,682 | docker/cli | cli-plugins/manager/error.go | wrapAsPluginError | func wrapAsPluginError(err error, msg string) error {
return &pluginError{cause: errors.Wrap(err, msg)}
} | go | func wrapAsPluginError(err error, msg string) error {
return &pluginError{cause: errors.Wrap(err, msg)}
} | [
"func",
"wrapAsPluginError",
"(",
"err",
"error",
",",
"msg",
"string",
")",
"error",
"{",
"return",
"&",
"pluginError",
"{",
"cause",
":",
"errors",
".",
"Wrap",
"(",
"err",
",",
"msg",
")",
"}",
"\n",
"}"
] | // wrapAsPluginError wraps an error in a pluginError with an
// additional message, analogous to errors.Wrapf. | [
"wrapAsPluginError",
"wraps",
"an",
"error",
"in",
"a",
"pluginError",
"with",
"an",
"additional",
"message",
"analogous",
"to",
"errors",
".",
"Wrapf",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli-plugins/manager/error.go#L35-L37 |
159,683 | docker/cli | cli-plugins/manager/error.go | NewPluginError | func NewPluginError(msg string, args ...interface{}) error {
return &pluginError{cause: errors.Errorf(msg, args...)}
} | go | func NewPluginError(msg string, args ...interface{}) error {
return &pluginError{cause: errors.Errorf(msg, args...)}
} | [
"func",
"NewPluginError",
"(",
"msg",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"&",
"pluginError",
"{",
"cause",
":",
"errors",
".",
"Errorf",
"(",
"msg",
",",
"args",
"...",
")",
"}",
"\n",
"}"
] | // NewPluginError creates a new pluginError, analogous to
// errors.Errorf. | [
"NewPluginError",
"creates",
"a",
"new",
"pluginError",
"analogous",
"to",
"errors",
".",
"Errorf",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli-plugins/manager/error.go#L41-L43 |
159,684 | docker/cli | cli/command/container/tty.go | resizeTtyTo | func resizeTtyTo(ctx context.Context, client client.ContainerAPIClient, id string, height, width uint, isExec bool) error {
if height == 0 && width == 0 {
return nil
}
options := types.ResizeOptions{
Height: height,
Width: width,
}
var err error
if isExec {
err = client.ContainerExecResize(ctx, id, options)
} else {
err = client.ContainerResize(ctx, id, options)
}
if err != nil {
logrus.Debugf("Error resize: %s\r", err)
}
return err
} | go | func resizeTtyTo(ctx context.Context, client client.ContainerAPIClient, id string, height, width uint, isExec bool) error {
if height == 0 && width == 0 {
return nil
}
options := types.ResizeOptions{
Height: height,
Width: width,
}
var err error
if isExec {
err = client.ContainerExecResize(ctx, id, options)
} else {
err = client.ContainerResize(ctx, id, options)
}
if err != nil {
logrus.Debugf("Error resize: %s\r", err)
}
return err
} | [
"func",
"resizeTtyTo",
"(",
"ctx",
"context",
".",
"Context",
",",
"client",
"client",
".",
"ContainerAPIClient",
",",
"id",
"string",
",",
"height",
",",
"width",
"uint",
",",
"isExec",
"bool",
")",
"error",
"{",
"if",
"height",
"==",
"0",
"&&",
"width"... | // resizeTtyTo resizes tty to specific height and width | [
"resizeTtyTo",
"resizes",
"tty",
"to",
"specific",
"height",
"and",
"width"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/container/tty.go#L19-L40 |
159,685 | docker/cli | cli/command/container/tty.go | resizeTty | func resizeTty(ctx context.Context, cli command.Cli, id string, isExec bool) error {
height, width := cli.Out().GetTtySize()
return resizeTtyTo(ctx, cli.Client(), id, height, width, isExec)
} | go | func resizeTty(ctx context.Context, cli command.Cli, id string, isExec bool) error {
height, width := cli.Out().GetTtySize()
return resizeTtyTo(ctx, cli.Client(), id, height, width, isExec)
} | [
"func",
"resizeTty",
"(",
"ctx",
"context",
".",
"Context",
",",
"cli",
"command",
".",
"Cli",
",",
"id",
"string",
",",
"isExec",
"bool",
")",
"error",
"{",
"height",
",",
"width",
":=",
"cli",
".",
"Out",
"(",
")",
".",
"GetTtySize",
"(",
")",
"\... | // resizeTty is to resize the tty with cli out's tty size | [
"resizeTty",
"is",
"to",
"resize",
"the",
"tty",
"with",
"cli",
"out",
"s",
"tty",
"size"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/container/tty.go#L43-L46 |
159,686 | docker/cli | cli/command/container/tty.go | initTtySize | func initTtySize(ctx context.Context, cli command.Cli, id string, isExec bool, resizeTtyFunc func(ctx context.Context, cli command.Cli, id string, isExec bool) error) {
rttyFunc := resizeTtyFunc
if rttyFunc == nil {
rttyFunc = resizeTty
}
if err := rttyFunc(ctx, cli, id, isExec); err != nil {
go func() {
var err error
for retry := 0; retry < 5; retry++ {
time.Sleep(10 * time.Millisecond)
if err = rttyFunc(ctx, cli, id, isExec); err == nil {
break
}
}
if err != nil {
fmt.Fprintln(cli.Err(), "failed to resize tty, using default size")
}
}()
}
} | go | func initTtySize(ctx context.Context, cli command.Cli, id string, isExec bool, resizeTtyFunc func(ctx context.Context, cli command.Cli, id string, isExec bool) error) {
rttyFunc := resizeTtyFunc
if rttyFunc == nil {
rttyFunc = resizeTty
}
if err := rttyFunc(ctx, cli, id, isExec); err != nil {
go func() {
var err error
for retry := 0; retry < 5; retry++ {
time.Sleep(10 * time.Millisecond)
if err = rttyFunc(ctx, cli, id, isExec); err == nil {
break
}
}
if err != nil {
fmt.Fprintln(cli.Err(), "failed to resize tty, using default size")
}
}()
}
} | [
"func",
"initTtySize",
"(",
"ctx",
"context",
".",
"Context",
",",
"cli",
"command",
".",
"Cli",
",",
"id",
"string",
",",
"isExec",
"bool",
",",
"resizeTtyFunc",
"func",
"(",
"ctx",
"context",
".",
"Context",
",",
"cli",
"command",
".",
"Cli",
",",
"i... | // initTtySize is to init the tty's size to the same as the window, if there is an error, it will retry 5 times. | [
"initTtySize",
"is",
"to",
"init",
"the",
"tty",
"s",
"size",
"to",
"the",
"same",
"as",
"the",
"window",
"if",
"there",
"is",
"an",
"error",
"it",
"will",
"retry",
"5",
"times",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/container/tty.go#L49-L68 |
159,687 | docker/cli | cli/command/container/tty.go | MonitorTtySize | func MonitorTtySize(ctx context.Context, cli command.Cli, id string, isExec bool) error {
initTtySize(ctx, cli, id, isExec, resizeTty)
if runtime.GOOS == "windows" {
go func() {
prevH, prevW := cli.Out().GetTtySize()
for {
time.Sleep(time.Millisecond * 250)
h, w := cli.Out().GetTtySize()
if prevW != w || prevH != h {
resizeTty(ctx, cli, id, isExec)
}
prevH = h
prevW = w
}
}()
} else {
sigchan := make(chan os.Signal, 1)
gosignal.Notify(sigchan, signal.SIGWINCH)
go func() {
for range sigchan {
resizeTty(ctx, cli, id, isExec)
}
}()
}
return nil
} | go | func MonitorTtySize(ctx context.Context, cli command.Cli, id string, isExec bool) error {
initTtySize(ctx, cli, id, isExec, resizeTty)
if runtime.GOOS == "windows" {
go func() {
prevH, prevW := cli.Out().GetTtySize()
for {
time.Sleep(time.Millisecond * 250)
h, w := cli.Out().GetTtySize()
if prevW != w || prevH != h {
resizeTty(ctx, cli, id, isExec)
}
prevH = h
prevW = w
}
}()
} else {
sigchan := make(chan os.Signal, 1)
gosignal.Notify(sigchan, signal.SIGWINCH)
go func() {
for range sigchan {
resizeTty(ctx, cli, id, isExec)
}
}()
}
return nil
} | [
"func",
"MonitorTtySize",
"(",
"ctx",
"context",
".",
"Context",
",",
"cli",
"command",
".",
"Cli",
",",
"id",
"string",
",",
"isExec",
"bool",
")",
"error",
"{",
"initTtySize",
"(",
"ctx",
",",
"cli",
",",
"id",
",",
"isExec",
",",
"resizeTty",
")",
... | // MonitorTtySize updates the container tty size when the terminal tty changes size | [
"MonitorTtySize",
"updates",
"the",
"container",
"tty",
"size",
"when",
"the",
"terminal",
"tty",
"changes",
"size"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/container/tty.go#L71-L97 |
159,688 | docker/cli | cli/command/container/tty.go | ForwardAllSignals | func ForwardAllSignals(ctx context.Context, cli command.Cli, cid string) chan os.Signal {
sigc := make(chan os.Signal, 128)
signal.CatchAll(sigc)
go func() {
for s := range sigc {
if s == signal.SIGCHLD || s == signal.SIGPIPE {
continue
}
var sig string
for sigStr, sigN := range signal.SignalMap {
if sigN == s {
sig = sigStr
break
}
}
if sig == "" {
fmt.Fprintf(cli.Err(), "Unsupported signal: %v. Discarding.\n", s)
continue
}
if err := cli.Client().ContainerKill(ctx, cid, sig); err != nil {
logrus.Debugf("Error sending signal: %s", err)
}
}
}()
return sigc
} | go | func ForwardAllSignals(ctx context.Context, cli command.Cli, cid string) chan os.Signal {
sigc := make(chan os.Signal, 128)
signal.CatchAll(sigc)
go func() {
for s := range sigc {
if s == signal.SIGCHLD || s == signal.SIGPIPE {
continue
}
var sig string
for sigStr, sigN := range signal.SignalMap {
if sigN == s {
sig = sigStr
break
}
}
if sig == "" {
fmt.Fprintf(cli.Err(), "Unsupported signal: %v. Discarding.\n", s)
continue
}
if err := cli.Client().ContainerKill(ctx, cid, sig); err != nil {
logrus.Debugf("Error sending signal: %s", err)
}
}
}()
return sigc
} | [
"func",
"ForwardAllSignals",
"(",
"ctx",
"context",
".",
"Context",
",",
"cli",
"command",
".",
"Cli",
",",
"cid",
"string",
")",
"chan",
"os",
".",
"Signal",
"{",
"sigc",
":=",
"make",
"(",
"chan",
"os",
".",
"Signal",
",",
"128",
")",
"\n",
"signal... | // ForwardAllSignals forwards signals to the container | [
"ForwardAllSignals",
"forwards",
"signals",
"to",
"the",
"container"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/container/tty.go#L100-L126 |
159,689 | docker/cli | cli/command/container/formatter_stats.go | GetError | func (cs *Stats) GetError() error {
cs.mutex.Lock()
defer cs.mutex.Unlock()
return cs.err
} | go | func (cs *Stats) GetError() error {
cs.mutex.Lock()
defer cs.mutex.Unlock()
return cs.err
} | [
"func",
"(",
"cs",
"*",
"Stats",
")",
"GetError",
"(",
")",
"error",
"{",
"cs",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"cs",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"return",
"cs",
".",
"err",
"\n",
"}"
] | // GetError returns the container statistics error.
// This is used to determine whether the statistics are valid or not | [
"GetError",
"returns",
"the",
"container",
"statistics",
"error",
".",
"This",
"is",
"used",
"to",
"determine",
"whether",
"the",
"statistics",
"are",
"valid",
"or",
"not"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/container/formatter_stats.go#L53-L57 |
159,690 | docker/cli | cli/command/container/formatter_stats.go | SetErrorAndReset | func (cs *Stats) SetErrorAndReset(err error) {
cs.mutex.Lock()
defer cs.mutex.Unlock()
cs.CPUPercentage = 0
cs.Memory = 0
cs.MemoryPercentage = 0
cs.MemoryLimit = 0
cs.NetworkRx = 0
cs.NetworkTx = 0
cs.BlockRead = 0
cs.BlockWrite = 0
cs.PidsCurrent = 0
cs.err = err
cs.IsInvalid = true
} | go | func (cs *Stats) SetErrorAndReset(err error) {
cs.mutex.Lock()
defer cs.mutex.Unlock()
cs.CPUPercentage = 0
cs.Memory = 0
cs.MemoryPercentage = 0
cs.MemoryLimit = 0
cs.NetworkRx = 0
cs.NetworkTx = 0
cs.BlockRead = 0
cs.BlockWrite = 0
cs.PidsCurrent = 0
cs.err = err
cs.IsInvalid = true
} | [
"func",
"(",
"cs",
"*",
"Stats",
")",
"SetErrorAndReset",
"(",
"err",
"error",
")",
"{",
"cs",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"cs",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"cs",
".",
"CPUPercentage",
"=",
"0",
"\n",
"cs"... | // SetErrorAndReset zeroes all the container statistics and store the error.
// It is used when receiving time out error during statistics collecting to reduce lock overhead | [
"SetErrorAndReset",
"zeroes",
"all",
"the",
"container",
"statistics",
"and",
"store",
"the",
"error",
".",
"It",
"is",
"used",
"when",
"receiving",
"time",
"out",
"error",
"during",
"statistics",
"collecting",
"to",
"reduce",
"lock",
"overhead"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/container/formatter_stats.go#L61-L75 |
159,691 | docker/cli | cli/command/container/formatter_stats.go | SetError | func (cs *Stats) SetError(err error) {
cs.mutex.Lock()
defer cs.mutex.Unlock()
cs.err = err
if err != nil {
cs.IsInvalid = true
}
} | go | func (cs *Stats) SetError(err error) {
cs.mutex.Lock()
defer cs.mutex.Unlock()
cs.err = err
if err != nil {
cs.IsInvalid = true
}
} | [
"func",
"(",
"cs",
"*",
"Stats",
")",
"SetError",
"(",
"err",
"error",
")",
"{",
"cs",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"cs",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"cs",
".",
"err",
"=",
"err",
"\n",
"if",
"err",
"!=... | // SetError sets container statistics error | [
"SetError",
"sets",
"container",
"statistics",
"error"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/container/formatter_stats.go#L78-L85 |
159,692 | docker/cli | cli/command/container/formatter_stats.go | SetStatistics | func (cs *Stats) SetStatistics(s StatsEntry) {
cs.mutex.Lock()
defer cs.mutex.Unlock()
s.Container = cs.Container
cs.StatsEntry = s
} | go | func (cs *Stats) SetStatistics(s StatsEntry) {
cs.mutex.Lock()
defer cs.mutex.Unlock()
s.Container = cs.Container
cs.StatsEntry = s
} | [
"func",
"(",
"cs",
"*",
"Stats",
")",
"SetStatistics",
"(",
"s",
"StatsEntry",
")",
"{",
"cs",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"cs",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"s",
".",
"Container",
"=",
"cs",
".",
"Containe... | // SetStatistics set the container statistics | [
"SetStatistics",
"set",
"the",
"container",
"statistics"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/container/formatter_stats.go#L88-L93 |
159,693 | docker/cli | cli/command/container/formatter_stats.go | GetStatistics | func (cs *Stats) GetStatistics() StatsEntry {
cs.mutex.Lock()
defer cs.mutex.Unlock()
return cs.StatsEntry
} | go | func (cs *Stats) GetStatistics() StatsEntry {
cs.mutex.Lock()
defer cs.mutex.Unlock()
return cs.StatsEntry
} | [
"func",
"(",
"cs",
"*",
"Stats",
")",
"GetStatistics",
"(",
")",
"StatsEntry",
"{",
"cs",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"cs",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"return",
"cs",
".",
"StatsEntry",
"\n",
"}"
] | // GetStatistics returns container statistics with other meta data such as the container name | [
"GetStatistics",
"returns",
"container",
"statistics",
"with",
"other",
"meta",
"data",
"such",
"as",
"the",
"container",
"name"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/container/formatter_stats.go#L96-L100 |
159,694 | docker/cli | cli/command/container/formatter_stats.go | NewStatsFormat | func NewStatsFormat(source, osType string) formatter.Format {
if source == formatter.TableFormatKey {
if osType == winOSType {
return formatter.Format(winDefaultStatsTableFormat)
}
return formatter.Format(defaultStatsTableFormat)
}
return formatter.Format(source)
} | go | func NewStatsFormat(source, osType string) formatter.Format {
if source == formatter.TableFormatKey {
if osType == winOSType {
return formatter.Format(winDefaultStatsTableFormat)
}
return formatter.Format(defaultStatsTableFormat)
}
return formatter.Format(source)
} | [
"func",
"NewStatsFormat",
"(",
"source",
",",
"osType",
"string",
")",
"formatter",
".",
"Format",
"{",
"if",
"source",
"==",
"formatter",
".",
"TableFormatKey",
"{",
"if",
"osType",
"==",
"winOSType",
"{",
"return",
"formatter",
".",
"Format",
"(",
"winDefa... | // NewStatsFormat returns a format for rendering an CStatsContext | [
"NewStatsFormat",
"returns",
"a",
"format",
"for",
"rendering",
"an",
"CStatsContext"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/container/formatter_stats.go#L103-L111 |
159,695 | docker/cli | cli/command/container/formatter_stats.go | statsFormatWrite | func statsFormatWrite(ctx formatter.Context, Stats []StatsEntry, osType string, trunc bool) error {
render := func(format func(subContext formatter.SubContext) error) error {
for _, cstats := range Stats {
statsCtx := &statsContext{
s: cstats,
os: osType,
trunc: trunc,
}
if err := format(statsCtx); err != nil {
return err
}
}
return nil
}
memUsage := memUseHeader
if osType == winOSType {
memUsage = winMemUseHeader
}
statsCtx := statsContext{}
statsCtx.Header = formatter.SubHeaderContext{
"Container": containerHeader,
"Name": formatter.NameHeader,
"ID": formatter.ContainerIDHeader,
"CPUPerc": cpuPercHeader,
"MemUsage": memUsage,
"MemPerc": memPercHeader,
"NetIO": netIOHeader,
"BlockIO": blockIOHeader,
"PIDs": pidsHeader,
}
statsCtx.os = osType
return ctx.Write(&statsCtx, render)
} | go | func statsFormatWrite(ctx formatter.Context, Stats []StatsEntry, osType string, trunc bool) error {
render := func(format func(subContext formatter.SubContext) error) error {
for _, cstats := range Stats {
statsCtx := &statsContext{
s: cstats,
os: osType,
trunc: trunc,
}
if err := format(statsCtx); err != nil {
return err
}
}
return nil
}
memUsage := memUseHeader
if osType == winOSType {
memUsage = winMemUseHeader
}
statsCtx := statsContext{}
statsCtx.Header = formatter.SubHeaderContext{
"Container": containerHeader,
"Name": formatter.NameHeader,
"ID": formatter.ContainerIDHeader,
"CPUPerc": cpuPercHeader,
"MemUsage": memUsage,
"MemPerc": memPercHeader,
"NetIO": netIOHeader,
"BlockIO": blockIOHeader,
"PIDs": pidsHeader,
}
statsCtx.os = osType
return ctx.Write(&statsCtx, render)
} | [
"func",
"statsFormatWrite",
"(",
"ctx",
"formatter",
".",
"Context",
",",
"Stats",
"[",
"]",
"StatsEntry",
",",
"osType",
"string",
",",
"trunc",
"bool",
")",
"error",
"{",
"render",
":=",
"func",
"(",
"format",
"func",
"(",
"subContext",
"formatter",
".",... | // statsFormatWrite renders the context for a list of containers statistics | [
"statsFormatWrite",
"renders",
"the",
"context",
"for",
"a",
"list",
"of",
"containers",
"statistics"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/container/formatter_stats.go#L119-L151 |
159,696 | docker/cli | cli/command/container/logs.go | NewLogsCommand | func NewLogsCommand(dockerCli command.Cli) *cobra.Command {
var opts logsOptions
cmd := &cobra.Command{
Use: "logs [OPTIONS] CONTAINER",
Short: "Fetch the logs of a container",
Args: cli.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
opts.container = args[0]
return runLogs(dockerCli, &opts)
},
}
flags := cmd.Flags()
flags.BoolVarP(&opts.follow, "follow", "f", false, "Follow log output")
flags.StringVar(&opts.since, "since", "", "Show logs since timestamp (e.g. 2013-01-02T13:23:37) or relative (e.g. 42m for 42 minutes)")
flags.StringVar(&opts.until, "until", "", "Show logs before a timestamp (e.g. 2013-01-02T13:23:37) or relative (e.g. 42m for 42 minutes)")
flags.SetAnnotation("until", "version", []string{"1.35"})
flags.BoolVarP(&opts.timestamps, "timestamps", "t", false, "Show timestamps")
flags.BoolVar(&opts.details, "details", false, "Show extra details provided to logs")
flags.StringVar(&opts.tail, "tail", "all", "Number of lines to show from the end of the logs")
return cmd
} | go | func NewLogsCommand(dockerCli command.Cli) *cobra.Command {
var opts logsOptions
cmd := &cobra.Command{
Use: "logs [OPTIONS] CONTAINER",
Short: "Fetch the logs of a container",
Args: cli.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
opts.container = args[0]
return runLogs(dockerCli, &opts)
},
}
flags := cmd.Flags()
flags.BoolVarP(&opts.follow, "follow", "f", false, "Follow log output")
flags.StringVar(&opts.since, "since", "", "Show logs since timestamp (e.g. 2013-01-02T13:23:37) or relative (e.g. 42m for 42 minutes)")
flags.StringVar(&opts.until, "until", "", "Show logs before a timestamp (e.g. 2013-01-02T13:23:37) or relative (e.g. 42m for 42 minutes)")
flags.SetAnnotation("until", "version", []string{"1.35"})
flags.BoolVarP(&opts.timestamps, "timestamps", "t", false, "Show timestamps")
flags.BoolVar(&opts.details, "details", false, "Show extra details provided to logs")
flags.StringVar(&opts.tail, "tail", "all", "Number of lines to show from the end of the logs")
return cmd
} | [
"func",
"NewLogsCommand",
"(",
"dockerCli",
"command",
".",
"Cli",
")",
"*",
"cobra",
".",
"Command",
"{",
"var",
"opts",
"logsOptions",
"\n\n",
"cmd",
":=",
"&",
"cobra",
".",
"Command",
"{",
"Use",
":",
"\"",
"\"",
",",
"Short",
":",
"\"",
"\"",
",... | // NewLogsCommand creates a new cobra.Command for `docker logs` | [
"NewLogsCommand",
"creates",
"a",
"new",
"cobra",
".",
"Command",
"for",
"docker",
"logs"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/container/logs.go#L26-L48 |
159,697 | docker/cli | internal/pkg/containerized/snapshot.go | WithNewSnapshot | func WithNewSnapshot(i containerd.Image) containerd.NewContainerOpts {
return func(ctx context.Context, client *containerd.Client, c *containers.Container) error {
if c.Snapshotter == "" {
c.Snapshotter = containerd.DefaultSnapshotter
}
r, err := create(ctx, client, i, c.ID, "")
if err != nil {
return err
}
c.SnapshotKey = r.Key
c.Image = i.Name()
return nil
}
} | go | func WithNewSnapshot(i containerd.Image) containerd.NewContainerOpts {
return func(ctx context.Context, client *containerd.Client, c *containers.Container) error {
if c.Snapshotter == "" {
c.Snapshotter = containerd.DefaultSnapshotter
}
r, err := create(ctx, client, i, c.ID, "")
if err != nil {
return err
}
c.SnapshotKey = r.Key
c.Image = i.Name()
return nil
}
} | [
"func",
"WithNewSnapshot",
"(",
"i",
"containerd",
".",
"Image",
")",
"containerd",
".",
"NewContainerOpts",
"{",
"return",
"func",
"(",
"ctx",
"context",
".",
"Context",
",",
"client",
"*",
"containerd",
".",
"Client",
",",
"c",
"*",
"containers",
".",
"C... | // WithNewSnapshot creates a new snapshot managed by containerized | [
"WithNewSnapshot",
"creates",
"a",
"new",
"snapshot",
"managed",
"by",
"containerized"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/internal/pkg/containerized/snapshot.go#L30-L43 |
159,698 | docker/cli | internal/pkg/containerized/snapshot.go | WithUpgrade | func WithUpgrade(i containerd.Image) containerd.UpdateContainerOpts {
return func(ctx context.Context, client *containerd.Client, c *containers.Container) error {
revision, err := save(ctx, client, i, c)
if err != nil {
return err
}
c.Image = i.Name()
c.SnapshotKey = revision.Key
return nil
}
} | go | func WithUpgrade(i containerd.Image) containerd.UpdateContainerOpts {
return func(ctx context.Context, client *containerd.Client, c *containers.Container) error {
revision, err := save(ctx, client, i, c)
if err != nil {
return err
}
c.Image = i.Name()
c.SnapshotKey = revision.Key
return nil
}
} | [
"func",
"WithUpgrade",
"(",
"i",
"containerd",
".",
"Image",
")",
"containerd",
".",
"UpdateContainerOpts",
"{",
"return",
"func",
"(",
"ctx",
"context",
".",
"Context",
",",
"client",
"*",
"containerd",
".",
"Client",
",",
"c",
"*",
"containers",
".",
"Co... | // WithUpgrade upgrades an existing container's image to a new one | [
"WithUpgrade",
"upgrades",
"an",
"existing",
"container",
"s",
"image",
"to",
"a",
"new",
"one"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/internal/pkg/containerized/snapshot.go#L46-L56 |
159,699 | docker/cli | internal/pkg/containerized/snapshot.go | WithRollback | func WithRollback(ctx context.Context, client *containerd.Client, c *containers.Container) error {
prev, err := previous(ctx, client, c)
if err != nil {
return err
}
ss := client.SnapshotService(c.Snapshotter)
sInfo, err := ss.Stat(ctx, prev.Key)
if err != nil {
return err
}
snapshotImage, ok := sInfo.Labels[imageLabel]
if !ok {
return fmt.Errorf("snapshot %s does not have a service image label", prev.Key)
}
if snapshotImage == "" {
return fmt.Errorf("snapshot %s has an empty service image label", prev.Key)
}
c.Image = snapshotImage
c.SnapshotKey = prev.Key
return nil
} | go | func WithRollback(ctx context.Context, client *containerd.Client, c *containers.Container) error {
prev, err := previous(ctx, client, c)
if err != nil {
return err
}
ss := client.SnapshotService(c.Snapshotter)
sInfo, err := ss.Stat(ctx, prev.Key)
if err != nil {
return err
}
snapshotImage, ok := sInfo.Labels[imageLabel]
if !ok {
return fmt.Errorf("snapshot %s does not have a service image label", prev.Key)
}
if snapshotImage == "" {
return fmt.Errorf("snapshot %s has an empty service image label", prev.Key)
}
c.Image = snapshotImage
c.SnapshotKey = prev.Key
return nil
} | [
"func",
"WithRollback",
"(",
"ctx",
"context",
".",
"Context",
",",
"client",
"*",
"containerd",
".",
"Client",
",",
"c",
"*",
"containers",
".",
"Container",
")",
"error",
"{",
"prev",
",",
"err",
":=",
"previous",
"(",
"ctx",
",",
"client",
",",
"c",... | // WithRollback rolls back to the previous container's revision | [
"WithRollback",
"rolls",
"back",
"to",
"the",
"previous",
"container",
"s",
"revision"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/internal/pkg/containerized/snapshot.go#L59-L79 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.