@@ -85,6 +85,7 @@ func (cl *configLoader) Load(log log.Logger) (*latest.Config, error) {
8585 var images map [string ]* latest.Image
8686 var deployments map [string ]* latest.DeploymentConfig
8787 var dev map [string ]* latest.DevPod
88+ var pipelines map [string ]* latest.Pipeline
8889 baseDir := filepath .Dir (cl .composePath )
8990
9091 if len (dockerCompose .Networks ) > 0 {
@@ -154,18 +155,24 @@ func (cl *configLoader) Load(log log.Logger) (*latest.Config, error) {
154155 return nil , err
155156 }
156157
157- // for secretName, secret := range dockerCompose.Secrets {
158- // createHook, err := createSecretHook(secretName, cwd, secret)
159- // if err != nil {
160- // return nil, err
161- // }
162- // hooks = append(hooks, createHook)
163- // hooks = append(hooks, deleteSecretHook(secretName))
164- // }
158+ for secretName , secret := range dockerCompose .Secrets {
159+ if pipelines == nil {
160+ pipelines = map [string ]* latest.Pipeline {}
161+ }
162+
163+ devSecretStep , err := createSecretPipeline (secretName , cwd , secret )
164+ if err != nil {
165+ return nil , err
166+ }
167+
168+ pipelines ["dev" ] = devSecretStep
169+ pipelines ["purge" ] = deleteSecretPipeline (secretName )
170+ }
165171
166172 config .Images = images
167173 config .Deployments = deployments
168174 config .Dev = dev
175+ config .Pipelines = pipelines
169176 // config.Hooks = hooks
170177
171178 return config , nil
@@ -322,38 +329,38 @@ func imageConfig(cwd string, service composetypes.ServiceConfig) (*latest.Image,
322329 return image , nil
323330}
324331
325- // func createSecretHook (name string, cwd string, secret composetypes.SecretConfig) (*latest.HookConfig , error) {
326- // file, err := filepath.Rel(cwd, filepath.Join(cwd, secret.File))
327- // if err != nil {
328- // return nil, err
329- // }
332+ func createSecretPipeline (name string , cwd string , secret composetypes.SecretConfig ) (* latest.Pipeline , error ) {
333+ file , err := filepath .Rel (cwd , filepath .Join (cwd , secret .File ))
334+ if err != nil {
335+ return nil , err
336+ }
330337
331- // return &latest.HookConfig {
332- // Events: []string{"before:deploy"},
333- // Command: fmt.Sprintf("kubectl create secret generic %s --namespace=${devspace.namespace} --dry-run=client --from-file=%s=%s -o yaml | kubectl apply -f -" , name, name, filepath.ToSlash(file)),
334- // }, nil
335- // }
338+ return & latest.Pipeline {
339+ Run : fmt . Sprintf ( `kubectl create secret generic %s --namespace=${devspace.namespace} --dry-run=client --from-file=%s=%s -o yaml | kubectl apply -f -
340+ run_default_pipeline dev` , name , name , filepath .ToSlash (file )),
341+ }, nil
342+ }
336343
337- // func deleteSecretHook (name string) *latest.HookConfig {
338- // return &latest.HookConfig {
339- // Events: []string{"after: purge"},
340- // Command: fmt.Sprintf(" kubectl delete secret %s --namespace=${devspace.namespace} --ignore-not-found" , name),
341- // }
342- // }
344+ func deleteSecretPipeline (name string ) * latest.Pipeline {
345+ return & latest.Pipeline {
346+ Run : fmt . Sprintf ( `run_default_pipeline purge
347+ kubectl delete secret %s --namespace=${devspace.namespace} --ignore-not-found` , name ),
348+ }
349+ }
343350
344351func (cl * configLoader ) deploymentConfig (service composetypes.ServiceConfig , composeVolumes map [string ]composetypes.VolumeConfig , log log.Logger ) (* latest.DeploymentConfig , error ) {
345352 values := map [string ]interface {}{}
346353
347- // volumes, volumeMounts, bindVolumeMounts := volumesConfig(service, composeVolumes, log)
348- // if len(volumes) > 0 {
349- // values["volumes"] = volumes
350- // }
354+ volumes , volumeMounts , _ := volumesConfig (service , composeVolumes , log )
355+ if len (volumes ) > 0 {
356+ values ["volumes" ] = volumes
357+ }
351358
352- // if hasLocalSync(service) {
353- // values["initContainers"] = []interface{}{initContainerConfig(service, bindVolumeMounts)}
354- // }
359+ // if hasLocalSync(service) {
360+ // values["initContainers"] = []interface{}{initContainerConfig(service, bindVolumeMounts)}
361+ // }
355362
356- container , err := containerConfig (service , [] interface {}{} )
363+ container , err := containerConfig (service , volumeMounts )
357364 if err != nil {
358365 return nil , err
359366 }
@@ -445,73 +452,72 @@ func (cl *configLoader) deploymentConfig(service composetypes.ServiceConfig, com
445452 }, nil
446453}
447454
448- // func volumesConfig(
449- // service composetypes.ServiceConfig,
450- // composeVolumes map[string]composetypes.VolumeConfig,
451- // log log.Logger,
452- // ) (volumes []interface{}, volumeMounts []interface{}, bindVolumeMounts []interface{}) {
453- // for _, secret := range service.Secrets {
454- // volume := createSecretVolume(secret)
455- // volumes = append(volumes, volume)
456-
457- // volumeMount := createSecretVolumeMount(secret)
458- // volumeMounts = append(volumeMounts, volumeMount)
459- // }
460-
461- // var volumeVolumes []composetypes.ServiceVolumeConfig
462- // var bindVolumes []composetypes.ServiceVolumeConfig
463- // var tmpfsVolumes []composetypes.ServiceVolumeConfig
464- // for _, serviceVolume := range service.Volumes {
465- // switch serviceVolume.Type {
466- // case composetypes.VolumeTypeBind:
467- // bindVolumes = append(bindVolumes, serviceVolume)
468- // case composetypes.VolumeTypeTmpfs:
469- // tmpfsVolumes = append(tmpfsVolumes, serviceVolume)
470- // case composetypes.VolumeTypeVolume:
471- // volumeVolumes = append(volumeVolumes, serviceVolume)
472- // default:
473- // log.Warnf("%s volumes are not supported", serviceVolume.Type)
474- // }
475- // }
476-
477- // volumeMap := map[string]interface{}{}
478- // for idx, volumeVolume := range volumeVolumes {
479- // volumeName := resolveServiceVolumeName(service, volumeVolume, idx+1)
480- // _, ok := volumeMap[volumeName]
481- // if !ok {
482- // volume := createVolume(volumeName, DefaultVolumeSize)
483- // volumes = append(volumes, volume)
484- // volumeMap[volumeName] = volume
485- // }
455+ func volumesConfig (
456+ service composetypes.ServiceConfig ,
457+ composeVolumes map [string ]composetypes.VolumeConfig ,
458+ log log.Logger ,
459+ ) (volumes []interface {}, volumeMounts []interface {}, bindVolumeMounts []interface {}) {
460+ for _ , secret := range service .Secrets {
461+ volume := createSecretVolume (secret )
462+ volumes = append (volumes , volume )
463+
464+ volumeMount := createSecretVolumeMount (secret )
465+ volumeMounts = append (volumeMounts , volumeMount )
466+ }
467+
468+ var volumeVolumes []composetypes.ServiceVolumeConfig
469+ var bindVolumes []composetypes.ServiceVolumeConfig
470+ var tmpfsVolumes []composetypes.ServiceVolumeConfig
471+ for _ , serviceVolume := range service .Volumes {
472+ switch serviceVolume .Type {
473+ case composetypes .VolumeTypeBind :
474+ bindVolumes = append (bindVolumes , serviceVolume )
475+ case composetypes .VolumeTypeTmpfs :
476+ tmpfsVolumes = append (tmpfsVolumes , serviceVolume )
477+ case composetypes .VolumeTypeVolume :
478+ volumeVolumes = append (volumeVolumes , serviceVolume )
479+ default :
480+ log .Warnf ("%s volumes are not supported" , serviceVolume .Type )
481+ }
482+ }
486483
487- // volumeMount := createServiceVolumeMount(volumeName, volumeVolume)
488- // volumeMounts = append(volumeMounts, volumeMount)
489- // }
484+ volumeMap := map [string ]interface {}{}
485+ for idx , volumeVolume := range volumeVolumes {
486+ volumeName := resolveServiceVolumeName (service , volumeVolume , idx + 1 )
487+ _ , ok := volumeMap [volumeName ]
488+ if ! ok {
489+ volume := createVolume (volumeName , DefaultVolumeSize )
490+ volumes = append (volumes , volume )
491+ volumeMap [volumeName ] = volume
492+ }
490493
491- // for _, tmpfsVolume := range tmpfsVolumes {
492- // volumeName := resolveServiceVolumeName(service, tmpfsVolume, len(volumes))
493- // volume := createEmptyDirVolume(volumeName, tmpfsVolume)
494- // volumes = append(volumes, volume)
494+ volumeMount := createServiceVolumeMount (volumeName , volumeVolume )
495+ volumeMounts = append (volumeMounts , volumeMount )
496+ }
495497
496- // volumeMount := createServiceVolumeMount(volumeName, tmpfsVolume)
497- // volumeMounts = append(volumeMounts, volumeMount)
498- // }
498+ for _ , tmpfsVolume := range tmpfsVolumes {
499+ volumeName := resolveServiceVolumeName (service , tmpfsVolume , len (volumes ))
500+ volume := createEmptyDirVolume (volumeName , tmpfsVolume )
501+ volumes = append (volumes , volume )
499502
500- // for idx, bindVolume := range bindVolumes {
501- // volumeName := fmt.Sprintf("volume-%d", idx+1)
502- // volume := createEmptyDirVolume(volumeName, bindVolume)
503- // volumes = append(volumes, volume)
503+ volumeMount := createServiceVolumeMount (volumeName , tmpfsVolume )
504+ volumeMounts = append (volumeMounts , volumeMount )
505+ }
504506
505- // volumeMount := createServiceVolumeMount(volumeName, bindVolume)
506- // volumeMounts = append(volumeMounts, volumeMount)
507+ for idx , bindVolume := range bindVolumes {
508+ volumeName := fmt .Sprintf ("volume-%d" , idx + 1 )
509+ volume := createEmptyDirVolume (volumeName , bindVolume )
510+ volumes = append (volumes , volume )
507511
508- // bindVolumeMount := createInitVolumeMount(volumeName, bindVolume)
509- // bindVolumeMounts = append(bindVolumeMounts, bindVolumeMount)
510- // }
512+ volumeMount := createServiceVolumeMount (volumeName , bindVolume )
513+ volumeMounts = append (volumeMounts , volumeMount )
511514
512- // return volumes, volumeMounts, bindVolumeMounts
515+ bindVolumeMount := createInitVolumeMount (volumeName , bindVolume )
516+ bindVolumeMounts = append (bindVolumeMounts , bindVolumeMount )
517+ }
513518
514- // }
519+ return volumes , volumeMounts , bindVolumeMounts
520+ }
515521
516522func containerConfig (service composetypes.ServiceConfig , volumeMounts []interface {}) (map [string ]interface {}, error ) {
517523 container := map [string ]interface {}{
@@ -620,68 +626,68 @@ func containerLivenessProbe(health *composetypes.HealthCheckConfig) (map[string]
620626 return livenessProbe , nil
621627}
622628
623- // func createEmptyDirVolume(volumeName string, volume composetypes.ServiceVolumeConfig) interface{} {
624- // // create an emptyDir volume
625- // emptyDir := map[string]interface{}{}
626- // if volume.Tmpfs != nil {
627- // emptyDir["sizeLimit"] = fmt.Sprintf("%d", volume.Tmpfs.Size)
628- // }
629- // return map[string]interface{}{
630- // "name": volumeName,
631- // "emptyDir": emptyDir,
632- // }
633- // }
629+ func createEmptyDirVolume (volumeName string , volume composetypes.ServiceVolumeConfig ) interface {} {
630+ // create an emptyDir volume
631+ emptyDir := map [string ]interface {}{}
632+ if volume .Tmpfs != nil {
633+ emptyDir ["sizeLimit" ] = fmt .Sprintf ("%d" , volume .Tmpfs .Size )
634+ }
635+ return map [string ]interface {}{
636+ "name" : volumeName ,
637+ "emptyDir" : emptyDir ,
638+ }
639+ }
634640
635- // func createSecretVolume(secret composetypes.ServiceSecretConfig) interface{} {
636- // return map[string]interface{}{
637- // "name": secret.Source,
638- // "secret": map[string]interface{}{
639- // "secretName": secret.Source,
640- // },
641- // }
642- // }
641+ func createSecretVolume (secret composetypes.ServiceSecretConfig ) interface {} {
642+ return map [string ]interface {}{
643+ "name" : secret .Source ,
644+ "secret" : map [string ]interface {}{
645+ "secretName" : secret .Source ,
646+ },
647+ }
648+ }
643649
644- // func createSecretVolumeMount(secret composetypes.ServiceSecretConfig) interface{} {
645- // target := secret.Source
646- // if secret.Target != "" {
647- // target = secret.Target
648- // }
649- // return map[string]interface{}{
650- // "containerPath": fmt.Sprintf("/run/secrets/%s", target),
651- // "volume": map[string]interface{}{
652- // "name": secret.Source,
653- // "subPath": target,
654- // "readOnly": true,
655- // },
656- // }
657- // }
650+ func createSecretVolumeMount (secret composetypes.ServiceSecretConfig ) interface {} {
651+ target := secret .Source
652+ if secret .Target != "" {
653+ target = secret .Target
654+ }
655+ return map [string ]interface {}{
656+ "containerPath" : fmt .Sprintf ("/run/secrets/%s" , target ),
657+ "volume" : map [string ]interface {}{
658+ "name" : secret .Source ,
659+ "subPath" : target ,
660+ "readOnly" : true ,
661+ },
662+ }
663+ }
658664
659- // func createServiceVolumeMount(volumeName string, volume composetypes.ServiceVolumeConfig) interface{} {
660- // return map[string]interface{}{
661- // "containerPath": volume.Target,
662- // "volume": map[string]interface{}{
663- // "name": volumeName,
664- // "readOnly": volume.ReadOnly,
665- // },
666- // }
667- // }
665+ func createServiceVolumeMount (volumeName string , volume composetypes.ServiceVolumeConfig ) interface {} {
666+ return map [string ]interface {}{
667+ "containerPath" : volume .Target ,
668+ "volume" : map [string ]interface {}{
669+ "name" : volumeName ,
670+ "readOnly" : volume .ReadOnly ,
671+ },
672+ }
673+ }
668674
669- // func createInitVolumeMount(volumeName string, volume composetypes.ServiceVolumeConfig) interface{} {
670- // return map[string]interface{}{
671- // "containerPath": volume.Target,
672- // "volume": map[string]interface{}{
673- // "name": volumeName,
674- // "readOnly": false,
675- // },
676- // }
677- // }
675+ func createInitVolumeMount (volumeName string , volume composetypes.ServiceVolumeConfig ) interface {} {
676+ return map [string ]interface {}{
677+ "containerPath" : volume .Target ,
678+ "volume" : map [string ]interface {}{
679+ "name" : volumeName ,
680+ "readOnly" : false ,
681+ },
682+ }
683+ }
678684
679- // func createVolume(name string, size string) interface{} {
680- // return map[string]interface{}{
681- // "name": name,
682- // "size": size,
683- // }
684- // }
685+ func createVolume (name string , size string ) interface {} {
686+ return map [string ]interface {}{
687+ "name" : name ,
688+ "size" : size ,
689+ }
690+ }
685691
686692func formatName (name string ) string {
687693 return regexp .MustCompile (`[\._]` ).ReplaceAllString (name , "-" )
@@ -724,13 +730,13 @@ func resolveImage(service composetypes.ServiceConfig) string {
724730// return localSubPath
725731// }
726732
727- // func resolveServiceVolumeName(service composetypes.ServiceConfig, volume composetypes.ServiceVolumeConfig, idx int) string {
728- // volumeName := volume.Source
729- // if volumeName == "" {
730- // volumeName = fmt.Sprintf("%s-%d", formatName(service.Name), idx)
731- // }
732- // return volumeName
733- // }
733+ func resolveServiceVolumeName (service composetypes.ServiceConfig , volume composetypes.ServiceVolumeConfig , idx int ) string {
734+ volumeName := volume .Source
735+ if volumeName == "" {
736+ volumeName = fmt .Sprintf ("%s-%d" , formatName (service .Name ), idx )
737+ }
738+ return volumeName
739+ }
734740
735741// func createWaitHook(service composetypes.ServiceConfig) *latest.HookConfig {
736742// serviceName := formatName(service.Name)
0 commit comments