mirror of
https://github.com/docker/compose.git
synced 2025-07-23 05:34:36 +02:00
Check external filesystems exist on compose up
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
be4b9a6812
commit
e903326e1a
@ -23,4 +23,6 @@ const (
|
|||||||
NetworkTag = "com.docker.compose.network"
|
NetworkTag = "com.docker.compose.network"
|
||||||
// ServiceTag allow to track resource related to a compose service
|
// ServiceTag allow to track resource related to a compose service
|
||||||
ServiceTag = "com.docker.compose.service"
|
ServiceTag = "com.docker.compose.service"
|
||||||
|
// VolumeTag allow to track resource related to a compose volume
|
||||||
|
VolumeTag = "com.docker.compose.volume"
|
||||||
)
|
)
|
||||||
|
@ -38,6 +38,7 @@ type awsResources struct {
|
|||||||
loadBalancer string
|
loadBalancer string
|
||||||
loadBalancerType string
|
loadBalancerType string
|
||||||
securityGroups map[string]string
|
securityGroups map[string]string
|
||||||
|
filesystems map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *awsResources) serviceSecurityGroups(service types.ServiceConfig) []string {
|
func (r *awsResources) serviceSecurityGroups(service types.ServiceConfig) []string {
|
||||||
@ -72,7 +73,7 @@ func (b *ecsAPIService) parse(ctx context.Context, project *types.Project) (awsR
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return r, err
|
return r, err
|
||||||
}
|
}
|
||||||
r.securityGroups, err = b.parseSecurityGroupExtension(ctx, project)
|
r.securityGroups, err = b.parseExternalNetworks(ctx, project)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return r, err
|
return r, err
|
||||||
}
|
}
|
||||||
@ -139,7 +140,7 @@ func (b *ecsAPIService) parseLoadBalancerExtension(ctx context.Context, project
|
|||||||
return "", "", nil
|
return "", "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *ecsAPIService) parseSecurityGroupExtension(ctx context.Context, project *types.Project) (map[string]string, error) {
|
func (b *ecsAPIService) parseExternalNetworks(ctx context.Context, project *types.Project) (map[string]string, error) {
|
||||||
securityGroups := make(map[string]string, len(project.Networks))
|
securityGroups := make(map[string]string, len(project.Networks))
|
||||||
for name, net := range project.Networks {
|
for name, net := range project.Networks {
|
||||||
if !net.External.External {
|
if !net.External.External {
|
||||||
@ -163,6 +164,25 @@ func (b *ecsAPIService) parseSecurityGroupExtension(ctx context.Context, project
|
|||||||
return securityGroups, nil
|
return securityGroups, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *ecsAPIService) parseExternalVolumes(ctx context.Context, project *types.Project) (map[string]string, error) {
|
||||||
|
filesystems := make(map[string]string, len(project.Volumes))
|
||||||
|
// project.Volumes.filter(|v| v.External.External).first(|v| b.SDK.FileSystemExists(ctx, vol.Name))?
|
||||||
|
for name, vol := range project.Volumes {
|
||||||
|
if !vol.External.External {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
exists, err := b.SDK.FileSystemExists(ctx, vol.Name)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if !exists {
|
||||||
|
return nil, fmt.Errorf("EFS file system %s doesn't exist", vol.Name)
|
||||||
|
}
|
||||||
|
filesystems[name] = vol.Name
|
||||||
|
}
|
||||||
|
return filesystems, nil
|
||||||
|
}
|
||||||
|
|
||||||
// ensureResources create required resources in template if not yet defined
|
// ensureResources create required resources in template if not yet defined
|
||||||
func (b *ecsAPIService) ensureResources(resources *awsResources, project *types.Project, template *cloudformation.Template) {
|
func (b *ecsAPIService) ensureResources(resources *awsResources, project *types.Project, template *cloudformation.Template) {
|
||||||
b.ensureCluster(resources, project, template)
|
b.ensureCluster(resources, project, template)
|
||||||
@ -210,6 +230,12 @@ func (b *ecsAPIService) ensureNetworks(r *awsResources, project *types.Project,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *ecsAPIService) ensureVolumes(r *awsResources, project *types.Project, template *cloudformation.Template) {
|
||||||
|
if r.filesystems == nil {
|
||||||
|
r.filesystems = make(map[string]string, len(project.Volumes))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (b *ecsAPIService) ensureLoadBalancer(r *awsResources, project *types.Project, template *cloudformation.Template) {
|
func (b *ecsAPIService) ensureLoadBalancer(r *awsResources, project *types.Project, template *cloudformation.Template) {
|
||||||
if r.loadBalancer != "" {
|
if r.loadBalancer != "" {
|
||||||
return
|
return
|
||||||
|
32
ecs/sdk.go
32
ecs/sdk.go
@ -858,3 +858,35 @@ func (s sdk) DeleteAutoscalingGroup(ctx context.Context, arn string) error {
|
|||||||
})
|
})
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s sdk) FileSystemExists(ctx context.Context, id string) (bool, error) {
|
||||||
|
desc, err := s.EFS.DescribeFileSystemsWithContext(ctx, &efs.DescribeFileSystemsInput{
|
||||||
|
FileSystemId: aws.String(id),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
return len(desc.FileSystems) > 0, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s sdk) CreateFileSystem(ctx context.Context, name string) (string, error) {
|
||||||
|
res, err := s.EFS.CreateFileSystemWithContext(ctx, &efs.CreateFileSystemInput{
|
||||||
|
Tags: []*efs.Tag{
|
||||||
|
{
|
||||||
|
Key: aws.String(compose.VolumeTag),
|
||||||
|
Value: aws.String(name),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return aws.StringValue(res.FileSystemId), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s sdk) DeleteFileSystem(ctx context.Context, id string) error {
|
||||||
|
_, err := s.EFS.DeleteFileSystemWithContext(ctx, &efs.DeleteFileSystemInput{
|
||||||
|
FileSystemId: aws.String(id),
|
||||||
|
})
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user