mirror of https://github.com/docker/compose.git
create directory in container using `mkdir -p`
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
4bf2fe9fed
commit
852c9e80b4
|
@ -314,25 +314,50 @@ func (s *composeService) makeSyncFn(ctx context.Context, project *types.Project,
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return nil
|
return nil
|
||||||
case opt := <-needSync:
|
case opt := <-needSync:
|
||||||
if fi, statErr := os.Stat(opt.HostPath); statErr == nil && !fi.IsDir() {
|
service, err := project.GetService(opt.Service)
|
||||||
err := s.Copy(ctx, project.Name, api.CopyOptions{
|
if err != nil {
|
||||||
Source: opt.HostPath,
|
return err
|
||||||
Destination: fmt.Sprintf("%s:%s", opt.Service, opt.ContainerPath),
|
}
|
||||||
})
|
scale := 1
|
||||||
if err != nil {
|
if service.Deploy != nil && service.Deploy.Replicas != nil {
|
||||||
return err
|
scale = int(*service.Deploy.Replicas)
|
||||||
|
}
|
||||||
|
|
||||||
|
if fi, statErr := os.Stat(opt.HostPath); statErr == nil {
|
||||||
|
if fi.IsDir() {
|
||||||
|
for i := 1; i <= scale; i++ {
|
||||||
|
_, err := s.Exec(ctx, project.Name, api.RunOptions{
|
||||||
|
Service: opt.Service,
|
||||||
|
Command: []string{"mkdir", "-p", opt.ContainerPath},
|
||||||
|
Index: i,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
logrus.Warnf("failed to create %q from %s: %v", opt.ContainerPath, opt.Service, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fmt.Fprintf(s.stdinfo(), "%s created\n", opt.ContainerPath)
|
||||||
|
} else {
|
||||||
|
err := s.Copy(ctx, project.Name, api.CopyOptions{
|
||||||
|
Source: opt.HostPath,
|
||||||
|
Destination: fmt.Sprintf("%s:%s", opt.Service, opt.ContainerPath),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
fmt.Fprintf(s.stdinfo(), "%s updated\n", opt.ContainerPath)
|
||||||
}
|
}
|
||||||
fmt.Fprintf(s.stdinfo(), "%s updated\n", opt.ContainerPath)
|
|
||||||
} else if errors.Is(statErr, fs.ErrNotExist) {
|
} else if errors.Is(statErr, fs.ErrNotExist) {
|
||||||
_, err := s.Exec(ctx, project.Name, api.RunOptions{
|
for i := 1; i <= scale; i++ {
|
||||||
Service: opt.Service,
|
_, err := s.Exec(ctx, project.Name, api.RunOptions{
|
||||||
Command: []string{"rm", "-rf", opt.ContainerPath},
|
Service: opt.Service,
|
||||||
Index: 1,
|
Command: []string{"rm", "-rf", opt.ContainerPath},
|
||||||
})
|
Index: i,
|
||||||
if err != nil {
|
})
|
||||||
logrus.Warnf("failed to delete %q from %s: %v", opt.ContainerPath, opt.Service, err)
|
if err != nil {
|
||||||
|
logrus.Warnf("failed to delete %q from %s: %v", opt.ContainerPath, opt.Service, err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fmt.Fprintf(s.stdinfo(), "%s deleted from container\n", opt.ContainerPath)
|
fmt.Fprintf(s.stdinfo(), "%s deleted from service\n", opt.ContainerPath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue