@@ -122,26 +122,28 @@ func (s *composeService) postProcessProject(project *types.Project, options api.
122122 return nil , errors .New ("project name can't be empty. Use ProjectName option to set a valid name" )
123123 }
124124
125+ // When the target is a job, skip service-oriented processing (profiles, service selection)
126+ // and only select the job's service dependencies.
127+ if len (options .Services ) == 1 && project .Jobs != nil {
128+ if _ , ok := project .Jobs [options .Services [0 ]]; ok {
129+ s .addCustomLabels (project , options )
130+ project , err := project .WithSelectedJob (options .Services [0 ])
131+ if err != nil {
132+ return nil , err
133+ }
134+ if ! options .All {
135+ project = project .WithoutUnnecessaryResources ()
136+ }
137+ return project , nil
138+ }
139+ }
140+
125141 project , err := project .WithServicesEnabled (options .Services ... )
126142 if err != nil {
127143 return nil , err
128144 }
129145
130- // Add custom labels
131- for name , s := range project .Services {
132- s .CustomLabels = map [string ]string {
133- api .ProjectLabel : project .Name ,
134- api .ServiceLabel : name ,
135- api .VersionLabel : api .ComposeVersion ,
136- api .WorkingDirLabel : project .WorkingDir ,
137- api .ConfigFilesLabel : strings .Join (project .ComposeFiles , "," ),
138- api .OneoffLabel : "False" ,
139- }
140- if len (options .EnvFiles ) != 0 {
141- s .CustomLabels [api .EnvironmentFileLabel ] = strings .Join (options .EnvFiles , "," )
142- }
143- project .Services [name ] = s
144- }
146+ s .addCustomLabels (project , options )
145147
146148 project , err = project .WithSelectedServices (options .Services )
147149 if err != nil {
@@ -155,3 +157,20 @@ func (s *composeService) postProcessProject(project *types.Project, options api.
155157
156158 return project , nil
157159}
160+
161+ func (s * composeService ) addCustomLabels (project * types.Project , options api.ProjectLoadOptions ) {
162+ for name , svc := range project .Services {
163+ svc .CustomLabels = map [string ]string {
164+ api .ProjectLabel : project .Name ,
165+ api .ServiceLabel : name ,
166+ api .VersionLabel : api .ComposeVersion ,
167+ api .WorkingDirLabel : project .WorkingDir ,
168+ api .ConfigFilesLabel : strings .Join (project .ComposeFiles , "," ),
169+ api .OneoffLabel : "False" ,
170+ }
171+ if len (options .EnvFiles ) != 0 {
172+ svc .CustomLabels [api .EnvironmentFileLabel ] = strings .Join (options .EnvFiles , "," )
173+ }
174+ project .Services [name ] = svc
175+ }
176+ }
0 commit comments