@@ -15,9 +15,8 @@ import (
1515 composetypes "github.com/compose-spec/compose-go/types"
1616 "github.com/loft-sh/devspace/pkg/devspace/config/constants"
1717 "github.com/loft-sh/devspace/pkg/devspace/config/versions/latest"
18- "github.com/loft-sh/devspace/pkg/devspace/deploy/deployer/helm"
1918 "github.com/loft-sh/devspace/pkg/util/log"
20- "gopkg.in/yaml.v2 "
19+ "gopkg.in/yaml.v3 "
2120 v1 "k8s.io/api/core/v1"
2221)
2322
@@ -81,7 +80,6 @@ func (cl *configLoader) Load(log log.Logger) (*latest.Config, error) {
8180 return nil , err
8281 }
8382
84- // var hooks []*latest.HookConfig
8583 var images map [string ]* latest.Image
8684 var deployments map [string ]* latest.DeploymentConfig
8785 var dev map [string ]* latest.DevPod
@@ -130,25 +128,6 @@ func (cl *configLoader) Load(log log.Logger) (*latest.Config, error) {
130128 dev [service .Name ] = devConfig
131129 }
132130
133- // bindVolumeHooks := []*latest.HookConfig{}
134- // for _, volume := range service.Volumes {
135- // if volume.Type == composetypes.VolumeTypeBind {
136- // bindVolumeHook := createUploadVolumeHook(service, volume)
137- // bindVolumeHooks = append(bindVolumeHooks, bindVolumeHook)
138- // }
139- // }
140-
141- // if len(bindVolumeHooks) > 0 {
142- // hooks = append(hooks, bindVolumeHooks...)
143- // hooks = append(hooks, createUploadDoneHook(service))
144- // }
145-
146- // _, isDependency := dependentsMap[service.Name]
147- // if isDependency {
148- // waitHook := createWaitHook(service)
149- // hooks = append(hooks, waitHook)
150- // }
151-
152131 return nil
153132 })
154133 if err != nil {
@@ -198,80 +177,64 @@ func addDevConfig(service composetypes.ServiceConfig, baseDir string, log log.Lo
198177 var dev * latest.DevPod
199178
200179 devPorts := []* latest.PortMapping {}
180+ for _ , port := range service .Ports {
181+ portMapping := & latest.PortMapping {}
201182
202- if len (service .Ports ) > 0 {
203- if dev == nil {
204- dev = & latest.DevPod {
205- LabelSelector : labelSelector (service .Name ),
206- Ports : []* latest.PortMapping {},
207- }
183+ if port .Published == 0 {
184+ log .Warnf ("Unassigned port ranges are not supported: %s" , port .Target )
185+ continue
208186 }
209- for _ , port := range service .Ports {
210- portMapping := & latest.PortMapping {}
211187
212- if port .Published == 0 {
213- log .Warnf ("Unassigned port ranges are not supported: %s" , port .Target )
214- continue
215- }
188+ if port .Published != port .Target {
189+ portMapping .Port = fmt .Sprint (port .Published ) + ":" + fmt .Sprint (port .Target )
190+ } else {
191+ portMapping .Port = fmt .Sprint (port .Published )
192+ }
216193
217- if port .Published != port .Target {
218- portMapping .Port = fmt .Sprint (port .Published ) + ":" + fmt .Sprint (port .Target )
219- } else {
220- portMapping .Port = fmt .Sprint (port .Published )
221- }
194+ if port .HostIP != "" {
195+ portMapping .BindAddress = port .HostIP
196+ }
222197
223- if port .HostIP != "" {
224- portMapping .BindAddress = port .HostIP
225- }
198+ devPorts = append (devPorts , portMapping )
199+ }
226200
227- devPorts = append (devPorts , portMapping )
228- }
201+ for _ , expose := range service .Expose {
202+ devPorts = append (devPorts , & latest.PortMapping {
203+ Port : expose ,
204+ })
229205 }
230206
231- if len (service .Expose ) > 0 {
232- if dev == nil {
233- dev = & latest.DevPod {
234- LabelSelector : labelSelector (service .Name ),
207+ syncConfigs := []* latest.SyncConfig {}
208+ for _ , volume := range service .Volumes {
209+ if volume .Type == composetypes .VolumeTypeBind {
210+ sync := & latest.SyncConfig {
211+ Path : strings .Join ([]string {resolveLocalPath (volume ), volume .Target }, ":" ),
212+ StartContainer : true ,
235213 }
236- }
237214
238- for _ , expose := range service .Expose {
239- devPorts = append (devPorts , & latest.PortMapping {
240- Port : expose ,
241- })
215+ _ , err := os .Stat (filepath .Join (baseDir , volume .Source , DockerIgnorePath ))
216+ if err == nil {
217+ sync .ExcludeFile = DockerIgnorePath
218+ }
219+
220+ syncConfigs = append (syncConfigs , sync )
242221 }
243222 }
244223
245- // devSync := dev.Sync
246- // if devSync == nil {
247- // devSync = []*latest.SyncConfig{}
248- // }
249-
250- // for _, volume := range service.Volumes {
251- // if volume.Type == composetypes.VolumeTypeBind {
252- // sync := &latest.SyncConfig{
253- // LabelSelector: labelSelector(service.Name),
254- // ContainerName: resolveContainerName(service),
255- // LocalSubPath: resolveLocalPath(volume),
256- // ContainerPath: volume.Target,
257- // }
258-
259- // _, err := os.Stat(filepath.Join(baseDir, volume.Source, DockerIgnorePath))
260- // if err == nil {
261- // sync.ExcludeFile = DockerIgnorePath
262- // }
263-
264- // devSync = append(devSync, sync)
265- // }
266- // }
224+ if len (devPorts ) > 0 || len (syncConfigs ) > 0 {
225+ dev = & latest.DevPod {
226+ LabelSelector : labelSelector (service .Name ),
227+ }
228+ }
267229
268230 if len (devPorts ) > 0 {
269231 dev .Ports = devPorts
270232 }
271233
272- // if len(devSync) > 0 {
273- // dev.Sync = devSync
274- // }
234+ if len (syncConfigs ) > 0 {
235+ dev .Sync = syncConfigs
236+ dev .Command = service .Entrypoint
237+ }
275238
276239 return dev , nil
277240}
@@ -356,10 +319,6 @@ func (cl *configLoader) deploymentConfig(service composetypes.ServiceConfig, com
356319 values ["volumes" ] = volumes
357320 }
358321
359- // if hasLocalSync(service) {
360- // values["initContainers"] = []interface{}{initContainerConfig(service, bindVolumeMounts)}
361- // }
362-
363322 container , err := containerConfig (service , volumeMounts )
364323 if err != nil {
365324 return nil , err
@@ -443,10 +402,6 @@ func (cl *configLoader) deploymentConfig(service composetypes.ServiceConfig, com
443402
444403 return & latest.DeploymentConfig {
445404 Helm : & latest.HelmConfig {
446- Chart : & latest.ChartConfig {
447- Name : helm .DevSpaceChartConfig .Name ,
448- RepoURL : helm .DevSpaceChartConfig .RepoURL ,
449- },
450405 Values : values ,
451406 },
452407 }, nil
@@ -491,7 +446,7 @@ func volumesConfig(
491446 volumeMap [volumeName ] = volume
492447 }
493448
494- volumeMount := createServiceVolumeMount (volumeName , volumeVolume )
449+ volumeMount := createSharedVolumeMount (volumeName , volumeVolume )
495450 volumeMounts = append (volumeMounts , volumeMount )
496451 }
497452
@@ -662,6 +617,22 @@ func createSecretVolumeMount(secret composetypes.ServiceSecretConfig) interface{
662617 }
663618}
664619
620+ func createSharedVolumeMount (volumeName string , volume composetypes.ServiceVolumeConfig ) interface {} {
621+ volumeConfig := map [string ]interface {}{
622+ "name" : volumeName ,
623+ "shared" : true ,
624+ }
625+
626+ if volume .ReadOnly {
627+ volumeConfig ["readOnly" ] = true
628+ }
629+
630+ return map [string ]interface {}{
631+ "containerPath" : volume .Target ,
632+ "volume" : volumeConfig ,
633+ }
634+ }
635+
665636func createServiceVolumeMount (volumeName string , volume composetypes.ServiceVolumeConfig ) interface {} {
666637 return map [string ]interface {}{
667638 "containerPath" : volume .Target ,
@@ -693,19 +664,6 @@ func formatName(name string) string {
693664 return regexp .MustCompile (`[\._]` ).ReplaceAllString (name , "-" )
694665}
695666
696- // func initContainerConfig(service composetypes.ServiceConfig, volumeMounts []interface{}) map[string]interface{} {
697- // return map[string]interface{}{
698- // "name": UploadVolumesContainerName,
699- // "image": "alpine",
700- // "command": []interface{}{"sh"},
701- // "args": []interface{}{
702- // "-c",
703- // "while [ ! -f /tmp/done ]; do sleep 2; done",
704- // },
705- // "volumeMounts": volumeMounts,
706- // }
707- // }
708-
709667func resolveContainerName (service composetypes.ServiceConfig ) string {
710668 if service .ContainerName != "" {
711669 return formatName (service .ContainerName )
@@ -721,14 +679,14 @@ func resolveImage(service composetypes.ServiceConfig) string {
721679 return image
722680}
723681
724- // func resolveLocalPath(volume composetypes.ServiceVolumeConfig) string {
725- // localSubPath := volume.Source
682+ func resolveLocalPath (volume composetypes.ServiceVolumeConfig ) string {
683+ localSubPath := volume .Source
726684
727- // if strings.HasPrefix(localSubPath, "~") {
728- // localSubPath = fmt.Sprintf(`$!(echo "$HOME /%s") `, strings.TrimLeft(localSubPath, "~/"))
729- // }
730- // return localSubPath
731- // }
685+ if strings .HasPrefix (localSubPath , "~" ) {
686+ localSubPath = fmt .Sprintf (`${devspace.userHome} /%s` , strings .TrimLeft (localSubPath , "~/" ))
687+ }
688+ return localSubPath
689+ }
732690
733691func resolveServiceVolumeName (service composetypes.ServiceConfig , volume composetypes.ServiceVolumeConfig , idx int ) string {
734692 volumeName := volume .Source
@@ -738,48 +696,6 @@ func resolveServiceVolumeName(service composetypes.ServiceConfig, volume compose
738696 return volumeName
739697}
740698
741- // func createWaitHook(service composetypes.ServiceConfig) *latest.HookConfig {
742- // serviceName := formatName(service.Name)
743- // return &latest.HookConfig{
744- // Events: []string{fmt.Sprintf("after:deploy:%s", serviceName)},
745- // Container: &latest.HookContainer{
746- // LabelSelector: labelSelector(serviceName),
747- // ContainerName: resolveContainerName(service),
748- // },
749- // Wait: &latest.HookWaitConfig{
750- // Running: true,
751- // TerminatedWithCode: ptr.Int32(0),
752- // },
753- // }
754- // }
755-
756- // func createUploadVolumeHook(service composetypes.ServiceConfig, volume composetypes.ServiceVolumeConfig) *latest.HookConfig {
757- // serviceName := formatName(service.Name)
758- // return &latest.HookConfig{
759- // Events: []string{"after:deploy:" + serviceName},
760- // Upload: &latest.HookSyncConfig{
761- // LocalPath: resolveLocalPath(volume),
762- // ContainerPath: volume.Target,
763- // },
764- // Container: &latest.HookContainer{
765- // LabelSelector: labelSelector(service.Name),
766- // ContainerName: UploadVolumesContainerName,
767- // },
768- // }
769- // }
770-
771- // func createUploadDoneHook(service composetypes.ServiceConfig) *latest.HookConfig {
772- // serviceName := formatName(service.Name)
773- // return &latest.HookConfig{
774- // Events: []string{"after:deploy:" + serviceName},
775- // Command: "touch /tmp/done",
776- // Container: &latest.HookContainer{
777- // LabelSelector: labelSelector(service.Name),
778- // ContainerName: UploadVolumesContainerName,
779- // },
780- // }
781- // }
782-
783699// func calculateDependentsMap(dockerCompose *composetypes.Project) (map[string][]string, error) {
784700// tree := map[string][]string{}
785701// err := dockerCompose.WithServices(nil, func(service composetypes.ServiceConfig) error {
@@ -808,12 +724,3 @@ func labelSelector(serviceName string) map[string]string {
808724func hasBuild (service composetypes.ServiceConfig ) bool {
809725 return service .Build != nil
810726}
811-
812- // func hasLocalSync(service composetypes.ServiceConfig) bool {
813- // for _, volume := range service.Volumes {
814- // if volume.Type == composetypes.VolumeTypeBind {
815- // return true
816- // }
817- // }
818- // return false
819- // }
0 commit comments