@@ -22,13 +22,15 @@ import (
2222 "context"
2323 "fmt"
2424 "strconv"
25+ "strings"
2526 "time"
2627
2728 "github.com/compose-spec/compose-go/v2/types"
2829 "github.com/docker/docker/api/types/container"
2930)
3031
3132func (s * composeService ) injectSecrets (ctx context.Context , project * types.Project , service types.ServiceConfig , id string ) error {
33+ var ctrConfig * container.Config
3234 for _ , config := range service .Secrets {
3335 file := project .Secrets [config .Source ]
3436 if file .Environment == "" {
@@ -53,6 +55,25 @@ func (s *composeService) injectSecrets(ctx context.Context, project *types.Proje
5355 }
5456 content = env
5557 }
58+
59+ if config .UID == "" && config .GID == "" {
60+ if ctrConfig == nil {
61+ ctr , err := s .apiClient ().ContainerInspect (ctx , id )
62+ if err != nil {
63+ return err
64+ }
65+ ctrConfig = ctr .Config
66+ }
67+
68+ parts := strings .Split (ctrConfig .User , ":" )
69+ if len (parts ) > 0 {
70+ config .UID = parts [0 ]
71+ }
72+ if len (parts ) > 1 {
73+ config .GID = parts [1 ]
74+ }
75+ }
76+
5677 b , err := createTar (content , types .FileReferenceConfig (config ))
5778 if err != nil {
5879 return err
@@ -69,6 +90,7 @@ func (s *composeService) injectSecrets(ctx context.Context, project *types.Proje
6990}
7091
7192func (s * composeService ) injectConfigs (ctx context.Context , project * types.Project , service types.ServiceConfig , id string ) error {
93+ var ctrConfig * container.Config
7294 for _ , config := range service .Configs {
7395 file := project .Configs [config .Source ]
7496 content := file .Content
@@ -91,6 +113,24 @@ func (s *composeService) injectConfigs(ctx context.Context, project *types.Proje
91113 config .Target = "/" + config .Source
92114 }
93115
116+ if config .UID == "" && config .GID == "" {
117+ if ctrConfig == nil {
118+ ctr , err := s .apiClient ().ContainerInspect (ctx , id )
119+ if err != nil {
120+ return err
121+ }
122+ ctrConfig = ctr .Config
123+ }
124+
125+ parts := strings .Split (ctrConfig .User , ":" )
126+ if len (parts ) > 0 {
127+ config .UID = parts [0 ]
128+ }
129+ if len (parts ) > 1 {
130+ config .GID = parts [1 ]
131+ }
132+ }
133+
94134 b , err := createTar (content , types .FileReferenceConfig (config ))
95135 if err != nil {
96136 return err
0 commit comments