volumes.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. Copyright 2020 Docker Compose CLI authors
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package ecs
  14. import (
  15. "fmt"
  16. "github.com/docker/compose-cli/api/compose"
  17. "github.com/awslabs/goformation/v4/cloudformation"
  18. "github.com/awslabs/goformation/v4/cloudformation/efs"
  19. "github.com/compose-spec/compose-go/types"
  20. )
  21. func (b *ecsAPIService) createNFSMountTarget(project *types.Project, resources awsResources, template *cloudformation.Template) {
  22. for volume := range project.Volumes {
  23. for _, subnet := range resources.subnets {
  24. name := fmt.Sprintf("%sNFSMountTargetOn%s", normalizeResourceName(volume), normalizeResourceName(subnet.ID()))
  25. template.Resources[name] = &efs.MountTarget{
  26. FileSystemId: resources.filesystems[volume].ID(),
  27. SecurityGroups: resources.allSecurityGroups(),
  28. SubnetId: subnet.ID(),
  29. }
  30. }
  31. }
  32. }
  33. func (b *ecsAPIService) mountTargets(volume string, resources awsResources) []string {
  34. var refs []string
  35. for _, subnet := range resources.subnets {
  36. refs = append(refs, fmt.Sprintf("%sNFSMountTargetOn%s", normalizeResourceName(volume), normalizeResourceName(subnet.ID())))
  37. }
  38. return refs
  39. }
  40. func (b *ecsAPIService) createAccessPoints(project *types.Project, r awsResources, template *cloudformation.Template) {
  41. for name, volume := range project.Volumes {
  42. n := fmt.Sprintf("%sAccessPoint", normalizeResourceName(name))
  43. uid := volume.DriverOpts["uid"]
  44. gid := volume.DriverOpts["gid"]
  45. permissions := volume.DriverOpts["permissions"]
  46. path := volume.DriverOpts["root_directory"]
  47. ap := efs.AccessPoint{
  48. AccessPointTags: []efs.AccessPoint_AccessPointTag{
  49. {
  50. Key: compose.ProjectTag,
  51. Value: project.Name,
  52. },
  53. {
  54. Key: compose.VolumeTag,
  55. Value: name,
  56. },
  57. {
  58. Key: "Name",
  59. Value: fmt.Sprintf("%s_%s", project.Name, name),
  60. },
  61. },
  62. FileSystemId: r.filesystems[name].ID(),
  63. }
  64. if uid != "" {
  65. ap.PosixUser = &efs.AccessPoint_PosixUser{
  66. Uid: uid,
  67. Gid: gid,
  68. }
  69. }
  70. if path != "" {
  71. root := efs.AccessPoint_RootDirectory{
  72. Path: path,
  73. }
  74. ap.RootDirectory = &root
  75. if uid != "" {
  76. root.CreationInfo = &efs.AccessPoint_CreationInfo{
  77. OwnerUid: uid,
  78. OwnerGid: gid,
  79. Permissions: permissions,
  80. }
  81. }
  82. }
  83. template.Resources[n] = &ap
  84. }
  85. }